yeah! it simulates the user activity! woo! awesome
[ozzloy@gmail.com/oble] / dbushello.c
CommitLineData
b8b01547 1#include <dbus/dbus.h>
2#include <dbus/dbus-glib.h>
3#include <stdlib.h>
4#include <stdio.h>
5
6 int
7main (int argc, char **argv)
8{
9 DBusGConnection *connection;
10 GError *error;
11 DBusGProxy *proxy;
12 char **name_list;
13 char **name_list_ptr;
14
15 g_type_init ();
16
17 error = NULL;
18 connection = dbus_g_bus_get (DBUS_BUS_SESSION,
19 &error);
20 if (connection == NULL)
21 {
22 g_printerr ("Failed to open connection to bus: %s\n",
23 error->message);
24 g_error_free (error);
25 exit (1);
26 }
27
28 /* Create a proxy object for the "bus driver" (name "org.freedesktop.DBus") */
29
30 proxy = dbus_g_proxy_new_for_name (connection,
31 DBUS_SERVICE_DBUS,
32 DBUS_PATH_DBUS,
33 DBUS_INTERFACE_DBUS);
34
35 /* Call ListNames method, wait for reply */
36 error = NULL;
37 if (!dbus_g_proxy_call (proxy, "ListNames", &error, G_TYPE_INVALID,
38 G_TYPE_STRV, &name_list, G_TYPE_INVALID))
39 {
40 /* Just do demonstrate remote exceptions versus regular GError */
41 if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION)
42 g_printerr ("Caught remote method exception %s: %s",
43 dbus_g_error_get_name (error),
44 error->message);
45 else
46 g_printerr ("Error: %s\n", error->message);
47 g_error_free (error);
48 exit (1);
49 }
50
51 /* Print the results */
52
53 g_print ("Names on the message bus:\n");
54
55 for (name_list_ptr = name_list; *name_list_ptr; name_list_ptr++)
56 {
57 g_print (" %s\n", *name_list_ptr);
58 }
59 g_strfreev (name_list);
60
61 g_object_unref (proxy);
62
63 return 0;
64}
65