1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
#include <dbus/dbus-glib.h>
#include <stdio.h>
#include <stdlib.h>
static void lose (const char *fmt, ...) G_GNUC_NORETURN G_GNUC_PRINTF (1, 2);
static void lose_gerror (const char *prefix, GError *error) G_GNUC_NORETURN;
static void
lose (const char *str, ...)
{
va_list args;
va_start (args, str);
vfprintf (stderr, str, args);
fputc ('\n', stderr);
va_end (args);
exit (1);
}
static void
lose_gerror (const char *prefix, GError *error)
{
lose ("%s: %s", prefix, error->message);
}
typedef struct TestObject TestObject;
typedef struct TestObjectClass TestObjectClass;
GType test_object_get_type (void);
struct TestObject
{
GObject parent;
};
struct TestObjectClass
{
GObjectClass parent;
};
enum
{
HELLO_SIGNAL,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
#define TEST_TYPE_OBJECT (test_object_get_type ())
#define TEST_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), TEST_TYPE_OBJECT, TestObject))
#define TEST_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TEST_TYPE_OBJECT, TestObjectClass))
#define TEST_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), TEST_TYPE_OBJECT))
#define TEST_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TEST_TYPE_OBJECT))
#define TEST_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TEST_TYPE_OBJECT, TestObjectClass))
G_DEFINE_TYPE(TestObject, test_object, G_TYPE_OBJECT)
gboolean test_object_emit_hello_signal (TestObject *obj, GError **error);
#include "example-signal-emitter-glue.h"
static void
test_object_init (TestObject *obj)
{
}
static void
test_object_class_init (TestObjectClass *klass)
{
signals[HELLO_SIGNAL] =
g_signal_new ("hello_signal",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
0,
NULL, NULL,
g_cclosure_marshal_VOID__STRING,
G_TYPE_NONE, 1, G_TYPE_STRING);
}
gboolean
test_object_emit_hello_signal (TestObject *obj, GError **error)
{
g_signal_emit (obj, signals[HELLO_SIGNAL], 0, "Hello");
return TRUE;
}
int
main (int argc, char **argv)
{
DBusGConnection *bus;
DBusGProxy *bus_proxy;
GError *error = NULL;
TestObject *obj;
GMainLoop *mainloop;
guint request_name_result;
g_type_init ();
mainloop = g_main_loop_new (NULL, FALSE);
bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (!bus)
lose_gerror ("Couldn't connect to session bus", error);
bus_proxy = dbus_g_proxy_new_for_name (bus, "org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus");
if (!dbus_g_proxy_call (bus_proxy, "RequestName", &error,
G_TYPE_STRING, "org.designfu.TestService",
G_TYPE_UINT, DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT,
G_TYPE_INVALID,
G_TYPE_UINT, &request_name_result,
G_TYPE_INVALID))
lose_gerror ("Failed to acquire org.designfu.TestService", error);
obj = g_object_new (TEST_TYPE_OBJECT, NULL);
dbus_g_object_type_install_info (TEST_TYPE_OBJECT, &dbus_glib_test_object_object_info);
dbus_g_connection_register_g_object (bus, "/org/designfu/TestService/object", G_OBJECT (obj));
printf ("test service running\n");
g_main_loop_run (mainloop);
exit (0);
}
|