revert between 56095 -> 55830 in arch
[AROS.git] / rom / dbus / test / dbus-ping-send.c
blobec1faca6ade4418c57fcde9a8b73e44a8a0f1294
1 #include <glib.h>
2 #include <dbus/dbus.h>
3 #include <dbus/dbus-glib.h>
5 static gboolean send_ping (DBusConnection *bus);
7 int
8 main (int argc, char **argv)
10 GMainLoop *loop;
11 DBusConnection *bus;
12 DBusError error;
14 /* Create a new event loop to run in */
15 loop = g_main_loop_new (NULL, FALSE);
17 /* Get a connection to the session bus */
18 dbus_error_init (&error);
19 bus = dbus_bus_get (DBUS_BUS_SESSION, &error);
20 if (!bus) {
21 g_warning ("Failed to connect to the D-BUS daemon: %s", error.message);
22 dbus_error_free (&error);
23 return 1;
26 /* Set up this connection to work in a GLib event loop */
27 dbus_connection_setup_with_g_main (bus, NULL);
28 /* Every second call send_ping() with the bus as an argument*/
29 g_timeout_add (1000, (GSourceFunc)send_ping, bus);
31 /* Start the event loop */
32 g_main_loop_run (loop);
33 return 0;
36 static gboolean
37 send_ping (DBusConnection *bus)
39 DBusMessage *message;
41 /* Create a new signal "Ping" on the "com.burtonini.dbus.Signal" interface,
42 * from the object "/com/burtonini/dbus/ping". */
43 message = dbus_message_new_signal ("/com/burtonini/dbus/ping",
44 "com.burtonini.dbus.Signal", "Ping");
45 /* Append the string "Ping!" to the signal */
46 dbus_message_append_args (message,
47 DBUS_TYPE_STRING, "Ping!",
48 DBUS_TYPE_INVALID);
49 /* Send the signal */
50 dbus_connection_send (bus, message, NULL);
51 /* Free the signal now we have finished with it */
52 dbus_message_unref (message);
53 /* Tell the user we send a signal */
54 g_print("Ping!\n");
55 /* Return TRUE to tell the event loop we want to be called again */
56 return TRUE;