index.html
Main Page
|
modules.html
Modules
|
namespaces.html
Namespace List
|
hierarchy.html
Class Hierarchy
|
annotated.html
Data Structures
|
dirs.html
Directories
|
files.html
File List
|
namespacemembers.html
Namespace Members
|
functions.html
Data Fields
|
pages.html
Related Pages
dir_000005.html
glib
&raquo
dir_000006.html
examples
example-signal-recipient.c
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
struct__DBusGProxy.html
DBusGProxy
*proxy = arg;
00033
00034
group__DBusGLib.html#ga43
dbus_g_proxy_call_no_reply
(proxy,
"emitHelloSignal"
, G_TYPE_INVALID);
00035
return
group__DBusMacros.html#ga2
TRUE
;
00036 }
00037
00038
static
void
00039 hello_signal_handler (
struct__DBusGProxy.html
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
struct__DBusGProxy.html
DBusGProxy
*remote_object;
00049   GError *error =
group__DBusMacros.html#ga4
NULL
;
00050   GMainLoop *mainloop;
00051
00052   g_type_init ();
00053
00054   mainloop = g_main_loop_new (
group__DBusMacros.html#ga4
NULL
,
group__DBusMacros.html#ga3
FALSE
);
00055
00056   bus =
group__DBusGLib.html#ga16
dbus_g_bus_get
(DBUS_BUS_SESSION, &error);
00057
if
(!bus)
00058     lose_gerror (
"Couldn't connect to session bus"
, error);
00059
00060
/* We use _for_name_owner in order to track this particular service
00061
* instance, which lets us receive signals.
00062
*/
00063   remote_object =
group__DBusGLib.html#ga31
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
/* IMPORTANT:
00071
*
00072
* Note because this signal's signature is VOID__STRING, we do not
00073
* need to register a marshaller, since there is a builtin one.
00074
* However for other signatures, you must generate a marshaller,
00075
* then call dbus_g_object_register_marshaller.  It would look like
00076
* this:
00077
*
00078
* dbus_g_object_register_marshaller (g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_INVALID);
00079
*
00080
*/
00081
00082
/* Tell DBus what the type signature of the signal callback is; this
00083
* allows us to sanity-check incoming messages before invoking the
00084
* callback.  You need to do this once for each proxy you create,
00085
* not every time you want to connect to the signal.
00086
*/
00087
group__DBusGLib.html#ga47
dbus_g_proxy_add_signal
(remote_object,
"HelloSignal"
, G_TYPE_STRING, G_TYPE_INVALID);
00088
00089
/* Actually connect to the signal.  Note you can call
00090
* dbus_g_proxy_connect_signal multiple times for one invocation of
00091
* dbus_g_proxy_add_signal.
00092
*/
00093
group__DBusGLib.html#ga48
dbus_g_proxy_connect_signal
(remote_object,
"HelloSignal"
, G_CALLBACK (hello_signal_handler),
00094
group__DBusMacros.html#ga4
NULL
,
group__DBusMacros.html#ga4
NULL
);
00095
00096
00097   g_timeout_add (2000, emit_signal, remote_object);
00098
00099   g_main_loop_run (mainloop);
00100
00101   exit (0);
00102 }
Generated on Tue Sep 13 01:28:08 2005 for D-BUS by
http://www.doxygen.org/index.html
doxygen
1.4.4
