00001 #include <dbus/dbus-glib.h>
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004
00005 static void lose (const char *fmt, ...) G_GNUC_NORETURN G_GNUC_PRINTF (1, 2);
00006 static void lose_gerror (const char *prefix, GError *error) G_GNUC_NORETURN;
00007
00008 static void
00009 lose (const char *str, ...)
00010 {
00011 va_list args;
00012
00013 va_start (args, str);
00014
00015 vfprintf (stderr, str, args);
00016 fputc ('\n', stderr);
00017
00018 va_end (args);
00019
00020 exit (1);
00021 }
00022
00023 static void
00024 lose_gerror (const char *prefix, GError *error)
00025 {
00026 lose ("%s: %s", prefix, error->message);
00027 }
00028
00029 static gboolean
00030 emit_signal (gpointer arg)
00031 {
00032 DBusGProxy *proxy = arg;
00033
00034 dbus_g_proxy_call_no_reply (proxy, "emitHelloSignal", G_TYPE_INVALID);
00035 return TRUE;
00036 }
00037
00038 static void
00039 hello_signal_handler (DBusGProxy *proxy, const char *hello_string, gpointer user_data)
00040 {
00041 printf ("Received signal and it says: %s\n", hello_string);
00042 }
00043
00044 int
00045 main (int argc, char **argv)
00046 {
00047 DBusGConnection *bus;
00048 DBusGProxy *remote_object;
00049 GError *error = NULL;
00050 GMainLoop *mainloop;
00051
00052 g_type_init ();
00053
00054 mainloop = g_main_loop_new (NULL, FALSE);
00055
00056 bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
00057 if (!bus)
00058 lose_gerror ("Couldn't connect to session bus", error);
00059
00060
00061
00062
00063 remote_object = dbus_g_proxy_new_for_name (bus,
00064 "org.designfu.TestService",
00065 "/org/designfu/TestService/object",
00066 "org.designfu.TestService");
00067 if (!remote_object)
00068 lose_gerror ("Failed to get name owner", error);
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 dbus_g_proxy_add_signal (remote_object, "HelloSignal", G_TYPE_STRING, G_TYPE_INVALID);
00088
00089
00090
00091
00092
00093 dbus_g_proxy_connect_signal (remote_object, "HelloSignal", G_CALLBACK (hello_signal_handler),
00094 NULL, NULL);
00095
00096
00097 g_timeout_add (2000, emit_signal, remote_object);
00098
00099 g_main_loop_run (mainloop);
00100
00101 exit (0);
00102 }