3 #include <dbus/dbus-glib.h>
5 static gboolean
send_ping (DBusConnection
*bus
);
8 main (int argc
, char **argv
)
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
);
21 g_warning ("Failed to connect to the D-BUS daemon: %s", error
.message
);
22 dbus_error_free (&error
);
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
);
37 send_ping (DBusConnection
*bus
)
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!",
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 */
55 /* Return TRUE to tell the event loop we want to be called again */