Nimjox
Nimjox

Reputation: 1381

How to list all object paths under a dbus service, in C with gio/glib?

A follow up to this question but I'd like to do it in C, not python, with glib-2.0/gio-2.0. I've really been having a hard time finding an example of this, in C, and the documentation is hard to read for a new comer as it's just a giant api list.

Upvotes: 2

Views: 1796

Answers (1)

lzmartinico
lzmartinico

Reputation: 159

For client-side DBus calls, you can use a GDbusProxy object in glib. Using org.freedesktop.DBus.Introspectable as in the original question:

int
main (int argc, char *argv[])
{
  GError *error;
  GDBusProxyFlags flags;
  GDBusProxy *proxy;
  gpointer data;

  loop = g_main_loop_new (NULL, FALSE);

  error = NULL;
  proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM
                                     flags,
                                     NULL, /* GDBusInterfaceInfo */
                                     name, /* your service name */
                                     object_path, /* your root object */
                                   "org.freedesktop.DBus.Introspectable",
                                     NULL, /* GCancellable */
                                     &error);
g_dbus_proxy_call(proxy,
                 "Introspect", NULL,
                  G_DBUS_CALL_FLAGS_NONE,
                 -1, NULL,
                  (GAsyncReadyCallback) some_callback,
                  &data);

Then you can define the function some_callback to handle the xml containing the objects.

Upvotes: 1

Related Questions