2003-09-30 02:43:21 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu" -*- */
|
|
|
|
|
#include "dbus-glib.h"
|
|
|
|
|
#include <stdio.h>
|
2003-10-12 05:59:39 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
2003-09-30 02:43:21 +00:00
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main (int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
DBusConnection *connection;
|
|
|
|
|
GMainLoop *loop;
|
2003-10-12 05:59:39 +00:00
|
|
|
GError *error;
|
|
|
|
|
DBusGProxy *driver;
|
|
|
|
|
DBusPendingCall *call;
|
|
|
|
|
char **service_list;
|
|
|
|
|
int service_list_len;
|
|
|
|
|
int i;
|
2003-09-30 02:43:21 +00:00
|
|
|
|
2003-10-12 05:59:39 +00:00
|
|
|
g_type_init ();
|
|
|
|
|
|
2003-09-30 02:43:21 +00:00
|
|
|
loop = g_main_loop_new (NULL, FALSE);
|
|
|
|
|
|
2003-10-12 05:59:39 +00:00
|
|
|
error = NULL;
|
|
|
|
|
connection = dbus_bus_get_with_g_main (DBUS_BUS_SESSION,
|
|
|
|
|
&error);
|
2003-09-30 02:43:21 +00:00
|
|
|
if (connection == NULL)
|
|
|
|
|
{
|
2003-10-12 05:59:39 +00:00
|
|
|
g_printerr ("Failed to open connection to bus: %s\n",
|
|
|
|
|
error->message);
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
exit (1);
|
2003-09-30 02:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
2003-10-12 05:59:39 +00:00
|
|
|
/* Create a proxy object for the "bus driver" */
|
|
|
|
|
|
|
|
|
|
driver = dbus_gproxy_new_for_service (connection,
|
|
|
|
|
DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
|
|
|
|
|
DBUS_PATH_ORG_FREEDESKTOP_DBUS,
|
|
|
|
|
DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS);
|
|
|
|
|
|
|
|
|
|
/* Call ListServices method */
|
|
|
|
|
|
|
|
|
|
call = dbus_gproxy_begin_call (driver, "ListServices", DBUS_TYPE_INVALID);
|
2003-09-30 02:43:21 +00:00
|
|
|
|
2003-10-12 05:59:39 +00:00
|
|
|
error = NULL;
|
|
|
|
|
if (!dbus_gproxy_end_call (driver, call, &error,
|
|
|
|
|
DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
|
|
|
|
|
&service_list, &service_list_len,
|
|
|
|
|
DBUS_TYPE_INVALID))
|
|
|
|
|
{
|
|
|
|
|
g_printerr ("Failed to complete ListServices call: %s\n",
|
|
|
|
|
error->message);
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
2003-09-30 02:43:21 +00:00
|
|
|
|
2003-10-12 05:59:39 +00:00
|
|
|
g_print ("Services on the message bus:\n");
|
|
|
|
|
i = 0;
|
|
|
|
|
while (i < service_list_len)
|
2003-09-30 02:43:21 +00:00
|
|
|
{
|
2003-10-12 05:59:39 +00:00
|
|
|
g_assert (service_list[i] != NULL);
|
|
|
|
|
g_print (" %s\n", service_list[i]);
|
|
|
|
|
++i;
|
2003-09-30 02:43:21 +00:00
|
|
|
}
|
2003-10-12 05:59:39 +00:00
|
|
|
g_assert (service_list[i] == NULL);
|
2003-09-30 02:43:21 +00:00
|
|
|
|
2003-10-12 05:59:39 +00:00
|
|
|
dbus_free_string_array (service_list);
|
|
|
|
|
|
|
|
|
|
g_object_unref (G_OBJECT (driver));
|
2003-09-30 02:43:21 +00:00
|
|
|
|
2003-10-12 05:59:39 +00:00
|
|
|
g_print ("Successfully completed %s\n", argv[0]);
|
2003-09-30 02:43:21 +00:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|