Merge lp:~cjdahlin/libnih/async into lp:libnih/1.0
- async
- Merge into trunk
Proposed by
Scott James Remnant (Canonical)
Status: | Merged |
---|---|
Merge reported by: | Scott James Remnant (Canonical) |
Merged at revision: | not available |
Proposed branch: | lp:~cjdahlin/libnih/async |
Merge into: | lp:libnih/1.0 |
Diff against target: |
4862 lines 3 files modified
ChangeLog (+28/-0) nih-dbus-tool/tests/test_com.netsplit.Nih.Test_proxy.c (+2162/-0) nih/nih_dbus_tool.py.OTHER (+2635/-0) |
To merge this branch: | bzr merge lp:~cjdahlin/libnih/async |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Scott James Remnant (Canonical) | Approve | ||
Review via email: mp+12818@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Scott James Remnant (Canonical) (canonical-scott) wrote : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'ChangeLog' | |||
2 | --- ChangeLog 2009-08-11 10:30:25 +0000 | |||
3 | +++ ChangeLog 2009-10-03 06:00:27 +0000 | |||
4 | @@ -1,3 +1,4 @@ | |||
5 | 1 | <<<<<<< TREE | ||
6 | 1 | 2009-08-11 Scott James Remnant <scott@netsplit.com> | 2 | 2009-08-11 Scott James Remnant <scott@netsplit.com> |
7 | 2 | 3 | ||
8 | 3 | * nih/test_alloc.h (TEST_ALLOC_NOT_PARENT): Add the opposite test | 4 | * nih/test_alloc.h (TEST_ALLOC_NOT_PARENT): Add the opposite test |
9 | @@ -2671,6 +2672,33 @@ | |||
10 | 2671 | Fix the test case to not compare a void * with strcmp | 2672 | Fix the test case to not compare a void * with strcmp |
11 | 2672 | 2673 | ||
12 | 2673 | 2008-01-29 Casey Dahlin <cdahlin@redhat.com> | 2674 | 2008-01-29 Casey Dahlin <cdahlin@redhat.com> |
13 | 2675 | ======= | ||
14 | 2676 | 2009-2-09 Casey Dahlin <cdahlin@redhat.com> | ||
15 | 2677 | |||
16 | 2678 | * nih/tests/test_com.netsplit.Nih.Test_proxy.c: Even more tests for | ||
17 | 2679 | async calls. | ||
18 | 2680 | |||
19 | 2681 | 2009-2-01 Casey Dahlin <cdahlin@redhat.com> | ||
20 | 2682 | |||
21 | 2683 | * nih/nih_dbus_tool.py (Method.asyncDispatchPrototype): Rename | ||
22 | 2684 | typedefs for callbacks from NihDBusCallback_foo_method to | ||
23 | 2685 | FooMethodCallback. Same for Errback. | ||
24 | 2686 | |||
25 | 2687 | * nih/nih_dbus_tool.py (Method.asyncDispatchFunction): Check for and | ||
26 | 2688 | properly handle error returns fron DBus. Also be sure to call the | ||
27 | 2689 | errback for various memory/parse errors. | ||
28 | 2690 | |||
29 | 2691 | * nih/nih_dbus_tool.py (Method.exportTypedefs): More changes for new | ||
30 | 2692 | typedef names. | ||
31 | 2693 | |||
32 | 2694 | * nih/nih_dbus_tool.py (camelate): New function to convert | ||
33 | 2695 | underscore_delineated to CamelCase. | ||
34 | 2696 | |||
35 | 2697 | * nih/tests/test_com.netsplit.Nih.Test_proxy.c: Loads more tests for | ||
36 | 2698 | async calls. | ||
37 | 2699 | |||
38 | 2700 | 2009-1-29 Casey Dahlin <cdahlin@redhat.com> | ||
39 | 2701 | >>>>>>> MERGE-SOURCE | ||
40 | 2674 | 2702 | ||
41 | 2675 | * nih/nih_dbus_tool.py (Method.asyncDispatchPrototype): Prototype for | 2703 | * nih/nih_dbus_tool.py (Method.asyncDispatchPrototype): Prototype for |
42 | 2676 | new asynchronous dispatch function, explained below. | 2704 | new asynchronous dispatch function, explained below. |
43 | 2677 | 2705 | ||
44 | === modified file 'nih-dbus-tool/tests/test_com.netsplit.Nih.Test_proxy.c' | |||
45 | --- nih-dbus-tool/tests/test_com.netsplit.Nih.Test_proxy.c 2009-08-03 15:29:45 +0000 | |||
46 | +++ nih-dbus-tool/tests/test_com.netsplit.Nih.Test_proxy.c 2009-10-03 06:00:27 +0000 | |||
47 | @@ -37,6 +37,7 @@ | |||
48 | 37 | #include <nih/signal.h> | 37 | #include <nih/signal.h> |
49 | 38 | #include <nih/main.h> | 38 | #include <nih/main.h> |
50 | 39 | #include <nih/error.h> | 39 | #include <nih/error.h> |
51 | 40 | <<<<<<< TREE | ||
52 | 40 | 41 | ||
53 | 41 | #include <nih-dbus/dbus_connection.h> | 42 | #include <nih-dbus/dbus_connection.h> |
54 | 42 | #include <nih-dbus/dbus_object.h> | 43 | #include <nih-dbus/dbus_object.h> |
55 | @@ -50204,6 +50205,2167 @@ | |||
56 | 50204 | TEST_DBUS_END (dbus_pid); | 50205 | TEST_DBUS_END (dbus_pid); |
57 | 50205 | 50206 | ||
58 | 50206 | dbus_shutdown (); | 50207 | dbus_shutdown (); |
59 | 50208 | ======= | ||
60 | 50209 | #include <nih/errors.h> | ||
61 | 50210 | |||
62 | 50211 | #include <nih/dbus.h> | ||
63 | 50212 | |||
64 | 50213 | #include "com.netsplit.Nih.Test_proxy.h" | ||
65 | 50214 | #include "com.netsplit.Nih.Test_impl.h" | ||
66 | 50215 | |||
67 | 50216 | |||
68 | 50217 | static void async_fail_errback (NihDBusProxy *my_proxy, void *userdata); | ||
69 | 50218 | |||
70 | 50219 | void | ||
71 | 50220 | test_method_dispatch (void) | ||
72 | 50221 | { | ||
73 | 50222 | DBusConnection *conn; | ||
74 | 50223 | NihDBusProxy *proxy; | ||
75 | 50224 | NihError *err; | ||
76 | 50225 | NihDBusError *dbus_err; | ||
77 | 50226 | char *output; | ||
78 | 50227 | uint8_t byte_arg; | ||
79 | 50228 | int boolean_arg; | ||
80 | 50229 | int16_t int16_arg; | ||
81 | 50230 | uint16_t uint16_arg; | ||
82 | 50231 | int32_t int32_arg; | ||
83 | 50232 | uint32_t uint32_arg; | ||
84 | 50233 | int64_t int64_arg; | ||
85 | 50234 | uint64_t uint64_arg; | ||
86 | 50235 | double double_arg; | ||
87 | 50236 | int32_t *int32_array; | ||
88 | 50237 | char **str_array; | ||
89 | 50238 | size_t array_len; | ||
90 | 50239 | int ret; | ||
91 | 50240 | int called; | ||
92 | 50241 | |||
93 | 50242 | TEST_GROUP ("method dispatching"); | ||
94 | 50243 | |||
95 | 50244 | |||
96 | 50245 | /* Check that we can make a D-Bus method call, passing in the | ||
97 | 50246 | * expected arguments and receiving the expected arguments in the | ||
98 | 50247 | * reply. | ||
99 | 50248 | */ | ||
100 | 50249 | TEST_FEATURE ("with valid argument"); | ||
101 | 50250 | conn = my_setup (); | ||
102 | 50251 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
103 | 50252 | |||
104 | 50253 | output = NULL; | ||
105 | 50254 | |||
106 | 50255 | ret = proxy_test_method (proxy, "test data", 0, &output); | ||
107 | 50256 | |||
108 | 50257 | TEST_EQ (ret, 0); | ||
109 | 50258 | |||
110 | 50259 | TEST_NE_P (output, NULL); | ||
111 | 50260 | TEST_ALLOC_PARENT (output, proxy); | ||
112 | 50261 | TEST_EQ_STR (output, "test data"); | ||
113 | 50262 | |||
114 | 50263 | nih_free (proxy); | ||
115 | 50264 | |||
116 | 50265 | my_teardown (conn); | ||
117 | 50266 | |||
118 | 50267 | |||
119 | 50268 | /* Check that we can make an asynchronous D-Bus method call, passing in | ||
120 | 50269 | * the expected arguments and receiving the expected arguments in the | ||
121 | 50270 | * callback. | ||
122 | 50271 | */ | ||
123 | 50272 | TEST_FEATURE ("with valid argument (async)"); | ||
124 | 50273 | conn = my_setup (); | ||
125 | 50274 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
126 | 50275 | |||
127 | 50276 | auto void async_with_valid_argument (NihDBusProxy *proxy, void *userdata, char *output); | ||
128 | 50277 | |||
129 | 50278 | called = 0; | ||
130 | 50279 | |||
131 | 50280 | ret = proxy_test_method_async (proxy, "test data", 0, | ||
132 | 50281 | async_with_valid_argument, async_fail_errback, "userdata"); | ||
133 | 50282 | |||
134 | 50283 | TEST_EQ (ret, 0); | ||
135 | 50284 | |||
136 | 50285 | void async_with_valid_argument (NihDBusProxy *my_proxy, void *userdata, char *async_output) | ||
137 | 50286 | { | ||
138 | 50287 | TEST_NE_P (async_output, NULL); | ||
139 | 50288 | TEST_ALLOC_PARENT (async_output, proxy); | ||
140 | 50289 | TEST_EQ_STR (async_output, "test data"); | ||
141 | 50290 | TEST_EQ_STR (userdata, "userdata"); | ||
142 | 50291 | TEST_EQ_P (my_proxy, proxy); | ||
143 | 50292 | called = 1; | ||
144 | 50293 | } | ||
145 | 50294 | |||
146 | 50295 | while (! called) | ||
147 | 50296 | dbus_connection_read_write_dispatch (conn, -1); | ||
148 | 50297 | |||
149 | 50298 | nih_free (proxy); | ||
150 | 50299 | |||
151 | 50300 | my_teardown (conn); | ||
152 | 50301 | |||
153 | 50302 | |||
154 | 50303 | /* Check that if the method call returns a D-Bus error, the async proxy | ||
155 | 50304 | * call triggers the error handler and sets the appropriate error. | ||
156 | 50305 | */ | ||
157 | 50306 | TEST_FEATURE ("with returned D-Bus error"); | ||
158 | 50307 | conn = my_setup (); | ||
159 | 50308 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
160 | 50309 | |||
161 | 50310 | output = NULL; | ||
162 | 50311 | |||
163 | 50312 | ret = proxy_test_method (proxy, "test data", 1, &output); | ||
164 | 50313 | |||
165 | 50314 | TEST_LT (ret, 1); | ||
166 | 50315 | |||
167 | 50316 | err = nih_error_get (); | ||
168 | 50317 | TEST_EQ (err->number, NIH_DBUS_ERROR); | ||
169 | 50318 | TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); | ||
170 | 50319 | |||
171 | 50320 | dbus_err = (NihDBusError *)err; | ||
172 | 50321 | TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.IllegalValue"); | ||
173 | 50322 | |||
174 | 50323 | nih_free (dbus_err); | ||
175 | 50324 | |||
176 | 50325 | nih_free (proxy); | ||
177 | 50326 | |||
178 | 50327 | my_teardown (conn); | ||
179 | 50328 | |||
180 | 50329 | |||
181 | 50330 | /* Check that if the method call returns a D-Bus error, the proxy | ||
182 | 50331 | * call returns a negative number and raises the same D-Bus error. | ||
183 | 50332 | */ | ||
184 | 50333 | TEST_FEATURE ("with returned D-Bus error (async)"); | ||
185 | 50334 | conn = my_setup (); | ||
186 | 50335 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
187 | 50336 | |||
188 | 50337 | output = NULL; | ||
189 | 50338 | |||
190 | 50339 | auto void async_with_dbus_error_errback (NihDBusProxy *proxy, void *userdata); | ||
191 | 50340 | |||
192 | 50341 | called = 0; | ||
193 | 50342 | |||
194 | 50343 | ret = proxy_test_method_async (proxy, "test data", 1, (ProxyTestMethodCallback)async_fail_errback, | ||
195 | 50344 | async_with_dbus_error_errback,"user data"); | ||
196 | 50345 | |||
197 | 50346 | TEST_EQ (ret, 0); | ||
198 | 50347 | |||
199 | 50348 | void async_with_dbus_error_errback (NihDBusProxy *my_proxy, void *userdata) | ||
200 | 50349 | { | ||
201 | 50350 | err = nih_error_get (); | ||
202 | 50351 | TEST_EQ (err->number, NIH_DBUS_ERROR); | ||
203 | 50352 | TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); | ||
204 | 50353 | |||
205 | 50354 | dbus_err = (NihDBusError *)err; | ||
206 | 50355 | TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.IllegalValue"); | ||
207 | 50356 | TEST_EQ_STR (userdata, "user data"); | ||
208 | 50357 | TEST_EQ_P (my_proxy, proxy); | ||
209 | 50358 | called = 1; | ||
210 | 50359 | } | ||
211 | 50360 | |||
212 | 50361 | while (! called) | ||
213 | 50362 | dbus_connection_read_write_dispatch (conn, -1); | ||
214 | 50363 | |||
215 | 50364 | nih_free (dbus_err); | ||
216 | 50365 | |||
217 | 50366 | nih_free (proxy); | ||
218 | 50367 | |||
219 | 50368 | my_teardown (conn); | ||
220 | 50369 | |||
221 | 50370 | |||
222 | 50371 | /* Check that in out of memory conditions, D-Bus automatically | ||
223 | 50372 | * repeats the method call so we don't notice on the client side. | ||
224 | 50373 | */ | ||
225 | 50374 | TEST_FEATURE ("with out of memory error"); | ||
226 | 50375 | conn = my_setup (); | ||
227 | 50376 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
228 | 50377 | |||
229 | 50378 | output = NULL; | ||
230 | 50379 | |||
231 | 50380 | ret = proxy_test_method (proxy, "test data", 2, &output); | ||
232 | 50381 | |||
233 | 50382 | TEST_EQ (ret, 0); | ||
234 | 50383 | |||
235 | 50384 | TEST_NE_P (output, NULL); | ||
236 | 50385 | TEST_ALLOC_PARENT (output, proxy); | ||
237 | 50386 | TEST_EQ_STR (output, "test data"); | ||
238 | 50387 | |||
239 | 50388 | nih_free (proxy); | ||
240 | 50389 | |||
241 | 50390 | my_teardown (conn); | ||
242 | 50391 | |||
243 | 50392 | |||
244 | 50393 | /* Check that in out of memory conditions, D-Bus automatically | ||
245 | 50394 | * repeats the method call so we don't notice on the client side, even | ||
246 | 50395 | * when the call is asynchronous. | ||
247 | 50396 | */ | ||
248 | 50397 | TEST_FEATURE ("with out of memory error (async)"); | ||
249 | 50398 | conn = my_setup (); | ||
250 | 50399 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
251 | 50400 | |||
252 | 50401 | auto void async_with_oom (NihDBusProxy *proxy, void *userdata, char *output); | ||
253 | 50402 | |||
254 | 50403 | called = 0; | ||
255 | 50404 | |||
256 | 50405 | ret = proxy_test_method_async (proxy, "test data", 2, | ||
257 | 50406 | async_with_valid_argument, async_fail_errback, "userdata"); | ||
258 | 50407 | |||
259 | 50408 | TEST_EQ (ret, 0); | ||
260 | 50409 | |||
261 | 50410 | void async_with_oom (NihDBusProxy *my_proxy, void *userdata, char *async_output) | ||
262 | 50411 | { | ||
263 | 50412 | TEST_NE_P (async_output, NULL); | ||
264 | 50413 | TEST_ALLOC_PARENT (async_output, proxy); | ||
265 | 50414 | TEST_EQ_STR (async_output, "test data"); | ||
266 | 50415 | TEST_EQ_STR (userdata, "userdata"); | ||
267 | 50416 | TEST_EQ_P (my_proxy, proxy); | ||
268 | 50417 | called = 1; | ||
269 | 50418 | } | ||
270 | 50419 | |||
271 | 50420 | while (! called) | ||
272 | 50421 | dbus_connection_read_write_dispatch (conn, -1); | ||
273 | 50422 | |||
274 | 50423 | nih_free (proxy); | ||
275 | 50424 | |||
276 | 50425 | my_teardown (conn); | ||
277 | 50426 | |||
278 | 50427 | |||
279 | 50428 | /* Check that an error unknown to D-Bus is turned into a generic | ||
280 | 50429 | * failed error. | ||
281 | 50430 | */ | ||
282 | 50431 | TEST_FEATURE ("with unknown error"); | ||
283 | 50432 | conn = my_setup (); | ||
284 | 50433 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
285 | 50434 | |||
286 | 50435 | output = NULL; | ||
287 | 50436 | |||
288 | 50437 | ret = proxy_test_method (proxy, "test data", 3, &output); | ||
289 | 50438 | |||
290 | 50439 | TEST_LT (ret, 1); | ||
291 | 50440 | |||
292 | 50441 | err = nih_error_get (); | ||
293 | 50442 | TEST_EQ (err->number, NIH_DBUS_ERROR); | ||
294 | 50443 | TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); | ||
295 | 50444 | |||
296 | 50445 | dbus_err = (NihDBusError *)err; | ||
297 | 50446 | TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); | ||
298 | 50447 | |||
299 | 50448 | nih_free (dbus_err); | ||
300 | 50449 | |||
301 | 50450 | nih_free (proxy); | ||
302 | 50451 | |||
303 | 50452 | my_teardown (conn); | ||
304 | 50453 | |||
305 | 50454 | |||
306 | 50455 | /* Check that an error unknown to D-Bus is turned into a generic | ||
307 | 50456 | * failed error for an async call. | ||
308 | 50457 | */ | ||
309 | 50458 | TEST_FEATURE ("with unknown error (async)"); | ||
310 | 50459 | conn = my_setup (); | ||
311 | 50460 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
312 | 50461 | |||
313 | 50462 | auto void async_with_unknown (NihDBusProxy *proxy, void *userdata); | ||
314 | 50463 | |||
315 | 50464 | called = 0; | ||
316 | 50465 | |||
317 | 50466 | ret = proxy_test_method_async (proxy, "test data", 3, | ||
318 | 50467 | (ProxyTestMethodCallback)async_fail_errback, async_with_unknown, "userdata"); | ||
319 | 50468 | |||
320 | 50469 | TEST_EQ (ret, 0); | ||
321 | 50470 | |||
322 | 50471 | void async_with_unknown (NihDBusProxy *my_proxy, void *userdata) | ||
323 | 50472 | { | ||
324 | 50473 | err = nih_error_get (); | ||
325 | 50474 | TEST_EQ (err->number, NIH_DBUS_ERROR); | ||
326 | 50475 | TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); | ||
327 | 50476 | |||
328 | 50477 | dbus_err = (NihDBusError *)err; | ||
329 | 50478 | TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); | ||
330 | 50479 | |||
331 | 50480 | nih_free (dbus_err); | ||
332 | 50481 | |||
333 | 50482 | TEST_EQ_STR (userdata, "userdata"); | ||
334 | 50483 | TEST_EQ_P (my_proxy, proxy); | ||
335 | 50484 | called = 1; | ||
336 | 50485 | } | ||
337 | 50486 | |||
338 | 50487 | while (! called) | ||
339 | 50488 | dbus_connection_read_write_dispatch (conn, -1); | ||
340 | 50489 | |||
341 | 50490 | nih_free (proxy); | ||
342 | 50491 | |||
343 | 50492 | my_teardown (conn); | ||
344 | 50493 | |||
345 | 50494 | |||
346 | 50495 | /* Check that the fact the server implementation is asynchronous | ||
347 | 50496 | * is hidden and the call blocks until the reply comes back anyway. | ||
348 | 50497 | */ | ||
349 | 50498 | TEST_FEATURE ("with valid argument to async call"); | ||
350 | 50499 | conn = my_setup (); | ||
351 | 50500 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
352 | 50501 | |||
353 | 50502 | output = NULL; | ||
354 | 50503 | |||
355 | 50504 | ret = proxy_test_async_method (proxy, "test data", 0, &output); | ||
356 | 50505 | |||
357 | 50506 | TEST_EQ (ret, 0); | ||
358 | 50507 | |||
359 | 50508 | TEST_NE_P (output, NULL); | ||
360 | 50509 | TEST_ALLOC_PARENT (output, proxy); | ||
361 | 50510 | TEST_EQ_STR (output, "test data"); | ||
362 | 50511 | |||
363 | 50512 | nih_free (proxy); | ||
364 | 50513 | |||
365 | 50514 | my_teardown (conn); | ||
366 | 50515 | |||
367 | 50516 | |||
368 | 50517 | /* Check that the fact the server implementation is asynchronous | ||
369 | 50518 | * doesn't affect asynchronous calls from us. | ||
370 | 50519 | */ | ||
371 | 50520 | TEST_FEATURE ("with valid argument to async call (async)"); | ||
372 | 50521 | conn = my_setup (); | ||
373 | 50522 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
374 | 50523 | |||
375 | 50524 | auto void async_with_async (NihDBusProxy *my_proxy, void *userdata, char *async_output); | ||
376 | 50525 | |||
377 | 50526 | called = 0; | ||
378 | 50527 | |||
379 | 50528 | ret = proxy_test_async_method_async (proxy, "test data", 0, | ||
380 | 50529 | async_with_async, async_fail_errback, "userdata"); | ||
381 | 50530 | |||
382 | 50531 | TEST_EQ (ret, 0); | ||
383 | 50532 | |||
384 | 50533 | void async_with_async (NihDBusProxy *my_proxy, void *userdata, char *async_output) | ||
385 | 50534 | { | ||
386 | 50535 | TEST_NE_P (async_output, NULL); | ||
387 | 50536 | TEST_ALLOC_PARENT (async_output, proxy); | ||
388 | 50537 | TEST_EQ_STR (async_output, "test data"); | ||
389 | 50538 | TEST_EQ_STR (userdata, "userdata"); | ||
390 | 50539 | TEST_EQ_P (my_proxy, proxy); | ||
391 | 50540 | called = 1; | ||
392 | 50541 | } | ||
393 | 50542 | |||
394 | 50543 | while (! called) | ||
395 | 50544 | dbus_connection_read_write_dispatch (conn, -1); | ||
396 | 50545 | |||
397 | 50546 | nih_free (proxy); | ||
398 | 50547 | |||
399 | 50548 | my_teardown (conn); | ||
400 | 50549 | |||
401 | 50550 | |||
402 | 50551 | /* Check that an error returned from an asynchronous server-side | ||
403 | 50552 | * call still comes back as an error. | ||
404 | 50553 | */ | ||
405 | 50554 | TEST_FEATURE ("with returned D-Bus error from async call"); | ||
406 | 50555 | conn = my_setup (); | ||
407 | 50556 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
408 | 50557 | |||
409 | 50558 | output = NULL; | ||
410 | 50559 | |||
411 | 50560 | ret = proxy_test_async_method (proxy, "test data", 1, &output); | ||
412 | 50561 | |||
413 | 50562 | TEST_LT (ret, 1); | ||
414 | 50563 | |||
415 | 50564 | err = nih_error_get (); | ||
416 | 50565 | TEST_EQ (err->number, NIH_DBUS_ERROR); | ||
417 | 50566 | TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); | ||
418 | 50567 | |||
419 | 50568 | dbus_err = (NihDBusError *)err; | ||
420 | 50569 | TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.IllegalValue"); | ||
421 | 50570 | |||
422 | 50571 | nih_free (dbus_err); | ||
423 | 50572 | |||
424 | 50573 | nih_free (proxy); | ||
425 | 50574 | |||
426 | 50575 | my_teardown (conn); | ||
427 | 50576 | |||
428 | 50577 | |||
429 | 50578 | /* Check that an error returned from an asynchronous server-side | ||
430 | 50579 | * call still comes back as an error to an async client call. | ||
431 | 50580 | */ | ||
432 | 50581 | TEST_FEATURE ("with returned D-Bus error from async call (async)"); | ||
433 | 50582 | conn = my_setup (); | ||
434 | 50583 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
435 | 50584 | |||
436 | 50585 | auto void async_with_async_err (NihDBusProxy *my_proxy, void *userdata); | ||
437 | 50586 | |||
438 | 50587 | called = 0; | ||
439 | 50588 | |||
440 | 50589 | ret = proxy_test_async_method_async (proxy, "test data", 1, | ||
441 | 50590 | (ProxyTestAsyncMethodCallback)async_fail_errback, async_with_async_err, "userdata"); | ||
442 | 50591 | |||
443 | 50592 | TEST_EQ (ret, 0); | ||
444 | 50593 | |||
445 | 50594 | void async_with_async_err (NihDBusProxy *my_proxy, void *userdata) | ||
446 | 50595 | { | ||
447 | 50596 | err = nih_error_get (); | ||
448 | 50597 | TEST_EQ (err->number, NIH_DBUS_ERROR); | ||
449 | 50598 | TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); | ||
450 | 50599 | |||
451 | 50600 | dbus_err = (NihDBusError *)err; | ||
452 | 50601 | TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.IllegalValue"); | ||
453 | 50602 | |||
454 | 50603 | nih_free (dbus_err); | ||
455 | 50604 | |||
456 | 50605 | TEST_EQ_STR (userdata, "userdata"); | ||
457 | 50606 | TEST_EQ_P (my_proxy, proxy); | ||
458 | 50607 | called = 1; | ||
459 | 50608 | } | ||
460 | 50609 | |||
461 | 50610 | while (! called) | ||
462 | 50611 | dbus_connection_read_write_dispatch (conn, -1); | ||
463 | 50612 | |||
464 | 50613 | nih_free (proxy); | ||
465 | 50614 | |||
466 | 50615 | my_teardown (conn); | ||
467 | 50616 | |||
468 | 50617 | |||
469 | 50618 | /* Check that in out of memory conditions, D-Bus automatically | ||
470 | 50619 | * repeats the method call so we don't notice on the client side | ||
471 | 50620 | * even for async server-side calls. | ||
472 | 50621 | */ | ||
473 | 50622 | TEST_FEATURE ("with out of memory error from async call"); | ||
474 | 50623 | conn = my_setup (); | ||
475 | 50624 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
476 | 50625 | |||
477 | 50626 | output = NULL; | ||
478 | 50627 | |||
479 | 50628 | ret = proxy_test_async_method (proxy, "test data", 2, &output); | ||
480 | 50629 | |||
481 | 50630 | TEST_EQ (ret, 0); | ||
482 | 50631 | |||
483 | 50632 | TEST_NE_P (output, NULL); | ||
484 | 50633 | TEST_ALLOC_PARENT (output, proxy); | ||
485 | 50634 | TEST_EQ_STR (output, "test data"); | ||
486 | 50635 | |||
487 | 50636 | nih_free (proxy); | ||
488 | 50637 | |||
489 | 50638 | my_teardown (conn); | ||
490 | 50639 | |||
491 | 50640 | |||
492 | 50641 | /* Check that in out of memory conditions, D-Bus automatically | ||
493 | 50642 | * repeats the method call so we don't notice on the client side | ||
494 | 50643 | * even for async server-side calls, when our call was async. | ||
495 | 50644 | */ | ||
496 | 50645 | TEST_FEATURE ("with out of memory error from async call (async)"); | ||
497 | 50646 | conn = my_setup (); | ||
498 | 50647 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
499 | 50648 | |||
500 | 50649 | auto void async_with_async_oom (NihDBusProxy *my_proxy, void *userdata, char *async_output); | ||
501 | 50650 | |||
502 | 50651 | called = 0; | ||
503 | 50652 | |||
504 | 50653 | ret = proxy_test_async_method_async (proxy, "test data", 2, | ||
505 | 50654 | async_with_async_oom, async_fail_errback, "userdata"); | ||
506 | 50655 | |||
507 | 50656 | TEST_EQ (ret, 0); | ||
508 | 50657 | |||
509 | 50658 | void async_with_async_oom (NihDBusProxy *my_proxy, void *userdata, char *async_output) | ||
510 | 50659 | { | ||
511 | 50660 | TEST_NE_P (async_output, NULL); | ||
512 | 50661 | TEST_ALLOC_PARENT (async_output, proxy); | ||
513 | 50662 | TEST_EQ_STR (async_output, "test data"); | ||
514 | 50663 | TEST_EQ_STR (userdata, "userdata"); | ||
515 | 50664 | TEST_EQ_P (my_proxy, proxy); | ||
516 | 50665 | called = 1; | ||
517 | 50666 | } | ||
518 | 50667 | |||
519 | 50668 | while (! called) | ||
520 | 50669 | dbus_connection_read_write_dispatch (conn, -1); | ||
521 | 50670 | |||
522 | 50671 | nih_free (proxy); | ||
523 | 50672 | |||
524 | 50673 | my_teardown (conn); | ||
525 | 50674 | |||
526 | 50675 | |||
527 | 50676 | /* Check that an error unknown to D-Bus is turned into a generic | ||
528 | 50677 | * failed error. | ||
529 | 50678 | */ | ||
530 | 50679 | TEST_FEATURE ("with unknown error from async call"); | ||
531 | 50680 | conn = my_setup (); | ||
532 | 50681 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
533 | 50682 | |||
534 | 50683 | output = NULL; | ||
535 | 50684 | |||
536 | 50685 | ret = proxy_test_async_method (proxy, "test data", 3, &output); | ||
537 | 50686 | |||
538 | 50687 | TEST_LT (ret, 1); | ||
539 | 50688 | |||
540 | 50689 | err = nih_error_get (); | ||
541 | 50690 | TEST_EQ (err->number, NIH_DBUS_ERROR); | ||
542 | 50691 | TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); | ||
543 | 50692 | |||
544 | 50693 | dbus_err = (NihDBusError *)err; | ||
545 | 50694 | TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); | ||
546 | 50695 | |||
547 | 50696 | nih_free (dbus_err); | ||
548 | 50697 | |||
549 | 50698 | nih_free (proxy); | ||
550 | 50699 | |||
551 | 50700 | my_teardown (conn); | ||
552 | 50701 | |||
553 | 50702 | |||
554 | 50703 | /* Check that an error unknown to D-Bus is turned into a generic | ||
555 | 50704 | * failed error for an async call. | ||
556 | 50705 | */ | ||
557 | 50706 | TEST_FEATURE ("with unknown error from async call (async)"); | ||
558 | 50707 | conn = my_setup (); | ||
559 | 50708 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
560 | 50709 | |||
561 | 50710 | auto void async_with_async_unknown (NihDBusProxy *my_proxy, void *userdata); | ||
562 | 50711 | |||
563 | 50712 | called = 0; | ||
564 | 50713 | |||
565 | 50714 | ret = proxy_test_async_method_async (proxy, "test data", 3, | ||
566 | 50715 | (ProxyTestAsyncMethodCallback)async_fail_errback, async_with_async_unknown, "userdata"); | ||
567 | 50716 | |||
568 | 50717 | TEST_EQ (ret, 0); | ||
569 | 50718 | |||
570 | 50719 | void async_with_async_unknown (NihDBusProxy *my_proxy, void *userdata) | ||
571 | 50720 | { | ||
572 | 50721 | err = nih_error_get (); | ||
573 | 50722 | TEST_EQ (err->number, NIH_DBUS_ERROR); | ||
574 | 50723 | TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); | ||
575 | 50724 | |||
576 | 50725 | dbus_err = (NihDBusError *)err; | ||
577 | 50726 | TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); | ||
578 | 50727 | |||
579 | 50728 | nih_free (dbus_err); | ||
580 | 50729 | |||
581 | 50730 | TEST_EQ_STR (userdata, "userdata"); | ||
582 | 50731 | TEST_EQ_P (my_proxy, proxy); | ||
583 | 50732 | called = 1; | ||
584 | 50733 | } | ||
585 | 50734 | |||
586 | 50735 | while (! called) | ||
587 | 50736 | dbus_connection_read_write_dispatch (conn, -1); | ||
588 | 50737 | |||
589 | 50738 | nih_free (proxy); | ||
590 | 50739 | |||
591 | 50740 | my_teardown (conn); | ||
592 | 50741 | |||
593 | 50742 | |||
594 | 50743 | /* Check that a condition whereby the wrong arguments are returned | ||
595 | 50744 | * from a method call results in a special illegal arguments error | ||
596 | 50745 | * being returned. | ||
597 | 50746 | */ | ||
598 | 50747 | TEST_FEATURE ("with wrong argument type in reply"); | ||
599 | 50748 | conn = my_setup (); | ||
600 | 50749 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
601 | 50750 | |||
602 | 50751 | output = NULL; | ||
603 | 50752 | |||
604 | 50753 | ret = proxy_test_async_method (proxy, "test data", 4, &output); | ||
605 | 50754 | |||
606 | 50755 | TEST_LT (ret, 1); | ||
607 | 50756 | |||
608 | 50757 | err = nih_error_get (); | ||
609 | 50758 | TEST_EQ (err->number, NIH_DBUS_INVALID_ARGS); | ||
610 | 50759 | nih_free (err); | ||
611 | 50760 | |||
612 | 50761 | nih_free (proxy); | ||
613 | 50762 | |||
614 | 50763 | my_teardown (conn); | ||
615 | 50764 | |||
616 | 50765 | |||
617 | 50766 | /* Check that a condition whereby the wrong arguments are returned | ||
618 | 50767 | * from a method call results in a special illegal arguments error | ||
619 | 50768 | * being passed to the errback. | ||
620 | 50769 | */ | ||
621 | 50770 | TEST_FEATURE ("with wrong argument type in reply (async)"); | ||
622 | 50771 | conn = my_setup (); | ||
623 | 50772 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
624 | 50773 | |||
625 | 50774 | auto void with_wrong_argument_type_in_reply_async (NihDBusProxy *my_proxy, void *userdata); | ||
626 | 50775 | |||
627 | 50776 | called = 0; | ||
628 | 50777 | |||
629 | 50778 | ret = proxy_test_async_method_async (proxy, "test data", 4, | ||
630 | 50779 | (ProxyTestAsyncMethodCallback)async_fail_errback, | ||
631 | 50780 | with_wrong_argument_type_in_reply_async, "userdata"); | ||
632 | 50781 | |||
633 | 50782 | TEST_EQ (ret, 0); | ||
634 | 50783 | |||
635 | 50784 | void with_wrong_argument_type_in_reply_async (NihDBusProxy *my_proxy, void *userdata) | ||
636 | 50785 | { | ||
637 | 50786 | err = nih_error_get (); | ||
638 | 50787 | TEST_EQ (err->number, NIH_DBUS_INVALID_ARGS); | ||
639 | 50788 | nih_free (err); | ||
640 | 50789 | TEST_EQ_STR (userdata, "userdata"); | ||
641 | 50790 | TEST_EQ_P (my_proxy, proxy); | ||
642 | 50791 | called = 1; | ||
643 | 50792 | } | ||
644 | 50793 | |||
645 | 50794 | while (! called) | ||
646 | 50795 | dbus_connection_read_write_dispatch (conn, -1); | ||
647 | 50796 | |||
648 | 50797 | nih_free (proxy); | ||
649 | 50798 | |||
650 | 50799 | my_teardown (conn); | ||
651 | 50800 | |||
652 | 50801 | |||
653 | 50802 | /* Check that a condition whereby too many arguments are returned | ||
654 | 50803 | * from a method call results in a special illegal arguments error | ||
655 | 50804 | * being returned. | ||
656 | 50805 | */ | ||
657 | 50806 | TEST_FEATURE ("with too many arguments in reply"); | ||
658 | 50807 | conn = my_setup (); | ||
659 | 50808 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
660 | 50809 | |||
661 | 50810 | auto void with_too_many_args_in_reply_async (NihDBusProxy *my_proxy, void *userdata); | ||
662 | 50811 | |||
663 | 50812 | called = 0; | ||
664 | 50813 | |||
665 | 50814 | ret = proxy_test_async_method_async (proxy, "test data", 5, | ||
666 | 50815 | (ProxyTestAsyncMethodCallback)async_fail_errback, | ||
667 | 50816 | with_too_many_args_in_reply_async, "userdata"); | ||
668 | 50817 | |||
669 | 50818 | TEST_EQ (ret, 0); | ||
670 | 50819 | |||
671 | 50820 | void with_too_many_args_in_reply_async (NihDBusProxy *my_proxy, void *userdata) | ||
672 | 50821 | { | ||
673 | 50822 | err = nih_error_get (); | ||
674 | 50823 | TEST_EQ (err->number, NIH_DBUS_INVALID_ARGS); | ||
675 | 50824 | nih_free (err); | ||
676 | 50825 | TEST_EQ_STR (userdata, "userdata"); | ||
677 | 50826 | TEST_EQ_P (my_proxy, proxy); | ||
678 | 50827 | called = 1; | ||
679 | 50828 | } | ||
680 | 50829 | |||
681 | 50830 | while (! called) | ||
682 | 50831 | dbus_connection_read_write_dispatch (conn, -1); | ||
683 | 50832 | |||
684 | 50833 | nih_free (proxy); | ||
685 | 50834 | |||
686 | 50835 | my_teardown (conn); | ||
687 | 50836 | |||
688 | 50837 | |||
689 | 50838 | /* Check that a condition whereby too many arguments are returned | ||
690 | 50839 | * from a method call results in a special illegal arguments error | ||
691 | 50840 | * being passed to the errback. | ||
692 | 50841 | */ | ||
693 | 50842 | TEST_FEATURE ("with too many arguments in reply (async)"); | ||
694 | 50843 | conn = my_setup (); | ||
695 | 50844 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
696 | 50845 | |||
697 | 50846 | output = NULL; | ||
698 | 50847 | |||
699 | 50848 | ret = proxy_test_async_method (proxy, "test data", 5, &output); | ||
700 | 50849 | |||
701 | 50850 | TEST_LT (ret, 1); | ||
702 | 50851 | |||
703 | 50852 | err = nih_error_get (); | ||
704 | 50853 | TEST_EQ (err->number, NIH_DBUS_INVALID_ARGS); | ||
705 | 50854 | nih_free (err); | ||
706 | 50855 | |||
707 | 50856 | nih_free (proxy); | ||
708 | 50857 | |||
709 | 50858 | my_teardown (conn); | ||
710 | 50859 | |||
711 | 50860 | |||
712 | 50861 | /* Check that a condition whereby arguments are missing from the | ||
713 | 50862 | * method call return results in a special illegal arguments error | ||
714 | 50863 | * being returned. | ||
715 | 50864 | */ | ||
716 | 50865 | TEST_FEATURE ("with missing arguments in reply"); | ||
717 | 50866 | conn = my_setup (); | ||
718 | 50867 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
719 | 50868 | |||
720 | 50869 | output = NULL; | ||
721 | 50870 | |||
722 | 50871 | ret = proxy_test_async_method (proxy, "test data", 6, &output); | ||
723 | 50872 | |||
724 | 50873 | TEST_LT (ret, 1); | ||
725 | 50874 | |||
726 | 50875 | err = nih_error_get (); | ||
727 | 50876 | TEST_EQ (err->number, NIH_DBUS_INVALID_ARGS); | ||
728 | 50877 | nih_free (err); | ||
729 | 50878 | |||
730 | 50879 | nih_free (proxy); | ||
731 | 50880 | |||
732 | 50881 | my_teardown (conn); | ||
733 | 50882 | |||
734 | 50883 | |||
735 | 50884 | /* Check that a condition whereby arguments are missing from the | ||
736 | 50885 | * method call return results in a special illegal arguments error | ||
737 | 50886 | * being passed to the errback. | ||
738 | 50887 | */ | ||
739 | 50888 | TEST_FEATURE ("with missing arguments in reply (async)"); | ||
740 | 50889 | conn = my_setup (); | ||
741 | 50890 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
742 | 50891 | |||
743 | 50892 | auto void with_missing_args_in_reply_async (NihDBusProxy *my_proxy, void *userdata); | ||
744 | 50893 | |||
745 | 50894 | called = 0; | ||
746 | 50895 | |||
747 | 50896 | ret = proxy_test_async_method_async (proxy, "test data", 6, | ||
748 | 50897 | (ProxyTestAsyncMethodCallback)async_fail_errback, | ||
749 | 50898 | with_missing_args_in_reply_async, "userdata"); | ||
750 | 50899 | |||
751 | 50900 | TEST_EQ (ret, 0); | ||
752 | 50901 | |||
753 | 50902 | void with_missing_args_in_reply_async (NihDBusProxy *my_proxy, void *userdata) | ||
754 | 50903 | { | ||
755 | 50904 | err = nih_error_get (); | ||
756 | 50905 | TEST_EQ (err->number, NIH_DBUS_INVALID_ARGS); | ||
757 | 50906 | nih_free (err); | ||
758 | 50907 | TEST_EQ_STR (userdata, "userdata"); | ||
759 | 50908 | TEST_EQ_P (my_proxy, proxy); | ||
760 | 50909 | called = 1; | ||
761 | 50910 | } | ||
762 | 50911 | |||
763 | 50912 | while (! called) | ||
764 | 50913 | dbus_connection_read_write_dispatch (conn, -1); | ||
765 | 50914 | |||
766 | 50915 | nih_free (proxy); | ||
767 | 50916 | |||
768 | 50917 | my_teardown (conn); | ||
769 | 50918 | |||
770 | 50919 | |||
771 | 50920 | /* Check that an input argument of Byte type is dispatched | ||
772 | 50921 | * correctly. | ||
773 | 50922 | */ | ||
774 | 50923 | TEST_FEATURE ("with Byte input argument"); | ||
775 | 50924 | conn = my_setup (); | ||
776 | 50925 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
777 | 50926 | |||
778 | 50927 | output = NULL; | ||
779 | 50928 | |||
780 | 50929 | ret = proxy_byte_to_str (proxy, 65, &output); | ||
781 | 50930 | |||
782 | 50931 | TEST_EQ (ret, 0); | ||
783 | 50932 | |||
784 | 50933 | TEST_NE_P (output, NULL); | ||
785 | 50934 | TEST_ALLOC_PARENT (output, proxy); | ||
786 | 50935 | TEST_EQ_STR (output, "65"); | ||
787 | 50936 | |||
788 | 50937 | nih_free (proxy); | ||
789 | 50938 | |||
790 | 50939 | my_teardown (conn); | ||
791 | 50940 | |||
792 | 50941 | |||
793 | 50942 | /* Check that an input argument of Byte type is dispatched | ||
794 | 50943 | * correctly by an async call. | ||
795 | 50944 | */ | ||
796 | 50945 | TEST_FEATURE ("with Byte input argument (async)"); | ||
797 | 50946 | conn = my_setup (); | ||
798 | 50947 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
799 | 50948 | |||
800 | 50949 | auto void with_byte_input_argument (NihDBusProxy *my_proxy, char *userdata, char *my_output); | ||
801 | 50950 | |||
802 | 50951 | called = 0; | ||
803 | 50952 | ret = proxy_byte_to_str_async (proxy, 65, (ProxyByteToStrCallback)with_byte_input_argument, async_fail_errback, "user data"); | ||
804 | 50953 | |||
805 | 50954 | TEST_EQ (ret, 0); | ||
806 | 50955 | |||
807 | 50956 | void with_byte_input_argument (NihDBusProxy *my_proxy, char *userdata, char *my_output) | ||
808 | 50957 | { | ||
809 | 50958 | TEST_EQ_P (my_proxy, proxy); | ||
810 | 50959 | TEST_EQ_STR (userdata, "user data"); | ||
811 | 50960 | TEST_NE_P (my_output, NULL); | ||
812 | 50961 | TEST_ALLOC_PARENT (my_output, proxy); | ||
813 | 50962 | TEST_EQ_STR (my_output, "65"); | ||
814 | 50963 | called = 1; | ||
815 | 50964 | } | ||
816 | 50965 | |||
817 | 50966 | while (! called) | ||
818 | 50967 | dbus_connection_read_write_dispatch (conn, -1); | ||
819 | 50968 | |||
820 | 50969 | nih_free (proxy); | ||
821 | 50970 | |||
822 | 50971 | my_teardown (conn); | ||
823 | 50972 | |||
824 | 50973 | |||
825 | 50974 | /* Check that an output argument of Byte type is marshalled | ||
826 | 50975 | * correctly. | ||
827 | 50976 | */ | ||
828 | 50977 | TEST_FEATURE ("with Byte output argument"); | ||
829 | 50978 | conn = my_setup (); | ||
830 | 50979 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
831 | 50980 | |||
832 | 50981 | byte_arg = 0; | ||
833 | 50982 | |||
834 | 50983 | ret = proxy_str_to_byte (proxy, "65", &byte_arg); | ||
835 | 50984 | |||
836 | 50985 | TEST_EQ (ret, 0); | ||
837 | 50986 | |||
838 | 50987 | TEST_EQ (byte_arg, 65); | ||
839 | 50988 | |||
840 | 50989 | nih_free (proxy); | ||
841 | 50990 | |||
842 | 50991 | my_teardown (conn); | ||
843 | 50992 | |||
844 | 50993 | |||
845 | 50994 | /* Check that an output argument of Byte type is marshalled | ||
846 | 50995 | * correctly for asynchronous calls. | ||
847 | 50996 | */ | ||
848 | 50997 | TEST_FEATURE ("with Byte output argument (async)"); | ||
849 | 50998 | conn = my_setup (); | ||
850 | 50999 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
851 | 51000 | |||
852 | 51001 | auto void with_byte_output_argument (NihDBusProxy *my_proxy, char *userdata, typeof(byte_arg) my_byte_arg); | ||
853 | 51002 | |||
854 | 51003 | called = 0; | ||
855 | 51004 | |||
856 | 51005 | ret = proxy_str_to_byte_async (proxy, "65", (ProxyStrToByteCallback)with_byte_output_argument, async_fail_errback, "user data"); | ||
857 | 51006 | |||
858 | 51007 | TEST_EQ (ret, 0); | ||
859 | 51008 | |||
860 | 51009 | void with_byte_output_argument (NihDBusProxy *my_proxy, char *userdata, typeof(byte_arg) my_byte_arg) | ||
861 | 51010 | { | ||
862 | 51011 | TEST_EQ_P (my_proxy, proxy); | ||
863 | 51012 | TEST_EQ_STR (userdata, "user data"); | ||
864 | 51013 | TEST_EQ (my_byte_arg, 65); | ||
865 | 51014 | called = 1; | ||
866 | 51015 | } | ||
867 | 51016 | |||
868 | 51017 | while (! called) | ||
869 | 51018 | dbus_connection_read_write_dispatch (conn, -1); | ||
870 | 51019 | |||
871 | 51020 | nih_free (proxy); | ||
872 | 51021 | |||
873 | 51022 | my_teardown (conn); | ||
874 | 51023 | |||
875 | 51024 | |||
876 | 51025 | /* Check that an input argument of Boolean type is dispatched | ||
877 | 51026 | * correctly. | ||
878 | 51027 | */ | ||
879 | 51028 | TEST_FEATURE ("with Boolean input argument"); | ||
880 | 51029 | conn = my_setup (); | ||
881 | 51030 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
882 | 51031 | |||
883 | 51032 | output = NULL; | ||
884 | 51033 | |||
885 | 51034 | ret = proxy_boolean_to_str (proxy, 1, &output); | ||
886 | 51035 | |||
887 | 51036 | TEST_EQ (ret, 0); | ||
888 | 51037 | |||
889 | 51038 | TEST_NE_P (output, NULL); | ||
890 | 51039 | TEST_ALLOC_PARENT (output, proxy); | ||
891 | 51040 | TEST_EQ_STR (output, "True"); | ||
892 | 51041 | |||
893 | 51042 | nih_free (proxy); | ||
894 | 51043 | |||
895 | 51044 | my_teardown (conn); | ||
896 | 51045 | |||
897 | 51046 | |||
898 | 51047 | /* Check that an input argument of Boolean type is dispatched | ||
899 | 51048 | * correctly for asynchronous calls. | ||
900 | 51049 | */ | ||
901 | 51050 | TEST_FEATURE ("with Boolean input argument (async)"); | ||
902 | 51051 | conn = my_setup (); | ||
903 | 51052 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
904 | 51053 | |||
905 | 51054 | auto void with_boolean_input_argument (NihDBusProxy *proxy, char *userdata, char *output); | ||
906 | 51055 | |||
907 | 51056 | called = 0; | ||
908 | 51057 | ret = proxy_boolean_to_str_async (proxy, 1, (ProxyBooleanToStrCallback)with_boolean_input_argument, async_fail_errback, "user data"); | ||
909 | 51058 | |||
910 | 51059 | TEST_EQ (ret, 0); | ||
911 | 51060 | |||
912 | 51061 | void with_boolean_input_argument (NihDBusProxy *my_proxy, char *userdata, char *my_output) | ||
913 | 51062 | { | ||
914 | 51063 | TEST_EQ_STR (userdata, "user data"); | ||
915 | 51064 | TEST_EQ_P (my_proxy, proxy); | ||
916 | 51065 | TEST_NE_P (my_output, NULL); | ||
917 | 51066 | TEST_ALLOC_PARENT (my_output, proxy); | ||
918 | 51067 | TEST_EQ_STR (my_output, "True"); | ||
919 | 51068 | |||
920 | 51069 | called = 1; | ||
921 | 51070 | } | ||
922 | 51071 | |||
923 | 51072 | while (! called) | ||
924 | 51073 | dbus_connection_read_write_dispatch (conn, -1); | ||
925 | 51074 | |||
926 | 51075 | nih_free (proxy); | ||
927 | 51076 | |||
928 | 51077 | my_teardown (conn); | ||
929 | 51078 | |||
930 | 51079 | |||
931 | 51080 | /* Check that an output argument of Boolean type is marshalled | ||
932 | 51081 | * correctly. | ||
933 | 51082 | */ | ||
934 | 51083 | TEST_FEATURE ("with Boolean output argument"); | ||
935 | 51084 | conn = my_setup (); | ||
936 | 51085 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
937 | 51086 | |||
938 | 51087 | boolean_arg = TRUE; | ||
939 | 51088 | |||
940 | 51089 | ret = proxy_str_to_boolean (proxy, "False", &boolean_arg); | ||
941 | 51090 | |||
942 | 51091 | TEST_EQ (ret, 0); | ||
943 | 51092 | |||
944 | 51093 | TEST_EQ (boolean_arg, FALSE); | ||
945 | 51094 | |||
946 | 51095 | nih_free (proxy); | ||
947 | 51096 | |||
948 | 51097 | my_teardown (conn); | ||
949 | 51098 | |||
950 | 51099 | |||
951 | 51100 | /* Check that an output argument of Boolean type is marshalled | ||
952 | 51101 | * correctly for asynchronous calls. | ||
953 | 51102 | */ | ||
954 | 51103 | TEST_FEATURE ("with Boolean output argument (async)"); | ||
955 | 51104 | conn = my_setup (); | ||
956 | 51105 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
957 | 51106 | |||
958 | 51107 | auto void with_boolean_output_argument (NihDBusProxy *my_proxy, char *userdata, typeof(boolean_arg) my_boolean_arg); | ||
959 | 51108 | |||
960 | 51109 | called = 0; | ||
961 | 51110 | |||
962 | 51111 | ret = proxy_str_to_boolean_async (proxy, "False", (ProxyStrToBooleanCallback)with_boolean_output_argument, async_fail_errback, "user data"); | ||
963 | 51112 | |||
964 | 51113 | TEST_EQ (ret, 0); | ||
965 | 51114 | |||
966 | 51115 | void with_boolean_output_argument (NihDBusProxy *my_proxy, char *userdata, typeof(boolean_arg) my_boolean_arg) | ||
967 | 51116 | { | ||
968 | 51117 | TEST_EQ_P (my_proxy, proxy); | ||
969 | 51118 | TEST_EQ_STR (userdata, "user data"); | ||
970 | 51119 | TEST_EQ (my_boolean_arg, 0); | ||
971 | 51120 | called = 1; | ||
972 | 51121 | } | ||
973 | 51122 | |||
974 | 51123 | while (! called) | ||
975 | 51124 | dbus_connection_read_write_dispatch (conn, -1); | ||
976 | 51125 | |||
977 | 51126 | nih_free (proxy); | ||
978 | 51127 | |||
979 | 51128 | my_teardown (conn); | ||
980 | 51129 | |||
981 | 51130 | |||
982 | 51131 | /* Check that an input argument of Int16 type is dispatched | ||
983 | 51132 | * correctly. | ||
984 | 51133 | */ | ||
985 | 51134 | TEST_FEATURE ("with Int16 input argument"); | ||
986 | 51135 | conn = my_setup (); | ||
987 | 51136 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
988 | 51137 | |||
989 | 51138 | output = NULL; | ||
990 | 51139 | |||
991 | 51140 | ret = proxy_int16_to_str (proxy, 1701, &output); | ||
992 | 51141 | |||
993 | 51142 | TEST_EQ (ret, 0); | ||
994 | 51143 | |||
995 | 51144 | TEST_NE_P (output, NULL); | ||
996 | 51145 | TEST_ALLOC_PARENT (output, proxy); | ||
997 | 51146 | TEST_EQ_STR (output, "1701"); | ||
998 | 51147 | |||
999 | 51148 | nih_free (proxy); | ||
1000 | 51149 | |||
1001 | 51150 | my_teardown (conn); | ||
1002 | 51151 | |||
1003 | 51152 | |||
1004 | 51153 | /* Check that an input argument of Int16 type is dispatched | ||
1005 | 51154 | * correctly from an asynchronous call. | ||
1006 | 51155 | */ | ||
1007 | 51156 | TEST_FEATURE ("with Int16 input argument (async)"); | ||
1008 | 51157 | conn = my_setup (); | ||
1009 | 51158 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1010 | 51159 | |||
1011 | 51160 | auto void with_int16_input_argument (NihDBusProxy *proxy, char *userdata, char *output); | ||
1012 | 51161 | |||
1013 | 51162 | called = 0; | ||
1014 | 51163 | ret = proxy_int16_to_str_async (proxy, 1701, (ProxyInt16ToStrCallback)with_int16_input_argument, async_fail_errback, "user data"); | ||
1015 | 51164 | |||
1016 | 51165 | TEST_EQ (ret, 0); | ||
1017 | 51166 | |||
1018 | 51167 | void with_int16_input_argument (NihDBusProxy *my_proxy, char *userdata, char *my_output) | ||
1019 | 51168 | { | ||
1020 | 51169 | TEST_EQ_STR (userdata, "user data"); | ||
1021 | 51170 | TEST_EQ_P (my_proxy, proxy); | ||
1022 | 51171 | TEST_NE_P (my_output, NULL); | ||
1023 | 51172 | TEST_ALLOC_PARENT (my_output, proxy); | ||
1024 | 51173 | TEST_EQ_STR (my_output, "1701"); | ||
1025 | 51174 | called = 1; | ||
1026 | 51175 | } | ||
1027 | 51176 | |||
1028 | 51177 | while (! called) | ||
1029 | 51178 | dbus_connection_read_write_dispatch (conn, -1); | ||
1030 | 51179 | |||
1031 | 51180 | nih_free (proxy); | ||
1032 | 51181 | |||
1033 | 51182 | my_teardown (conn); | ||
1034 | 51183 | |||
1035 | 51184 | |||
1036 | 51185 | /* Check that an output argument of Int16 type is marshalled | ||
1037 | 51186 | * correctly. | ||
1038 | 51187 | */ | ||
1039 | 51188 | TEST_FEATURE ("with Int16 output argument"); | ||
1040 | 51189 | conn = my_setup (); | ||
1041 | 51190 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1042 | 51191 | |||
1043 | 51192 | int16_arg = 0; | ||
1044 | 51193 | |||
1045 | 51194 | ret = proxy_str_to_int16 (proxy, "1701", &int16_arg); | ||
1046 | 51195 | |||
1047 | 51196 | TEST_EQ (ret, 0); | ||
1048 | 51197 | |||
1049 | 51198 | TEST_EQ (int16_arg, 1701); | ||
1050 | 51199 | |||
1051 | 51200 | nih_free (proxy); | ||
1052 | 51201 | |||
1053 | 51202 | my_teardown (conn); | ||
1054 | 51203 | |||
1055 | 51204 | |||
1056 | 51205 | /* Check that an output argument of Int16 type is marshalled | ||
1057 | 51206 | * correctly for asynchronous calls. | ||
1058 | 51207 | */ | ||
1059 | 51208 | TEST_FEATURE ("with Int16 output argument (async)"); | ||
1060 | 51209 | conn = my_setup (); | ||
1061 | 51210 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1062 | 51211 | |||
1063 | 51212 | auto void with_int16_output_argument (NihDBusProxy *my_proxy, char *userdata, typeof(int16_arg) my_int16_arg); | ||
1064 | 51213 | |||
1065 | 51214 | called = 0; | ||
1066 | 51215 | |||
1067 | 51216 | ret = proxy_str_to_int16_async (proxy, "65", (ProxyStrToInt16Callback)with_int16_output_argument, async_fail_errback, "user data"); | ||
1068 | 51217 | |||
1069 | 51218 | TEST_EQ (ret, 0); | ||
1070 | 51219 | |||
1071 | 51220 | void with_int16_output_argument (NihDBusProxy *my_proxy, char *userdata, typeof(int16_arg) my_int16_arg) | ||
1072 | 51221 | { | ||
1073 | 51222 | TEST_EQ_P (my_proxy, proxy); | ||
1074 | 51223 | TEST_EQ_STR (userdata, "user data"); | ||
1075 | 51224 | TEST_EQ (my_int16_arg, 65); | ||
1076 | 51225 | called = 1; | ||
1077 | 51226 | } | ||
1078 | 51227 | |||
1079 | 51228 | while (! called) | ||
1080 | 51229 | dbus_connection_read_write_dispatch (conn, -1); | ||
1081 | 51230 | |||
1082 | 51231 | nih_free (proxy); | ||
1083 | 51232 | |||
1084 | 51233 | my_teardown (conn); | ||
1085 | 51234 | |||
1086 | 51235 | |||
1087 | 51236 | /* Check that an input argument of UInt16 type is dispatched | ||
1088 | 51237 | * correctly. | ||
1089 | 51238 | */ | ||
1090 | 51239 | TEST_FEATURE ("with UInt16 input argument"); | ||
1091 | 51240 | conn = my_setup (); | ||
1092 | 51241 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1093 | 51242 | |||
1094 | 51243 | output = NULL; | ||
1095 | 51244 | |||
1096 | 51245 | ret = proxy_uint16_to_str (proxy, 1701, &output); | ||
1097 | 51246 | |||
1098 | 51247 | TEST_EQ (ret, 0); | ||
1099 | 51248 | |||
1100 | 51249 | TEST_NE_P (output, NULL); | ||
1101 | 51250 | TEST_ALLOC_PARENT (output, proxy); | ||
1102 | 51251 | TEST_EQ_STR (output, "1701"); | ||
1103 | 51252 | |||
1104 | 51253 | nih_free (proxy); | ||
1105 | 51254 | |||
1106 | 51255 | my_teardown (conn); | ||
1107 | 51256 | |||
1108 | 51257 | |||
1109 | 51258 | /* Check that an input argument of UInt16 type is dispatched | ||
1110 | 51259 | * correctly for an asynchronous call. | ||
1111 | 51260 | */ | ||
1112 | 51261 | TEST_FEATURE ("with UInt16 input argument (async)"); | ||
1113 | 51262 | conn = my_setup (); | ||
1114 | 51263 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1115 | 51264 | |||
1116 | 51265 | auto void with_uint16_input_argument (NihDBusProxy *proxy, char *userdata, char *output); | ||
1117 | 51266 | |||
1118 | 51267 | called = 0; | ||
1119 | 51268 | ret = proxy_uint16_to_str_async (proxy, 1701, (ProxyUint16ToStrCallback)with_uint16_input_argument, async_fail_errback, "user data" ); | ||
1120 | 51269 | |||
1121 | 51270 | TEST_EQ (ret, 0); | ||
1122 | 51271 | |||
1123 | 51272 | void with_uint16_input_argument (NihDBusProxy *my_proxy, char *userdata, char *my_output) | ||
1124 | 51273 | { | ||
1125 | 51274 | TEST_EQ_STR (userdata, "user data"); | ||
1126 | 51275 | TEST_EQ_P (my_proxy, proxy); | ||
1127 | 51276 | TEST_NE_P (my_output, NULL); | ||
1128 | 51277 | TEST_ALLOC_PARENT (my_output, proxy); | ||
1129 | 51278 | TEST_EQ_STR (my_output, "1701"); | ||
1130 | 51279 | called = 1; | ||
1131 | 51280 | } | ||
1132 | 51281 | |||
1133 | 51282 | while (! called) | ||
1134 | 51283 | dbus_connection_read_write_dispatch (conn, -1); | ||
1135 | 51284 | |||
1136 | 51285 | nih_free (proxy); | ||
1137 | 51286 | |||
1138 | 51287 | my_teardown (conn); | ||
1139 | 51288 | |||
1140 | 51289 | |||
1141 | 51290 | /* Check that an output argument of UInt16 type is marshalled | ||
1142 | 51291 | * correctly. | ||
1143 | 51292 | */ | ||
1144 | 51293 | TEST_FEATURE ("with UInt16 output argument"); | ||
1145 | 51294 | conn = my_setup (); | ||
1146 | 51295 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1147 | 51296 | |||
1148 | 51297 | uint16_arg = 0; | ||
1149 | 51298 | |||
1150 | 51299 | ret = proxy_str_to_uint16 (proxy, "1701", &uint16_arg); | ||
1151 | 51300 | |||
1152 | 51301 | TEST_EQ (ret, 0); | ||
1153 | 51302 | |||
1154 | 51303 | TEST_EQ (uint16_arg, 1701); | ||
1155 | 51304 | |||
1156 | 51305 | nih_free (proxy); | ||
1157 | 51306 | |||
1158 | 51307 | my_teardown (conn); | ||
1159 | 51308 | |||
1160 | 51309 | |||
1161 | 51310 | /* Check that an output argument of UInt16 type is marshalled | ||
1162 | 51311 | * correctly for asynchronous calls. | ||
1163 | 51312 | */ | ||
1164 | 51313 | TEST_FEATURE ("with UInt16 output argument (async)"); | ||
1165 | 51314 | conn = my_setup (); | ||
1166 | 51315 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1167 | 51316 | |||
1168 | 51317 | auto void with_uint16_output_argument (NihDBusProxy *my_proxy, char *userdata, typeof(uint16_arg) my_uint16_arg); | ||
1169 | 51318 | |||
1170 | 51319 | called = 0; | ||
1171 | 51320 | |||
1172 | 51321 | ret = proxy_str_to_uint16_async (proxy, "65", (ProxyStrToUint16Callback)with_uint16_output_argument, async_fail_errback, "user data"); | ||
1173 | 51322 | |||
1174 | 51323 | TEST_EQ (ret, 0); | ||
1175 | 51324 | |||
1176 | 51325 | void with_uint16_output_argument (NihDBusProxy *my_proxy, char *userdata, typeof(uint16_arg) my_uint16_arg) | ||
1177 | 51326 | { | ||
1178 | 51327 | TEST_EQ_P (my_proxy, proxy); | ||
1179 | 51328 | TEST_EQ_STR (userdata, "user data"); | ||
1180 | 51329 | TEST_EQ (my_uint16_arg, 65); | ||
1181 | 51330 | called = 1; | ||
1182 | 51331 | } | ||
1183 | 51332 | |||
1184 | 51333 | while (! called) | ||
1185 | 51334 | dbus_connection_read_write_dispatch (conn, -1); | ||
1186 | 51335 | |||
1187 | 51336 | nih_free (proxy); | ||
1188 | 51337 | |||
1189 | 51338 | my_teardown (conn); | ||
1190 | 51339 | |||
1191 | 51340 | |||
1192 | 51341 | /* Check that an input argument of Int32 type is dispatched | ||
1193 | 51342 | * correctly. | ||
1194 | 51343 | */ | ||
1195 | 51344 | TEST_FEATURE ("with Int32 input argument"); | ||
1196 | 51345 | conn = my_setup (); | ||
1197 | 51346 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1198 | 51347 | |||
1199 | 51348 | output = NULL; | ||
1200 | 51349 | |||
1201 | 51350 | ret = proxy_int32_to_str (proxy, 1701, &output); | ||
1202 | 51351 | |||
1203 | 51352 | TEST_EQ (ret, 0); | ||
1204 | 51353 | |||
1205 | 51354 | TEST_NE_P (output, NULL); | ||
1206 | 51355 | TEST_ALLOC_PARENT (output, proxy); | ||
1207 | 51356 | TEST_EQ_STR (output, "1701"); | ||
1208 | 51357 | |||
1209 | 51358 | nih_free (proxy); | ||
1210 | 51359 | |||
1211 | 51360 | my_teardown (conn); | ||
1212 | 51361 | |||
1213 | 51362 | |||
1214 | 51363 | /* Check that an input argument of Int32 type is dispatched | ||
1215 | 51364 | * correctly during an asynchronous call. | ||
1216 | 51365 | */ | ||
1217 | 51366 | TEST_FEATURE ("with Int32 input argument (async)"); | ||
1218 | 51367 | conn = my_setup (); | ||
1219 | 51368 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1220 | 51369 | |||
1221 | 51370 | auto void with_int32_input_argument (NihDBusProxy *proxy, char *userdata, char *output); | ||
1222 | 51371 | |||
1223 | 51372 | called = 0; | ||
1224 | 51373 | ret = proxy_int32_to_str_async (proxy, 1701, (ProxyInt32ToStrCallback)with_int32_input_argument, async_fail_errback, "user data"); | ||
1225 | 51374 | |||
1226 | 51375 | TEST_EQ (ret, 0); | ||
1227 | 51376 | |||
1228 | 51377 | void with_int32_input_argument (NihDBusProxy *my_proxy, char *userdata, char *my_output) | ||
1229 | 51378 | { | ||
1230 | 51379 | TEST_EQ_STR (userdata, "user data"); | ||
1231 | 51380 | TEST_EQ_P (my_proxy, proxy); | ||
1232 | 51381 | TEST_NE_P (my_output, NULL); | ||
1233 | 51382 | TEST_ALLOC_PARENT (my_output, proxy); | ||
1234 | 51383 | TEST_EQ_STR (my_output, "1701"); | ||
1235 | 51384 | called = 1; | ||
1236 | 51385 | } | ||
1237 | 51386 | |||
1238 | 51387 | while (! called) | ||
1239 | 51388 | dbus_connection_read_write_dispatch (conn, -1); | ||
1240 | 51389 | |||
1241 | 51390 | nih_free (proxy); | ||
1242 | 51391 | |||
1243 | 51392 | my_teardown (conn); | ||
1244 | 51393 | |||
1245 | 51394 | |||
1246 | 51395 | /* Check that an output argument of Int32 type is marshalled | ||
1247 | 51396 | * correctly. | ||
1248 | 51397 | */ | ||
1249 | 51398 | TEST_FEATURE ("with Int32 output argument"); | ||
1250 | 51399 | conn = my_setup (); | ||
1251 | 51400 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1252 | 51401 | |||
1253 | 51402 | int32_arg = 0; | ||
1254 | 51403 | |||
1255 | 51404 | ret = proxy_str_to_int32 (proxy, "1701", &int32_arg); | ||
1256 | 51405 | |||
1257 | 51406 | TEST_EQ (ret, 0); | ||
1258 | 51407 | |||
1259 | 51408 | TEST_EQ (int32_arg, 1701); | ||
1260 | 51409 | |||
1261 | 51410 | nih_free (proxy); | ||
1262 | 51411 | |||
1263 | 51412 | my_teardown (conn); | ||
1264 | 51413 | |||
1265 | 51414 | |||
1266 | 51415 | /* Check that an output argument of Int32 type is marshalled | ||
1267 | 51416 | * correctly for asynchronous calls. | ||
1268 | 51417 | */ | ||
1269 | 51418 | TEST_FEATURE ("with Int32 output argument (async)"); | ||
1270 | 51419 | conn = my_setup (); | ||
1271 | 51420 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1272 | 51421 | |||
1273 | 51422 | auto void with_int32_output_argument (NihDBusProxy *my_proxy, char *userdata, typeof(int32_arg) my_int32_arg); | ||
1274 | 51423 | |||
1275 | 51424 | called = 0; | ||
1276 | 51425 | |||
1277 | 51426 | ret = proxy_str_to_int32_async (proxy, "65", (ProxyStrToInt32Callback)with_int32_output_argument, async_fail_errback, "user data"); | ||
1278 | 51427 | |||
1279 | 51428 | TEST_EQ (ret, 0); | ||
1280 | 51429 | |||
1281 | 51430 | void with_int32_output_argument (NihDBusProxy *my_proxy, char *userdata, typeof(int32_arg) my_int32_arg) | ||
1282 | 51431 | { | ||
1283 | 51432 | TEST_EQ_P (my_proxy, proxy); | ||
1284 | 51433 | TEST_EQ_STR (userdata, "user data"); | ||
1285 | 51434 | TEST_EQ (my_int32_arg, 65); | ||
1286 | 51435 | called = 1; | ||
1287 | 51436 | } | ||
1288 | 51437 | |||
1289 | 51438 | while (! called) | ||
1290 | 51439 | dbus_connection_read_write_dispatch (conn, -1); | ||
1291 | 51440 | |||
1292 | 51441 | nih_free (proxy); | ||
1293 | 51442 | |||
1294 | 51443 | my_teardown (conn); | ||
1295 | 51444 | |||
1296 | 51445 | |||
1297 | 51446 | /* Check that an input argument of UInt32 type is dispatched | ||
1298 | 51447 | * correctly. | ||
1299 | 51448 | */ | ||
1300 | 51449 | TEST_FEATURE ("with UInt32 input argument"); | ||
1301 | 51450 | conn = my_setup (); | ||
1302 | 51451 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1303 | 51452 | |||
1304 | 51453 | output = NULL; | ||
1305 | 51454 | |||
1306 | 51455 | ret = proxy_uint32_to_str (proxy, 1701, &output); | ||
1307 | 51456 | |||
1308 | 51457 | TEST_EQ (ret, 0); | ||
1309 | 51458 | |||
1310 | 51459 | TEST_NE_P (output, NULL); | ||
1311 | 51460 | TEST_ALLOC_PARENT (output, proxy); | ||
1312 | 51461 | TEST_EQ_STR (output, "1701"); | ||
1313 | 51462 | |||
1314 | 51463 | nih_free (proxy); | ||
1315 | 51464 | |||
1316 | 51465 | my_teardown (conn); | ||
1317 | 51466 | |||
1318 | 51467 | |||
1319 | 51468 | /* Check that an input argument of UInt32 type is dispatched | ||
1320 | 51469 | * correctly for an asynchronous call. | ||
1321 | 51470 | */ | ||
1322 | 51471 | TEST_FEATURE ("with UInt32 input argument (async)"); | ||
1323 | 51472 | conn = my_setup (); | ||
1324 | 51473 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1325 | 51474 | |||
1326 | 51475 | auto void with_uint32_input_argument (NihDBusProxy *proxy, char *userdata, char *output); | ||
1327 | 51476 | |||
1328 | 51477 | called = 0; | ||
1329 | 51478 | ret = proxy_uint32_to_str_async (proxy, 1701, (ProxyUint32ToStrCallback)with_uint32_input_argument, async_fail_errback, "user data" ); | ||
1330 | 51479 | |||
1331 | 51480 | TEST_EQ (ret, 0); | ||
1332 | 51481 | |||
1333 | 51482 | void with_uint32_input_argument (NihDBusProxy *my_proxy, char *userdata, char *my_output) | ||
1334 | 51483 | { | ||
1335 | 51484 | TEST_EQ_STR (userdata, "user data"); | ||
1336 | 51485 | TEST_EQ_P (my_proxy, proxy); | ||
1337 | 51486 | TEST_NE_P (my_output, NULL); | ||
1338 | 51487 | TEST_ALLOC_PARENT (my_output, proxy); | ||
1339 | 51488 | TEST_EQ_STR (my_output, "1701"); | ||
1340 | 51489 | called = 1; | ||
1341 | 51490 | } | ||
1342 | 51491 | |||
1343 | 51492 | while (! called) | ||
1344 | 51493 | dbus_connection_read_write_dispatch (conn, -1); | ||
1345 | 51494 | |||
1346 | 51495 | nih_free (proxy); | ||
1347 | 51496 | |||
1348 | 51497 | my_teardown (conn); | ||
1349 | 51498 | |||
1350 | 51499 | |||
1351 | 51500 | /* Check that an output argument of UInt32 type is marshalled | ||
1352 | 51501 | * correctly. | ||
1353 | 51502 | */ | ||
1354 | 51503 | TEST_FEATURE ("with UInt32 output argument"); | ||
1355 | 51504 | conn = my_setup (); | ||
1356 | 51505 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1357 | 51506 | |||
1358 | 51507 | uint32_arg = 0; | ||
1359 | 51508 | |||
1360 | 51509 | ret = proxy_str_to_uint32 (proxy, "1701", &uint32_arg); | ||
1361 | 51510 | |||
1362 | 51511 | TEST_EQ (ret, 0); | ||
1363 | 51512 | |||
1364 | 51513 | TEST_EQ (uint32_arg, 1701); | ||
1365 | 51514 | |||
1366 | 51515 | nih_free (proxy); | ||
1367 | 51516 | |||
1368 | 51517 | my_teardown (conn); | ||
1369 | 51518 | |||
1370 | 51519 | |||
1371 | 51520 | /* Check that an output argument of UInt32 type is marshalled | ||
1372 | 51521 | * correctly for asynchronous calls. | ||
1373 | 51522 | */ | ||
1374 | 51523 | TEST_FEATURE ("with UInt32 output argument (async)"); | ||
1375 | 51524 | conn = my_setup (); | ||
1376 | 51525 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1377 | 51526 | |||
1378 | 51527 | auto void with_uint32_output_argument (NihDBusProxy *my_proxy, char *userdata, typeof(uint32_arg) my_uint32_arg); | ||
1379 | 51528 | |||
1380 | 51529 | called = 0; | ||
1381 | 51530 | |||
1382 | 51531 | ret = proxy_str_to_uint32_async (proxy, "65", (ProxyStrToUint32Callback)with_uint32_output_argument, async_fail_errback, "user data"); | ||
1383 | 51532 | |||
1384 | 51533 | TEST_EQ (ret, 0); | ||
1385 | 51534 | |||
1386 | 51535 | void with_uint32_output_argument (NihDBusProxy *my_proxy, char *userdata, typeof(uint32_arg) my_uint32_arg) | ||
1387 | 51536 | { | ||
1388 | 51537 | TEST_EQ_P (my_proxy, proxy); | ||
1389 | 51538 | TEST_EQ_STR (userdata, "user data"); | ||
1390 | 51539 | TEST_EQ (my_uint32_arg, 65); | ||
1391 | 51540 | called = 1; | ||
1392 | 51541 | } | ||
1393 | 51542 | |||
1394 | 51543 | while (! called) | ||
1395 | 51544 | dbus_connection_read_write_dispatch (conn, -1); | ||
1396 | 51545 | |||
1397 | 51546 | nih_free (proxy); | ||
1398 | 51547 | |||
1399 | 51548 | my_teardown (conn); | ||
1400 | 51549 | |||
1401 | 51550 | |||
1402 | 51551 | /* Check that an input argument of Int64 type is dispatched | ||
1403 | 51552 | * correctly. | ||
1404 | 51553 | */ | ||
1405 | 51554 | TEST_FEATURE ("with Int64 input argument"); | ||
1406 | 51555 | conn = my_setup (); | ||
1407 | 51556 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1408 | 51557 | |||
1409 | 51558 | output = NULL; | ||
1410 | 51559 | |||
1411 | 51560 | ret = proxy_int64_to_str (proxy, 1701, &output); | ||
1412 | 51561 | |||
1413 | 51562 | TEST_EQ (ret, 0); | ||
1414 | 51563 | |||
1415 | 51564 | TEST_NE_P (output, NULL); | ||
1416 | 51565 | TEST_ALLOC_PARENT (output, proxy); | ||
1417 | 51566 | TEST_EQ_STR (output, "1701"); | ||
1418 | 51567 | |||
1419 | 51568 | nih_free (proxy); | ||
1420 | 51569 | |||
1421 | 51570 | my_teardown (conn); | ||
1422 | 51571 | |||
1423 | 51572 | |||
1424 | 51573 | /* Check that an input argument of Int64 type is dispatched | ||
1425 | 51574 | * correctly for an asynchronous call. | ||
1426 | 51575 | */ | ||
1427 | 51576 | TEST_FEATURE ("with Int64 input argument (async)"); | ||
1428 | 51577 | conn = my_setup (); | ||
1429 | 51578 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1430 | 51579 | |||
1431 | 51580 | auto void with_int64_input_argument (NihDBusProxy *proxy, char *userdata, char *output); | ||
1432 | 51581 | |||
1433 | 51582 | called = 0; | ||
1434 | 51583 | ret = proxy_int64_to_str_async (proxy, 1701, (ProxyInt64ToStrCallback)with_int64_input_argument, async_fail_errback, "user data" ); | ||
1435 | 51584 | |||
1436 | 51585 | TEST_EQ (ret, 0); | ||
1437 | 51586 | |||
1438 | 51587 | void with_int64_input_argument (NihDBusProxy *my_proxy, char *userdata, char *my_output) | ||
1439 | 51588 | { | ||
1440 | 51589 | TEST_EQ_STR (userdata, "user data"); | ||
1441 | 51590 | TEST_EQ_P (my_proxy, proxy); | ||
1442 | 51591 | TEST_NE_P (my_output, NULL); | ||
1443 | 51592 | TEST_ALLOC_PARENT (my_output, proxy); | ||
1444 | 51593 | TEST_EQ_STR (my_output, "1701"); | ||
1445 | 51594 | called = 1; | ||
1446 | 51595 | } | ||
1447 | 51596 | |||
1448 | 51597 | while (! called) | ||
1449 | 51598 | dbus_connection_read_write_dispatch (conn, -1); | ||
1450 | 51599 | |||
1451 | 51600 | nih_free (proxy); | ||
1452 | 51601 | |||
1453 | 51602 | my_teardown (conn); | ||
1454 | 51603 | |||
1455 | 51604 | |||
1456 | 51605 | /* Check that an output argument of Int64 type is marshalled | ||
1457 | 51606 | * correctly. | ||
1458 | 51607 | */ | ||
1459 | 51608 | TEST_FEATURE ("with Int64 output argument"); | ||
1460 | 51609 | conn = my_setup (); | ||
1461 | 51610 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1462 | 51611 | |||
1463 | 51612 | int64_arg = 0; | ||
1464 | 51613 | |||
1465 | 51614 | ret = proxy_str_to_int64 (proxy, "1701", &int64_arg); | ||
1466 | 51615 | |||
1467 | 51616 | TEST_EQ (ret, 0); | ||
1468 | 51617 | |||
1469 | 51618 | TEST_EQ (int64_arg, 1701); | ||
1470 | 51619 | |||
1471 | 51620 | nih_free (proxy); | ||
1472 | 51621 | |||
1473 | 51622 | my_teardown (conn); | ||
1474 | 51623 | |||
1475 | 51624 | |||
1476 | 51625 | /* Check that an output argument of Int64 type is marshalled | ||
1477 | 51626 | * correctly for asynchronous calls. | ||
1478 | 51627 | */ | ||
1479 | 51628 | TEST_FEATURE ("with Int64 output argument (async)"); | ||
1480 | 51629 | conn = my_setup (); | ||
1481 | 51630 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1482 | 51631 | |||
1483 | 51632 | auto void with_int64_output_argument (NihDBusProxy *my_proxy, char *userdata, typeof(int64_arg) my_int64_arg); | ||
1484 | 51633 | |||
1485 | 51634 | called = 0; | ||
1486 | 51635 | |||
1487 | 51636 | ret = proxy_str_to_int64_async (proxy, "65", (ProxyStrToInt64Callback)with_int64_output_argument, async_fail_errback, "user data"); | ||
1488 | 51637 | |||
1489 | 51638 | TEST_EQ (ret, 0); | ||
1490 | 51639 | |||
1491 | 51640 | void with_int64_output_argument (NihDBusProxy *my_proxy, char *userdata, typeof(int64_arg) my_int64_arg) | ||
1492 | 51641 | { | ||
1493 | 51642 | TEST_EQ_P (my_proxy, proxy); | ||
1494 | 51643 | TEST_EQ_STR (userdata, "user data"); | ||
1495 | 51644 | TEST_EQ (my_int64_arg, 65); | ||
1496 | 51645 | called = 1; | ||
1497 | 51646 | } | ||
1498 | 51647 | |||
1499 | 51648 | while (! called) | ||
1500 | 51649 | dbus_connection_read_write_dispatch (conn, -1); | ||
1501 | 51650 | |||
1502 | 51651 | nih_free (proxy); | ||
1503 | 51652 | |||
1504 | 51653 | my_teardown (conn); | ||
1505 | 51654 | |||
1506 | 51655 | |||
1507 | 51656 | /* Check that an input argument of UInt64 type is dispatched | ||
1508 | 51657 | * correctly. | ||
1509 | 51658 | */ | ||
1510 | 51659 | TEST_FEATURE ("with UInt64 input argument"); | ||
1511 | 51660 | conn = my_setup (); | ||
1512 | 51661 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1513 | 51662 | |||
1514 | 51663 | output = NULL; | ||
1515 | 51664 | |||
1516 | 51665 | ret = proxy_uint64_to_str (proxy, 1701, &output); | ||
1517 | 51666 | |||
1518 | 51667 | TEST_EQ (ret, 0); | ||
1519 | 51668 | |||
1520 | 51669 | TEST_NE_P (output, NULL); | ||
1521 | 51670 | TEST_ALLOC_PARENT (output, proxy); | ||
1522 | 51671 | TEST_EQ_STR (output, "1701"); | ||
1523 | 51672 | |||
1524 | 51673 | nih_free (proxy); | ||
1525 | 51674 | |||
1526 | 51675 | my_teardown (conn); | ||
1527 | 51676 | |||
1528 | 51677 | |||
1529 | 51678 | /* Check that an input argument of UInt64 type is dispatched | ||
1530 | 51679 | * correctly for an asynchronous call. | ||
1531 | 51680 | */ | ||
1532 | 51681 | TEST_FEATURE ("with UInt64 input argument (async)"); | ||
1533 | 51682 | conn = my_setup (); | ||
1534 | 51683 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1535 | 51684 | |||
1536 | 51685 | auto void with_uint64_input_argument (NihDBusProxy *proxy, char *userdata, char *output); | ||
1537 | 51686 | |||
1538 | 51687 | called = 0; | ||
1539 | 51688 | ret = proxy_uint64_to_str_async (proxy, 1701, (ProxyUint64ToStrCallback)with_uint64_input_argument, async_fail_errback, "user data" ); | ||
1540 | 51689 | |||
1541 | 51690 | TEST_EQ (ret, 0); | ||
1542 | 51691 | |||
1543 | 51692 | void with_uint64_input_argument (NihDBusProxy *my_proxy, char *userdata, char *my_output) | ||
1544 | 51693 | { | ||
1545 | 51694 | TEST_EQ_STR (userdata, "user data"); | ||
1546 | 51695 | TEST_EQ_P (my_proxy, proxy); | ||
1547 | 51696 | TEST_NE_P (my_output, NULL); | ||
1548 | 51697 | TEST_ALLOC_PARENT (my_output, proxy); | ||
1549 | 51698 | TEST_EQ_STR (my_output, "1701"); | ||
1550 | 51699 | called = 1; | ||
1551 | 51700 | } | ||
1552 | 51701 | |||
1553 | 51702 | while (! called) | ||
1554 | 51703 | dbus_connection_read_write_dispatch (conn, -1); | ||
1555 | 51704 | |||
1556 | 51705 | nih_free (proxy); | ||
1557 | 51706 | |||
1558 | 51707 | my_teardown (conn); | ||
1559 | 51708 | |||
1560 | 51709 | |||
1561 | 51710 | /* Check that an output argument of UInt64 type is marshalled | ||
1562 | 51711 | * correctly. | ||
1563 | 51712 | */ | ||
1564 | 51713 | TEST_FEATURE ("with UInt64 output argument"); | ||
1565 | 51714 | conn = my_setup (); | ||
1566 | 51715 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1567 | 51716 | |||
1568 | 51717 | uint64_arg = 0; | ||
1569 | 51718 | |||
1570 | 51719 | ret = proxy_str_to_uint64 (proxy, "1701", &uint64_arg); | ||
1571 | 51720 | |||
1572 | 51721 | TEST_EQ (ret, 0); | ||
1573 | 51722 | |||
1574 | 51723 | TEST_EQ (uint64_arg, 1701); | ||
1575 | 51724 | |||
1576 | 51725 | nih_free (proxy); | ||
1577 | 51726 | |||
1578 | 51727 | my_teardown (conn); | ||
1579 | 51728 | |||
1580 | 51729 | |||
1581 | 51730 | /* Check that an output argument of UInt64 type is marshalled | ||
1582 | 51731 | * correctly for asynchronous calls. | ||
1583 | 51732 | */ | ||
1584 | 51733 | TEST_FEATURE ("with UInt64 output argument (async)"); | ||
1585 | 51734 | conn = my_setup (); | ||
1586 | 51735 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1587 | 51736 | |||
1588 | 51737 | auto void with_uint64_output_argument (NihDBusProxy *my_proxy, char *userdata, typeof(uint64_arg) my_uint64_arg); | ||
1589 | 51738 | |||
1590 | 51739 | called = 0; | ||
1591 | 51740 | |||
1592 | 51741 | ret = proxy_str_to_uint64_async (proxy, "65", (ProxyStrToUint64Callback)with_uint64_output_argument, async_fail_errback, "user data"); | ||
1593 | 51742 | |||
1594 | 51743 | TEST_EQ (ret, 0); | ||
1595 | 51744 | |||
1596 | 51745 | void with_uint64_output_argument (NihDBusProxy *my_proxy, char *userdata, typeof(uint64_arg) my_uint64_arg) | ||
1597 | 51746 | { | ||
1598 | 51747 | TEST_EQ_P (my_proxy, proxy); | ||
1599 | 51748 | TEST_EQ_STR (userdata, "user data"); | ||
1600 | 51749 | TEST_EQ (my_uint64_arg, 65); | ||
1601 | 51750 | called = 1; | ||
1602 | 51751 | } | ||
1603 | 51752 | |||
1604 | 51753 | while (! called) | ||
1605 | 51754 | dbus_connection_read_write_dispatch (conn, -1); | ||
1606 | 51755 | |||
1607 | 51756 | nih_free (proxy); | ||
1608 | 51757 | |||
1609 | 51758 | my_teardown (conn); | ||
1610 | 51759 | |||
1611 | 51760 | |||
1612 | 51761 | /* Check that an input argument of Double type is dispatched | ||
1613 | 51762 | * correctly. | ||
1614 | 51763 | */ | ||
1615 | 51764 | TEST_FEATURE ("with Double input argument"); | ||
1616 | 51765 | conn = my_setup (); | ||
1617 | 51766 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1618 | 51767 | |||
1619 | 51768 | output = NULL; | ||
1620 | 51769 | |||
1621 | 51770 | ret = proxy_double_to_str (proxy, 3.141592, &output); | ||
1622 | 51771 | |||
1623 | 51772 | TEST_EQ (ret, 0); | ||
1624 | 51773 | |||
1625 | 51774 | TEST_NE_P (output, NULL); | ||
1626 | 51775 | TEST_ALLOC_PARENT (output, proxy); | ||
1627 | 51776 | TEST_EQ_STR (output, "3.141592"); | ||
1628 | 51777 | |||
1629 | 51778 | nih_free (proxy); | ||
1630 | 51779 | |||
1631 | 51780 | my_teardown (conn); | ||
1632 | 51781 | |||
1633 | 51782 | |||
1634 | 51783 | /* Check that an input argument of Double type is dispatched | ||
1635 | 51784 | * correctly for an asynchronous call. | ||
1636 | 51785 | */ | ||
1637 | 51786 | TEST_FEATURE ("with Double input argument (async)"); | ||
1638 | 51787 | conn = my_setup (); | ||
1639 | 51788 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1640 | 51789 | |||
1641 | 51790 | auto void with_double_input_argument (NihDBusProxy *proxy, char *userdata, char *output); | ||
1642 | 51791 | |||
1643 | 51792 | called = 0; | ||
1644 | 51793 | ret = proxy_double_to_str_async (proxy, 3.141592, (ProxyDoubleToStrCallback)with_double_input_argument, async_fail_errback, "user data" ); | ||
1645 | 51794 | |||
1646 | 51795 | TEST_EQ (ret, 0); | ||
1647 | 51796 | |||
1648 | 51797 | void with_double_input_argument (NihDBusProxy *my_proxy, char *userdata, char *my_output) | ||
1649 | 51798 | { | ||
1650 | 51799 | TEST_EQ_STR (userdata, "user data"); | ||
1651 | 51800 | TEST_EQ_P (my_proxy, proxy); | ||
1652 | 51801 | TEST_NE_P (my_output, NULL); | ||
1653 | 51802 | TEST_ALLOC_PARENT (my_output, proxy); | ||
1654 | 51803 | TEST_EQ_STR (my_output, "3.141592"); | ||
1655 | 51804 | called = 1; | ||
1656 | 51805 | } | ||
1657 | 51806 | |||
1658 | 51807 | while (! called) | ||
1659 | 51808 | dbus_connection_read_write_dispatch (conn, -1); | ||
1660 | 51809 | |||
1661 | 51810 | nih_free (proxy); | ||
1662 | 51811 | |||
1663 | 51812 | my_teardown (conn); | ||
1664 | 51813 | |||
1665 | 51814 | |||
1666 | 51815 | /* Check that an output argument of Double type is marshalled | ||
1667 | 51816 | * correctly. | ||
1668 | 51817 | */ | ||
1669 | 51818 | TEST_FEATURE ("with Double output argument"); | ||
1670 | 51819 | conn = my_setup (); | ||
1671 | 51820 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1672 | 51821 | |||
1673 | 51822 | double_arg = 0; | ||
1674 | 51823 | |||
1675 | 51824 | ret = proxy_str_to_double (proxy, "3.141592", &double_arg); | ||
1676 | 51825 | |||
1677 | 51826 | TEST_EQ (ret, 0); | ||
1678 | 51827 | |||
1679 | 51828 | TEST_EQ (double_arg, 3.141592); | ||
1680 | 51829 | |||
1681 | 51830 | nih_free (proxy); | ||
1682 | 51831 | |||
1683 | 51832 | my_teardown (conn); | ||
1684 | 51833 | |||
1685 | 51834 | |||
1686 | 51835 | /* Check that an output argument of Double type is marshalled | ||
1687 | 51836 | * correctly for asynchronous calls. | ||
1688 | 51837 | */ | ||
1689 | 51838 | TEST_FEATURE ("with Double output argument (async)"); | ||
1690 | 51839 | conn = my_setup (); | ||
1691 | 51840 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1692 | 51841 | |||
1693 | 51842 | auto void with_double_output_argument (NihDBusProxy *my_proxy, char *userdata, typeof(double_arg) my_double_arg); | ||
1694 | 51843 | |||
1695 | 51844 | called = 0; | ||
1696 | 51845 | |||
1697 | 51846 | ret = proxy_str_to_double_async (proxy, "3.141592", (ProxyStrToDoubleCallback)with_double_output_argument, async_fail_errback, "user data"); | ||
1698 | 51847 | |||
1699 | 51848 | TEST_EQ (ret, 0); | ||
1700 | 51849 | |||
1701 | 51850 | void with_double_output_argument (NihDBusProxy *my_proxy, char *userdata, typeof(double_arg) my_double_arg) | ||
1702 | 51851 | { | ||
1703 | 51852 | TEST_EQ_P (my_proxy, proxy); | ||
1704 | 51853 | TEST_EQ_STR (userdata, "user data"); | ||
1705 | 51854 | TEST_EQ (my_double_arg, 3.141592); | ||
1706 | 51855 | called = 1; | ||
1707 | 51856 | } | ||
1708 | 51857 | |||
1709 | 51858 | while (! called) | ||
1710 | 51859 | dbus_connection_read_write_dispatch (conn, -1); | ||
1711 | 51860 | |||
1712 | 51861 | nih_free (proxy); | ||
1713 | 51862 | |||
1714 | 51863 | my_teardown (conn); | ||
1715 | 51864 | |||
1716 | 51865 | |||
1717 | 51866 | /* Check that an input argument of ObjectPath type is dispatched | ||
1718 | 51867 | * correctly. | ||
1719 | 51868 | */ | ||
1720 | 51869 | TEST_FEATURE ("with ObjectPath input argument"); | ||
1721 | 51870 | conn = my_setup (); | ||
1722 | 51871 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1723 | 51872 | |||
1724 | 51873 | output = NULL; | ||
1725 | 51874 | |||
1726 | 51875 | ret = proxy_object_path_to_str (proxy, "/com/netsplit/Nih", &output); | ||
1727 | 51876 | |||
1728 | 51877 | TEST_EQ (ret, 0); | ||
1729 | 51878 | |||
1730 | 51879 | TEST_NE_P (output, NULL); | ||
1731 | 51880 | TEST_ALLOC_PARENT (output, proxy); | ||
1732 | 51881 | TEST_EQ_STR (output, "/com/netsplit/Nih"); | ||
1733 | 51882 | |||
1734 | 51883 | nih_free (proxy); | ||
1735 | 51884 | |||
1736 | 51885 | my_teardown (conn); | ||
1737 | 51886 | |||
1738 | 51887 | |||
1739 | 51888 | /* Check that an input argument of ObjectPath type is dispatched | ||
1740 | 51889 | * correctly for an asynchronous call. | ||
1741 | 51890 | */ | ||
1742 | 51891 | TEST_FEATURE ("with ObjectPath input argument (async)"); | ||
1743 | 51892 | conn = my_setup (); | ||
1744 | 51893 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1745 | 51894 | |||
1746 | 51895 | auto void with_object_path_input_argument (NihDBusProxy *proxy, char *userdata, char *output); | ||
1747 | 51896 | |||
1748 | 51897 | called = 0; | ||
1749 | 51898 | ret = proxy_object_path_to_str_async (proxy, "/com/netsplit/Nih", (ProxyObjectPathToStrCallback)with_object_path_input_argument, async_fail_errback, "user data" ); | ||
1750 | 51899 | |||
1751 | 51900 | TEST_EQ (ret, 0); | ||
1752 | 51901 | |||
1753 | 51902 | void with_object_path_input_argument (NihDBusProxy *my_proxy, char *userdata, char *my_output) | ||
1754 | 51903 | { | ||
1755 | 51904 | TEST_EQ_STR (userdata, "user data"); | ||
1756 | 51905 | TEST_EQ_P (my_proxy, proxy); | ||
1757 | 51906 | TEST_NE_P (my_output, NULL); | ||
1758 | 51907 | TEST_ALLOC_PARENT (my_output, proxy); | ||
1759 | 51908 | TEST_EQ_STR (my_output, "/com/netsplit/Nih"); | ||
1760 | 51909 | called = 1; | ||
1761 | 51910 | } | ||
1762 | 51911 | |||
1763 | 51912 | while (! called) | ||
1764 | 51913 | dbus_connection_read_write_dispatch (conn, -1); | ||
1765 | 51914 | |||
1766 | 51915 | nih_free (proxy); | ||
1767 | 51916 | |||
1768 | 51917 | my_teardown (conn); | ||
1769 | 51918 | |||
1770 | 51919 | |||
1771 | 51920 | /* Check that an output argument of ObjectPath type is marshalled | ||
1772 | 51921 | * correctly. | ||
1773 | 51922 | */ | ||
1774 | 51923 | TEST_FEATURE ("with ObjectPath output argument"); | ||
1775 | 51924 | conn = my_setup (); | ||
1776 | 51925 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1777 | 51926 | |||
1778 | 51927 | output = NULL; | ||
1779 | 51928 | |||
1780 | 51929 | ret = proxy_str_to_object_path (proxy, "/com/netsplit/Nih", &output); | ||
1781 | 51930 | |||
1782 | 51931 | TEST_EQ (ret, 0); | ||
1783 | 51932 | |||
1784 | 51933 | TEST_NE_P (output, NULL); | ||
1785 | 51934 | TEST_ALLOC_PARENT (output, proxy); | ||
1786 | 51935 | TEST_EQ_STR (output, "/com/netsplit/Nih"); | ||
1787 | 51936 | |||
1788 | 51937 | nih_free (proxy); | ||
1789 | 51938 | |||
1790 | 51939 | my_teardown (conn); | ||
1791 | 51940 | |||
1792 | 51941 | |||
1793 | 51942 | /* Check that an output argument of ObjectPath type is marshalled | ||
1794 | 51943 | * correctly for asynchronous calls. | ||
1795 | 51944 | */ | ||
1796 | 51945 | TEST_FEATURE ("with ObjectPath output argument (async)"); | ||
1797 | 51946 | conn = my_setup (); | ||
1798 | 51947 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1799 | 51948 | |||
1800 | 51949 | auto void with_object_path_output_argument (NihDBusProxy *my_proxy, char *userdata, char *my_object_path_arg); | ||
1801 | 51950 | |||
1802 | 51951 | called = 0; | ||
1803 | 51952 | |||
1804 | 51953 | ret = proxy_str_to_object_path_async (proxy, "/com/netsplit/Nih", (ProxyStrToObjectPathCallback)with_object_path_output_argument, async_fail_errback, "user data"); | ||
1805 | 51954 | |||
1806 | 51955 | TEST_EQ (ret, 0); | ||
1807 | 51956 | |||
1808 | 51957 | void with_object_path_output_argument (NihDBusProxy *my_proxy, char *userdata, char *my_object_path_arg) | ||
1809 | 51958 | { | ||
1810 | 51959 | TEST_EQ_P (my_proxy, proxy); | ||
1811 | 51960 | TEST_EQ_STR (userdata, "user data"); | ||
1812 | 51961 | TEST_NE_P (my_object_path_arg, NULL); | ||
1813 | 51962 | TEST_ALLOC_PARENT (my_object_path_arg, proxy); | ||
1814 | 51963 | TEST_EQ_STR (my_object_path_arg, "/com/netsplit/Nih"); | ||
1815 | 51964 | called = 1; | ||
1816 | 51965 | } | ||
1817 | 51966 | |||
1818 | 51967 | while (! called) | ||
1819 | 51968 | dbus_connection_read_write_dispatch (conn, -1); | ||
1820 | 51969 | |||
1821 | 51970 | nih_free (proxy); | ||
1822 | 51971 | |||
1823 | 51972 | my_teardown (conn); | ||
1824 | 51973 | |||
1825 | 51974 | |||
1826 | 51975 | /* Check that an input argument of Signature type is dispatched | ||
1827 | 51976 | * correctly. | ||
1828 | 51977 | */ | ||
1829 | 51978 | TEST_FEATURE ("with Signature input argument"); | ||
1830 | 51979 | conn = my_setup (); | ||
1831 | 51980 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1832 | 51981 | |||
1833 | 51982 | output = NULL; | ||
1834 | 51983 | |||
1835 | 51984 | ret = proxy_signature_to_str (proxy, "a{sv}", &output); | ||
1836 | 51985 | |||
1837 | 51986 | TEST_EQ (ret, 0); | ||
1838 | 51987 | |||
1839 | 51988 | TEST_NE_P (output, NULL); | ||
1840 | 51989 | TEST_ALLOC_PARENT (output, proxy); | ||
1841 | 51990 | TEST_EQ_STR (output, "a{sv}"); | ||
1842 | 51991 | |||
1843 | 51992 | nih_free (proxy); | ||
1844 | 51993 | |||
1845 | 51994 | my_teardown (conn); | ||
1846 | 51995 | |||
1847 | 51996 | |||
1848 | 51997 | /* Check that an input argument of Signature type is dispatched | ||
1849 | 51998 | * correctly for an asynchronous call. | ||
1850 | 51999 | */ | ||
1851 | 52000 | TEST_FEATURE ("with Signature input argument (async)"); | ||
1852 | 52001 | conn = my_setup (); | ||
1853 | 52002 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1854 | 52003 | |||
1855 | 52004 | auto void with_signature_input_argument (NihDBusProxy *proxy, char *userdata, char *output); | ||
1856 | 52005 | |||
1857 | 52006 | called = 0; | ||
1858 | 52007 | ret = proxy_signature_to_str_async (proxy, "a{sv}", (ProxySignatureToStrCallback)with_signature_input_argument, async_fail_errback, "user data" ); | ||
1859 | 52008 | |||
1860 | 52009 | TEST_EQ (ret, 0); | ||
1861 | 52010 | |||
1862 | 52011 | void with_signature_input_argument (NihDBusProxy *my_proxy, char *userdata, char *my_output) | ||
1863 | 52012 | { | ||
1864 | 52013 | TEST_EQ_STR (userdata, "user data"); | ||
1865 | 52014 | TEST_EQ_P (my_proxy, proxy); | ||
1866 | 52015 | TEST_NE_P (my_output, NULL); | ||
1867 | 52016 | TEST_ALLOC_PARENT (my_output, proxy); | ||
1868 | 52017 | TEST_EQ_STR (my_output, "a{sv}"); | ||
1869 | 52018 | called = 1; | ||
1870 | 52019 | } | ||
1871 | 52020 | |||
1872 | 52021 | while (! called) | ||
1873 | 52022 | dbus_connection_read_write_dispatch (conn, -1); | ||
1874 | 52023 | |||
1875 | 52024 | nih_free (proxy); | ||
1876 | 52025 | |||
1877 | 52026 | my_teardown (conn); | ||
1878 | 52027 | |||
1879 | 52028 | |||
1880 | 52029 | /* Check that an output argument of Signature type is marshalled | ||
1881 | 52030 | * correctly. | ||
1882 | 52031 | */ | ||
1883 | 52032 | TEST_FEATURE ("with Signature output argument"); | ||
1884 | 52033 | conn = my_setup (); | ||
1885 | 52034 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1886 | 52035 | |||
1887 | 52036 | output = NULL; | ||
1888 | 52037 | |||
1889 | 52038 | ret = proxy_str_to_signature (proxy, "a{sv}", &output); | ||
1890 | 52039 | |||
1891 | 52040 | TEST_EQ (ret, 0); | ||
1892 | 52041 | |||
1893 | 52042 | TEST_NE_P (output, NULL); | ||
1894 | 52043 | TEST_ALLOC_PARENT (output, proxy); | ||
1895 | 52044 | TEST_EQ_STR (output, "a{sv}"); | ||
1896 | 52045 | |||
1897 | 52046 | nih_free (proxy); | ||
1898 | 52047 | |||
1899 | 52048 | my_teardown (conn); | ||
1900 | 52049 | |||
1901 | 52050 | |||
1902 | 52051 | /* Check that an output argument of Signature type is marshalled | ||
1903 | 52052 | * correctly for asynchronous calls. | ||
1904 | 52053 | */ | ||
1905 | 52054 | TEST_FEATURE ("with Signature output argument (async)"); | ||
1906 | 52055 | conn = my_setup (); | ||
1907 | 52056 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1908 | 52057 | |||
1909 | 52058 | auto void with_signature_output_argument (NihDBusProxy *my_proxy, char *userdata, char *my_signature_arg); | ||
1910 | 52059 | |||
1911 | 52060 | called = 0; | ||
1912 | 52061 | |||
1913 | 52062 | ret = proxy_str_to_signature_async (proxy, "a{sv}", (ProxyStrToSignatureCallback)with_signature_output_argument, async_fail_errback, "user data"); | ||
1914 | 52063 | |||
1915 | 52064 | TEST_EQ (ret, 0); | ||
1916 | 52065 | |||
1917 | 52066 | void with_signature_output_argument (NihDBusProxy *my_proxy, char *userdata, char *my_signature_arg) | ||
1918 | 52067 | { | ||
1919 | 52068 | TEST_EQ_P (my_proxy, proxy); | ||
1920 | 52069 | TEST_EQ_STR (userdata, "user data"); | ||
1921 | 52070 | TEST_NE_P (my_signature_arg, NULL); | ||
1922 | 52071 | TEST_ALLOC_PARENT (my_signature_arg, proxy); | ||
1923 | 52072 | TEST_EQ_STR (my_signature_arg, "a{sv}"); | ||
1924 | 52073 | called = 1; | ||
1925 | 52074 | } | ||
1926 | 52075 | |||
1927 | 52076 | while (! called) | ||
1928 | 52077 | dbus_connection_read_write_dispatch (conn, -1); | ||
1929 | 52078 | |||
1930 | 52079 | nih_free (proxy); | ||
1931 | 52080 | |||
1932 | 52081 | my_teardown (conn); | ||
1933 | 52082 | |||
1934 | 52083 | |||
1935 | 52084 | /* Check that an input argument of Array type with Int32 members | ||
1936 | 52085 | * is dispatched correctly. | ||
1937 | 52086 | */ | ||
1938 | 52087 | TEST_FEATURE ("with Int32 Array input argument"); | ||
1939 | 52088 | conn = my_setup (); | ||
1940 | 52089 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1941 | 52090 | |||
1942 | 52091 | int32_array = nih_alloc (NULL, sizeof (int32_t) * 6); | ||
1943 | 52092 | int32_array[0] = 4; | ||
1944 | 52093 | int32_array[1] = 8; | ||
1945 | 52094 | int32_array[2] = 15; | ||
1946 | 52095 | int32_array[3] = 16; | ||
1947 | 52096 | int32_array[4] = 23; | ||
1948 | 52097 | int32_array[5] = 42; | ||
1949 | 52098 | array_len = 6; | ||
1950 | 52099 | |||
1951 | 52100 | output = NULL; | ||
1952 | 52101 | |||
1953 | 52102 | ret = proxy_int32_array_to_str (proxy, int32_array, array_len, | ||
1954 | 52103 | &output); | ||
1955 | 52104 | |||
1956 | 52105 | TEST_EQ (ret, 0); | ||
1957 | 52106 | |||
1958 | 52107 | TEST_NE_P (output, NULL); | ||
1959 | 52108 | TEST_ALLOC_PARENT (output, proxy); | ||
1960 | 52109 | TEST_EQ_STR (output, "4 8 15 16 23 42"); | ||
1961 | 52110 | |||
1962 | 52111 | nih_free (proxy); | ||
1963 | 52112 | nih_free (int32_array); | ||
1964 | 52113 | |||
1965 | 52114 | my_teardown (conn); | ||
1966 | 52115 | |||
1967 | 52116 | |||
1968 | 52117 | /* Check that an input argument of Array type with Int32 members | ||
1969 | 52118 | * is dispatched correctly for asynchronous calls. | ||
1970 | 52119 | */ | ||
1971 | 52120 | TEST_FEATURE ("with Int32 Array input argument (async)"); | ||
1972 | 52121 | conn = my_setup (); | ||
1973 | 52122 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
1974 | 52123 | |||
1975 | 52124 | auto void with_int_array_input_argument (NihDBusProxy *proxy, char *userdata, char *output); | ||
1976 | 52125 | |||
1977 | 52126 | int32_array = nih_alloc (NULL, sizeof (int32_t) * 6); | ||
1978 | 52127 | int32_array[0] = 4; | ||
1979 | 52128 | int32_array[1] = 8; | ||
1980 | 52129 | int32_array[2] = 15; | ||
1981 | 52130 | int32_array[3] = 16; | ||
1982 | 52131 | int32_array[4] = 23; | ||
1983 | 52132 | int32_array[5] = 42; | ||
1984 | 52133 | array_len = 6; | ||
1985 | 52134 | |||
1986 | 52135 | called = 0; | ||
1987 | 52136 | ret = proxy_int32_array_to_str_async (proxy, int32_array, array_len, | ||
1988 | 52137 | (ProxyInt32ArrayToStrCallback)with_int_array_input_argument, async_fail_errback, | ||
1989 | 52138 | "user data"); | ||
1990 | 52139 | |||
1991 | 52140 | TEST_EQ (ret, 0); | ||
1992 | 52141 | |||
1993 | 52142 | void with_int_array_input_argument (NihDBusProxy *my_proxy, char *userdata, char *my_output) | ||
1994 | 52143 | { | ||
1995 | 52144 | TEST_EQ_STR (userdata, "user data"); | ||
1996 | 52145 | TEST_EQ_P (my_proxy, proxy); | ||
1997 | 52146 | TEST_NE_P (my_output, NULL); | ||
1998 | 52147 | TEST_ALLOC_PARENT (my_output, proxy); | ||
1999 | 52148 | TEST_EQ_STR (my_output, "4 8 15 16 23 42"); | ||
2000 | 52149 | called = 1; | ||
2001 | 52150 | } | ||
2002 | 52151 | |||
2003 | 52152 | while (! called) | ||
2004 | 52153 | dbus_connection_read_write_dispatch (conn, -1); | ||
2005 | 52154 | |||
2006 | 52155 | nih_free (proxy); | ||
2007 | 52156 | nih_free (int32_array); | ||
2008 | 52157 | |||
2009 | 52158 | my_teardown (conn); | ||
2010 | 52159 | |||
2011 | 52160 | |||
2012 | 52161 | /* Check that an output argument of Array type with Int32 members | ||
2013 | 52162 | * is marshalled correctly. | ||
2014 | 52163 | */ | ||
2015 | 52164 | TEST_FEATURE ("with Int32 Array output argument"); | ||
2016 | 52165 | conn = my_setup (); | ||
2017 | 52166 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
2018 | 52167 | |||
2019 | 52168 | int32_array = NULL; | ||
2020 | 52169 | array_len = 0; | ||
2021 | 52170 | |||
2022 | 52171 | ret = proxy_str_to_int32_array (proxy, "4 8 15 16 23 42", | ||
2023 | 52172 | &int32_array, &array_len); | ||
2024 | 52173 | |||
2025 | 52174 | TEST_EQ (ret, 0); | ||
2026 | 52175 | |||
2027 | 52176 | TEST_NE_P (int32_array, NULL); | ||
2028 | 52177 | TEST_ALLOC_PARENT (int32_array, proxy); | ||
2029 | 52178 | TEST_EQ (array_len, 6); | ||
2030 | 52179 | TEST_EQ (int32_array[0], 4); | ||
2031 | 52180 | TEST_EQ (int32_array[1], 8); | ||
2032 | 52181 | TEST_EQ (int32_array[2], 15); | ||
2033 | 52182 | TEST_EQ (int32_array[3], 16); | ||
2034 | 52183 | TEST_EQ (int32_array[4], 23); | ||
2035 | 52184 | TEST_EQ (int32_array[5], 42); | ||
2036 | 52185 | |||
2037 | 52186 | nih_free (proxy); | ||
2038 | 52187 | |||
2039 | 52188 | my_teardown (conn); | ||
2040 | 52189 | |||
2041 | 52190 | |||
2042 | 52191 | /* Check that an output argument of Array type with Int32 members | ||
2043 | 52192 | * is marshalled correctly for asynchronous calls. | ||
2044 | 52193 | */ | ||
2045 | 52194 | TEST_FEATURE ("with Int32 Array output argument (async)"); | ||
2046 | 52195 | conn = my_setup (); | ||
2047 | 52196 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
2048 | 52197 | |||
2049 | 52198 | auto void with_int_array_output_argument (NihDBusProxy *my_proxy, char *userdata, int *my_intarray, int my_len); | ||
2050 | 52199 | |||
2051 | 52200 | called = 0; | ||
2052 | 52201 | ret = proxy_str_to_int32_array_async (proxy, "4 8 15 16 23 42", | ||
2053 | 52202 | (ProxyStrToInt32ArrayCallback)with_int_array_output_argument, async_fail_errback, "user data"); | ||
2054 | 52203 | |||
2055 | 52204 | TEST_EQ (ret, 0); | ||
2056 | 52205 | |||
2057 | 52206 | void with_int_array_output_argument (NihDBusProxy *my_proxy, char *userdata, int *my_intarray, int my_len) | ||
2058 | 52207 | { | ||
2059 | 52208 | TEST_EQ_STR (userdata, "user data"); | ||
2060 | 52209 | TEST_EQ_P (my_proxy, proxy); | ||
2061 | 52210 | TEST_NE_P (my_intarray, NULL); | ||
2062 | 52211 | TEST_ALLOC_PARENT (my_intarray, proxy); | ||
2063 | 52212 | TEST_EQ (my_len, 6); | ||
2064 | 52213 | TEST_EQ (my_intarray[0], 4); | ||
2065 | 52214 | TEST_EQ (my_intarray[1], 8); | ||
2066 | 52215 | TEST_EQ (my_intarray[2], 15); | ||
2067 | 52216 | TEST_EQ (my_intarray[3], 16); | ||
2068 | 52217 | TEST_EQ (my_intarray[4], 23); | ||
2069 | 52218 | TEST_EQ (my_intarray[5], 42); | ||
2070 | 52219 | called = 1; | ||
2071 | 52220 | } | ||
2072 | 52221 | |||
2073 | 52222 | while (! called) | ||
2074 | 52223 | dbus_connection_read_write_dispatch (conn, -1); | ||
2075 | 52224 | |||
2076 | 52225 | nih_free (proxy); | ||
2077 | 52226 | |||
2078 | 52227 | my_teardown (conn); | ||
2079 | 52228 | |||
2080 | 52229 | |||
2081 | 52230 | /* Check that an input argument of Array type with String members | ||
2082 | 52231 | * is dispatched correctly. | ||
2083 | 52232 | */ | ||
2084 | 52233 | TEST_FEATURE ("with String Array input argument"); | ||
2085 | 52234 | conn = my_setup (); | ||
2086 | 52235 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
2087 | 52236 | |||
2088 | 52237 | str_array = nih_alloc (NULL, sizeof (char *) * 5); | ||
2089 | 52238 | str_array[0] = "this"; | ||
2090 | 52239 | str_array[1] = "is"; | ||
2091 | 52240 | str_array[2] = "a"; | ||
2092 | 52241 | str_array[3] = "test"; | ||
2093 | 52242 | str_array[4] = NULL; | ||
2094 | 52243 | |||
2095 | 52244 | output = NULL; | ||
2096 | 52245 | |||
2097 | 52246 | ret = proxy_str_array_to_str (proxy, str_array, &output); | ||
2098 | 52247 | |||
2099 | 52248 | TEST_EQ (ret, 0); | ||
2100 | 52249 | |||
2101 | 52250 | TEST_NE_P (output, NULL); | ||
2102 | 52251 | TEST_ALLOC_PARENT (output, proxy); | ||
2103 | 52252 | TEST_EQ_STR (output, "this is a test"); | ||
2104 | 52253 | |||
2105 | 52254 | nih_free (proxy); | ||
2106 | 52255 | nih_free (str_array); | ||
2107 | 52256 | |||
2108 | 52257 | my_teardown (conn); | ||
2109 | 52258 | |||
2110 | 52259 | |||
2111 | 52260 | /* Check that an input argument of Array type with String members | ||
2112 | 52261 | * is dispatched correctly for async calls. | ||
2113 | 52262 | */ | ||
2114 | 52263 | TEST_FEATURE ("with String Array input argument (async)"); | ||
2115 | 52264 | conn = my_setup (); | ||
2116 | 52265 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
2117 | 52266 | |||
2118 | 52267 | auto void with_str_array_input_argument (NihDBusProxy *my_proxy, char *userdata, char *my_output); | ||
2119 | 52268 | |||
2120 | 52269 | str_array = nih_alloc (NULL, sizeof (char *) * 5); | ||
2121 | 52270 | str_array[0] = "this"; | ||
2122 | 52271 | str_array[1] = "is"; | ||
2123 | 52272 | str_array[2] = "a"; | ||
2124 | 52273 | str_array[3] = "test"; | ||
2125 | 52274 | str_array[4] = NULL; | ||
2126 | 52275 | |||
2127 | 52276 | called = 0; | ||
2128 | 52277 | ret = proxy_str_array_to_str_async (proxy, str_array, (ProxyStrArrayToStrCallback)with_str_array_input_argument, async_fail_errback, "user data"); | ||
2129 | 52278 | |||
2130 | 52279 | TEST_EQ (ret, 0); | ||
2131 | 52280 | |||
2132 | 52281 | void with_str_array_input_argument (NihDBusProxy *my_proxy, char *userdata, char *my_output) | ||
2133 | 52282 | { | ||
2134 | 52283 | TEST_EQ_STR (userdata, "user data"); | ||
2135 | 52284 | TEST_EQ_P (my_proxy, proxy); | ||
2136 | 52285 | TEST_NE_P (my_output, NULL); | ||
2137 | 52286 | TEST_ALLOC_PARENT (my_output, proxy); | ||
2138 | 52287 | TEST_EQ_STR (my_output, "this is a test"); | ||
2139 | 52288 | called = 1; | ||
2140 | 52289 | } | ||
2141 | 52290 | |||
2142 | 52291 | while (! called) | ||
2143 | 52292 | dbus_connection_read_write_dispatch (conn, -1); | ||
2144 | 52293 | |||
2145 | 52294 | nih_free (proxy); | ||
2146 | 52295 | nih_free (str_array); | ||
2147 | 52296 | |||
2148 | 52297 | my_teardown (conn); | ||
2149 | 52298 | |||
2150 | 52299 | |||
2151 | 52300 | /* Check that an output argument of Array type with String members | ||
2152 | 52301 | * is marshalled correctly. | ||
2153 | 52302 | */ | ||
2154 | 52303 | TEST_FEATURE ("with String Array output argument"); | ||
2155 | 52304 | conn = my_setup (); | ||
2156 | 52305 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
2157 | 52306 | |||
2158 | 52307 | str_array = NULL; | ||
2159 | 52308 | |||
2160 | 52309 | ret = proxy_str_to_str_array (proxy, "this is a test", &str_array); | ||
2161 | 52310 | |||
2162 | 52311 | TEST_EQ (ret, 0); | ||
2163 | 52312 | |||
2164 | 52313 | TEST_NE_P (str_array, NULL); | ||
2165 | 52314 | TEST_ALLOC_PARENT (str_array, proxy); | ||
2166 | 52315 | TEST_EQ_STR (str_array[0], "this"); | ||
2167 | 52316 | TEST_EQ_STR (str_array[1], "is"); | ||
2168 | 52317 | TEST_EQ_STR (str_array[2], "a"); | ||
2169 | 52318 | TEST_EQ_STR (str_array[3], "test"); | ||
2170 | 52319 | TEST_EQ_P (str_array[4], NULL); | ||
2171 | 52320 | |||
2172 | 52321 | nih_free (proxy); | ||
2173 | 52322 | |||
2174 | 52323 | my_teardown (conn); | ||
2175 | 52324 | |||
2176 | 52325 | |||
2177 | 52326 | /* Check that an output argument of Array type with String members | ||
2178 | 52327 | * is marshalled correctly for asynchronous calls. | ||
2179 | 52328 | */ | ||
2180 | 52329 | TEST_FEATURE ("with String Array output argument (async)"); | ||
2181 | 52330 | conn = my_setup (); | ||
2182 | 52331 | proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih"); | ||
2183 | 52332 | |||
2184 | 52333 | auto void with_str_array_output_argument (NihDBusProxy *my_proxy, char *userdata, char **my_str_array); | ||
2185 | 52334 | |||
2186 | 52335 | called = 0; | ||
2187 | 52336 | |||
2188 | 52337 | ret = proxy_str_to_str_array_async (proxy, "this is a test", (ProxyStrToStrArrayCallback)with_str_array_output_argument, async_fail_errback, "user data"); | ||
2189 | 52338 | |||
2190 | 52339 | TEST_EQ (ret, 0); | ||
2191 | 52340 | |||
2192 | 52341 | void with_str_array_output_argument (NihDBusProxy *my_proxy, char *userdata, char **my_str_array) | ||
2193 | 52342 | { | ||
2194 | 52343 | TEST_EQ_STR (userdata, "user data"); | ||
2195 | 52344 | TEST_EQ_P (my_proxy, proxy); | ||
2196 | 52345 | TEST_NE_P (my_str_array, NULL); | ||
2197 | 52346 | TEST_ALLOC_PARENT (my_str_array, proxy); | ||
2198 | 52347 | TEST_EQ_STR (my_str_array[0], "this"); | ||
2199 | 52348 | TEST_EQ_STR (my_str_array[1], "is"); | ||
2200 | 52349 | TEST_EQ_STR (my_str_array[2], "a"); | ||
2201 | 52350 | TEST_EQ_STR (my_str_array[3], "test"); | ||
2202 | 52351 | TEST_EQ_P (my_str_array[4], NULL); | ||
2203 | 52352 | called = 1; | ||
2204 | 52353 | } | ||
2205 | 52354 | |||
2206 | 52355 | while (! called) | ||
2207 | 52356 | dbus_connection_read_write_dispatch (conn, -1); | ||
2208 | 52357 | |||
2209 | 52358 | nih_free (proxy); | ||
2210 | 52359 | |||
2211 | 52360 | my_teardown (conn); | ||
2212 | 52361 | } | ||
2213 | 52362 | |||
2214 | 52363 | |||
2215 | 52364 | static void | ||
2216 | 52365 | async_fail_errback (NihDBusProxy *my_proxy, void *userdata) | ||
2217 | 52366 | { | ||
2218 | 52367 | TEST_FAILED ("Called wrong asynchronous handler"); | ||
2219 | 52368 | >>>>>>> MERGE-SOURCE | ||
2220 | 50207 | } | 52369 | } |
2221 | 50208 | 52370 | ||
2222 | 50209 | 52371 | ||
2223 | 50210 | 52372 | ||
2224 | === added file 'nih/nih_dbus_tool.py.OTHER' | |||
2225 | --- nih/nih_dbus_tool.py.OTHER 1970-01-01 00:00:00 +0000 | |||
2226 | +++ nih/nih_dbus_tool.py.OTHER 2009-10-03 06:00:27 +0000 | |||
2227 | @@ -0,0 +1,2635 @@ | |||
2228 | 1 | #!/usr/bin/env python | ||
2229 | 2 | # -*- coding: utf-8 -*- | ||
2230 | 3 | # | ||
2231 | 4 | # nih_dbus_tool.py - D-Bus binding generation tool | ||
2232 | 5 | # | ||
2233 | 6 | # Copyright © 2008 Scott James Remnant <scott@netsplit.com>. | ||
2234 | 7 | # | ||
2235 | 8 | # This program is free software; you can redistribute it and/or modify | ||
2236 | 9 | # it under the terms of the GNU General Public License as published by | ||
2237 | 10 | # the Free Software Foundation; either version 2 of the License, or | ||
2238 | 11 | # (at your option) any later version. | ||
2239 | 12 | # | ||
2240 | 13 | # This program is distributed in the hope that it will be useful, | ||
2241 | 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2242 | 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2243 | 16 | # GNU General Public License for more details. | ||
2244 | 17 | # | ||
2245 | 18 | # You should have received a copy of the GNU General Public License | ||
2246 | 19 | # along with this program; if not, write to the Free Software | ||
2247 | 20 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
2248 | 21 | |||
2249 | 22 | import os | ||
2250 | 23 | import re | ||
2251 | 24 | import sys | ||
2252 | 25 | |||
2253 | 26 | from optparse import OptionParser | ||
2254 | 27 | from xml.etree import ElementTree | ||
2255 | 28 | |||
2256 | 29 | |||
2257 | 30 | # Replaced by autoconf-obtained strings | ||
2258 | 31 | PACKAGE_NAME = "@PACKAGE_NAME@" | ||
2259 | 32 | PACKAGE_COPYRIGHT = "@PACKAGE_COPYRIGHT@" | ||
2260 | 33 | |||
2261 | 34 | # Prefix for external functions | ||
2262 | 35 | extern_prefix = "dbus" | ||
2263 | 36 | |||
2264 | 37 | # Generator mode | ||
2265 | 38 | mode = "object" | ||
2266 | 39 | |||
2267 | 40 | |||
2268 | 41 | # Conversion for external C names | ||
2269 | 42 | NAME_RE = re.compile(r'([a-z0-9])([A-Z])') | ||
2270 | 43 | |||
2271 | 44 | # Namespace for our own tags and attributes | ||
2272 | 45 | XMLNS = "http://www.netsplit.com/nih/dbus" | ||
2273 | 46 | |||
2274 | 47 | |||
2275 | 48 | # arrays of arrays with length (ends up being an array of a struct) | ||
2276 | 49 | # - instead of using self.type.c_type and name, we should iterate | ||
2277 | 50 | # over its vars? -- array will have foo_elem and foo_elem_len | ||
2278 | 51 | # | ||
2279 | 52 | # struct type | ||
2280 | 53 | # variant type (at least fallback to requiring them to define the marshal?) | ||
2281 | 54 | # - one way might be just to pass a container or fake message? | ||
2282 | 55 | |||
2283 | 56 | # "proxy" mode: | ||
2284 | 57 | # async function dispatch | ||
2285 | 58 | # function dispatch with no reply | ||
2286 | 59 | # configurable timeout, autostart, etc. for function dispatch | ||
2287 | 60 | # signal marshal | ||
2288 | 61 | # - called when a signal we're expecting happens, will have a message | ||
2289 | 62 | # object and will call a handler with that -- need an object equivalent, | ||
2290 | 63 | # "proxy" likely | ||
2291 | 64 | |||
2292 | 65 | |||
2293 | 66 | class DBusType(object): | ||
2294 | 67 | """D-Bus type. | ||
2295 | 68 | |||
2296 | 69 | This abstract class represents the base of all D-Bus types that we | ||
2297 | 70 | can handle. | ||
2298 | 71 | """ | ||
2299 | 72 | |||
2300 | 73 | @classmethod | ||
2301 | 74 | def fromElement(cls, elem): | ||
2302 | 75 | name = elem.get("name") | ||
2303 | 76 | if name is None: | ||
2304 | 77 | raise AttributeError, "Argument name may not be null" | ||
2305 | 78 | |||
2306 | 79 | type = elem.get("type") | ||
2307 | 80 | if type is None: | ||
2308 | 81 | raise AttributeError, "Argument type may not be null" | ||
2309 | 82 | |||
2310 | 83 | direction = elem.get("direction", "in") | ||
2311 | 84 | if direction not in ( "in", "out" ): | ||
2312 | 85 | raise AttributeError, "Direction must be 'in' or 'out'" | ||
2313 | 86 | |||
2314 | 87 | type_cls = cls.typeOf(type) | ||
2315 | 88 | return type_cls.fromArgument(name, direction) | ||
2316 | 89 | |||
2317 | 90 | @classmethod | ||
2318 | 91 | def fromArgument(cls, name, direction="in"): | ||
2319 | 92 | self = cls(name) | ||
2320 | 93 | self.direction = direction | ||
2321 | 94 | |||
2322 | 95 | return self | ||
2323 | 96 | |||
2324 | 97 | def __init__(self, name): | ||
2325 | 98 | self.name = name | ||
2326 | 99 | |||
2327 | 100 | @classmethod | ||
2328 | 101 | def typeOf(cls, code): | ||
2329 | 102 | """Return type for given type signature code.""" | ||
2330 | 103 | if code == "y": | ||
2331 | 104 | return DBusByte | ||
2332 | 105 | elif code == "b": | ||
2333 | 106 | return DBusBoolean | ||
2334 | 107 | elif code == "n": | ||
2335 | 108 | return DBusInt16 | ||
2336 | 109 | elif code == "q": | ||
2337 | 110 | return DBusUInt16 | ||
2338 | 111 | elif code == "i": | ||
2339 | 112 | return DBusInt32 | ||
2340 | 113 | elif code == "u": | ||
2341 | 114 | return DBusUInt32 | ||
2342 | 115 | elif code == "x": | ||
2343 | 116 | return DBusInt64 | ||
2344 | 117 | elif code == "t": | ||
2345 | 118 | return DBusUInt64 | ||
2346 | 119 | elif code == "d": | ||
2347 | 120 | return DBusDouble | ||
2348 | 121 | elif code == "s": | ||
2349 | 122 | return DBusString | ||
2350 | 123 | elif code == "o": | ||
2351 | 124 | return DBusObjectPath | ||
2352 | 125 | elif code == "g": | ||
2353 | 126 | return DBusSignature | ||
2354 | 127 | elif code[0] == "a": | ||
2355 | 128 | return DBusArray.forType(cls.typeOf(code[-1])) | ||
2356 | 129 | else: | ||
2357 | 130 | raise AttributeError, "Unknown or unhandled type '%s'" % code | ||
2358 | 131 | |||
2359 | 132 | def realType(self, c_type, pointer=False, const=False): | ||
2360 | 133 | """Real type. | ||
2361 | 134 | |||
2362 | 135 | Returns a string containing the C type name for this type, with | ||
2363 | 136 | pointer and const modifications added. | ||
2364 | 137 | """ | ||
2365 | 138 | if pointer: | ||
2366 | 139 | c_type = pointerify(c_type) | ||
2367 | 140 | if const: | ||
2368 | 141 | c_type = constify(c_type) | ||
2369 | 142 | |||
2370 | 143 | return c_type | ||
2371 | 144 | |||
2372 | 145 | def signature(self, pointer=False, const=False): | ||
2373 | 146 | """Type signature. | ||
2374 | 147 | |||
2375 | 148 | Returns a string containing the D-Bus type signature for this type. | ||
2376 | 149 | """ | ||
2377 | 150 | return None | ||
2378 | 151 | |||
2379 | 152 | def vars(self, pointer=False, const=False): | ||
2380 | 153 | """Variable type and name. | ||
2381 | 154 | |||
2382 | 155 | Returns a list containing a single tuple of the C type used for this | ||
2383 | 156 | type and the name given when creating the instance. | ||
2384 | 157 | """ | ||
2385 | 158 | return [] | ||
2386 | 159 | |||
2387 | 160 | def names(self, pointer=False, const=False): | ||
2388 | 161 | """Variable name. | ||
2389 | 162 | |||
2390 | 163 | Returns a list containing a single string; the name given when creating | ||
2391 | 164 | the instance. | ||
2392 | 165 | """ | ||
2393 | 166 | return [] | ||
2394 | 167 | |||
2395 | 168 | def locals(self, pointer=False, const=False): | ||
2396 | 169 | """Local variable type and name. | ||
2397 | 170 | |||
2398 | 171 | Returns a list containing necessary local variables for iteration | ||
2399 | 172 | of this type. | ||
2400 | 173 | """ | ||
2401 | 174 | return [] | ||
2402 | 175 | |||
2403 | 176 | def marshal(self, iter_name, parent, type_error, mem_error, | ||
2404 | 177 | pointer=False, const=False): | ||
2405 | 178 | """Marshalling code. | ||
2406 | 179 | |||
2407 | 180 | Returns a string containing the code that will marshal from an | ||
2408 | 181 | iterator with the name given into a local variable with the | ||
2409 | 182 | type and name as returned by vars(). | ||
2410 | 183 | """ | ||
2411 | 184 | return None | ||
2412 | 185 | |||
2413 | 186 | def dispatch(self, iter_name, mem_error, | ||
2414 | 187 | pointer=False, const=False): | ||
2415 | 188 | """Dispatching code. | ||
2416 | 189 | |||
2417 | 190 | Returns a string containing the code that will dispatch from a | ||
2418 | 191 | local variable with the type and name as returned by vars() to | ||
2419 | 192 | an iterator with the name given. | ||
2420 | 193 | """ | ||
2421 | 194 | return None | ||
2422 | 195 | |||
2423 | 196 | |||
2424 | 197 | class DBusBasicType(DBusType): | ||
2425 | 198 | """D-Bus basic type. | ||
2426 | 199 | |||
2427 | 200 | This abstract class represents the base of all basic D-Bus types that | ||
2428 | 201 | we can handle. These share the code to marshal from a DBusMessage into | ||
2429 | 202 | a variable and dispatch from a variable back into a DBusMessage. | ||
2430 | 203 | """ | ||
2431 | 204 | |||
2432 | 205 | def signature(self, pointer=False, const=False): | ||
2433 | 206 | """Type signature. | ||
2434 | 207 | |||
2435 | 208 | Returns a string containing the D-Bus type signature for this type. | ||
2436 | 209 | """ | ||
2437 | 210 | return self.dbus_code | ||
2438 | 211 | |||
2439 | 212 | def vars(self, pointer=False, const=False): | ||
2440 | 213 | """Variable type and name. | ||
2441 | 214 | |||
2442 | 215 | Returns a list containing a single tuple of the C type used for this | ||
2443 | 216 | type and the name given when creating the instance. | ||
2444 | 217 | """ | ||
2445 | 218 | return [ ( self.realType(self.c_type, pointer, const), self.name ) ] | ||
2446 | 219 | |||
2447 | 220 | def names(self, pointer=False, const=False): | ||
2448 | 221 | """Variable name. | ||
2449 | 222 | |||
2450 | 223 | Returns a list containing a single string; the name given when creating | ||
2451 | 224 | the instance. | ||
2452 | 225 | """ | ||
2453 | 226 | return [ self.name ] | ||
2454 | 227 | |||
2455 | 228 | def locals(self, pointer=False, const=False): | ||
2456 | 229 | """Local variable type and name. | ||
2457 | 230 | |||
2458 | 231 | Returns a list containing necessary local variables for iteration | ||
2459 | 232 | of this type. | ||
2460 | 233 | """ | ||
2461 | 234 | return [] | ||
2462 | 235 | |||
2463 | 236 | def marshal(self, iter_name, parent, type_error, mem_error, | ||
2464 | 237 | pointer=False, const=False): | ||
2465 | 238 | """Marshalling code. | ||
2466 | 239 | |||
2467 | 240 | Returns a string containing the code that will marshal from an | ||
2468 | 241 | iterator with the name given into a local variable with the | ||
2469 | 242 | type and name as returned by vars(). | ||
2470 | 243 | """ | ||
2471 | 244 | name = self.name | ||
2472 | 245 | if pointer: | ||
2473 | 246 | name = "*%s" % (name, ) | ||
2474 | 247 | |||
2475 | 248 | return """\ | ||
2476 | 249 | if (dbus_message_iter_get_arg_type (&%s) != %s) { | ||
2477 | 250 | %s | ||
2478 | 251 | } | ||
2479 | 252 | |||
2480 | 253 | dbus_message_iter_get_basic (&%s, &%s); | ||
2481 | 254 | |||
2482 | 255 | dbus_message_iter_next (&%s); | ||
2483 | 256 | """ % (iter_name, self.dbus_type, type_error, | ||
2484 | 257 | iter_name, name, | ||
2485 | 258 | iter_name) | ||
2486 | 259 | |||
2487 | 260 | def dispatch(self, iter_name, mem_error, | ||
2488 | 261 | pointer=False, const=False): | ||
2489 | 262 | """Dispatching code. | ||
2490 | 263 | |||
2491 | 264 | Returns a string containing the code that will dispatch from a | ||
2492 | 265 | local variable with the type and name as returned by vars() to | ||
2493 | 266 | an iterator with the name given. | ||
2494 | 267 | """ | ||
2495 | 268 | name = self.name | ||
2496 | 269 | if pointer: | ||
2497 | 270 | name = "*%s" % (name, ) | ||
2498 | 271 | |||
2499 | 272 | return """\ | ||
2500 | 273 | if (! dbus_message_iter_append_basic (&%s, %s, &%s)) { | ||
2501 | 274 | %s | ||
2502 | 275 | } | ||
2503 | 276 | """ % (iter_name, self.dbus_type, name, mem_error) | ||
2504 | 277 | |||
2505 | 278 | |||
2506 | 279 | class DBusByte(DBusBasicType): | ||
2507 | 280 | """D-Bus byte. | ||
2508 | 281 | |||
2509 | 282 | This class represents the D-Bus byte type and should be instantiated with | ||
2510 | 283 | the name of the variable. It shares marshalling and dispatch code with | ||
2511 | 284 | the other basic types. | ||
2512 | 285 | """ | ||
2513 | 286 | c_type = "uint8_t" | ||
2514 | 287 | dbus_code = "y" | ||
2515 | 288 | dbus_type = "DBUS_TYPE_BYTE" | ||
2516 | 289 | |||
2517 | 290 | class DBusBoolean(DBusBasicType): | ||
2518 | 291 | """D-Bus boolean. | ||
2519 | 292 | |||
2520 | 293 | This class represents the D-Bus boolean type and should be instantiated | ||
2521 | 294 | with the name of the variable. It shares marshalling and dispatch code | ||
2522 | 295 | with the other basic types. | ||
2523 | 296 | """ | ||
2524 | 297 | c_type = "int" | ||
2525 | 298 | dbus_code = "b" | ||
2526 | 299 | dbus_type = "DBUS_TYPE_BOOLEAN" | ||
2527 | 300 | |||
2528 | 301 | class DBusInt16(DBusBasicType): | ||
2529 | 302 | """D-Bus 16-bit integer. | ||
2530 | 303 | |||
2531 | 304 | This class represents the D-Bus int16 type and should be instantiated with | ||
2532 | 305 | the name of the variable. It shares marshalling and dispatch code with | ||
2533 | 306 | the other basic types. | ||
2534 | 307 | """ | ||
2535 | 308 | c_type = "int16_t" | ||
2536 | 309 | dbus_code = "n" | ||
2537 | 310 | dbus_type = "DBUS_TYPE_INT16" | ||
2538 | 311 | |||
2539 | 312 | class DBusUInt16(DBusBasicType): | ||
2540 | 313 | """D-Bus 16-bit unsigned integer. | ||
2541 | 314 | |||
2542 | 315 | This class represents the D-Bus uint16 type and should be instantiated with | ||
2543 | 316 | the name of the variable. It shares marshalling and dispatch code with | ||
2544 | 317 | the other basic types. | ||
2545 | 318 | """ | ||
2546 | 319 | c_type = "uint16_t" | ||
2547 | 320 | dbus_code = "q" | ||
2548 | 321 | dbus_type = "DBUS_TYPE_UINT16" | ||
2549 | 322 | |||
2550 | 323 | class DBusInt32(DBusBasicType): | ||
2551 | 324 | """D-Bus 32-bit integer. | ||
2552 | 325 | |||
2553 | 326 | This class represents the D-Bus int32 type and should be instantiated with | ||
2554 | 327 | the name of the variable. It shares marshalling and dispatch code with | ||
2555 | 328 | the other basic types. | ||
2556 | 329 | """ | ||
2557 | 330 | c_type = "int32_t" | ||
2558 | 331 | dbus_code = "i" | ||
2559 | 332 | dbus_type = "DBUS_TYPE_INT32" | ||
2560 | 333 | |||
2561 | 334 | class DBusUInt32(DBusBasicType): | ||
2562 | 335 | """D-Bus 32-bit unsigned integer. | ||
2563 | 336 | |||
2564 | 337 | This class represents the D-Bus uint32 type and should be instantiated with | ||
2565 | 338 | the name of the variable. It shares marshalling and dispatch code with | ||
2566 | 339 | the other basic types. | ||
2567 | 340 | """ | ||
2568 | 341 | c_type = "uint32_t" | ||
2569 | 342 | dbus_code = "u" | ||
2570 | 343 | dbus_type = "DBUS_TYPE_UINT32" | ||
2571 | 344 | |||
2572 | 345 | class DBusInt64(DBusBasicType): | ||
2573 | 346 | """D-Bus 64-bit integer. | ||
2574 | 347 | |||
2575 | 348 | This class represents the D-Bus int64 type and should be instantiated with | ||
2576 | 349 | the name of the variable. It shares marshalling and dispatch code with | ||
2577 | 350 | the other basic types. | ||
2578 | 351 | """ | ||
2579 | 352 | c_type = "int64_t" | ||
2580 | 353 | dbus_code = "x" | ||
2581 | 354 | dbus_type = "DBUS_TYPE_INT64" | ||
2582 | 355 | |||
2583 | 356 | class DBusUInt64(DBusBasicType): | ||
2584 | 357 | """D-Bus 64-bit unsigned integer. | ||
2585 | 358 | |||
2586 | 359 | This class represents the D-Bus uint64 type and should be instantiated with | ||
2587 | 360 | the name of the variable. It shares marshalling and dispatch code with | ||
2588 | 361 | the other basic types. | ||
2589 | 362 | """ | ||
2590 | 363 | c_type = "uint64_t" | ||
2591 | 364 | dbus_code = "t" | ||
2592 | 365 | dbus_type = "DBUS_TYPE_UINT64" | ||
2593 | 366 | |||
2594 | 367 | class DBusDouble(DBusBasicType): | ||
2595 | 368 | """D-Bus double. | ||
2596 | 369 | |||
2597 | 370 | This class represents the D-Bus double type and should be instantiated | ||
2598 | 371 | with the name of the variable. It shares marshalling and dispatch code | ||
2599 | 372 | with the other basic types. | ||
2600 | 373 | """ | ||
2601 | 374 | c_type = "double" | ||
2602 | 375 | dbus_code = "d" | ||
2603 | 376 | dbus_type = "DBUS_TYPE_DOUBLE" | ||
2604 | 377 | |||
2605 | 378 | |||
2606 | 379 | class DBusStringType(DBusBasicType): | ||
2607 | 380 | """D-Bus string type. | ||
2608 | 381 | |||
2609 | 382 | This abstract class represents the base of all string-derived D-Bus types | ||
2610 | 383 | that we can handle. These share the code to marshal from a DBusMessage | ||
2611 | 384 | into a variable, the code to dispatch from a variable back into a | ||
2612 | 385 | DBusMessage and the same basic C type. | ||
2613 | 386 | |||
2614 | 387 | They differ from the fundamental basic type in that the marshalled copy | ||
2615 | 388 | of the string is not direct from the message, but an allocated copy; | ||
2616 | 389 | this is because they cannot be simply passed by value, and may wish to | ||
2617 | 390 | be stored. | ||
2618 | 391 | """ | ||
2619 | 392 | c_type = "char *" | ||
2620 | 393 | |||
2621 | 394 | def locals(self, pointer=False, const=False): | ||
2622 | 395 | """Local variable type and name. | ||
2623 | 396 | |||
2624 | 397 | Returns a list containing necessary local variables for iteration | ||
2625 | 398 | of this type. | ||
2626 | 399 | """ | ||
2627 | 400 | return [ ( self.realType(self.c_type, const=const), | ||
2628 | 401 | "_".join((self.name, "value")) ) ] | ||
2629 | 402 | |||
2630 | 403 | def marshal(self, iter_name, parent, type_error, mem_error, | ||
2631 | 404 | pointer=False, const=False): | ||
2632 | 405 | """Marshalling code. | ||
2633 | 406 | |||
2634 | 407 | Returns a string containing the code that will marshal from an | ||
2635 | 408 | iterator with the name given into a local variable with the | ||
2636 | 409 | type and name as returned by vars(). | ||
2637 | 410 | """ | ||
2638 | 411 | name = self.name | ||
2639 | 412 | if pointer: | ||
2640 | 413 | name = "*%s" % (name, ) | ||
2641 | 414 | |||
2642 | 415 | value_name = "_".join((self.name, "value")) | ||
2643 | 416 | |||
2644 | 417 | return """\ | ||
2645 | 418 | if (dbus_message_iter_get_arg_type (&%s) != %s) { | ||
2646 | 419 | %s | ||
2647 | 420 | } | ||
2648 | 421 | |||
2649 | 422 | dbus_message_iter_get_basic (&%s, &%s); | ||
2650 | 423 | |||
2651 | 424 | %s = nih_strdup (%s, %s); | ||
2652 | 425 | if (! %s) { | ||
2653 | 426 | %s | ||
2654 | 427 | } | ||
2655 | 428 | |||
2656 | 429 | dbus_message_iter_next (&%s); | ||
2657 | 430 | """ % (iter_name, self.dbus_type, type_error, | ||
2658 | 431 | iter_name, value_name, | ||
2659 | 432 | name, parent, value_name, | ||
2660 | 433 | name, mem_error, | ||
2661 | 434 | iter_name) | ||
2662 | 435 | |||
2663 | 436 | def dispatch(self, iter_name, mem_error, | ||
2664 | 437 | pointer=False, const=False): | ||
2665 | 438 | """Dispatching code. | ||
2666 | 439 | |||
2667 | 440 | Returns a string containing the code that will dispatch from a | ||
2668 | 441 | local variable with the type and name as returned by vars() to | ||
2669 | 442 | an iterator with the name given. | ||
2670 | 443 | """ | ||
2671 | 444 | name = self.name | ||
2672 | 445 | if pointer: | ||
2673 | 446 | name = "*%s" % (name, ) | ||
2674 | 447 | |||
2675 | 448 | value_name = "_".join((self.name, "value")) | ||
2676 | 449 | |||
2677 | 450 | return """\ | ||
2678 | 451 | %s = %s; | ||
2679 | 452 | if (! dbus_message_iter_append_basic (&%s, %s, &%s)) { | ||
2680 | 453 | %s | ||
2681 | 454 | } | ||
2682 | 455 | """ % (value_name, name, | ||
2683 | 456 | iter_name, self.dbus_type, value_name, mem_error) | ||
2684 | 457 | |||
2685 | 458 | |||
2686 | 459 | class DBusString(DBusStringType): | ||
2687 | 460 | """D-Bus string. | ||
2688 | 461 | |||
2689 | 462 | This class represents the D-Bus string type and should be instantiated | ||
2690 | 463 | with the name of the variable. It shares marshalling and dispatch code | ||
2691 | 464 | and underlying C type with the other string types. | ||
2692 | 465 | """ | ||
2693 | 466 | dbus_type = "DBUS_TYPE_STRING" | ||
2694 | 467 | dbus_code = "s" | ||
2695 | 468 | |||
2696 | 469 | class DBusObjectPath(DBusStringType): | ||
2697 | 470 | """D-Bus object path. | ||
2698 | 471 | |||
2699 | 472 | This class represents the D-Bus object path type and should be instantiated | ||
2700 | 473 | with the name of the variable. It shares marshalling and dispatch code | ||
2701 | 474 | and underlying C type with the other string types. | ||
2702 | 475 | """ | ||
2703 | 476 | dbus_type = "DBUS_TYPE_OBJECT_PATH" | ||
2704 | 477 | dbus_code = "o" | ||
2705 | 478 | |||
2706 | 479 | class DBusSignature(DBusStringType): | ||
2707 | 480 | """D-Bus type signature. | ||
2708 | 481 | |||
2709 | 482 | This class represents the D-Bus signature type and should be instantiated | ||
2710 | 483 | with the name of the variable. It shares marshalling and dispatch code | ||
2711 | 484 | and underlying C type with the other string types. | ||
2712 | 485 | """ | ||
2713 | 486 | dbus_type = "DBUS_TYPE_SIGNATURE" | ||
2714 | 487 | dbus_code = "g" | ||
2715 | 488 | |||
2716 | 489 | |||
2717 | 490 | class DBusArray(DBusType): | ||
2718 | 491 | """D-Bus array. | ||
2719 | 492 | |||
2720 | 493 | This class represents the D-Bus array type, it should be first | ||
2721 | 494 | sub-classed with member_type set to an appropriate other class (the | ||
2722 | 495 | forType classmethod can do that for you) and then instantiated with | ||
2723 | 496 | the name of the variable. | ||
2724 | 497 | """ | ||
2725 | 498 | dbus_type = "DBUS_TYPE_ARRAY" | ||
2726 | 499 | dbus_code = "a" | ||
2727 | 500 | |||
2728 | 501 | @classmethod | ||
2729 | 502 | def forType(cls, type): | ||
2730 | 503 | class _DBusArray(DBusArray): | ||
2731 | 504 | member_type = type | ||
2732 | 505 | |||
2733 | 506 | return _DBusArray | ||
2734 | 507 | |||
2735 | 508 | def __init__(self, name): | ||
2736 | 509 | super(DBusArray, self).__init__(name) | ||
2737 | 510 | |||
2738 | 511 | self.iter_name = "%s_iter" % (self.name,) | ||
2739 | 512 | self.len_name = "%s_len" % (self.name,) | ||
2740 | 513 | self.loop_name = "%s_p" % (self.name,) | ||
2741 | 514 | |||
2742 | 515 | self.type = self.member_type("%s_elem" % (self.name, )) | ||
2743 | 516 | # FIXME doesn't handle arrays of simple arrays since the length | ||
2744 | 517 | # field is lost. | ||
2745 | 518 | assert (len(self.type.vars()) == 1) | ||
2746 | 519 | |||
2747 | 520 | self.c_type = pointerify(self.type.c_type) | ||
2748 | 521 | |||
2749 | 522 | def signature(self, pointer=False, const=False): | ||
2750 | 523 | """Type signature. | ||
2751 | 524 | |||
2752 | 525 | Returns a string containing the D-Bus type signature for this type. | ||
2753 | 526 | """ | ||
2754 | 527 | return self.dbus_code + self.type.signature() | ||
2755 | 528 | |||
2756 | 529 | def locals(self, pointer=False, const=False): | ||
2757 | 530 | """Local variable type and name. | ||
2758 | 531 | |||
2759 | 532 | Returns a list containing necessary local variables for iteration | ||
2760 | 533 | of this type. | ||
2761 | 534 | """ | ||
2762 | 535 | locals = [ ( "DBusMessageIter", self.iter_name )] | ||
2763 | 536 | if self.type.c_type.endswith("*"): | ||
2764 | 537 | locals.append(( "size_t", self.len_name )) | ||
2765 | 538 | |||
2766 | 539 | return locals | ||
2767 | 540 | |||
2768 | 541 | def vars(self, pointer=False, const=False): | ||
2769 | 542 | """Variable type and name. | ||
2770 | 543 | |||
2771 | 544 | Returns a list containing tuples of C type and name for each type | ||
2772 | 545 | within this group. | ||
2773 | 546 | """ | ||
2774 | 547 | vars = [ ( self.realType(self.c_type, pointer, const), | ||
2775 | 548 | self.name ) ] | ||
2776 | 549 | if not self.type.c_type.endswith("*"): | ||
2777 | 550 | vars.append(( self.realType("size_t", pointer, const), | ||
2778 | 551 | self.len_name )) | ||
2779 | 552 | |||
2780 | 553 | return vars | ||
2781 | 554 | |||
2782 | 555 | def names(self, pointer=False, const=False): | ||
2783 | 556 | """Variable name. | ||
2784 | 557 | |||
2785 | 558 | Returns a list containing a single string; the name given when creating | ||
2786 | 559 | the instance. | ||
2787 | 560 | """ | ||
2788 | 561 | names = [ self.name ] | ||
2789 | 562 | if not self.type.c_type.endswith("*"): | ||
2790 | 563 | names.append(self.len_name) | ||
2791 | 564 | |||
2792 | 565 | return names | ||
2793 | 566 | |||
2794 | 567 | def marshal(self, iter_name, parent, type_error, mem_error, | ||
2795 | 568 | pointer=False, const=False): | ||
2796 | 569 | """Marshalling code. | ||
2797 | 570 | |||
2798 | 571 | Returns a string containing the code that will marshal from an | ||
2799 | 572 | iterator with the name given into local variables with the | ||
2800 | 573 | types and names as returned by vars(). | ||
2801 | 574 | """ | ||
2802 | 575 | name = self.name | ||
2803 | 576 | len_name = self.len_name | ||
2804 | 577 | if pointer: | ||
2805 | 578 | name = "*%s" % (name, ) | ||
2806 | 579 | if not self.type.c_type.endswith("*"): | ||
2807 | 580 | len_name = "*%s" % (len_name, ) | ||
2808 | 581 | |||
2809 | 582 | code = """\ | ||
2810 | 583 | if (dbus_message_iter_get_arg_type (&%s) != %s) { | ||
2811 | 584 | %s | ||
2812 | 585 | } | ||
2813 | 586 | |||
2814 | 587 | if (dbus_message_iter_get_element_type (&%s) != %s) { | ||
2815 | 588 | %s | ||
2816 | 589 | } | ||
2817 | 590 | |||
2818 | 591 | dbus_message_iter_recurse (&%s, &%s); | ||
2819 | 592 | |||
2820 | 593 | %s = NULL; | ||
2821 | 594 | %s = 0; | ||
2822 | 595 | |||
2823 | 596 | while (dbus_message_iter_get_arg_type (&%s) != DBUS_TYPE_INVALID) { | ||
2824 | 597 | """ % (iter_name, self.dbus_type, type_error, | ||
2825 | 598 | iter_name, self.type.dbus_type, type_error, | ||
2826 | 599 | iter_name, self.iter_name, | ||
2827 | 600 | name, len_name, | ||
2828 | 601 | self.iter_name) | ||
2829 | 602 | |||
2830 | 603 | vars = self.type.vars() | ||
2831 | 604 | vars.extend(self.type.locals()) | ||
2832 | 605 | code += indent(''.join("%s;\n" % var for var in lineup_vars(vars)), 1) | ||
2833 | 606 | |||
2834 | 607 | code += "\n" | ||
2835 | 608 | code += indent(self.type.marshal("%s_iter" % self.name, parent, | ||
2836 | 609 | type_error, mem_error), 1) | ||
2837 | 610 | |||
2838 | 611 | code += "\n" | ||
2839 | 612 | code += indent("""\ | ||
2840 | 613 | %s = nih_realloc (%s, %s, sizeof (%s) * ((%s) + 1)); | ||
2841 | 614 | if (! %s) { | ||
2842 | 615 | %s | ||
2843 | 616 | } | ||
2844 | 617 | |||
2845 | 618 | (%s)[(%s)++] = %s; | ||
2846 | 619 | """ % (name, name, parent, self.type.c_type, len_name, | ||
2847 | 620 | name, mem_error, | ||
2848 | 621 | name, len_name, self.type.name), 1) | ||
2849 | 622 | |||
2850 | 623 | code += "\n" | ||
2851 | 624 | code += """\ | ||
2852 | 625 | } | ||
2853 | 626 | |||
2854 | 627 | dbus_message_iter_next (&%s); | ||
2855 | 628 | """ % (iter_name, ) | ||
2856 | 629 | |||
2857 | 630 | if self.type.c_type.endswith("*"): | ||
2858 | 631 | code += "\n" | ||
2859 | 632 | code += """\ | ||
2860 | 633 | %s = nih_realloc (%s, %s, sizeof (%s) * ((%s) + 1)); | ||
2861 | 634 | if (! %s) { | ||
2862 | 635 | %s | ||
2863 | 636 | } | ||
2864 | 637 | |||
2865 | 638 | (%s)[(%s)] = NULL; | ||
2866 | 639 | """ % (name, name, parent, self.type.c_type, len_name, | ||
2867 | 640 | name, mem_error, | ||
2868 | 641 | name, len_name) | ||
2869 | 642 | |||
2870 | 643 | return code | ||
2871 | 644 | |||
2872 | 645 | def dispatch(self, iter_name, mem_error, | ||
2873 | 646 | pointer=False, const=False): | ||
2874 | 647 | """Dispatching code. | ||
2875 | 648 | |||
2876 | 649 | Returns a string containing the code that will dispatch from | ||
2877 | 650 | local variables with the types and names as returned by vars() to | ||
2878 | 651 | an iterator with the name given. | ||
2879 | 652 | """ | ||
2880 | 653 | name = self.name | ||
2881 | 654 | len_name = self.len_name | ||
2882 | 655 | if pointer: | ||
2883 | 656 | name = "*%s" % (name, ) | ||
2884 | 657 | if not self.type.c_type.endswith("*"): | ||
2885 | 658 | len_name = "*%s" % (len_name, ) | ||
2886 | 659 | |||
2887 | 660 | code = """\ | ||
2888 | 661 | if (! dbus_message_iter_open_container (&%s, %s, \"%s\", &%s)) { | ||
2889 | 662 | %s | ||
2890 | 663 | } | ||
2891 | 664 | """ % (iter_name, self.dbus_type, self.type.signature(), | ||
2892 | 665 | self.iter_name, mem_error) | ||
2893 | 666 | |||
2894 | 667 | code += "\n" | ||
2895 | 668 | if self.type.c_type.endswith("*"): | ||
2896 | 669 | code += """\ | ||
2897 | 670 | %s = 0; | ||
2898 | 671 | for (%s%s = %s; %s && *%s; %s++) { | ||
2899 | 672 | """ % (len_name, | ||
2900 | 673 | self.realType(self.c_type, const=const), self.loop_name, name, | ||
2901 | 674 | self.loop_name, self.loop_name, | ||
2902 | 675 | self.loop_name) | ||
2903 | 676 | else: | ||
2904 | 677 | code += """\ | ||
2905 | 678 | for (%s%s = %s; %s < %s + %s; %s++) { | ||
2906 | 679 | """ % (self.realType(self.c_type, const=const), self.loop_name, name, | ||
2907 | 680 | self.loop_name, name, len_name, self.loop_name) | ||
2908 | 681 | |||
2909 | 682 | vars = self.type.vars() | ||
2910 | 683 | vars.extend(self.type.locals()) | ||
2911 | 684 | code += indent(''.join("%s;\n" % var for var in lineup_vars(vars)), 1) | ||
2912 | 685 | |||
2913 | 686 | code += "\n" | ||
2914 | 687 | code += indent("""\ | ||
2915 | 688 | %s = *%s; | ||
2916 | 689 | """ % (self.type.name, self.loop_name), 1) | ||
2917 | 690 | |||
2918 | 691 | code += "\n" | ||
2919 | 692 | code += indent(self.type.dispatch(self.iter_name, mem_error), 1) | ||
2920 | 693 | |||
2921 | 694 | if self.type.c_type.endswith("*"): | ||
2922 | 695 | code += "\n" | ||
2923 | 696 | code += indent("""\ | ||
2924 | 697 | (%s)++; | ||
2925 | 698 | """ % (len_name, ), 1) | ||
2926 | 699 | |||
2927 | 700 | code += """\ | ||
2928 | 701 | } | ||
2929 | 702 | |||
2930 | 703 | if (! dbus_message_iter_close_container (&%s, &%s)) { | ||
2931 | 704 | %s | ||
2932 | 705 | } | ||
2933 | 706 | """ % (iter_name, self.iter_name, mem_error) | ||
2934 | 707 | |||
2935 | 708 | return code | ||
2936 | 709 | |||
2937 | 710 | |||
2938 | 711 | class DBusGroup(object): | ||
2939 | 712 | def __init__(self, types, pointer=False, const=False): | ||
2940 | 713 | self.types = types | ||
2941 | 714 | self.pointer = pointer | ||
2942 | 715 | self.const = const | ||
2943 | 716 | |||
2944 | 717 | def signature(self): | ||
2945 | 718 | """Type signature. | ||
2946 | 719 | |||
2947 | 720 | Returns a string containing the D-Bus type signature for this type. | ||
2948 | 721 | """ | ||
2949 | 722 | signature = "" | ||
2950 | 723 | |||
2951 | 724 | for type in self.types: | ||
2952 | 725 | signature += type.signature(pointer=self.pointer, const=self.const) | ||
2953 | 726 | |||
2954 | 727 | return signature | ||
2955 | 728 | |||
2956 | 729 | def vars(self): | ||
2957 | 730 | """Variable type and name. | ||
2958 | 731 | |||
2959 | 732 | Returns a list containing tuples of C type and name for each type | ||
2960 | 733 | within this group. | ||
2961 | 734 | """ | ||
2962 | 735 | vars = [] | ||
2963 | 736 | |||
2964 | 737 | for type in self.types: | ||
2965 | 738 | vars.extend(type.vars(pointer=self.pointer, const=self.const)) | ||
2966 | 739 | |||
2967 | 740 | return vars | ||
2968 | 741 | |||
2969 | 742 | def names(self): | ||
2970 | 743 | """Variable names. | ||
2971 | 744 | |||
2972 | 745 | Returns a list of names of all types in this group. | ||
2973 | 746 | """ | ||
2974 | 747 | names = [] | ||
2975 | 748 | |||
2976 | 749 | for type in self.types: | ||
2977 | 750 | names.extend(type.names()) | ||
2978 | 751 | return names | ||
2979 | 752 | |||
2980 | 753 | def locals(self): | ||
2981 | 754 | """Local variable type and name. | ||
2982 | 755 | |||
2983 | 756 | Returns a list containing necessary local variables for iteration | ||
2984 | 757 | of this type. | ||
2985 | 758 | """ | ||
2986 | 759 | locals = [] | ||
2987 | 760 | |||
2988 | 761 | for type in self.types: | ||
2989 | 762 | locals.extend(type.locals(pointer=self.pointer, const=self.const)) | ||
2990 | 763 | |||
2991 | 764 | return locals | ||
2992 | 765 | |||
2993 | 766 | def marshal(self, iter_name, parent, type_error, mem_error): | ||
2994 | 767 | """Marshalling code. | ||
2995 | 768 | |||
2996 | 769 | Returns a string containing the code that will marshal from an | ||
2997 | 770 | iterator with the name given into local variables with the | ||
2998 | 771 | types and names as returned by vars(). | ||
2999 | 772 | """ | ||
3000 | 773 | code = "" | ||
3001 | 774 | |||
3002 | 775 | for type in self.types: | ||
3003 | 776 | if code: | ||
3004 | 777 | code += "\n" | ||
3005 | 778 | code += type.marshal(iter_name, parent, type_error, mem_error, | ||
3006 | 779 | pointer=self.pointer, const=self.const) | ||
3007 | 780 | |||
3008 | 781 | if code: | ||
3009 | 782 | code += "\n" | ||
3010 | 783 | code += """\ | ||
3011 | 784 | if (dbus_message_iter_get_arg_type (&%s) != DBUS_TYPE_INVALID) { | ||
3012 | 785 | %s | ||
3013 | 786 | } | ||
3014 | 787 | """ % (iter_name, type_error) | ||
3015 | 788 | |||
3016 | 789 | return code | ||
3017 | 790 | |||
3018 | 791 | def dispatch(self, iter_name, mem_error): | ||
3019 | 792 | """Dispatching code. | ||
3020 | 793 | |||
3021 | 794 | Returns a string containing the code that will dispatch from | ||
3022 | 795 | local variables with the types and names as returned by vars() to | ||
3023 | 796 | an iterator with the name given. | ||
3024 | 797 | """ | ||
3025 | 798 | code = "" | ||
3026 | 799 | |||
3027 | 800 | for type in self.types: | ||
3028 | 801 | if code: | ||
3029 | 802 | code += "\n" | ||
3030 | 803 | code += type.dispatch(iter_name, mem_error, | ||
3031 | 804 | pointer=self.pointer, const=self.const) | ||
3032 | 805 | |||
3033 | 806 | return code | ||
3034 | 807 | |||
3035 | 808 | |||
3036 | 809 | class Generator(object): | ||
3037 | 810 | def staticPrototypes(self): | ||
3038 | 811 | """Static prototypes. | ||
3039 | 812 | |||
3040 | 813 | Returns an array of static function prototypes which are normally | ||
3041 | 814 | placed in a block at the top of the source file. | ||
3042 | 815 | |||
3043 | 816 | Each prototype is a (retval, name, args, attributes) tuple. | ||
3044 | 817 | """ | ||
3045 | 818 | return [] | ||
3046 | 819 | |||
3047 | 820 | def exportTypedefs(self): | ||
3048 | 821 | """Exported typedefs. | ||
3049 | 822 | |||
3050 | 823 | Type definitions that should be placed in the header. | ||
3051 | 824 | |||
3052 | 825 | Each typedef is the code to define it, including any documentation and | ||
3053 | 826 | default value. | ||
3054 | 827 | """ | ||
3055 | 828 | return [] | ||
3056 | 829 | |||
3057 | 830 | def externPrototypes(self): | ||
3058 | 831 | """Extern prototypes. | ||
3059 | 832 | |||
3060 | 833 | Returns an array of extern function prototypes which are normally | ||
3061 | 834 | placed in a block at the top of the source file, in lieu of | ||
3062 | 835 | missing headers. | ||
3063 | 836 | |||
3064 | 837 | Each prototype is a (retval, name, args, attributes) tuple. | ||
3065 | 838 | """ | ||
3066 | 839 | return [] | ||
3067 | 840 | |||
3068 | 841 | def variables(self): | ||
3069 | 842 | """Variables. | ||
3070 | 843 | |||
3071 | 844 | Returns an array of both static and exported global variables | ||
3072 | 845 | normally placed in a block at the top of the source file. | ||
3073 | 846 | |||
3074 | 847 | Each variable is the code to define it, including any documentation | ||
3075 | 848 | and default value. | ||
3076 | 849 | """ | ||
3077 | 850 | return [] | ||
3078 | 851 | |||
3079 | 852 | def functions(self): | ||
3080 | 853 | """Functions. | ||
3081 | 854 | |||
3082 | 855 | Returns an array of both static and exported functions which | ||
3083 | 856 | consistute the bulk of the source file. | ||
3084 | 857 | |||
3085 | 858 | Each function is the code to define it, including any documentation. | ||
3086 | 859 | """ | ||
3087 | 860 | return [] | ||
3088 | 861 | |||
3089 | 862 | def definitions(self): | ||
3090 | 863 | """Definitions. | ||
3091 | 864 | |||
3092 | 865 | Returns an array of structure and type definitions which are | ||
3093 | 866 | normally placed in a block in the header file. | ||
3094 | 867 | |||
3095 | 868 | Each definition is the code to define it, including any documentation. | ||
3096 | 869 | """ | ||
3097 | 870 | return [] | ||
3098 | 871 | |||
3099 | 872 | def exports(self): | ||
3100 | 873 | """Exports. | ||
3101 | 874 | |||
3102 | 875 | Returns an array of prototypes for exported variables which are | ||
3103 | 876 | placed as a block inside the extern part of the header file. | ||
3104 | 877 | |||
3105 | 878 | Each export is a (type, name) tuple. | ||
3106 | 879 | """ | ||
3107 | 880 | return [] | ||
3108 | 881 | |||
3109 | 882 | def exportPrototypes(self): | ||
3110 | 883 | """Function prototypes. | ||
3111 | 884 | |||
3112 | 885 | Returns an array of exported function prototypes which are normally | ||
3113 | 886 | placed in a block inside the extern part of the header file. | ||
3114 | 887 | |||
3115 | 888 | Each prototype is a (retval, name, args, attributes) tuple. | ||
3116 | 889 | """ | ||
3117 | 890 | return [] | ||
3118 | 891 | |||
3119 | 892 | |||
3120 | 893 | class Member(Generator): | ||
3121 | 894 | def __init__(self, interface, name): | ||
3122 | 895 | self.interface = interface | ||
3123 | 896 | self.name = name | ||
3124 | 897 | |||
3125 | 898 | @property | ||
3126 | 899 | def c_name(self): | ||
3127 | 900 | return self.name | ||
3128 | 901 | |||
3129 | 902 | @property | ||
3130 | 903 | def extern_name(self): | ||
3131 | 904 | return "_".join(( extern_prefix, | ||
3132 | 905 | NAME_RE.sub("\\1_\\2", self.c_name).lower())) | ||
3133 | 906 | |||
3134 | 907 | |||
3135 | 908 | class MemberWithArgs(Member): | ||
3136 | 909 | @classmethod | ||
3137 | 910 | def fromElement(cls, interface, elem): | ||
3138 | 911 | name = elem.get("name") | ||
3139 | 912 | if name is None: | ||
3140 | 913 | raise AttributeError, "Name may not be null" | ||
3141 | 914 | |||
3142 | 915 | types = [ DBusType.fromElement(e) for e in elem.findall("arg") ] | ||
3143 | 916 | |||
3144 | 917 | self = cls(interface, name, types) | ||
3145 | 918 | self.style = elem.get(ElementTree.QName(XMLNS, mode), self.style) | ||
3146 | 919 | return self | ||
3147 | 920 | |||
3148 | 921 | def __init__(self, interface, name, types): | ||
3149 | 922 | super(MemberWithArgs, self).__init__(interface, name) | ||
3150 | 923 | |||
3151 | 924 | self.style = "sync" | ||
3152 | 925 | self.types = types | ||
3153 | 926 | |||
3154 | 927 | def argArray(self): | ||
3155 | 928 | """Argument array. | ||
3156 | 929 | |||
3157 | 930 | Returns a string containing code to initialise the array of arguments | ||
3158 | 931 | used for nih_dbus_object_new(). | ||
3159 | 932 | """ | ||
3160 | 933 | code = """\ | ||
3161 | 934 | static const NihDBusArg %s[] = { | ||
3162 | 935 | """ % "_".join([ self.interface.c_name, self.c_name, "args" ]) | ||
3163 | 936 | |||
3164 | 937 | array = [] | ||
3165 | 938 | for type in self.types: | ||
3166 | 939 | if type.direction == "in": | ||
3167 | 940 | direction = "NIH_DBUS_ARG_IN" | ||
3168 | 941 | elif type.direction == "out": | ||
3169 | 942 | direction = "NIH_DBUS_ARG_OUT" | ||
3170 | 943 | |||
3171 | 944 | array.append(( "\"%s\"" % type.name, | ||
3172 | 945 | "\"%s\"" % type.signature(), | ||
3173 | 946 | direction )) | ||
3174 | 947 | |||
3175 | 948 | for line in lineup_array(array): | ||
3176 | 949 | code += indent("%s,\n" % line, 1) | ||
3177 | 950 | |||
3178 | 951 | code += """\ | ||
3179 | 952 | { NULL } | ||
3180 | 953 | }; | ||
3181 | 954 | """ | ||
3182 | 955 | return code | ||
3183 | 956 | |||
3184 | 957 | def variables(self): | ||
3185 | 958 | """Variables. | ||
3186 | 959 | |||
3187 | 960 | Returns an array of both static and exported global variables | ||
3188 | 961 | normally placed in a block at the top of the source file. | ||
3189 | 962 | |||
3190 | 963 | Each variable is the code to define it, including any documentation | ||
3191 | 964 | and default value. | ||
3192 | 965 | """ | ||
3193 | 966 | variables = [] | ||
3194 | 967 | if mode == "object": | ||
3195 | 968 | variables.append(self.argArray()) | ||
3196 | 969 | |||
3197 | 970 | return variables | ||
3198 | 971 | |||
3199 | 972 | |||
3200 | 973 | class Method(MemberWithArgs): | ||
3201 | 974 | def __init__(self, interface, name, types): | ||
3202 | 975 | super(Method, self).__init__(interface, name, types) | ||
3203 | 976 | |||
3204 | 977 | def marshalPrototype(self): | ||
3205 | 978 | """Marshalling function prototype. | ||
3206 | 979 | |||
3207 | 980 | Returns a (retval, name, args, attributes) tuple for the prototype | ||
3208 | 981 | of the marshaller function. | ||
3209 | 982 | """ | ||
3210 | 983 | return ( "static DBusHandlerResult", | ||
3211 | 984 | "_".join([ self.interface.c_name, self.c_name, "marshal" ]), | ||
3212 | 985 | [ ( "NihDBusObject *", "object" ), | ||
3213 | 986 | ( "NihDBusMessage *", "message" ) ], | ||
3214 | 987 | None ) | ||
3215 | 988 | |||
3216 | 989 | def marshalFunction(self): | ||
3217 | 990 | """Marshalling function. | ||
3218 | 991 | |||
3219 | 992 | Returns a string containing a marshaller function that takes | ||
3220 | 993 | arguments from a D-Bus message, calls a C handler function with | ||
3221 | 994 | them passed properly, then constructs a reply if successful. | ||
3222 | 995 | """ | ||
3223 | 996 | in_args = DBusGroup([t for t in self.types if t.direction == "in"]) | ||
3224 | 997 | out_args = DBusGroup([t for t in self.types if t.direction == "out"]) | ||
3225 | 998 | |||
3226 | 999 | name = "_".join([ self.interface.c_name, self.c_name, "marshal" ]) | ||
3227 | 1000 | code = """\ | ||
3228 | 1001 | static DBusHandlerResult | ||
3229 | 1002 | %s (NihDBusObject *object, | ||
3230 | 1003 | %s NihDBusMessage *message) | ||
3231 | 1004 | { | ||
3232 | 1005 | """ % (name, " " * len(name)) | ||
3233 | 1006 | |||
3234 | 1007 | # Declare local variables for the iterator, reply and those needed | ||
3235 | 1008 | # for both input and output arguments. | ||
3236 | 1009 | vars = [ ( "DBusMessageIter", "iter" ), | ||
3237 | 1010 | ( "DBusMessage *", "reply = NULL" ) ] | ||
3238 | 1011 | vars.extend(in_args.vars()) | ||
3239 | 1012 | vars.extend(in_args.locals()) | ||
3240 | 1013 | if self.style != "async": | ||
3241 | 1014 | vars.extend(out_args.vars()) | ||
3242 | 1015 | vars.extend(out_args.locals()) | ||
3243 | 1016 | |||
3244 | 1017 | code += indent(''.join("%s;\n" % var for var in lineup_vars(vars)), 1) | ||
3245 | 1018 | |||
3246 | 1019 | # Pre-amble for the function | ||
3247 | 1020 | code += "\n" | ||
3248 | 1021 | code += indent("""\ | ||
3249 | 1022 | nih_assert (object != NULL); | ||
3250 | 1023 | nih_assert (message != NULL); | ||
3251 | 1024 | """, 1); | ||
3252 | 1025 | |||
3253 | 1026 | # Marshal the input arguments into local variables | ||
3254 | 1027 | code += "\n" | ||
3255 | 1028 | code += indent("""\ | ||
3256 | 1029 | /* Iterate the arguments to the message and marshal into arguments | ||
3257 | 1030 | * for our own function call. | ||
3258 | 1031 | */ | ||
3259 | 1032 | dbus_message_iter_init (message->message, &iter); | ||
3260 | 1033 | """, 1) | ||
3261 | 1034 | code += "\n" | ||
3262 | 1035 | |||
3263 | 1036 | mem_error = indent("""\ | ||
3264 | 1037 | return DBUS_HANDLER_RESULT_NEED_MEMORY; | ||
3265 | 1038 | """, 1) | ||
3266 | 1039 | type_error = indent("""\ | ||
3267 | 1040 | reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, | ||
3268 | 1041 | _("Invalid arguments to %s method")); | ||
3269 | 1042 | if (! reply) { | ||
3270 | 1043 | %s | ||
3271 | 1044 | } | ||
3272 | 1045 | |||
3273 | 1046 | goto send; | ||
3274 | 1047 | """ % (self.name, mem_error), 1) | ||
3275 | 1048 | code += indent(in_args.marshal("iter", "message", | ||
3276 | 1049 | type_error, mem_error), 1) | ||
3277 | 1050 | |||
3278 | 1051 | # Construct the function call | ||
3279 | 1052 | args = [ "object->data", "message" ] | ||
3280 | 1053 | args.extend(n for t, n in in_args.vars()) | ||
3281 | 1054 | if self.style != "async": | ||
3282 | 1055 | args.extend("&%s" % n for t, n in out_args.vars()) | ||
3283 | 1056 | |||
3284 | 1057 | code += "\n" | ||
3285 | 1058 | code += indent("""\ | ||
3286 | 1059 | /* Call the handler function. */ | ||
3287 | 1060 | if (%s (%s) < 0) { | ||
3288 | 1061 | NihError *err; | ||
3289 | 1062 | |||
3290 | 1063 | err = nih_error_get (); | ||
3291 | 1064 | if (err->number == ENOMEM) { | ||
3292 | 1065 | nih_free (err); | ||
3293 | 1066 | |||
3294 | 1067 | return DBUS_HANDLER_RESULT_NEED_MEMORY; | ||
3295 | 1068 | } else if (err->number == NIH_DBUS_ERROR) { | ||
3296 | 1069 | NihDBusError *dbus_err = (NihDBusError *)err; | ||
3297 | 1070 | |||
3298 | 1071 | reply = dbus_message_new_error (message->message, | ||
3299 | 1072 | dbus_err->name, | ||
3300 | 1073 | err->message); | ||
3301 | 1074 | nih_free (err); | ||
3302 | 1075 | |||
3303 | 1076 | if (! reply) | ||
3304 | 1077 | return DBUS_HANDLER_RESULT_NEED_MEMORY; | ||
3305 | 1078 | |||
3306 | 1079 | goto send; | ||
3307 | 1080 | } else { | ||
3308 | 1081 | reply = dbus_message_new_error (message->message, | ||
3309 | 1082 | DBUS_ERROR_FAILED, | ||
3310 | 1083 | err->message); | ||
3311 | 1084 | nih_free (err); | ||
3312 | 1085 | |||
3313 | 1086 | if (! reply) | ||
3314 | 1087 | return DBUS_HANDLER_RESULT_NEED_MEMORY; | ||
3315 | 1088 | |||
3316 | 1089 | goto send; | ||
3317 | 1090 | } | ||
3318 | 1091 | } | ||
3319 | 1092 | """ % (self.extern_name, ", ".join(args)), 1) | ||
3320 | 1093 | |||
3321 | 1094 | if self.style == "async": | ||
3322 | 1095 | code += "\n" | ||
3323 | 1096 | code += indent("return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;\n", 1) | ||
3324 | 1097 | else: | ||
3325 | 1098 | # Be well-behaved and make the function return immediately | ||
3326 | 1099 | # if no reply is expected | ||
3327 | 1100 | code += "\n" | ||
3328 | 1101 | code += indent("""\ | ||
3329 | 1102 | /* If the sender doesn't care about a reply, don't bother wasting | ||
3330 | 1103 | * effort constructing and sending one. | ||
3331 | 1104 | */ | ||
3332 | 1105 | if (dbus_message_get_no_reply (message->message)) | ||
3333 | 1106 | return DBUS_HANDLER_RESULT_HANDLED; | ||
3334 | 1107 | """, 1) | ||
3335 | 1108 | |||
3336 | 1109 | # Create reply and dispatch the local variables into output | ||
3337 | 1110 | # arguments | ||
3338 | 1111 | code += "\n" | ||
3339 | 1112 | code += indent("""\ | ||
3340 | 1113 | /* Construct the reply message */ | ||
3341 | 1114 | reply = dbus_message_new_method_return (message->message); | ||
3342 | 1115 | if (! reply) | ||
3343 | 1116 | return DBUS_HANDLER_RESULT_NEED_MEMORY; | ||
3344 | 1117 | |||
3345 | 1118 | dbus_message_iter_init_append (reply, &iter); | ||
3346 | 1119 | """, 1) | ||
3347 | 1120 | code += "\n" | ||
3348 | 1121 | |||
3349 | 1122 | mem_error = indent("""\ | ||
3350 | 1123 | dbus_message_unref (reply); | ||
3351 | 1124 | return DBUS_HANDLER_RESULT_NEED_MEMORY; | ||
3352 | 1125 | """, 1) | ||
3353 | 1126 | code += indent(out_args.dispatch("iter", mem_error), 1) | ||
3354 | 1127 | |||
3355 | 1128 | # Send the reply | ||
3356 | 1129 | code += "\nsend:\n" | ||
3357 | 1130 | code += indent("""\ | ||
3358 | 1131 | /* Send the reply, appending it to the outgoing queue. */ | ||
3359 | 1132 | if (! dbus_connection_send (message->conn, reply, NULL)) { | ||
3360 | 1133 | dbus_message_unref (reply); | ||
3361 | 1134 | return DBUS_HANDLER_RESULT_NEED_MEMORY; | ||
3362 | 1135 | } | ||
3363 | 1136 | |||
3364 | 1137 | dbus_message_unref (reply); | ||
3365 | 1138 | |||
3366 | 1139 | return DBUS_HANDLER_RESULT_HANDLED; | ||
3367 | 1140 | """, 1) | ||
3368 | 1141 | |||
3369 | 1142 | code += "}\n" | ||
3370 | 1143 | |||
3371 | 1144 | return code | ||
3372 | 1145 | |||
3373 | 1146 | def handlerPrototype(self): | ||
3374 | 1147 | """Handler function prototype. | ||
3375 | 1148 | |||
3376 | 1149 | Returns a (retval, name, args, attributes) tuple for the prototype | ||
3377 | 1150 | of the handler function that the user must define. | ||
3378 | 1151 | """ | ||
3379 | 1152 | in_args = DBusGroup([t for t in self.types if t.direction == "in"], | ||
3380 | 1153 | const=True) | ||
3381 | 1154 | out_args = DBusGroup([t for t in self.types if t.direction == "out"], | ||
3382 | 1155 | pointer=True) | ||
3383 | 1156 | |||
3384 | 1157 | vars = [ ("void *", "data"), | ||
3385 | 1158 | ("NihDBusMessage *", "message") ] | ||
3386 | 1159 | vars.extend(in_args.vars()) | ||
3387 | 1160 | if self.style != "async": | ||
3388 | 1161 | vars.extend(out_args.vars()) | ||
3389 | 1162 | |||
3390 | 1163 | return ( "extern int", | ||
3391 | 1164 | self.extern_name, | ||
3392 | 1165 | vars, | ||
3393 | 1166 | None ) | ||
3394 | 1167 | |||
3395 | 1168 | def replyPrototype(self): | ||
3396 | 1169 | """Reply function prototype. | ||
3397 | 1170 | |||
3398 | 1171 | Returns a (retval, name, args, attributes) tuple for the prototype | ||
3399 | 1172 | of the reply function defined for async functions. | ||
3400 | 1173 | """ | ||
3401 | 1174 | out_args = DBusGroup([t for t in self.types if t.direction == "out"], | ||
3402 | 1175 | const=True) | ||
3403 | 1176 | |||
3404 | 1177 | vars = [("NihDBusMessage *", "message") ] | ||
3405 | 1178 | vars.extend(out_args.vars()) | ||
3406 | 1179 | |||
3407 | 1180 | return ( "int", | ||
3408 | 1181 | "_".join([ self.extern_name, "reply" ]), | ||
3409 | 1182 | vars, | ||
3410 | 1183 | None ) | ||
3411 | 1184 | |||
3412 | 1185 | def replyFunction(self): | ||
3413 | 1186 | """Reply function. | ||
3414 | 1187 | |||
3415 | 1188 | Returns a string containing a reply function that takes its | ||
3416 | 1189 | arguments and produces a D-Bus message reply. | ||
3417 | 1190 | """ | ||
3418 | 1191 | out_args = DBusGroup([t for t in self.types if t.direction == "out"], | ||
3419 | 1192 | const=True) | ||
3420 | 1193 | |||
3421 | 1194 | name = "_".join([ self.extern_name, "reply" ]) | ||
3422 | 1195 | vars = [ ( "NihDBusMessage *", "message" ) ] | ||
3423 | 1196 | vars.extend(out_args.vars()) | ||
3424 | 1197 | |||
3425 | 1198 | code = "int\n%s (" % (name, ) | ||
3426 | 1199 | code += (",\n" + " " * (len(name) + 2)).join(lineup_vars(vars)) | ||
3427 | 1200 | code += ")\n{\n" | ||
3428 | 1201 | |||
3429 | 1202 | # Declare local variables for the iterator and the reply | ||
3430 | 1203 | vars = [ ( "DBusMessageIter", "iter" ), | ||
3431 | 1204 | ( "DBusMessage *", "reply = NULL" ) ] | ||
3432 | 1205 | vars.extend(out_args.locals()) | ||
3433 | 1206 | |||
3434 | 1207 | code += indent(''.join("%s;\n" % var for var in lineup_vars(vars)), 1) | ||
3435 | 1208 | |||
3436 | 1209 | # Pre-amble for the function | ||
3437 | 1210 | code += "\n" | ||
3438 | 1211 | code += indent("""\ | ||
3439 | 1212 | nih_assert (message != NULL); | ||
3440 | 1213 | """, 1); | ||
3441 | 1214 | |||
3442 | 1215 | # Be well-behaved and don't actually send the reply if one is | ||
3443 | 1216 | # not expected | ||
3444 | 1217 | code += "\n" | ||
3445 | 1218 | code += indent("""\ | ||
3446 | 1219 | /* If the sender doesn't care about a reply, don't bother wasting | ||
3447 | 1220 | * effort constructing and sending one. | ||
3448 | 1221 | */ | ||
3449 | 1222 | if (dbus_message_get_no_reply (message->message)) { | ||
3450 | 1223 | nih_free (message); | ||
3451 | 1224 | return 0; | ||
3452 | 1225 | } | ||
3453 | 1226 | """, 1) | ||
3454 | 1227 | |||
3455 | 1228 | # Create reply and dispatch the local variables into output | ||
3456 | 1229 | # arguments | ||
3457 | 1230 | code += "\n" | ||
3458 | 1231 | code += indent("""\ | ||
3459 | 1232 | /* Construct the reply message */ | ||
3460 | 1233 | reply = dbus_message_new_method_return (message->message); | ||
3461 | 1234 | if (! reply) | ||
3462 | 1235 | return -1; | ||
3463 | 1236 | |||
3464 | 1237 | dbus_message_iter_init_append (reply, &iter); | ||
3465 | 1238 | """, 1) | ||
3466 | 1239 | code += "\n" | ||
3467 | 1240 | |||
3468 | 1241 | mem_error = indent("""\ | ||
3469 | 1242 | dbus_message_unref (reply); | ||
3470 | 1243 | return -1; | ||
3471 | 1244 | """, 1) | ||
3472 | 1245 | code += indent(out_args.dispatch("iter", mem_error), 1) | ||
3473 | 1246 | |||
3474 | 1247 | # Send the reply | ||
3475 | 1248 | code += "\n" | ||
3476 | 1249 | code += indent("""\ | ||
3477 | 1250 | /* Send the reply, appending it to the outgoing queue. */ | ||
3478 | 1251 | if (! dbus_connection_send (message->conn, reply, NULL)) { | ||
3479 | 1252 | dbus_message_unref (reply); | ||
3480 | 1253 | return -1; | ||
3481 | 1254 | } | ||
3482 | 1255 | |||
3483 | 1256 | dbus_message_unref (reply); | ||
3484 | 1257 | nih_free (message); | ||
3485 | 1258 | |||
3486 | 1259 | return 0; | ||
3487 | 1260 | """, 1) | ||
3488 | 1261 | |||
3489 | 1262 | code += "}\n" | ||
3490 | 1263 | |||
3491 | 1264 | return code | ||
3492 | 1265 | |||
3493 | 1266 | def asyncNotifyPrototype(self): | ||
3494 | 1267 | """Asynchronous dispatch function prototype. | ||
3495 | 1268 | |||
3496 | 1269 | Returns a (retval, name, args, attributes) tuple for the prototype | ||
3497 | 1270 | of the asynchronous dispatch function. | ||
3498 | 1271 | """ | ||
3499 | 1272 | vars = [ ( "DBusPendingCall *", "call" ), | ||
3500 | 1273 | ( "NihAsyncNotifyData *", "data" ) ] | ||
3501 | 1274 | |||
3502 | 1275 | return ( "static void", | ||
3503 | 1276 | self.extern_name + "_async_notify", | ||
3504 | 1277 | vars, ( ) ) | ||
3505 | 1278 | |||
3506 | 1279 | def asyncDispatchPrototype(self): | ||
3507 | 1280 | """Asynchronous dispatch function prototype. | ||
3508 | 1281 | |||
3509 | 1282 | Returns a (retval, name, args, attributes) tuple for the prototype | ||
3510 | 1283 | of the asynchronous dispatch function. | ||
3511 | 1284 | """ | ||
3512 | 1285 | in_args = DBusGroup([t for t in self.types if t.direction == "in"], | ||
3513 | 1286 | const=True) | ||
3514 | 1287 | out_args = DBusGroup([t for t in self.types if t.direction == "out"]) | ||
3515 | 1288 | |||
3516 | 1289 | vars = [ ( "NihDBusProxy *", "proxy" ) ] | ||
3517 | 1290 | vars.extend(in_args.vars()) | ||
3518 | 1291 | vars += [ ( "%sCallback" % camelate(self.extern_name), "callback" ), | ||
3519 | 1292 | ( "%sErrback" % camelate(self.extern_name), "errback" ), | ||
3520 | 1293 | ( "void *", "userdata" ) ] | ||
3521 | 1294 | |||
3522 | 1295 | return ( "int", | ||
3523 | 1296 | self.extern_name + "_async", | ||
3524 | 1297 | vars, | ||
3525 | 1298 | ( "warn_unused_result", ) ) | ||
3526 | 1299 | |||
3527 | 1300 | def dispatchPrototype(self): | ||
3528 | 1301 | """Dispatch function prototype. | ||
3529 | 1302 | |||
3530 | 1303 | Returns a (retval, name, args, attributes) tuple for the prototype | ||
3531 | 1304 | of the dispatch function. | ||
3532 | 1305 | """ | ||
3533 | 1306 | in_args = DBusGroup([t for t in self.types if t.direction == "in"], | ||
3534 | 1307 | const=True) | ||
3535 | 1308 | out_args = DBusGroup([t for t in self.types if t.direction == "out"], | ||
3536 | 1309 | pointer=True) | ||
3537 | 1310 | |||
3538 | 1311 | vars = [ ( "NihDBusProxy *", "proxy" ) ] | ||
3539 | 1312 | vars.extend(in_args.vars()) | ||
3540 | 1313 | # FIXME async doesn't have these, but has a callback instead | ||
3541 | 1314 | vars.extend(out_args.vars()) | ||
3542 | 1315 | |||
3543 | 1316 | return ( "int", | ||
3544 | 1317 | self.extern_name, | ||
3545 | 1318 | vars, | ||
3546 | 1319 | ( "warn_unused_result", ) ) | ||
3547 | 1320 | |||
3548 | 1321 | def asyncNotifyFunction(self): | ||
3549 | 1322 | """Asynchronous notification function. | ||
3550 | 1323 | |||
3551 | 1324 | Called when an asynchronously dispatched function returns something. | ||
3552 | 1325 | Fetches out the arguments and passes them to a user-supplied function. | ||
3553 | 1326 | """ | ||
3554 | 1327 | out_args = DBusGroup([t for t in self.types if t.direction == "out"]) | ||
3555 | 1328 | |||
3556 | 1329 | vars = [ ( "DBusPendingCall *", "call" ), | ||
3557 | 1330 | ( "NihAsyncNotifyData *", "data" ) ] | ||
3558 | 1331 | |||
3559 | 1332 | code = "static void\n%s (" % (self.extern_name + "_async_notify", ) | ||
3560 | 1333 | code += (",\n" + " " * (len(self.extern_name + "_async_notify") + 2)).join(lineup_vars(vars)) | ||
3561 | 1334 | code += ")\n{\n" | ||
3562 | 1335 | |||
3563 | 1336 | # Declare local variables for the iterator, reply and those needed | ||
3564 | 1337 | # for both input and output arguments. | ||
3565 | 1338 | vars = [ ( "DBusMessage *", "reply" ), | ||
3566 | 1339 | ( "DBusMessageIter", "iter" ), | ||
3567 | 1340 | ( "int", "type" ) ] | ||
3568 | 1341 | vars.extend(out_args.locals()) | ||
3569 | 1342 | vars.extend(out_args.vars()) | ||
3570 | 1343 | code += indent(''.join("%s;\n" % var for var in lineup_vars(vars)), 1) | ||
3571 | 1344 | |||
3572 | 1345 | # Pre-amble for the function | ||
3573 | 1346 | code += "\n" | ||
3574 | 1347 | |||
3575 | 1348 | code += indent("""\ | ||
3576 | 1349 | reply = dbus_pending_call_steal_reply(call); | ||
3577 | 1350 | |||
3578 | 1351 | nih_assert (reply != NULL); | ||
3579 | 1352 | |||
3580 | 1353 | type = dbus_message_get_type (reply); | ||
3581 | 1354 | |||
3582 | 1355 | nih_assert (type == DBUS_MESSAGE_TYPE_METHOD_RETURN || | ||
3583 | 1356 | type == DBUS_MESSAGE_TYPE_ERROR); | ||
3584 | 1357 | |||
3585 | 1358 | if (type == DBUS_MESSAGE_TYPE_ERROR) { | ||
3586 | 1359 | char *name; | ||
3587 | 1360 | DBusError error; | ||
3588 | 1361 | |||
3589 | 1362 | dbus_error_init (&error); | ||
3590 | 1363 | dbus_set_error_from_message (&error, reply); | ||
3591 | 1364 | |||
3592 | 1365 | if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { | ||
3593 | 1366 | errno = ENOMEM; | ||
3594 | 1367 | nih_error_raise_system (); | ||
3595 | 1368 | } else { | ||
3596 | 1369 | nih_dbus_error_raise (error.name, error.message); | ||
3597 | 1370 | } | ||
3598 | 1371 | |||
3599 | 1372 | ((%sErrback)data->err_handler)(data->proxy, data->userdata); | ||
3600 | 1373 | |||
3601 | 1374 | dbus_error_free (&error); | ||
3602 | 1375 | goto out; | ||
3603 | 1376 | } | ||
3604 | 1377 | """ % camelate(self.extern_name), 1); | ||
3605 | 1378 | |||
3606 | 1379 | # Marshal the reply arguments into output arguments | ||
3607 | 1380 | code += "\n" | ||
3608 | 1381 | code += indent("""\ | ||
3609 | 1382 | /* Iterate the arguments to the reply and marshal into output | ||
3610 | 1383 | * arguments from our own function call. | ||
3611 | 1384 | */ | ||
3612 | 1385 | dbus_message_iter_init (reply, &iter); | ||
3613 | 1386 | """, 1); | ||
3614 | 1387 | code += "\n" | ||
3615 | 1388 | |||
3616 | 1389 | mem_error = indent("""\ | ||
3617 | 1390 | errno = ENOMEM; | ||
3618 | 1391 | nih_error_raise_system (); | ||
3619 | 1392 | ((%sErrback)data->err_handler)(data->proxy, data->userdata); | ||
3620 | 1393 | goto out; | ||
3621 | 1394 | """ % camelate(self.extern_name), 1) | ||
3622 | 1395 | type_error = indent("""\ | ||
3623 | 1396 | nih_error_raise (NIH_DBUS_INVALID_ARGS, NIH_DBUS_INVALID_ARGS_STR); | ||
3624 | 1397 | ((%sErrback)data->err_handler)(data->proxy, data->userdata); | ||
3625 | 1398 | goto out; | ||
3626 | 1399 | """ % camelate(self.extern_name), 1); | ||
3627 | 1400 | code += indent(out_args.marshal("iter", "data->proxy", | ||
3628 | 1401 | type_error, mem_error), 1) | ||
3629 | 1402 | |||
3630 | 1403 | code += "\n\n" | ||
3631 | 1404 | code += indent("""\ | ||
3632 | 1405 | ((%sCallback)data->handler)(%s); | ||
3633 | 1406 | """ % (camelate(self.extern_name), ", ".join([ "data->proxy", "data->userdata" ] + out_args.names())), 1) | ||
3634 | 1407 | |||
3635 | 1408 | code += "out:\n" | ||
3636 | 1409 | code += indent("""\ | ||
3637 | 1410 | |||
3638 | 1411 | dbus_message_unref (reply); | ||
3639 | 1412 | dbus_pending_call_unref (call); | ||
3640 | 1413 | |||
3641 | 1414 | return; | ||
3642 | 1415 | """, 1) | ||
3643 | 1416 | |||
3644 | 1417 | code += "}\n" | ||
3645 | 1418 | |||
3646 | 1419 | return code | ||
3647 | 1420 | |||
3648 | 1421 | def asyncDispatchFunction(self): | ||
3649 | 1422 | """Asynchronous dispatching function. | ||
3650 | 1423 | |||
3651 | 1424 | Returns a string containing a dispatcher function that takes arguments | ||
3652 | 1425 | identical to those taken by a particular dbus method, and pointers to | ||
3653 | 1426 | variables where the return values from that method might be stored. Then | ||
3654 | 1427 | sends a dbus message and waits for a reply to come, and populates the | ||
3655 | 1428 | reply arguments with the contents of the reply message. | ||
3656 | 1429 | """ | ||
3657 | 1430 | in_args = DBusGroup([t for t in self.types if t.direction == "in"], | ||
3658 | 1431 | const=True) | ||
3659 | 1432 | out_args = DBusGroup([t for t in self.types if t.direction == "out"]) | ||
3660 | 1433 | |||
3661 | 1434 | vars = [ ( "NihDBusProxy *", "proxy" ) ] | ||
3662 | 1435 | vars.extend(in_args.vars()) | ||
3663 | 1436 | vars += [ ( "%sCallback" % camelate(self.extern_name), "callback" ), | ||
3664 | 1437 | ( "%sErrback" % camelate(self.extern_name), "errback" ), | ||
3665 | 1438 | ( "void *", "userdata" ) ] | ||
3666 | 1439 | |||
3667 | 1440 | code = "int\n%s (" % (self.extern_name + "_async", ) | ||
3668 | 1441 | code += (",\n" + " " * (len(self.extern_name + "_async") + 2)).join(lineup_vars(vars)) | ||
3669 | 1442 | code += ")\n{\n" | ||
3670 | 1443 | |||
3671 | 1444 | # Declare local variables for the iterator, reply and those needed | ||
3672 | 1445 | # for both input and output arguments. | ||
3673 | 1446 | vars = [ ( "DBusMessage *", "message" ), | ||
3674 | 1447 | ( "DBusMessageIter", "iter" ), | ||
3675 | 1448 | ( "DBusPendingCall *", "call" ), | ||
3676 | 1449 | ( "NihAsyncNotifyData *", "data" ) ] | ||
3677 | 1450 | vars.extend(in_args.locals()) | ||
3678 | 1451 | code += indent(''.join("%s;\n" % var for var in lineup_vars(vars)), 1) | ||
3679 | 1452 | |||
3680 | 1453 | # Pre-amble for the function | ||
3681 | 1454 | code += "\n" | ||
3682 | 1455 | code += indent("""\ | ||
3683 | 1456 | nih_assert (proxy != NULL); | ||
3684 | 1457 | nih_assert ((errback != NULL && callback != NULL) || | ||
3685 | 1458 | (errback == NULL && callback == NULL)); | ||
3686 | 1459 | """, 1); | ||
3687 | 1460 | |||
3688 | 1461 | # Dispatch the input arguments into a new local message | ||
3689 | 1462 | code += "\n" | ||
3690 | 1463 | code += indent("""\ | ||
3691 | 1464 | message = dbus_message_new_method_call (proxy->name, proxy->path, "%s", "%s"); | ||
3692 | 1465 | if (! message) | ||
3693 | 1466 | nih_return_no_memory_error (-1); | ||
3694 | 1467 | |||
3695 | 1468 | /* Iterate the arguments to the function and dispatch into | ||
3696 | 1469 | * message arguments. | ||
3697 | 1470 | */ | ||
3698 | 1471 | dbus_message_iter_init_append (message, &iter); | ||
3699 | 1472 | """ % (self.interface.name, self.name), 1) | ||
3700 | 1473 | code += "\n" | ||
3701 | 1474 | |||
3702 | 1475 | # FIXME autostart? | ||
3703 | 1476 | |||
3704 | 1477 | mem_error = indent("""\ | ||
3705 | 1478 | dbus_message_unref (message); | ||
3706 | 1479 | nih_return_no_memory_error (-1); | ||
3707 | 1480 | """, 1) | ||
3708 | 1481 | code += indent(in_args.dispatch("iter", mem_error), 1) | ||
3709 | 1482 | |||
3710 | 1483 | # FIXME timeout should be configurable | ||
3711 | 1484 | # FIXME expect no reply? | ||
3712 | 1485 | code += "\n" | ||
3713 | 1486 | code += indent("""\ | ||
3714 | 1487 | /* If we don't specify a callback, just finish it now */ | ||
3715 | 1488 | if (! callback) { | ||
3716 | 1489 | dbus_bool_t succ = dbus_connection_send (proxy->conn, message, NULL); | ||
3717 | 1490 | dbus_message_unref (message); | ||
3718 | 1491 | if (! succ) | ||
3719 | 1492 | nih_return_no_memory_error (-1); | ||
3720 | 1493 | return 0; | ||
3721 | 1494 | } | ||
3722 | 1495 | |||
3723 | 1496 | /* Send the reply, appending it to the outgoing queue and blocking. */ | ||
3724 | 1497 | if (! dbus_connection_send_with_reply (proxy->conn, message, &call, -1)) { | ||
3725 | 1498 | dbus_message_unref (message); | ||
3726 | 1499 | nih_return_no_memory_error (-1); | ||
3727 | 1500 | } | ||
3728 | 1501 | |||
3729 | 1502 | data = nih_new (proxy, NihAsyncNotifyData); | ||
3730 | 1503 | if (! data) | ||
3731 | 1504 | nih_return_no_memory_error (-1); | ||
3732 | 1505 | |||
3733 | 1506 | data->proxy = proxy; | ||
3734 | 1507 | data->userdata = userdata; | ||
3735 | 1508 | data->handler = callback; | ||
3736 | 1509 | data->err_handler = errback; | ||
3737 | 1510 | |||
3738 | 1511 | |||
3739 | 1512 | dbus_pending_call_set_notify(call, (DBusPendingCallNotifyFunction)%s_async_notify, data, (DBusFreeFunction)nih_free); | ||
3740 | 1513 | |||
3741 | 1514 | dbus_message_unref (message); | ||
3742 | 1515 | return 0; | ||
3743 | 1516 | """ % self.extern_name, 1); | ||
3744 | 1517 | |||
3745 | 1518 | code += "}\n" | ||
3746 | 1519 | |||
3747 | 1520 | return code | ||
3748 | 1521 | |||
3749 | 1522 | def dispatchFunction(self): | ||
3750 | 1523 | """Dispatching function. | ||
3751 | 1524 | |||
3752 | 1525 | Returns a string containing a dispatcher function that takes arguments | ||
3753 | 1526 | identical to those taken by a particular dbus method, and pointers to | ||
3754 | 1527 | variables where the return values from that method might be stored. Then | ||
3755 | 1528 | sends a dbus message and waits for a reply to come, and populates the | ||
3756 | 1529 | reply arguments with the contents of the reply message. | ||
3757 | 1530 | """ | ||
3758 | 1531 | in_args = DBusGroup([t for t in self.types if t.direction == "in"], | ||
3759 | 1532 | const=True) | ||
3760 | 1533 | out_args = DBusGroup([t for t in self.types if t.direction == "out"], | ||
3761 | 1534 | pointer=True) | ||
3762 | 1535 | |||
3763 | 1536 | vars = [ ( "NihDBusProxy *", "proxy" ) ] | ||
3764 | 1537 | vars.extend(in_args.vars()) | ||
3765 | 1538 | # FIXME async doesn't have these, but has a callback instead | ||
3766 | 1539 | vars.extend(out_args.vars()) | ||
3767 | 1540 | |||
3768 | 1541 | code = "int\n%s (" % (self.extern_name, ) | ||
3769 | 1542 | code += (",\n" + " " * (len(self.extern_name) + 2)).join(lineup_vars(vars)) | ||
3770 | 1543 | code += ")\n{\n" | ||
3771 | 1544 | |||
3772 | 1545 | # Declare local variables for the iterator, reply and those needed | ||
3773 | 1546 | # for both input and output arguments. | ||
3774 | 1547 | vars = [ ( "DBusMessage *", "message" ), | ||
3775 | 1548 | ( "DBusMessageIter", "iter" ), | ||
3776 | 1549 | ( "DBusMessage *", "reply = NULL" ), | ||
3777 | 1550 | ( "DBusError", "error" ) ] | ||
3778 | 1551 | vars.extend(in_args.locals()) | ||
3779 | 1552 | # FIXME not for async | ||
3780 | 1553 | vars.extend(out_args.locals()) | ||
3781 | 1554 | code += indent(''.join("%s;\n" % var for var in lineup_vars(vars)), 1) | ||
3782 | 1555 | |||
3783 | 1556 | # Pre-amble for the function | ||
3784 | 1557 | code += "\n" | ||
3785 | 1558 | code += indent("""\ | ||
3786 | 1559 | nih_assert (proxy != NULL); | ||
3787 | 1560 | """, 1); | ||
3788 | 1561 | |||
3789 | 1562 | # Dispatch the input arguments into a new local message | ||
3790 | 1563 | code += "\n" | ||
3791 | 1564 | code += indent("""\ | ||
3792 | 1565 | message = dbus_message_new_method_call (proxy->name, proxy->path, "%s", "%s"); | ||
3793 | 1566 | if (! message) | ||
3794 | 1567 | nih_return_no_memory_error (-1); | ||
3795 | 1568 | |||
3796 | 1569 | /* Iterate the arguments to the function and dispatch into | ||
3797 | 1570 | * message arguments. | ||
3798 | 1571 | */ | ||
3799 | 1572 | dbus_message_iter_init_append (message, &iter); | ||
3800 | 1573 | """ % (self.interface.name, self.name), 1) | ||
3801 | 1574 | code += "\n" | ||
3802 | 1575 | |||
3803 | 1576 | # FIXME autostart? | ||
3804 | 1577 | |||
3805 | 1578 | mem_error = indent("""\ | ||
3806 | 1579 | dbus_message_unref (message); | ||
3807 | 1580 | nih_return_no_memory_error (-1); | ||
3808 | 1581 | """, 1) | ||
3809 | 1582 | code += indent(in_args.dispatch("iter", mem_error), 1) | ||
3810 | 1583 | |||
3811 | 1584 | # FIXME timeout should be configurable | ||
3812 | 1585 | # FIXME expect no reply? | ||
3813 | 1586 | code += "\n" | ||
3814 | 1587 | code += indent("""\ | ||
3815 | 1588 | dbus_error_init (&error); | ||
3816 | 1589 | |||
3817 | 1590 | /* Send the reply, appending it to the outgoing queue and blocking. */ | ||
3818 | 1591 | reply = dbus_connection_send_with_reply_and_block (proxy->conn, message, -1, &error); | ||
3819 | 1592 | if (! reply) { | ||
3820 | 1593 | dbus_message_unref (message); | ||
3821 | 1594 | |||
3822 | 1595 | if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { | ||
3823 | 1596 | dbus_error_free (&error); | ||
3824 | 1597 | nih_return_no_memory_error (-1); | ||
3825 | 1598 | } else { | ||
3826 | 1599 | nih_dbus_error_raise (error.name, error.message); | ||
3827 | 1600 | dbus_error_free (&error); | ||
3828 | 1601 | return -1; | ||
3829 | 1602 | } | ||
3830 | 1603 | } | ||
3831 | 1604 | |||
3832 | 1605 | dbus_message_unref (message); | ||
3833 | 1606 | """, 1); | ||
3834 | 1607 | |||
3835 | 1608 | # Marshal the reply arguments into output arguments | ||
3836 | 1609 | code += "\n" | ||
3837 | 1610 | code += indent("""\ | ||
3838 | 1611 | /* Iterate the arguments to the reply and marshal into output | ||
3839 | 1612 | * arguments from our own function call. | ||
3840 | 1613 | */ | ||
3841 | 1614 | dbus_message_iter_init (reply, &iter); | ||
3842 | 1615 | """, 1); | ||
3843 | 1616 | code += "\n" | ||
3844 | 1617 | |||
3845 | 1618 | mem_error = indent("""\ | ||
3846 | 1619 | dbus_message_unref (reply); | ||
3847 | 1620 | nih_return_no_memory_error (-1); | ||
3848 | 1621 | """, 1) | ||
3849 | 1622 | type_error = indent("""\ | ||
3850 | 1623 | dbus_message_unref (reply); | ||
3851 | 1624 | nih_return_error (-1, NIH_DBUS_INVALID_ARGS, NIH_DBUS_INVALID_ARGS_STR); | ||
3852 | 1625 | """, 1); | ||
3853 | 1626 | code += indent(out_args.marshal("iter", "proxy", | ||
3854 | 1627 | type_error, mem_error), 1) | ||
3855 | 1628 | |||
3856 | 1629 | code += "\n" | ||
3857 | 1630 | code += indent("""\ | ||
3858 | 1631 | dbus_message_unref (reply); | ||
3859 | 1632 | |||
3860 | 1633 | return 0; | ||
3861 | 1634 | """, 1) | ||
3862 | 1635 | |||
3863 | 1636 | code += "}\n" | ||
3864 | 1637 | |||
3865 | 1638 | return code | ||
3866 | 1639 | |||
3867 | 1640 | def exportTypedefs(self): | ||
3868 | 1641 | """Exported typedefs. | ||
3869 | 1642 | |||
3870 | 1643 | Type definitions that should be placed in the header. | ||
3871 | 1644 | |||
3872 | 1645 | Each typedef is the code to define it, including any documentation and | ||
3873 | 1646 | default value. | ||
3874 | 1647 | """ | ||
3875 | 1648 | typedefs = [] | ||
3876 | 1649 | out_args = DBusGroup([t for t in self.types if t.direction == "out"]) | ||
3877 | 1650 | if mode == "proxy": | ||
3878 | 1651 | typedefs.append( ("void", | ||
3879 | 1652 | "(*%sCallback)" % camelate(self.extern_name), | ||
3880 | 1653 | [ ( "NihDBusProxy *", "proxy" ), | ||
3881 | 1654 | ( "void *", "userdata") ] + out_args.vars() | ||
3882 | 1655 | ) ) | ||
3883 | 1656 | typedefs.append( ("void", | ||
3884 | 1657 | "(*%sErrback)" % camelate(self.extern_name), | ||
3885 | 1658 | [ ( "NihDBusProxy *", "proxy" ), | ||
3886 | 1659 | ( "void *", "userdata") ] | ||
3887 | 1660 | ) ) | ||
3888 | 1661 | return typedefs | ||
3889 | 1662 | |||
3890 | 1663 | def staticPrototypes(self): | ||
3891 | 1664 | """Static prototypes. | ||
3892 | 1665 | |||
3893 | 1666 | Returns an array of static function prototypes which are normally | ||
3894 | 1667 | placed in a block at the top of the source file. | ||
3895 | 1668 | |||
3896 | 1669 | Each prototype is a (retval, name, args, attributes) tuple. | ||
3897 | 1670 | """ | ||
3898 | 1671 | prototypes = [] | ||
3899 | 1672 | if mode == "object": | ||
3900 | 1673 | prototypes.append(self.marshalPrototype()) | ||
3901 | 1674 | else: | ||
3902 | 1675 | prototypes.append(self.asyncNotifyPrototype()) | ||
3903 | 1676 | |||
3904 | 1677 | return prototypes | ||
3905 | 1678 | |||
3906 | 1679 | def externPrototypes(self): | ||
3907 | 1680 | """Extern prototypes. | ||
3908 | 1681 | |||
3909 | 1682 | Returns an array of extern function prototypes which are normally | ||
3910 | 1683 | placed in a block at the top of the source file, in lieu of | ||
3911 | 1684 | missing headers. | ||
3912 | 1685 | |||
3913 | 1686 | Each prototype is a (retval, name, args, attributes) tuple. | ||
3914 | 1687 | """ | ||
3915 | 1688 | prototypes = [] | ||
3916 | 1689 | if mode =="object": | ||
3917 | 1690 | prototypes.append(self.handlerPrototype()) | ||
3918 | 1691 | |||
3919 | 1692 | return prototypes | ||
3920 | 1693 | |||
3921 | 1694 | def functions(self): | ||
3922 | 1695 | """Functions. | ||
3923 | 1696 | |||
3924 | 1697 | Returns an array of both static and exported functions which | ||
3925 | 1698 | consistute the bulk of the source file. | ||
3926 | 1699 | |||
3927 | 1700 | Each function is the code to define it, including any documentation. | ||
3928 | 1701 | """ | ||
3929 | 1702 | functions = [] | ||
3930 | 1703 | if mode == "object": | ||
3931 | 1704 | functions.append(self.marshalFunction()) | ||
3932 | 1705 | if self.style == "async": | ||
3933 | 1706 | functions.append(self.replyFunction()) | ||
3934 | 1707 | else: | ||
3935 | 1708 | functions.append(self.dispatchFunction()) | ||
3936 | 1709 | functions.append(self.asyncDispatchFunction()) | ||
3937 | 1710 | functions.append(self.asyncNotifyFunction()) | ||
3938 | 1711 | |||
3939 | 1712 | return functions | ||
3940 | 1713 | |||
3941 | 1714 | def exportPrototypes(self): | ||
3942 | 1715 | """Function prototypes. | ||
3943 | 1716 | |||
3944 | 1717 | Returns an array of exported function prototypes which are normally | ||
3945 | 1718 | placed in a block inside the extern part of the header file. | ||
3946 | 1719 | |||
3947 | 1720 | Each prototype is a (retval, name, args, attributes) tuple. | ||
3948 | 1721 | """ | ||
3949 | 1722 | prototypes = [] | ||
3950 | 1723 | if mode == "object": | ||
3951 | 1724 | if self.style == "async": | ||
3952 | 1725 | prototypes.append(self.replyPrototype()) | ||
3953 | 1726 | else: | ||
3954 | 1727 | prototypes.append(self.dispatchPrototype()) | ||
3955 | 1728 | prototypes.append(self.asyncDispatchPrototype()) | ||
3956 | 1729 | |||
3957 | 1730 | return prototypes | ||
3958 | 1731 | |||
3959 | 1732 | |||
3960 | 1733 | class Signal(MemberWithArgs): | ||
3961 | 1734 | def __init__(self, interface, name, types): | ||
3962 | 1735 | super(Signal, self).__init__(interface, name, types) | ||
3963 | 1736 | |||
3964 | 1737 | def dispatchPrototype(self): | ||
3965 | 1738 | """Dispatch function prototype. | ||
3966 | 1739 | |||
3967 | 1740 | Returns a (retval, name, args, attributes) tuple for the prototype | ||
3968 | 1741 | of the dispatch function. | ||
3969 | 1742 | """ | ||
3970 | 1743 | args = DBusGroup(self.types, const=True) | ||
3971 | 1744 | |||
3972 | 1745 | vars = [ ( "DBusConnection *", "connection" ), | ||
3973 | 1746 | ( "const char *", "origin_path" ) ] | ||
3974 | 1747 | vars.extend(args.vars()) | ||
3975 | 1748 | |||
3976 | 1749 | return ( "int", | ||
3977 | 1750 | self.extern_name, | ||
3978 | 1751 | vars, | ||
3979 | 1752 | ( "warn_unused_result", ) ) | ||
3980 | 1753 | |||
3981 | 1754 | def dispatchFunction(self): | ||
3982 | 1755 | """Dispatch function. | ||
3983 | 1756 | |||
3984 | 1757 | Returns a string containing a dispatch function that takes puts | ||
3985 | 1758 | its arguments into a D-Bus message and sends it. | ||
3986 | 1759 | """ | ||
3987 | 1760 | args = DBusGroup(self.types, const=True) | ||
3988 | 1761 | |||
3989 | 1762 | vars = [ ( "DBusConnection *", "connection" ), | ||
3990 | 1763 | ( "const char *", "origin_path" ) ] | ||
3991 | 1764 | vars.extend(args.vars()) | ||
3992 | 1765 | |||
3993 | 1766 | code = "int\n%s (" % (self.extern_name, ) | ||
3994 | 1767 | code += (",\n" + " " * (len(self.extern_name) + 2)).join(lineup_vars(vars)) | ||
3995 | 1768 | code += ")\n{\n" | ||
3996 | 1769 | |||
3997 | 1770 | # Declare local variables for the message and iterator | ||
3998 | 1771 | vars = [ ( "DBusMessage *", "message"), | ||
3999 | 1772 | ( "DBusMessageIter", "iter" ) ] | ||
4000 | 1773 | vars.extend(args.locals()) | ||
4001 | 1774 | code += indent(''.join("%s;\n" % var for var in lineup_vars(vars)), 1) | ||
4002 | 1775 | |||
4003 | 1776 | # Pre-amble for the function | ||
4004 | 1777 | code += "\n" | ||
4005 | 1778 | code += indent("""\ | ||
4006 | 1779 | nih_assert (connection != NULL); | ||
4007 | 1780 | nih_assert (origin_path != NULL); | ||
4008 | 1781 | """, 1) | ||
4009 | 1782 | |||
4010 | 1783 | # Marshal the arguments into a new local message | ||
4011 | 1784 | code += "\n" | ||
4012 | 1785 | code += indent("""\ | ||
4013 | 1786 | message = dbus_message_new_signal (origin_path, "%s", "%s"); | ||
4014 | 1787 | if (! message) | ||
4015 | 1788 | return -1; | ||
4016 | 1789 | |||
4017 | 1790 | /* Iterate the arguments to the function and dispatch into | ||
4018 | 1791 | * message arguments. | ||
4019 | 1792 | */ | ||
4020 | 1793 | dbus_message_iter_init_append (message, &iter); | ||
4021 | 1794 | """ % (self.interface.name, self.name), 1) | ||
4022 | 1795 | code += "\n" | ||
4023 | 1796 | |||
4024 | 1797 | mem_error = indent("""\ | ||
4025 | 1798 | dbus_message_unref (message); | ||
4026 | 1799 | return -1; | ||
4027 | 1800 | """, 1) | ||
4028 | 1801 | code += indent(args.dispatch("iter", mem_error), 1) | ||
4029 | 1802 | |||
4030 | 1803 | code += "\n" | ||
4031 | 1804 | code += indent("""\ | ||
4032 | 1805 | /* Send the reply, appending it to the outgoing queue. */ | ||
4033 | 1806 | if (! dbus_connection_send (connection, message, NULL)) { | ||
4034 | 1807 | dbus_message_unref (message); | ||
4035 | 1808 | return -1; | ||
4036 | 1809 | } | ||
4037 | 1810 | |||
4038 | 1811 | dbus_message_unref (message); | ||
4039 | 1812 | |||
4040 | 1813 | return 0; | ||
4041 | 1814 | """, 1) | ||
4042 | 1815 | |||
4043 | 1816 | code += "}\n" | ||
4044 | 1817 | |||
4045 | 1818 | return code | ||
4046 | 1819 | |||
4047 | 1820 | def functions(self): | ||
4048 | 1821 | """Functions. | ||
4049 | 1822 | |||
4050 | 1823 | Returns an array of both static and exported functions which | ||
4051 | 1824 | consistute the bulk of the source file. | ||
4052 | 1825 | |||
4053 | 1826 | Each function is the code to define it, including any documentation. | ||
4054 | 1827 | """ | ||
4055 | 1828 | functions = [] | ||
4056 | 1829 | if mode == "object": | ||
4057 | 1830 | functions.append(self.dispatchFunction()) | ||
4058 | 1831 | |||
4059 | 1832 | return functions | ||
4060 | 1833 | |||
4061 | 1834 | def exportPrototypes(self): | ||
4062 | 1835 | """Function prototypes. | ||
4063 | 1836 | |||
4064 | 1837 | Returns an array of exported function prototypes which are normally | ||
4065 | 1838 | placed in a block inside the extern part of the header file. | ||
4066 | 1839 | |||
4067 | 1840 | Each prototype is a (retval, name, args, attributes) tuple. | ||
4068 | 1841 | """ | ||
4069 | 1842 | prototypes = [] | ||
4070 | 1843 | if mode == "object": | ||
4071 | 1844 | prototypes.append(self.dispatchPrototype()) | ||
4072 | 1845 | |||
4073 | 1846 | return prototypes | ||
4074 | 1847 | |||
4075 | 1848 | |||
4076 | 1849 | class Group(Generator): | ||
4077 | 1850 | def __init__(self, members): | ||
4078 | 1851 | self.members = members | ||
4079 | 1852 | |||
4080 | 1853 | def staticPrototypes(self): | ||
4081 | 1854 | """Static prototypes. | ||
4082 | 1855 | |||
4083 | 1856 | Returns an array of static function prototypes which are normally | ||
4084 | 1857 | placed in a block at the top of the source file. | ||
4085 | 1858 | |||
4086 | 1859 | Each prototype is a (retval, name, args, attributes) tuple. | ||
4087 | 1860 | """ | ||
4088 | 1861 | prototypes = [] | ||
4089 | 1862 | for member in self.members: | ||
4090 | 1863 | prototypes.extend(member.staticPrototypes()) | ||
4091 | 1864 | |||
4092 | 1865 | return prototypes | ||
4093 | 1866 | |||
4094 | 1867 | def externPrototypes(self): | ||
4095 | 1868 | """Extern prototypes. | ||
4096 | 1869 | |||
4097 | 1870 | Returns an array of extern function prototypes which are normally | ||
4098 | 1871 | placed in a block at the top of the source file, in lieu of | ||
4099 | 1872 | missing headers. | ||
4100 | 1873 | |||
4101 | 1874 | Each prototype is a (retval, name, args, attributes) tuple. | ||
4102 | 1875 | """ | ||
4103 | 1876 | prototypes = [] | ||
4104 | 1877 | for member in self.members: | ||
4105 | 1878 | prototypes.extend(member.externPrototypes()) | ||
4106 | 1879 | |||
4107 | 1880 | return prototypes | ||
4108 | 1881 | |||
4109 | 1882 | def exportTypedefs(self): | ||
4110 | 1883 | """Exported typedefs. | ||
4111 | 1884 | |||
4112 | 1885 | Type definitions that should be placed in the header. | ||
4113 | 1886 | |||
4114 | 1887 | Each typedef is the code to define it, including any documentation and | ||
4115 | 1888 | default value. | ||
4116 | 1889 | """ | ||
4117 | 1890 | typedefs = [] | ||
4118 | 1891 | for member in self.members: | ||
4119 | 1892 | typedefs.extend(member.exportTypedefs()) | ||
4120 | 1893 | |||
4121 | 1894 | return typedefs | ||
4122 | 1895 | |||
4123 | 1896 | def variables(self): | ||
4124 | 1897 | """Variables. | ||
4125 | 1898 | |||
4126 | 1899 | Returns an array of both static and exported global variables | ||
4127 | 1900 | normally placed in a block at the top of the source file. | ||
4128 | 1901 | |||
4129 | 1902 | Each variable is the code to define it, including any documentation | ||
4130 | 1903 | and default value. | ||
4131 | 1904 | """ | ||
4132 | 1905 | variables = [] | ||
4133 | 1906 | for member in self.members: | ||
4134 | 1907 | variables.extend(member.variables()) | ||
4135 | 1908 | |||
4136 | 1909 | return variables | ||
4137 | 1910 | |||
4138 | 1911 | def functions(self): | ||
4139 | 1912 | """Functions. | ||
4140 | 1913 | |||
4141 | 1914 | Returns an array of both static and exported functions which | ||
4142 | 1915 | consistute the bulk of the source file. | ||
4143 | 1916 | |||
4144 | 1917 | Each function is the code to define it, including any documentation. | ||
4145 | 1918 | """ | ||
4146 | 1919 | functions = [] | ||
4147 | 1920 | for member in self.members: | ||
4148 | 1921 | functions.extend(member.functions()) | ||
4149 | 1922 | |||
4150 | 1923 | return functions | ||
4151 | 1924 | |||
4152 | 1925 | def definitions(self): | ||
4153 | 1926 | """Definitions. | ||
4154 | 1927 | |||
4155 | 1928 | Returns an array of structure and type definitions which are | ||
4156 | 1929 | normally placed in a block in the header file. | ||
4157 | 1930 | |||
4158 | 1931 | Each definition is the code to define it, including any documentation. | ||
4159 | 1932 | """ | ||
4160 | 1933 | definitions = [] | ||
4161 | 1934 | for member in self.members: | ||
4162 | 1935 | definitions.extend(member.definitions()) | ||
4163 | 1936 | |||
4164 | 1937 | return definitions | ||
4165 | 1938 | |||
4166 | 1939 | def exports(self): | ||
4167 | 1940 | """Exports. | ||
4168 | 1941 | |||
4169 | 1942 | Returns an array of prototypes for exported variables which are | ||
4170 | 1943 | placed as a block inside the extern part of the header file. | ||
4171 | 1944 | |||
4172 | 1945 | Each export is a (type, name) tuple. | ||
4173 | 1946 | """ | ||
4174 | 1947 | exports = [] | ||
4175 | 1948 | for member in self.members: | ||
4176 | 1949 | exports.extend(member.exports()) | ||
4177 | 1950 | |||
4178 | 1951 | return exports | ||
4179 | 1952 | |||
4180 | 1953 | def exportPrototypes(self): | ||
4181 | 1954 | """Function prototypes. | ||
4182 | 1955 | |||
4183 | 1956 | Returns an array of exported function prototypes which are normally | ||
4184 | 1957 | placed in a block inside the extern part of the header file. | ||
4185 | 1958 | |||
4186 | 1959 | Each prototype is a (retval, name, args, attributes) tuple. | ||
4187 | 1960 | """ | ||
4188 | 1961 | prototypes = [] | ||
4189 | 1962 | for member in self.members: | ||
4190 | 1963 | prototypes.extend(member.exportPrototypes()) | ||
4191 | 1964 | |||
4192 | 1965 | return prototypes | ||
4193 | 1966 | |||
4194 | 1967 | |||
4195 | 1968 | class Interface(Group): | ||
4196 | 1969 | @classmethod | ||
4197 | 1970 | def fromElement(cls, elem): | ||
4198 | 1971 | name = elem.get("name") | ||
4199 | 1972 | if name is None: | ||
4200 | 1973 | raise AttributeError, "Interface name may not be null" | ||
4201 | 1974 | |||
4202 | 1975 | self = cls(name, []) | ||
4203 | 1976 | for e in elem.findall("method"): | ||
4204 | 1977 | method = Method.fromElement(self, e) | ||
4205 | 1978 | self.methods.append(method) | ||
4206 | 1979 | self.members.append(method) | ||
4207 | 1980 | for e in elem.findall("signal"): | ||
4208 | 1981 | signal = Signal.fromElement(self, e) | ||
4209 | 1982 | self.signals.append(signal) | ||
4210 | 1983 | self.members.append(signal) | ||
4211 | 1984 | |||
4212 | 1985 | return self | ||
4213 | 1986 | |||
4214 | 1987 | def __init__(self, name, members): | ||
4215 | 1988 | super(Interface, self).__init__(members) | ||
4216 | 1989 | |||
4217 | 1990 | self.name = name | ||
4218 | 1991 | self.methods = [] | ||
4219 | 1992 | self.signals = [] | ||
4220 | 1993 | |||
4221 | 1994 | @property | ||
4222 | 1995 | def c_name(self): | ||
4223 | 1996 | return self.name.replace(".", "_") | ||
4224 | 1997 | |||
4225 | 1998 | def methodsArray(self): | ||
4226 | 1999 | """Methods array. | ||
4227 | 2000 | |||
4228 | 2001 | Returns a string containing code to initialise the array of methods | ||
4229 | 2002 | used for nih_dbus_object_new(). | ||
4230 | 2003 | """ | ||
4231 | 2004 | code = """\ | ||
4232 | 2005 | const NihDBusMethod %s_methods[] = { | ||
4233 | 2006 | """ % self.c_name | ||
4234 | 2007 | |||
4235 | 2008 | array = [] | ||
4236 | 2009 | for method in self.methods: | ||
4237 | 2010 | if mode == "object": | ||
4238 | 2011 | func = "%s_marshal" % "_".join([ self.c_name, method.c_name ]) | ||
4239 | 2012 | else: | ||
4240 | 2013 | func = "NULL" | ||
4241 | 2014 | |||
4242 | 2015 | array.append(( "\"%s\"" % method.name, | ||
4243 | 2016 | func, | ||
4244 | 2017 | "%s_args" % "_".join([ self.c_name, method.c_name ]))) | ||
4245 | 2018 | |||
4246 | 2019 | for line in lineup_array(array): | ||
4247 | 2020 | code += indent("%s,\n" % line, 1) | ||
4248 | 2021 | |||
4249 | 2022 | code += """\ | ||
4250 | 2023 | { NULL } | ||
4251 | 2024 | }; | ||
4252 | 2025 | """ | ||
4253 | 2026 | return code | ||
4254 | 2027 | |||
4255 | 2028 | def signalsArray(self): | ||
4256 | 2029 | """Signals array. | ||
4257 | 2030 | |||
4258 | 2031 | Returns a string containing code to initialise the array of signals | ||
4259 | 2032 | used for nih_dbus_object_new(). | ||
4260 | 2033 | """ | ||
4261 | 2034 | code = """\ | ||
4262 | 2035 | const NihDBusSignal %s_signals[] = { | ||
4263 | 2036 | """ % self.c_name | ||
4264 | 2037 | |||
4265 | 2038 | array = [] | ||
4266 | 2039 | for signal in self.signals: | ||
4267 | 2040 | array.append(( "\"%s\"" % signal.name, | ||
4268 | 2041 | "%s_args" % "_".join([ self.c_name, signal.c_name ]))) | ||
4269 | 2042 | |||
4270 | 2043 | for line in lineup_array(array): | ||
4271 | 2044 | code += indent("%s,\n" % line, 1) | ||
4272 | 2045 | |||
4273 | 2046 | code += """\ | ||
4274 | 2047 | { NULL } | ||
4275 | 2048 | }; | ||
4276 | 2049 | """ | ||
4277 | 2050 | return code | ||
4278 | 2051 | |||
4279 | 2052 | def interfacePrototype(self): | ||
4280 | 2053 | """Interface structure prototype. | ||
4281 | 2054 | |||
4282 | 2055 | Returns a (type, name) tuple for the prototype of the interface | ||
4283 | 2056 | struct. | ||
4284 | 2057 | """ | ||
4285 | 2058 | return ( "const NihDBusInterface", "%s" % self.c_name ) | ||
4286 | 2059 | |||
4287 | 2060 | def interfaceStruct(self): | ||
4288 | 2061 | """Interface structure. | ||
4289 | 2062 | |||
4290 | 2063 | Returns a string containing code to define a structure containing | ||
4291 | 2064 | information about the interface. | ||
4292 | 2065 | """ | ||
4293 | 2066 | code = """\ | ||
4294 | 2067 | const NihDBusInterface %s = { | ||
4295 | 2068 | \"%s\", | ||
4296 | 2069 | %s_methods, | ||
4297 | 2070 | %s_signals, | ||
4298 | 2071 | NULL | ||
4299 | 2072 | """ % (self.c_name, self.name, self.c_name, self.c_name) | ||
4300 | 2073 | |||
4301 | 2074 | code += """\ | ||
4302 | 2075 | }; | ||
4303 | 2076 | """ | ||
4304 | 2077 | return code | ||
4305 | 2078 | |||
4306 | 2079 | def variables(self): | ||
4307 | 2080 | """Variables. | ||
4308 | 2081 | |||
4309 | 2082 | Returns an array of both static and exported global variables | ||
4310 | 2083 | normally placed in a block at the top of the source file. | ||
4311 | 2084 | |||
4312 | 2085 | Each variable is the code to define it, including any documentation | ||
4313 | 2086 | and default value. | ||
4314 | 2087 | """ | ||
4315 | 2088 | variables = super(Interface, self).variables() | ||
4316 | 2089 | if mode == "object": | ||
4317 | 2090 | variables.append(self.methodsArray()) | ||
4318 | 2091 | variables.append(self.signalsArray()) | ||
4319 | 2092 | variables.append(self.interfaceStruct()) | ||
4320 | 2093 | |||
4321 | 2094 | return variables | ||
4322 | 2095 | |||
4323 | 2096 | def exports(self): | ||
4324 | 2097 | """Exports. | ||
4325 | 2098 | |||
4326 | 2099 | Returns an array of prototypes for exported variables which are | ||
4327 | 2100 | placed as a block inside the extern part of the header file. | ||
4328 | 2101 | |||
4329 | 2102 | Each export is a (type, name) tuple. | ||
4330 | 2103 | """ | ||
4331 | 2104 | exports = super(Interface, self).exports() | ||
4332 | 2105 | if mode == "object": | ||
4333 | 2106 | exports.append(self.interfacePrototype()) | ||
4334 | 2107 | |||
4335 | 2108 | return exports | ||
4336 | 2109 | |||
4337 | 2110 | |||
4338 | 2111 | class Output(Group): | ||
4339 | 2112 | def __init__(self, basename, members): | ||
4340 | 2113 | super(Output, self).__init__(members) | ||
4341 | 2114 | |||
4342 | 2115 | self.basename = basename | ||
4343 | 2116 | |||
4344 | 2117 | def sourceFile(self): | ||
4345 | 2118 | """Generate source (.c) file. | ||
4346 | 2119 | |||
4347 | 2120 | Returns a string containing the code for the source (.c) file | ||
4348 | 2121 | of this code group. | ||
4349 | 2122 | """ | ||
4350 | 2123 | code = """\ | ||
4351 | 2124 | /* %s | ||
4352 | 2125 | * | ||
4353 | 2126 | * %s - %s | ||
4354 | 2127 | * | ||
4355 | 2128 | * %s | ||
4356 | 2129 | * | ||
4357 | 2130 | * This program is free software; you can redistribute it and/or modify | ||
4358 | 2131 | * it under the terms of the GNU General Public License as published by | ||
4359 | 2132 | * the Free Software Foundation; either version 2 of the License, or | ||
4360 | 2133 | * (at your option) any later version. | ||
4361 | 2134 | * | ||
4362 | 2135 | * This program is distributed in the hope that it will be useful, | ||
4363 | 2136 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4364 | 2137 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4365 | 2138 | * GNU General Public License for more details. | ||
4366 | 2139 | * | ||
4367 | 2140 | * You should have received a copy of the GNU General Public License | ||
4368 | 2141 | * along with this program; if not, write to the Free Software | ||
4369 | 2142 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
4370 | 2143 | */ | ||
4371 | 2144 | """ % (PACKAGE_NAME, "%s.c" % self.basename, "Auto-generated d-bus bindings", | ||
4372 | 2145 | PACKAGE_COPYRIGHT) | ||
4373 | 2146 | |||
4374 | 2147 | # Usual includes | ||
4375 | 2148 | if code: | ||
4376 | 2149 | code += "\n" | ||
4377 | 2150 | code += """\ | ||
4378 | 2151 | #ifdef HAVE_CONFIG_H | ||
4379 | 2152 | # include <config.h> | ||
4380 | 2153 | #endif /* HAVE_CONFIG_H */ | ||
4381 | 2154 | |||
4382 | 2155 | |||
4383 | 2156 | #include <dbus/dbus.h> | ||
4384 | 2157 | |||
4385 | 2158 | #include <errno.h> | ||
4386 | 2159 | |||
4387 | 2160 | #include <nih/macros.h> | ||
4388 | 2161 | #include <nih/alloc.h> | ||
4389 | 2162 | #include <nih/string.h> | ||
4390 | 2163 | #include <nih/logging.h> | ||
4391 | 2164 | #include <nih/error.h> | ||
4392 | 2165 | #include <nih/errors.h> | ||
4393 | 2166 | #include <nih/dbus.h> | ||
4394 | 2167 | |||
4395 | 2168 | #include "%s.h" | ||
4396 | 2169 | """ % (self.basename, ) | ||
4397 | 2170 | if mode == "proxy": | ||
4398 | 2171 | if code: | ||
4399 | 2172 | code += "\n\n" | ||
4400 | 2173 | code += """\ | ||
4401 | 2174 | /** | ||
4402 | 2175 | * NihAsyncNotifyData: | ||
4403 | 2176 | * @handler: The user handler that our libnih handler should call, | ||
4404 | 2177 | * @userdata: Data to pass to @handler, | ||
4405 | 2178 | * @proxy: The proxy object to which the call was made. | ||
4406 | 2179 | * | ||
4407 | 2180 | * This structure contains information that is assembled during an asynchronous | ||
4408 | 2181 | * method call and passed to the handler on the method's return. It should never | ||
4409 | 2182 | * be used directly by the user. | ||
4410 | 2183 | **/ | ||
4411 | 2184 | typedef struct nih_async_notify_data { | ||
4412 | 2185 | void *handler; | ||
4413 | 2186 | void *err_handler; | ||
4414 | 2187 | void *userdata; | ||
4415 | 2188 | NihDBusProxy *proxy; | ||
4416 | 2189 | } NihAsyncNotifyData;""" | ||
4417 | 2190 | # Extern function prototypes | ||
4418 | 2191 | protos = self.externPrototypes() | ||
4419 | 2192 | if protos: | ||
4420 | 2193 | if code: | ||
4421 | 2194 | code += "\n\n" | ||
4422 | 2195 | code += """\ | ||
4423 | 2196 | /* Prototypes for handler functions */ | ||
4424 | 2197 | """ | ||
4425 | 2198 | for line in lineup_protos(protos): | ||
4426 | 2199 | code += line | ||
4427 | 2200 | code += ";\n" | ||
4428 | 2201 | |||
4429 | 2202 | # Static function prototypes | ||
4430 | 2203 | protos = self.staticPrototypes() | ||
4431 | 2204 | if protos: | ||
4432 | 2205 | if code: | ||
4433 | 2206 | code += "\n\n" | ||
4434 | 2207 | code += """\ | ||
4435 | 2208 | /* Prototypes for static functions */ | ||
4436 | 2209 | """ | ||
4437 | 2210 | for line in lineup_protos(protos): | ||
4438 | 2211 | code += line | ||
4439 | 2212 | code += ";\n" | ||
4440 | 2213 | |||
4441 | 2214 | # Global variables | ||
4442 | 2215 | variables = self.variables() | ||
4443 | 2216 | if variables: | ||
4444 | 2217 | if code: | ||
4445 | 2218 | code += "\n" | ||
4446 | 2219 | for g in variables: | ||
4447 | 2220 | if code: | ||
4448 | 2221 | code += "\n" | ||
4449 | 2222 | code += g | ||
4450 | 2223 | |||
4451 | 2224 | # Function definitions | ||
4452 | 2225 | functions = self.functions() | ||
4453 | 2226 | if functions: | ||
4454 | 2227 | if code: | ||
4455 | 2228 | code += "\n" | ||
4456 | 2229 | for function in functions: | ||
4457 | 2230 | if code: | ||
4458 | 2231 | code += "\n" | ||
4459 | 2232 | code += function | ||
4460 | 2233 | |||
4461 | 2234 | return code | ||
4462 | 2235 | |||
4463 | 2236 | def headerFile(self): | ||
4464 | 2237 | """Generate header (.h) file. | ||
4465 | 2238 | |||
4466 | 2239 | Returns a string containing the code for the header (.h) file | ||
4467 | 2240 | of this code group. | ||
4468 | 2241 | """ | ||
4469 | 2242 | code = """\ | ||
4470 | 2243 | /* %s | ||
4471 | 2244 | * | ||
4472 | 2245 | * %s | ||
4473 | 2246 | * | ||
4474 | 2247 | * This program is free software; you can redistribute it and/or modify | ||
4475 | 2248 | * it under the terms of the GNU General Public License as published by | ||
4476 | 2249 | * the Free Software Foundation; either version 2 of the License, or | ||
4477 | 2250 | * (at your option) any later version. | ||
4478 | 2251 | * | ||
4479 | 2252 | * This program is distributed in the hope that it will be useful, | ||
4480 | 2253 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4481 | 2254 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4482 | 2255 | * GNU General Public License for more details. | ||
4483 | 2256 | * | ||
4484 | 2257 | * You should have received a copy of the GNU General Public License | ||
4485 | 2258 | * along with this program; if not, write to the Free Software | ||
4486 | 2259 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
4487 | 2260 | */ | ||
4488 | 2261 | """ % (PACKAGE_NAME, PACKAGE_COPYRIGHT) | ||
4489 | 2262 | |||
4490 | 2263 | # FIXME include sub-directory name in sentry? | ||
4491 | 2264 | sentry = "DBUS__%s_H" % self.basename.replace(".", "_").upper() | ||
4492 | 2265 | if code: | ||
4493 | 2266 | code += "\n" | ||
4494 | 2267 | code += """\ | ||
4495 | 2268 | #ifndef %s | ||
4496 | 2269 | #define %s | ||
4497 | 2270 | |||
4498 | 2271 | #include <dbus/dbus.h> | ||
4499 | 2272 | |||
4500 | 2273 | #include <nih/macros.h> | ||
4501 | 2274 | #include <nih/dbus.h> | ||
4502 | 2275 | """ % (sentry, sentry) | ||
4503 | 2276 | |||
4504 | 2277 | # Append structure definitions | ||
4505 | 2278 | definitions = self.definitions() | ||
4506 | 2279 | if definitions: | ||
4507 | 2280 | if code: | ||
4508 | 2281 | code += "\n" | ||
4509 | 2282 | for definition in definitions: | ||
4510 | 2283 | if code: | ||
4511 | 2284 | code += "\n" | ||
4512 | 2285 | code += definition | ||
4513 | 2286 | |||
4514 | 2287 | # Typedefs | ||
4515 | 2288 | typedefs = self.exportTypedefs() | ||
4516 | 2289 | if typedefs: | ||
4517 | 2290 | if code: | ||
4518 | 2291 | code += "\n\n" | ||
4519 | 2292 | for line in lineup_typedefs(typedefs): | ||
4520 | 2293 | code += line | ||
4521 | 2294 | code += "\n" | ||
4522 | 2295 | |||
4523 | 2296 | # Guard extern prototypes for C++ inclusion | ||
4524 | 2297 | if code: | ||
4525 | 2298 | code += "\n\n" | ||
4526 | 2299 | code += """\ | ||
4527 | 2300 | NIH_BEGIN_EXTERN | ||
4528 | 2301 | """ | ||
4529 | 2302 | |||
4530 | 2303 | # Line up the variable prototypes together and place in a block | ||
4531 | 2304 | globals = self.exports() | ||
4532 | 2305 | if globals: | ||
4533 | 2306 | if code: | ||
4534 | 2307 | code += "\n" | ||
4535 | 2308 | for line in lineup_vars(globals): | ||
4536 | 2309 | code += line | ||
4537 | 2310 | code += ";\n" | ||
4538 | 2311 | |||
4539 | 2312 | # Line up the function prototypes together and place in a block | ||
4540 | 2313 | protos = self.exportPrototypes() | ||
4541 | 2314 | if protos: | ||
4542 | 2315 | if code: | ||
4543 | 2316 | code += "\n" | ||
4544 | 2317 | for line in lineup_protos(protos): | ||
4545 | 2318 | code += line | ||
4546 | 2319 | code += ";\n" | ||
4547 | 2320 | |||
4548 | 2321 | # End the extern guard and header sentry | ||
4549 | 2322 | if code: | ||
4550 | 2323 | code += "\n" | ||
4551 | 2324 | code += """\ | ||
4552 | 2325 | NIH_END_EXTERN | ||
4553 | 2326 | |||
4554 | 2327 | #endif /* %s */ | ||
4555 | 2328 | """ % (sentry) | ||
4556 | 2329 | |||
4557 | 2330 | return code | ||
4558 | 2331 | |||
4559 | 2332 | |||
4560 | 2333 | # Complex: | ||
4561 | 2334 | # s (struct) -> pointer to a struct of a defined type (named after func + arg) | ||
4562 | 2335 | # e.g. typedef struct job_find_by_name_what { | ||
4563 | 2336 | # ... | ||
4564 | 2337 | # } JobFindByNameWhat; | ||
4565 | 2338 | # | ||
4566 | 2339 | # dbus_message_iter_recurse (ITER, SUB) | ||
4567 | 2340 | # OK = dbus_message_iter_close_container (ITER, SUB) | ||
4568 | 2341 | # | ||
4569 | 2342 | # dbus_message_iter_open_container (ITER, TYPE, NULL, SUB) | ||
4570 | 2343 | # OK = dbus_message_iter_close_container (ITER, SUB) | ||
4571 | 2344 | # | ||
4572 | 2345 | # thus we can make arrays of it too :-) | ||
4573 | 2346 | # struct-in-struct can just get arbitrary names | ||
4574 | 2347 | # | ||
4575 | 2348 | # | ||
4576 | 2349 | # Annoying" | ||
4577 | 2350 | # v (variant) -> seems to be a problem | ||
4578 | 2351 | # has a type signature then the data | ||
4579 | 2352 | # | ||
4580 | 2353 | # e (dict) -> problem for now (should be NihHash really) | ||
4581 | 2354 | # always arrays a{..} | ||
4582 | 2355 | # first type is basic | ||
4583 | 2356 | # second type is any (including struct) | ||
4584 | 2357 | |||
4585 | 2358 | |||
4586 | 2359 | def lineup_vars(vars): | ||
4587 | 2360 | """Lineup variable lists. | ||
4588 | 2361 | |||
4589 | 2362 | Returns an array of lines of C code to declare each of the variables | ||
4590 | 2363 | in vars, which should be an array of (type, name) tuples. The | ||
4591 | 2364 | declarations will be lined up in a pretty fashion. | ||
4592 | 2365 | |||
4593 | 2366 | It is up to the caller to add appropriate line-endings. | ||
4594 | 2367 | """ | ||
4595 | 2368 | exp_vars = [] | ||
4596 | 2369 | for type, name in vars: | ||
4597 | 2370 | basic = type.rstrip("*") | ||
4598 | 2371 | pointers = type[len(basic):] | ||
4599 | 2372 | basic = basic.rstrip() | ||
4600 | 2373 | exp_vars.append(( basic, pointers, name )) | ||
4601 | 2374 | |||
4602 | 2375 | if not exp_vars: | ||
4603 | 2376 | return [] | ||
4604 | 2377 | |||
4605 | 2378 | max_basic = max(len(b) for b,p,n in exp_vars) | ||
4606 | 2379 | max_pointers = max(len(p) for b,p,n in exp_vars) | ||
4607 | 2380 | |||
4608 | 2381 | lines = [] | ||
4609 | 2382 | for basic, pointers, name in exp_vars: | ||
4610 | 2383 | code = basic.ljust(max_basic) | ||
4611 | 2384 | code += pointers.rjust(max_pointers + 1) | ||
4612 | 2385 | code += name | ||
4613 | 2386 | |||
4614 | 2387 | lines.append(code) | ||
4615 | 2388 | |||
4616 | 2389 | return lines | ||
4617 | 2390 | |||
4618 | 2391 | def typedef_lineup_prefix(type): | ||
4619 | 2392 | """Pads a type name on the left so indent starts past (* | ||
4620 | 2393 | |||
4621 | 2394 | If a string begins with (* returns it. If it begins with * pad it on the | ||
4622 | 2395 | left with one space. If it begins with 0 pad with two spaces. | ||
4623 | 2396 | """ | ||
4624 | 2397 | if type.startswith("(*"): | ||
4625 | 2398 | return type | ||
4626 | 2399 | if type.startswith("*"): | ||
4627 | 2400 | return " " + type | ||
4628 | 2401 | return " " + type | ||
4629 | 2402 | |||
4630 | 2403 | def lineup_typedefs(typedefs): | ||
4631 | 2404 | """ Lineup typedef lists. | ||
4632 | 2405 | |||
4633 | 2406 | Returns an array of lines of C code to declare each of the typedefs | ||
4634 | 2407 | in typedefs, which should be an array of (type, name, args) | ||
4635 | 2408 | """ | ||
4636 | 2409 | defs = [] | ||
4637 | 2410 | max_type = max(len(t) for t,n,a in typedefs) | ||
4638 | 2411 | max_name = max(len(typedef_lineup_prefix(n)) for t,n,a in typedefs) | ||
4639 | 2412 | |||
4640 | 2413 | for type,name,args in typedefs: | ||
4641 | 2414 | code = "typedef " | ||
4642 | 2415 | code += type.ljust(max_type+1) | ||
4643 | 2416 | code += typedef_lineup_prefix(name).ljust(max_name+1) | ||
4644 | 2417 | code += "(" | ||
4645 | 2418 | code += ", ".join("%s%s%s" % (type, not type.endswith("*") and " " or "", | ||
4646 | 2419 | name) for type,name in args) | ||
4647 | 2420 | code += ");" | ||
4648 | 2421 | defs.append(code) | ||
4649 | 2422 | |||
4650 | 2423 | return defs | ||
4651 | 2424 | |||
4652 | 2425 | def lineup_protos(protos): | ||
4653 | 2426 | """Lineup prototype lists. | ||
4654 | 2427 | |||
4655 | 2428 | Returns an array of lines of C code to declare each of the prototypes | ||
4656 | 2429 | in protos, which should be an array of (retval, name, args, attributes) | ||
4657 | 2430 | tuples. The declarations will be lined up in a pretty fashion. | ||
4658 | 2431 | |||
4659 | 2432 | It is up to the caller to add appropriate line-endings. | ||
4660 | 2433 | """ | ||
4661 | 2434 | if not protos: | ||
4662 | 2435 | return [] | ||
4663 | 2436 | |||
4664 | 2437 | max_retval = max(len(r) for r,n,a,at in protos) | ||
4665 | 2438 | max_name = max(len(n) for r,n,a,at in protos) | ||
4666 | 2439 | |||
4667 | 2440 | if not [ True for r,n,a,at in protos if r.endswith("*") ]: | ||
4668 | 2441 | max_retval += 1 | ||
4669 | 2442 | |||
4670 | 2443 | lines = [] | ||
4671 | 2444 | for retval, name, args, attributes in protos: | ||
4672 | 2445 | code = retval.ljust(max_retval) | ||
4673 | 2446 | code += name.ljust(max_name + 1) | ||
4674 | 2447 | code += "(" | ||
4675 | 2448 | # FIXME split arguments over multiple lines maybe? | ||
4676 | 2449 | code += ", ".join("%s%s%s" % (type, not type.endswith("*") and " " or "", | ||
4677 | 2450 | name) for type,name in args) | ||
4678 | 2451 | code += ")" | ||
4679 | 2452 | if attributes: | ||
4680 | 2453 | code += "\n\t__attribute__ ((" + ", ".join(attributes) + "))" | ||
4681 | 2454 | |||
4682 | 2455 | lines.append(code) | ||
4683 | 2456 | |||
4684 | 2457 | return lines | ||
4685 | 2458 | |||
4686 | 2459 | def camelate(string): | ||
4687 | 2460 | """Make a _-delimited string CamelCase. | ||
4688 | 2461 | |||
4689 | 2462 | Not much else to say. | ||
4690 | 2463 | """ | ||
4691 | 2464 | return "".join([ x.capitalize() for x in string.split("_") ]) | ||
4692 | 2465 | |||
4693 | 2466 | def lineup_array(array): | ||
4694 | 2467 | """Lineup array definitions. | ||
4695 | 2468 | |||
4696 | 2469 | Returns an array of lines of C code to declare each of the array struct | ||
4697 | 2470 | definitions in array, which should be an array of tuples for each structure | ||
4698 | 2471 | member. The declarations will be lined up in a pretty fashion. | ||
4699 | 2472 | |||
4700 | 2473 | It is up to the caller to add appropriate line-endings. | ||
4701 | 2474 | """ | ||
4702 | 2475 | if not array: | ||
4703 | 2476 | return [] | ||
4704 | 2477 | |||
4705 | 2478 | max_len = [ max(len(entry[i]) for entry in array) | ||
4706 | 2479 | for i in range(0, len(array[0])) ] | ||
4707 | 2480 | |||
4708 | 2481 | lines = [] | ||
4709 | 2482 | for entry in array: | ||
4710 | 2483 | code = "{ " | ||
4711 | 2484 | |||
4712 | 2485 | for i, str in enumerate(entry): | ||
4713 | 2486 | if i < len(array[0]) - 1: | ||
4714 | 2487 | code += (str + ", ").ljust(max_len[i] + 2) | ||
4715 | 2488 | else: | ||
4716 | 2489 | code += str.ljust(max_len[i]) | ||
4717 | 2490 | |||
4718 | 2491 | code += " }" | ||
4719 | 2492 | |||
4720 | 2493 | lines.append(code) | ||
4721 | 2494 | |||
4722 | 2495 | return lines | ||
4723 | 2496 | |||
4724 | 2497 | |||
4725 | 2498 | def indent(str, level): | ||
4726 | 2499 | """Increase indent of string. | ||
4727 | 2500 | |||
4728 | 2501 | Returns the string with each line indented to the given level of tabs. | ||
4729 | 2502 | """ | ||
4730 | 2503 | output = "" | ||
4731 | 2504 | for line in str.splitlines(True): | ||
4732 | 2505 | if len(line.strip()): | ||
4733 | 2506 | output += ("\t" * level) + line | ||
4734 | 2507 | else: | ||
4735 | 2508 | output += line | ||
4736 | 2509 | return output | ||
4737 | 2510 | |||
4738 | 2511 | |||
4739 | 2512 | def pointerify(type): | ||
4740 | 2513 | """Turn C type into a pointer. | ||
4741 | 2514 | |||
4742 | 2515 | Returns the string for a pointer to the given C type. | ||
4743 | 2516 | """ | ||
4744 | 2517 | if type.endswith("*"): | ||
4745 | 2518 | return type + "*" | ||
4746 | 2519 | else: | ||
4747 | 2520 | return type + " *" | ||
4748 | 2521 | |||
4749 | 2522 | def constify(type): | ||
4750 | 2523 | """Type C pointer type into a const pointer. | ||
4751 | 2524 | |||
4752 | 2525 | Returns the string modified so that the pointer is a const pointer. | ||
4753 | 2526 | """ | ||
4754 | 2527 | if not type.endswith("*"): | ||
4755 | 2528 | return type | ||
4756 | 2529 | |||
4757 | 2530 | if type[:-1].endswith("*"): | ||
4758 | 2531 | return type[:-1] + " const *" | ||
4759 | 2532 | else: | ||
4760 | 2533 | return "const " + type | ||
4761 | 2534 | |||
4762 | 2535 | |||
4763 | 2536 | def main(): | ||
4764 | 2537 | global options | ||
4765 | 2538 | global extern_prefix | ||
4766 | 2539 | global mode | ||
4767 | 2540 | |||
4768 | 2541 | usage = "%prog [OPTION]... XMLFILE" | ||
4769 | 2542 | description = """\ | ||
4770 | 2543 | XMLFILE is a valid XML file containing information about one or more interfaces | ||
4771 | 2544 | in the D-Bus Introspection format, except that the top-level node may be | ||
4772 | 2545 | interface as well as node. | ||
4773 | 2546 | |||
4774 | 2547 | C code to marshal methods and dispatch signals (if --mode is object) or to | ||
4775 | 2548 | dispatch methods and marshal signals (if --mode is proxy) is written to | ||
4776 | 2549 | a .c and .h file in the current directory with the same base name as XMLFILE, | ||
4777 | 2550 | or to that specified by --output. | ||
4778 | 2551 | """ | ||
4779 | 2552 | |||
4780 | 2553 | parser = OptionParser(usage, description=description) | ||
4781 | 2554 | parser.add_option("--mode", type="string", metavar="MODE", | ||
4782 | 2555 | default="object", | ||
4783 | 2556 | help="Output mode: object, or proxy [default: %default]") | ||
4784 | 2557 | parser.add_option("-o", "--output", type="string", metavar="FILENAME", | ||
4785 | 2558 | help="Write C source to FILENAME, header alongside") | ||
4786 | 2559 | parser.add_option("--prefix", type="string", metavar="PREFIX", | ||
4787 | 2560 | default="dbus", | ||
4788 | 2561 | help="Prefix for externally supplied C functions [default: %default]") | ||
4789 | 2562 | |||
4790 | 2563 | (options, args) = parser.parse_args() | ||
4791 | 2564 | if len(args) != 1: | ||
4792 | 2565 | parser.error("incorrect number of arguments") | ||
4793 | 2566 | if options.mode not in ("object", "proxy"): | ||
4794 | 2567 | parser.error("invalid mode") | ||
4795 | 2568 | |||
4796 | 2569 | extern_prefix = options.prefix | ||
4797 | 2570 | mode = options.mode | ||
4798 | 2571 | |||
4799 | 2572 | # Figure out input and output filenames based on arguments; try and | ||
4800 | 2573 | # do the right thing in most circumstances | ||
4801 | 2574 | xml_filename = args.pop(0) | ||
4802 | 2575 | if options.output: | ||
4803 | 2576 | (root, ext) = os.path.splitext(options.output) | ||
4804 | 2577 | if ext and ext != ".h": | ||
4805 | 2578 | source_filename = options.output | ||
4806 | 2579 | else: | ||
4807 | 2580 | source_filename = os.path.extsep.join(( root, "c" )) | ||
4808 | 2581 | |||
4809 | 2582 | header_filename = os.path.extsep.join (( root, "h")) | ||
4810 | 2583 | basename = os.path.basename(root) | ||
4811 | 2584 | else: | ||
4812 | 2585 | basename = os.path.splitext(os.path.basename(xml_filename))[0] | ||
4813 | 2586 | source_filename = os.path.extsep.join(( basename, "c" )) | ||
4814 | 2587 | header_filename = os.path.extsep.join(( basename, "h" )) | ||
4815 | 2588 | |||
4816 | 2589 | (head, tail) = os.path.split(source_filename) | ||
4817 | 2590 | tmp_source_filename = os.path.join(head, ".%s.tmp" % tail) | ||
4818 | 2591 | |||
4819 | 2592 | (head, tail) = os.path.split(header_filename) | ||
4820 | 2593 | tmp_header_filename = os.path.join(head, ".%s.tmp" % tail) | ||
4821 | 2594 | |||
4822 | 2595 | |||
4823 | 2596 | # Parse the XML file into an ElementTree | ||
4824 | 2597 | tree = ElementTree.parse(xml_filename) | ||
4825 | 2598 | elem = tree.getroot() | ||
4826 | 2599 | |||
4827 | 2600 | # Walk the tree to find interfaces | ||
4828 | 2601 | interfaces = [] | ||
4829 | 2602 | if elem.tag == "interface": | ||
4830 | 2603 | interfaces.append(Interface.fromElement(elem)) | ||
4831 | 2604 | else: | ||
4832 | 2605 | for iface_e in elem.findall("interface"): | ||
4833 | 2606 | interfaces.append(Interface.fromElement(iface_e)) | ||
4834 | 2607 | |||
4835 | 2608 | # Generate and write output | ||
4836 | 2609 | o = Output(basename, interfaces) | ||
4837 | 2610 | try: | ||
4838 | 2611 | f = open(tmp_source_filename, "w") | ||
4839 | 2612 | try: | ||
4840 | 2613 | print >>f, o.sourceFile() | ||
4841 | 2614 | finally: | ||
4842 | 2615 | f.close() | ||
4843 | 2616 | |||
4844 | 2617 | f = open(tmp_header_filename, "w") | ||
4845 | 2618 | try: | ||
4846 | 2619 | print >>f, o.headerFile() | ||
4847 | 2620 | finally: | ||
4848 | 2621 | f.close() | ||
4849 | 2622 | |||
4850 | 2623 | os.rename(tmp_source_filename, source_filename) | ||
4851 | 2624 | os.rename(tmp_header_filename, header_filename) | ||
4852 | 2625 | except: | ||
4853 | 2626 | if os.path.exists(tmp_source_filename): | ||
4854 | 2627 | os.unlink(tmp_source_filename) | ||
4855 | 2628 | if os.path.exists(tmp_header_filename): | ||
4856 | 2629 | os.unlink(tmp_header_filename) | ||
4857 | 2630 | |||
4858 | 2631 | raise | ||
4859 | 2632 | |||
4860 | 2633 | |||
4861 | 2634 | if __name__ == "__main__": | ||
4862 | 2635 | main() |
This got merged and then improved, thanks Casey!