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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
#include <stdio.h>
#include "libnul.h"
#if 0
/* This may be a better way of doing it */
/* Better:
*
* nul_dbus_return
*/
static gboolean
on_do_stuff (nul_dbus_Context *context, int32_t birnan, uint32_t fish, gpointer data)
{
g_print ("do stuff called: ...");
x = g_strdup_printf ("asdf frasdf %d", fish);
nul_dbus_return (context, "Birnan was", x);
g_free (x);
return TRUE;
}
#endif
static gboolean
on_do_stuff (gpointer data,
int32_t birnan, uint32_t fish,
char **emfle, char **str)
{
g_print ("do stuff called: birnan: %d fish: %u\n", birnan, fish);
*emfle = g_strdup_printf ("Birnan was: %d", birnan);
*str = g_strdup_printf ("Fish was %u", fish);
return TRUE;
}
static gboolean
on_another_method (gpointer data, uint32_t x)
{
g_print ("another_method() called in (%s) with parameter %u\n", (char *)data, x);
return TRUE;
}
static void
load_image (gpointer data, const char *image, int *result)
{
g_print ("I should like load an image: %s\n", image);
*result = 87;
}
static nul_dbus_service_t *
make_service1 (void)
{
return nul_dbus_session_service (
"com.ssp.whatever",
nul_dbus_object (
"/com/ssp/whatever/birnan/emfle",
"object_info",
nul_dbus_interface (
"com.ssp.interface",
nul_dbus_method (
"do_stuff",
(nul_dbus_function_t)on_do_stuff,
nul_dbus_parameter_in ("birnan", nul_dbus_type_int32()),
nul_dbus_parameter_in ("fish", nul_dbus_type_uint32()),
nul_dbus_parameter_out ("emfle", nul_dbus_type_string()),
nul_dbus_parameter_out ("str", nul_dbus_type_string()),
NULL),
nul_dbus_method (
"another_method",
(nul_dbus_function_t)on_another_method,
nul_dbus_parameter_in ("n_times", nul_dbus_type_uint32()),
NULL),
NULL),
NULL),
NULL);
}
static nul_dbus_service_t *
make_service2 (gpointer data)
{
return nul_dbus_session_service (
"org.gnome.siv",
nul_dbus_object (
"/org/gnome/siv",
data,
nul_dbus_interface (
"org.gnome.siv",
nul_dbus_method (
"load_image",
(nul_dbus_function_t)load_image,
nul_dbus_parameter_in ("image", nul_dbus_type_string()),
nul_dbus_parameter_out ("result", nul_dbus_type_int32()),
NULL),
NULL),
NULL),
NULL);
}
static void
on_do_stuff_reply (const char *emfle, const char *str, const GError *err, gpointer data)
{
g_print ("do stuff reply: \"%s\", \"%s\"\n", emfle, str);
}
static void
on_reply (int result, const GError *err, nul_dbus_service_t *service)
{
if (!err)
g_print ("The result was %d\n", result);
else
g_print ("An error occurred\n");
nul_dbus_invoke (service,
"/com/ssp/whatever/birnan/emfle/com.ssp.interface.do_stuff",
(nul_dbus_function_t)on_do_stuff_reply, NULL,
100, 200);
}
nul_dbus_service_t *service;
nul_dbus_service_t *service2;
static gboolean
invokes (gpointer data)
{
int i;
printf ("idle\n");
for (i = 0; i < 3; ++i)
{
#if 0
nul_dbus_service_stop (service);
nul_dbus_service_start (service);
nul_dbus_service_stop (service);
nul_dbus_service_start (service);
#endif
nul_dbus_invoke (service2,
"/org/gnome/siv/org.gnome.siv.load_image",
(nul_dbus_function_t)on_reply, service,
"LOLCAT.PNG");
}
return FALSE;
}
int
main ()
{
GMainLoop *loop = g_main_loop_new (NULL, TRUE);
service = make_service1 ();
service2 = make_service2 ("hi");
if (!nul_dbus_service_start (service2))
{
g_print ("siv already exists, asking it to load the images instead\n");
}
if (!nul_dbus_service_start (service))
{
g_print ("Couldn't start the service\n");
}
g_idle_add (invokes, service2);
g_main_loop_run (loop);
return 0;
}
#if 0
void
bah()
{
nul_dbus_service_t *service = nul_dbus_session_service (
"org.gnome.ScreenSaver",
nul_dbus_object (
"/",
nul_dbus_interface (
"org.gnome.ScreenSaver",
nul_dbus_method (
"Throttle",
NULL, NULL,
nul_dbus_parameter_in ("application", nul_dbus_type_string()),
nul_dbus_parameter_in ("reason", nul_dbus_type_string()),
nul_dbus_parameter_out ("cookie", nul_dbus_type_uint32()),
NULL),
nul_dbus_signal (
"ActiveChanged",
nul_dbus_parameter_in ("new_value", nul_dbus_type_bool()),
NULL),
NULL),
NULL),
NULL);
nul_dbus_invoke (service, "/org.gnome.ScreenSaver.Throttle", reponse, NULL,
"MyApplication", "None of your business");
if (!nul_dbus_invoke_wait (service, "/org.gnome.ScreenSaver.Throttle", 1000, &err,
"MyApplication", "None of your business", &cookie))
{
g_print ("timeout\n");
}
nul_dbus_connect (service, "/org.gnome.ScreenSaver.ActiveChanged", on_active_changed, data);
}
#endif
|