C API D-Bus client

C.L. Hammond lappin at ag-networks.com
Mon Jun 6 13:52:58 PDT 2005


Hi,
I'm trying to create a simple D-Bus client to listen for messages and
print them out in a loop.

I am using the simple C API example found here
http://www.linuxjournal.com/article/7744 to send the messages.

However, I'm unsure about make a C API receiver.

I'm guessing the steps would be something similiar to the sender mentioned
above, which is :

1) connect to an existing bus

> DBusError error;
> DBusConnection *conn;
> dbus_error_init (&error);
> conn = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
> if (!conn) {
>     fprintf (stderr, "%s: %s\n",
>              err.name, err.message);
>     return 1;
> }

2) acquire a service

>  dbus_bus_acquire_service (conn, "org.pirate.parrot",
>                           0, &err);
> if (dbus_error_is_set (&err)) {
>     fprintf (stderr, "%s: %s\n",
>              err.name, err.message);
>     dbus_connection_disconnect (conn);
>     return;
> }


3) make a call to listen for a message.  The example mentioned above sends
a message at this point using : dbus_connection_send (conn, msg, NULL))
I'm guessing that I would want to call dbus_connection_pop_message here so
that I can receive a message.

Am I on the right track?  Does anyone have some example code that I can
take a look at for the C API?

thanks in advance
clh





More information about the dbus mailing list