1 /* -*- mode: C; c-file-style: "gnu" -*- */
8 main (int argc, char **argv)
10 DBusConnection *connection;
15 DBusPendingCall *call;
24 loop = g_main_loop_new (NULL, FALSE);
27 connection = dbus_bus_get_with_g_main (DBUS_BUS_SESSION,
29 if (connection == NULL)
31 g_printerr ("Failed to open connection to bus: %s\n",
37 /* Create a proxy object for the "bus driver" */
39 driver = dbus_gproxy_new_for_service (connection,
40 DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
41 DBUS_PATH_ORG_FREEDESKTOP_DBUS,
42 DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS);
44 /* Call ListServices method */
46 call = dbus_gproxy_begin_call (driver, "ListServices", DBUS_TYPE_INVALID);
49 if (!dbus_gproxy_end_call (driver, call, &error,
50 DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
51 &service_list, &service_list_len,
54 g_printerr ("Failed to complete ListServices call: %s\n",
60 g_print ("Services on the message bus:\n");
62 while (i < service_list_len)
64 g_assert (service_list[i] != NULL);
65 g_print (" %s\n", service_list[i]);
68 g_assert (service_list[i] == NULL);
70 dbus_free_string_array (service_list);
72 /* Test handling of unknown method */
73 call = dbus_gproxy_begin_call (driver, "ThisMethodDoesNotExist",
75 "blah blah blah blah blah",
81 if (dbus_gproxy_end_call (driver, call, &error,
84 g_printerr ("Calling nonexistent method succeeded!\n");
88 g_print ("Got EXPECTED error from calling unknown method: %s\n",
92 /* Activate a service */
93 call = dbus_gproxy_begin_call (driver, "ActivateService",
95 "org.freedesktop.DBus.TestSuiteEchoService",
101 if (!dbus_gproxy_end_call (driver, call, &error,
102 DBUS_TYPE_UINT32, &result,
105 g_printerr ("Failed to complete Activate call: %s\n",
107 g_error_free (error);
111 g_print ("Activation of echo service = 0x%x\n", result);
113 /* Activate a service again */
114 call = dbus_gproxy_begin_call (driver, "ActivateService",
116 "org.freedesktop.DBus.TestSuiteEchoService",
122 if (!dbus_gproxy_end_call (driver, call, &error,
123 DBUS_TYPE_UINT32, &result,
126 g_printerr ("Failed to complete Activate call: %s\n",
128 g_error_free (error);
132 g_print ("Duplicate activation of echo service = 0x%x\n", result);
134 /* Talk to the new service */
136 proxy = dbus_gproxy_new_for_service (connection,
137 "org.freedesktop.DBus.TestSuiteEchoService",
138 "/fixme/the/test/service/ignores/this", /* FIXME */
139 "org.freedesktop.TestSuite");
141 call = dbus_gproxy_begin_call (proxy, "Echo",
147 if (!dbus_gproxy_end_call (proxy, call, &error,
148 DBUS_TYPE_STRING, &str,
151 g_printerr ("Failed to complete Echo call: %s\n",
153 g_error_free (error);
157 g_print ("String echoed = \"%s\"\n", str);
160 g_object_unref (G_OBJECT (driver));
161 g_object_unref (G_OBJECT (proxy));
163 g_print ("Successfully completed %s\n", argv[0]);