dbus_pending_call_set_notify and threads management with the low-level C API

John (J5) Palmieri johnp at redhat.com
Mon Jul 17 09:01:35 PDT 2006


You need to actually read from the socket and dispatch.  Take a look at
the dbus_connection_read_write_dispatch API.

On Mon, 2006-07-17 at 13:39 +0200, cscm at meuh.dyndns.org wrote:
> Hi,
> 
> I'd like to make an asynchronous d-bus call with the low-level C API.
> I use the dbus_pending_call_set_notify function in order to setup my
> callback handler, but it's never called.
> 
> /* --- source code -- */
> DBusError err;
> DBusConnection* conn;
> DBusMessageIter iter;
> 
> dbus_error_init(&err);
> conn = dbus_bus_get(DBUS_BUS_SESSION, &err);
> 
> DBusMessage* msg;
> DBusPendingCall* pending = NULL;
> 
> msg = dbus_message_new_method_call(
>              "org.mozilla.TestService", "/",
>              "org.mozilla.TestInterface", "HelloAsync");
> 
> dbus_message_set_auto_start(msg, TRUE);
> dbus_connection_send_with_reply (conn, msg, &pending, -1);
> dbus_pending_call_set_notify(pending, callback, NULL, NULL);
> dbus_message_unref(msg);
> 
> while(42) {
>    printf("%d\n", dbus_pending_call_get_completed(pending));
>    sleep(1);
> }
> /* --- /source code -- */
> 
> My callback is defined like that:
> 
> /* --- callback -- */
> void callback(DBusPendingCall *pending, void *user_data) {
>     printf("Callback\n");
> }
> /* --- /callback -- */
> 
> My callback, is never called, so I've initialized the d-bus threads system
> with the gthreads library  (using the glib's dbus binding function table
> from the dbus-gthread.c file). (see the attached file for full source
> code).
> 
> Can someone give me pointers on threads and callback setup?
> 
> Best Regards,
> _______________________________________________ dbus mailing list dbus at lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/dbus
-- 



More information about the dbus mailing list