~jamesodhunt/ubuntu/raring/upstart/1.6

« back to all changes in this revision

Viewing changes to nih-dbus-tool/tests/expected/test_node_object_functions_standard.c

  • Committer: Scott James Remnant
  • Date: 2010-02-04 23:59:00 UTC
  • mfrom: (1185.1.9 upstream)
  • Revision ID: scott@netsplit.com-20100204235900-c0j0frow10azwsus
* New upstream release:
  - libnih has been separated out into its own project.
  - "start on" and "stop on" now support != matches.  LP: #513035.
  - Fixed crash in child when unable to spawn job.  LP: #451917.
  - No longer holds /dev/console open so SAK won't kill init.  LP: #486005.
  - Added missing OPTIONS section to init(8).  LP: #449883.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
static DBusHandlerResult
2
 
my_com_netsplit_Nih_Test_Poke_method (NihDBusObject * object,
3
 
                                      NihDBusMessage *message)
4
 
{
5
 
        DBusMessageIter iter;
6
 
        DBusMessage *   reply;
7
 
        uint32_t        address;
8
 
        char *          value;
9
 
        const char *    value_dbus;
10
 
 
11
 
        nih_assert (object != NULL);
12
 
        nih_assert (message != NULL);
13
 
 
14
 
        /* Iterate the arguments to the message and demarshal into arguments
15
 
         * for our own function call.
16
 
         */
17
 
        dbus_message_iter_init (message->message, &iter);
18
 
 
19
 
        /* Demarshal a uint32_t from the message */
20
 
        if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UINT32) {
21
 
                reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS,
22
 
                                                "Invalid arguments to Poke method");
23
 
                if (! reply)
24
 
                        return DBUS_HANDLER_RESULT_NEED_MEMORY;
25
 
 
26
 
                if (! dbus_connection_send (message->connection, reply, NULL)) {
27
 
                        dbus_message_unref (reply);
28
 
                        return DBUS_HANDLER_RESULT_NEED_MEMORY;
29
 
                }
30
 
 
31
 
                dbus_message_unref (reply);
32
 
                return DBUS_HANDLER_RESULT_HANDLED;
33
 
        }
34
 
 
35
 
        dbus_message_iter_get_basic (&iter, &address);
36
 
 
37
 
        dbus_message_iter_next (&iter);
38
 
 
39
 
        /* Demarshal a char * from the message */
40
 
        if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) {
41
 
                reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS,
42
 
                                                "Invalid arguments to Poke method");
43
 
                if (! reply)
44
 
                        return DBUS_HANDLER_RESULT_NEED_MEMORY;
45
 
 
46
 
                if (! dbus_connection_send (message->connection, reply, NULL)) {
47
 
                        dbus_message_unref (reply);
48
 
                        return DBUS_HANDLER_RESULT_NEED_MEMORY;
49
 
                }
50
 
 
51
 
                dbus_message_unref (reply);
52
 
                return DBUS_HANDLER_RESULT_HANDLED;
53
 
        }
54
 
 
55
 
        dbus_message_iter_get_basic (&iter, &value_dbus);
56
 
 
57
 
        value = nih_strdup (message, value_dbus);
58
 
        if (! value) {
59
 
                return DBUS_HANDLER_RESULT_NEED_MEMORY;
60
 
        }
61
 
 
62
 
        dbus_message_iter_next (&iter);
63
 
 
64
 
        if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) {
65
 
                reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS,
66
 
                                                "Invalid arguments to Poke method");
67
 
                if (! reply)
68
 
                        return DBUS_HANDLER_RESULT_NEED_MEMORY;
69
 
 
70
 
                if (! dbus_connection_send (message->connection, reply, NULL)) {
71
 
                        dbus_message_unref (reply);
72
 
                        return DBUS_HANDLER_RESULT_NEED_MEMORY;
73
 
                }
74
 
 
75
 
                dbus_message_unref (reply);
76
 
                return DBUS_HANDLER_RESULT_HANDLED;
77
 
        }
78
 
 
79
 
        /* Call the handler function */
80
 
        nih_error_push_context ();
81
 
        if (my_test_poke (object->data, message, address, value) < 0) {
82
 
                NihError *err;
83
 
 
84
 
                err = nih_error_get ();
85
 
                if (err->number == ENOMEM) {
86
 
                        nih_free (err);
87
 
                        nih_error_pop_context ();
88
 
 
89
 
                        return DBUS_HANDLER_RESULT_NEED_MEMORY;
90
 
                } else if (err->number == NIH_DBUS_ERROR) {
91
 
                        NihDBusError *dbus_err = (NihDBusError *)err;
92
 
 
93
 
                        reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message));
94
 
                        nih_free (err);
95
 
                        nih_error_pop_context ();
96
 
 
97
 
                        NIH_MUST (dbus_connection_send (message->connection, reply, NULL));
98
 
 
99
 
                        dbus_message_unref (reply);
100
 
                        return DBUS_HANDLER_RESULT_HANDLED;
101
 
                } else {
102
 
                        reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message));
103
 
                        nih_free (err);
104
 
                        nih_error_pop_context ();
105
 
 
106
 
                        NIH_MUST (dbus_connection_send (message->connection, reply, NULL));
107
 
 
108
 
                        dbus_message_unref (reply);
109
 
                        return DBUS_HANDLER_RESULT_HANDLED;
110
 
                }
111
 
        }
112
 
        nih_error_pop_context ();
113
 
 
114
 
        /* If the sender doesn't care about a reply, don't bother wasting
115
 
         * effort constructing and sending one.
116
 
         */
117
 
        if (dbus_message_get_no_reply (message->message))
118
 
                return DBUS_HANDLER_RESULT_HANDLED;
119
 
 
120
 
        do {
121
 
                __label__ enomem;
122
 
 
123
 
                /* Construct the reply message. */
124
 
                reply = dbus_message_new_method_return (message->message);
125
 
                if (! reply)
126
 
                        goto enomem;
127
 
 
128
 
                dbus_message_iter_init_append (reply, &iter);
129
 
        enomem: __attribute__ ((unused));
130
 
        } while (! reply);
131
 
 
132
 
        /* Send the reply, appending it to the outgoing queue. */
133
 
        NIH_MUST (dbus_connection_send (message->connection, reply, NULL));
134
 
 
135
 
        dbus_message_unref (reply);
136
 
 
137
 
        return DBUS_HANDLER_RESULT_HANDLED;
138
 
}
139
 
 
140
 
 
141
 
static DBusHandlerResult
142
 
my_com_netsplit_Nih_Test_Peek_method (NihDBusObject * object,
143
 
                                      NihDBusMessage *message)
144
 
{
145
 
        DBusMessageIter iter;
146
 
        DBusMessage *   reply;
147
 
        uint32_t        address;
148
 
 
149
 
        nih_assert (object != NULL);
150
 
        nih_assert (message != NULL);
151
 
 
152
 
        /* Iterate the arguments to the message and demarshal into arguments
153
 
         * for our own function call.
154
 
         */
155
 
        dbus_message_iter_init (message->message, &iter);
156
 
 
157
 
        /* Demarshal a uint32_t from the message */
158
 
        if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UINT32) {
159
 
                reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS,
160
 
                                                "Invalid arguments to Peek method");
161
 
                if (! reply)
162
 
                        return DBUS_HANDLER_RESULT_NEED_MEMORY;
163
 
 
164
 
                if (! dbus_connection_send (message->connection, reply, NULL)) {
165
 
                        dbus_message_unref (reply);
166
 
                        return DBUS_HANDLER_RESULT_NEED_MEMORY;
167
 
                }
168
 
 
169
 
                dbus_message_unref (reply);
170
 
                return DBUS_HANDLER_RESULT_HANDLED;
171
 
        }
172
 
 
173
 
        dbus_message_iter_get_basic (&iter, &address);
174
 
 
175
 
        dbus_message_iter_next (&iter);
176
 
 
177
 
        if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) {
178
 
                reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS,
179
 
                                                "Invalid arguments to Peek method");
180
 
                if (! reply)
181
 
                        return DBUS_HANDLER_RESULT_NEED_MEMORY;
182
 
 
183
 
                if (! dbus_connection_send (message->connection, reply, NULL)) {
184
 
                        dbus_message_unref (reply);
185
 
                        return DBUS_HANDLER_RESULT_NEED_MEMORY;
186
 
                }
187
 
 
188
 
                dbus_message_unref (reply);
189
 
                return DBUS_HANDLER_RESULT_HANDLED;
190
 
        }
191
 
 
192
 
        /* Call the handler function */
193
 
        nih_error_push_context ();
194
 
        if (my_test_peek (object->data, message, address) < 0) {
195
 
                NihError *err;
196
 
 
197
 
                err = nih_error_get ();
198
 
                if (err->number == ENOMEM) {
199
 
                        nih_free (err);
200
 
                        nih_error_pop_context ();
201
 
 
202
 
                        return DBUS_HANDLER_RESULT_NEED_MEMORY;
203
 
                } else if (err->number == NIH_DBUS_ERROR) {
204
 
                        NihDBusError *dbus_err = (NihDBusError *)err;
205
 
 
206
 
                        reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message));
207
 
                        nih_free (err);
208
 
                        nih_error_pop_context ();
209
 
 
210
 
                        NIH_MUST (dbus_connection_send (message->connection, reply, NULL));
211
 
 
212
 
                        dbus_message_unref (reply);
213
 
                        return DBUS_HANDLER_RESULT_HANDLED;
214
 
                } else {
215
 
                        reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message));
216
 
                        nih_free (err);
217
 
                        nih_error_pop_context ();
218
 
 
219
 
                        NIH_MUST (dbus_connection_send (message->connection, reply, NULL));
220
 
 
221
 
                        dbus_message_unref (reply);
222
 
                        return DBUS_HANDLER_RESULT_HANDLED;
223
 
                }
224
 
        }
225
 
        nih_error_pop_context ();
226
 
 
227
 
        return DBUS_HANDLER_RESULT_HANDLED;
228
 
}
229
 
 
230
 
int
231
 
my_test_peek_reply (NihDBusMessage *message,
232
 
                    const char *    value)
233
 
{
234
 
        DBusMessage *   reply;
235
 
        DBusMessageIter iter;
236
 
 
237
 
        nih_assert (message != NULL);
238
 
        nih_assert (value != NULL);
239
 
 
240
 
        /* If the sender doesn't care about a reply, don't bother wasting
241
 
         * effort constructing and sending one.
242
 
         */
243
 
        if (dbus_message_get_no_reply (message->message))
244
 
                return 0;
245
 
 
246
 
        /* Construct the reply message. */
247
 
        reply = dbus_message_new_method_return (message->message);
248
 
        if (! reply)
249
 
                return -1;
250
 
 
251
 
        dbus_message_iter_init_append (reply, &iter);
252
 
 
253
 
        /* Marshal a char * onto the message */
254
 
        if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &value)) {
255
 
                dbus_message_unref (reply);
256
 
                return -1;
257
 
        }
258
 
 
259
 
        /* Send the reply, appending it to the outgoing queue. */
260
 
        if (! dbus_connection_send (message->connection, reply, NULL)) {
261
 
                dbus_message_unref (reply);
262
 
                return -1;
263
 
        }
264
 
 
265
 
        dbus_message_unref (reply);
266
 
 
267
 
        return 0;
268
 
}
269
 
 
270
 
 
271
 
static DBusHandlerResult
272
 
my_com_netsplit_Nih_Test_IsValidAddress_method (NihDBusObject * object,
273
 
                                                NihDBusMessage *message)
274
 
{
275
 
        DBusMessageIter iter;
276
 
        DBusMessage *   reply;
277
 
        uint32_t        address;
278
 
        int             is_valid;
279
 
 
280
 
        nih_assert (object != NULL);
281
 
        nih_assert (message != NULL);
282
 
 
283
 
        /* Iterate the arguments to the message and demarshal into arguments
284
 
         * for our own function call.
285
 
         */
286
 
        dbus_message_iter_init (message->message, &iter);
287
 
 
288
 
        /* Demarshal a uint32_t from the message */
289
 
        if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UINT32) {
290
 
                reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS,
291
 
                                                "Invalid arguments to IsValidAddress method");
292
 
                if (! reply)
293
 
                        return DBUS_HANDLER_RESULT_NEED_MEMORY;
294
 
 
295
 
                if (! dbus_connection_send (message->connection, reply, NULL)) {
296
 
                        dbus_message_unref (reply);
297
 
                        return DBUS_HANDLER_RESULT_NEED_MEMORY;
298
 
                }
299
 
 
300
 
                dbus_message_unref (reply);
301
 
                return DBUS_HANDLER_RESULT_HANDLED;
302
 
        }
303
 
 
304
 
        dbus_message_iter_get_basic (&iter, &address);
305
 
 
306
 
        dbus_message_iter_next (&iter);
307
 
 
308
 
        if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) {
309
 
                reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS,
310
 
                                                "Invalid arguments to IsValidAddress method");
311
 
                if (! reply)
312
 
                        return DBUS_HANDLER_RESULT_NEED_MEMORY;
313
 
 
314
 
                if (! dbus_connection_send (message->connection, reply, NULL)) {
315
 
                        dbus_message_unref (reply);
316
 
                        return DBUS_HANDLER_RESULT_NEED_MEMORY;
317
 
                }
318
 
 
319
 
                dbus_message_unref (reply);
320
 
                return DBUS_HANDLER_RESULT_HANDLED;
321
 
        }
322
 
 
323
 
        /* Call the handler function */
324
 
        nih_error_push_context ();
325
 
        if (my_test_is_valid_address (object->data, message, address, &is_valid) < 0) {
326
 
                NihError *err;
327
 
 
328
 
                err = nih_error_get ();
329
 
                if (err->number == ENOMEM) {
330
 
                        nih_free (err);
331
 
                        nih_error_pop_context ();
332
 
 
333
 
                        return DBUS_HANDLER_RESULT_NEED_MEMORY;
334
 
                } else if (err->number == NIH_DBUS_ERROR) {
335
 
                        NihDBusError *dbus_err = (NihDBusError *)err;
336
 
 
337
 
                        reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message));
338
 
                        nih_free (err);
339
 
                        nih_error_pop_context ();
340
 
 
341
 
                        NIH_MUST (dbus_connection_send (message->connection, reply, NULL));
342
 
 
343
 
                        dbus_message_unref (reply);
344
 
                        return DBUS_HANDLER_RESULT_HANDLED;
345
 
                } else {
346
 
                        reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message));
347
 
                        nih_free (err);
348
 
                        nih_error_pop_context ();
349
 
 
350
 
                        NIH_MUST (dbus_connection_send (message->connection, reply, NULL));
351
 
 
352
 
                        dbus_message_unref (reply);
353
 
                        return DBUS_HANDLER_RESULT_HANDLED;
354
 
                }
355
 
        }
356
 
        nih_error_pop_context ();
357
 
 
358
 
        /* If the sender doesn't care about a reply, don't bother wasting
359
 
         * effort constructing and sending one.
360
 
         */
361
 
        if (dbus_message_get_no_reply (message->message))
362
 
                return DBUS_HANDLER_RESULT_HANDLED;
363
 
 
364
 
        do {
365
 
                __label__ enomem;
366
 
 
367
 
                /* Construct the reply message. */
368
 
                reply = dbus_message_new_method_return (message->message);
369
 
                if (! reply)
370
 
                        goto enomem;
371
 
 
372
 
                dbus_message_iter_init_append (reply, &iter);
373
 
 
374
 
                /* Marshal a int onto the message */
375
 
                if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &is_valid)) {
376
 
                        dbus_message_unref (reply);
377
 
                        reply = NULL;
378
 
                        goto enomem;
379
 
                }
380
 
        enomem: __attribute__ ((unused));
381
 
        } while (! reply);
382
 
 
383
 
        /* Send the reply, appending it to the outgoing queue. */
384
 
        NIH_MUST (dbus_connection_send (message->connection, reply, NULL));
385
 
 
386
 
        dbus_message_unref (reply);
387
 
 
388
 
        return DBUS_HANDLER_RESULT_HANDLED;
389
 
}
390
 
 
391
 
 
392
 
int
393
 
my_test_emit_bounce (DBusConnection *connection,
394
 
                     const char *    origin_path,
395
 
                     uint32_t        height,
396
 
                     int32_t         velocity)
397
 
{
398
 
        DBusMessage *   signal;
399
 
        DBusMessageIter iter;
400
 
 
401
 
        nih_assert (connection != NULL);
402
 
        nih_assert (origin_path != NULL);
403
 
 
404
 
        /* Construct the message. */
405
 
        signal = dbus_message_new_signal (origin_path, "com.netsplit.Nih.Test", "Bounce");
406
 
        if (! signal)
407
 
                return -1;
408
 
 
409
 
        dbus_message_iter_init_append (signal, &iter);
410
 
 
411
 
        /* Marshal a uint32_t onto the message */
412
 
        if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &height)) {
413
 
                dbus_message_unref (signal);
414
 
                return -1;
415
 
        }
416
 
 
417
 
        /* Marshal a int32_t onto the message */
418
 
        if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &velocity)) {
419
 
                dbus_message_unref (signal);
420
 
                return -1;
421
 
        }
422
 
 
423
 
        /* Send the signal, appending it to the outgoing queue. */
424
 
        if (! dbus_connection_send (connection, signal, NULL)) {
425
 
                dbus_message_unref (signal);
426
 
                return -1;
427
 
        }
428
 
 
429
 
        dbus_message_unref (signal);
430
 
 
431
 
        return 0;
432
 
}
433
 
 
434
 
 
435
 
int
436
 
my_test_emit_exploded (DBusConnection *connection,
437
 
                       const char *    origin_path)
438
 
{
439
 
        DBusMessage *   signal;
440
 
        DBusMessageIter iter;
441
 
 
442
 
        nih_assert (connection != NULL);
443
 
        nih_assert (origin_path != NULL);
444
 
 
445
 
        /* Construct the message. */
446
 
        signal = dbus_message_new_signal (origin_path, "com.netsplit.Nih.Test", "Exploded");
447
 
        if (! signal)
448
 
                return -1;
449
 
 
450
 
        dbus_message_iter_init_append (signal, &iter);
451
 
 
452
 
        /* Send the signal, appending it to the outgoing queue. */
453
 
        if (! dbus_connection_send (connection, signal, NULL)) {
454
 
                dbus_message_unref (signal);
455
 
                return -1;
456
 
        }
457
 
 
458
 
        dbus_message_unref (signal);
459
 
 
460
 
        return 0;
461
 
}
462
 
 
463
 
 
464
 
static int
465
 
my_com_netsplit_Nih_Test_colour_get (NihDBusObject *  object,
466
 
                                     NihDBusMessage * message,
467
 
                                     DBusMessageIter *iter)
468
 
{
469
 
        DBusMessageIter variter;
470
 
        char *          value;
471
 
 
472
 
        nih_assert (object != NULL);
473
 
        nih_assert (message != NULL);
474
 
        nih_assert (iter != NULL);
475
 
 
476
 
        /* Call the handler function */
477
 
        if (my_test_get_colour (object->data, message, &value) < 0)
478
 
                return -1;
479
 
 
480
 
        /* Append a variant onto the message to contain the property value. */
481
 
        if (! dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "s", &variter)) {
482
 
                nih_error_raise_no_memory ();
483
 
                return -1;
484
 
        }
485
 
 
486
 
        /* Marshal a char * onto the message */
487
 
        if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &value)) {
488
 
                dbus_message_iter_abandon_container (iter, &variter);
489
 
                nih_error_raise_no_memory ();
490
 
                return -1;
491
 
        }
492
 
 
493
 
        /* Finish the variant */
494
 
        if (! dbus_message_iter_close_container (iter, &variter)) {
495
 
                nih_error_raise_no_memory ();
496
 
                return -1;
497
 
        }
498
 
 
499
 
        return 0;
500
 
}
501
 
 
502
 
static int
503
 
my_com_netsplit_Nih_Test_colour_set (NihDBusObject *  object,
504
 
                                     NihDBusMessage * message,
505
 
                                     DBusMessageIter *iter)
506
 
{
507
 
        DBusMessageIter variter;
508
 
        const char *    value_dbus;
509
 
        char *          value;
510
 
 
511
 
        nih_assert (object != NULL);
512
 
        nih_assert (message != NULL);
513
 
        nih_assert (iter != NULL);
514
 
 
515
 
        /* Recurse into the variant */
516
 
        if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_VARIANT) {
517
 
                nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
518
 
                                             "Invalid arguments to colour property");
519
 
                return -1;
520
 
        }
521
 
 
522
 
        dbus_message_iter_recurse (iter, &variter);
523
 
 
524
 
        /* Demarshal a char * from the message */
525
 
        if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) {
526
 
                nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
527
 
                                             "Invalid arguments to colour property");
528
 
                return -1;
529
 
        }
530
 
 
531
 
        dbus_message_iter_get_basic (&variter, &value_dbus);
532
 
 
533
 
        value = nih_strdup (message, value_dbus);
534
 
        if (! value) {
535
 
                nih_error_raise_no_memory ();
536
 
                return -1;
537
 
        }
538
 
 
539
 
        dbus_message_iter_next (&variter);
540
 
 
541
 
        dbus_message_iter_next (iter);
542
 
 
543
 
        if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_INVALID) {
544
 
                nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
545
 
                                             "Invalid arguments to colour property");
546
 
                return -1;
547
 
        }
548
 
 
549
 
        /* Call the handler function */
550
 
        if (my_test_set_colour (object->data, message, value) < 0)
551
 
                return -1;
552
 
 
553
 
        return 0;
554
 
}
555
 
 
556
 
 
557
 
static int
558
 
my_com_netsplit_Nih_Test_size_get (NihDBusObject *  object,
559
 
                                   NihDBusMessage * message,
560
 
                                   DBusMessageIter *iter)
561
 
{
562
 
        DBusMessageIter variter;
563
 
        uint32_t        value;
564
 
 
565
 
        nih_assert (object != NULL);
566
 
        nih_assert (message != NULL);
567
 
        nih_assert (iter != NULL);
568
 
 
569
 
        /* Call the handler function */
570
 
        if (my_test_get_size (object->data, message, &value) < 0)
571
 
                return -1;
572
 
 
573
 
        /* Append a variant onto the message to contain the property value. */
574
 
        if (! dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "u", &variter)) {
575
 
                nih_error_raise_no_memory ();
576
 
                return -1;
577
 
        }
578
 
 
579
 
        /* Marshal a uint32_t onto the message */
580
 
        if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_UINT32, &value)) {
581
 
                dbus_message_iter_abandon_container (iter, &variter);
582
 
                nih_error_raise_no_memory ();
583
 
                return -1;
584
 
        }
585
 
 
586
 
        /* Finish the variant */
587
 
        if (! dbus_message_iter_close_container (iter, &variter)) {
588
 
                nih_error_raise_no_memory ();
589
 
                return -1;
590
 
        }
591
 
 
592
 
        return 0;
593
 
}
594
 
 
595
 
 
596
 
static int
597
 
my_com_netsplit_Nih_Test_touch_set (NihDBusObject *  object,
598
 
                                    NihDBusMessage * message,
599
 
                                    DBusMessageIter *iter)
600
 
{
601
 
        DBusMessageIter variter;
602
 
        int             value;
603
 
 
604
 
        nih_assert (object != NULL);
605
 
        nih_assert (message != NULL);
606
 
        nih_assert (iter != NULL);
607
 
 
608
 
        /* Recurse into the variant */
609
 
        if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_VARIANT) {
610
 
                nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
611
 
                                             "Invalid arguments to touch property");
612
 
                return -1;
613
 
        }
614
 
 
615
 
        dbus_message_iter_recurse (iter, &variter);
616
 
 
617
 
        /* Demarshal a int from the message */
618
 
        if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_BOOLEAN) {
619
 
                nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
620
 
                                             "Invalid arguments to touch property");
621
 
                return -1;
622
 
        }
623
 
 
624
 
        dbus_message_iter_get_basic (&variter, &value);
625
 
 
626
 
        dbus_message_iter_next (&variter);
627
 
 
628
 
        dbus_message_iter_next (iter);
629
 
 
630
 
        if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_INVALID) {
631
 
                nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
632
 
                                             "Invalid arguments to touch property");
633
 
                return -1;
634
 
        }
635
 
 
636
 
        /* Call the handler function */
637
 
        if (my_test_set_touch (object->data, message, value) < 0)
638
 
                return -1;
639
 
 
640
 
        return 0;
641
 
}
642
 
 
643
 
 
644
 
static DBusHandlerResult
645
 
my_com_netsplit_Nih_Foo_Bing_method (NihDBusObject * object,
646
 
                                     NihDBusMessage *message)
647
 
{
648
 
        DBusMessageIter iter;
649
 
        DBusMessage *   reply;
650
 
 
651
 
        nih_assert (object != NULL);
652
 
        nih_assert (message != NULL);
653
 
 
654
 
        /* Iterate the arguments to the message and demarshal into arguments
655
 
         * for our own function call.
656
 
         */
657
 
        dbus_message_iter_init (message->message, &iter);
658
 
 
659
 
        if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) {
660
 
                reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS,
661
 
                                                "Invalid arguments to Bing method");
662
 
                if (! reply)
663
 
                        return DBUS_HANDLER_RESULT_NEED_MEMORY;
664
 
 
665
 
                if (! dbus_connection_send (message->connection, reply, NULL)) {
666
 
                        dbus_message_unref (reply);
667
 
                        return DBUS_HANDLER_RESULT_NEED_MEMORY;
668
 
                }
669
 
 
670
 
                dbus_message_unref (reply);
671
 
                return DBUS_HANDLER_RESULT_HANDLED;
672
 
        }
673
 
 
674
 
        /* Call the handler function */
675
 
        nih_error_push_context ();
676
 
        if (my_foo_bing (object->data, message) < 0) {
677
 
                NihError *err;
678
 
 
679
 
                err = nih_error_get ();
680
 
                if (err->number == ENOMEM) {
681
 
                        nih_free (err);
682
 
                        nih_error_pop_context ();
683
 
 
684
 
                        return DBUS_HANDLER_RESULT_NEED_MEMORY;
685
 
                } else if (err->number == NIH_DBUS_ERROR) {
686
 
                        NihDBusError *dbus_err = (NihDBusError *)err;
687
 
 
688
 
                        reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message));
689
 
                        nih_free (err);
690
 
                        nih_error_pop_context ();
691
 
 
692
 
                        NIH_MUST (dbus_connection_send (message->connection, reply, NULL));
693
 
 
694
 
                        dbus_message_unref (reply);
695
 
                        return DBUS_HANDLER_RESULT_HANDLED;
696
 
                } else {
697
 
                        reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message));
698
 
                        nih_free (err);
699
 
                        nih_error_pop_context ();
700
 
 
701
 
                        NIH_MUST (dbus_connection_send (message->connection, reply, NULL));
702
 
 
703
 
                        dbus_message_unref (reply);
704
 
                        return DBUS_HANDLER_RESULT_HANDLED;
705
 
                }
706
 
        }
707
 
        nih_error_pop_context ();
708
 
 
709
 
        /* If the sender doesn't care about a reply, don't bother wasting
710
 
         * effort constructing and sending one.
711
 
         */
712
 
        if (dbus_message_get_no_reply (message->message))
713
 
                return DBUS_HANDLER_RESULT_HANDLED;
714
 
 
715
 
        do {
716
 
                __label__ enomem;
717
 
 
718
 
                /* Construct the reply message. */
719
 
                reply = dbus_message_new_method_return (message->message);
720
 
                if (! reply)
721
 
                        goto enomem;
722
 
 
723
 
                dbus_message_iter_init_append (reply, &iter);
724
 
        enomem: __attribute__ ((unused));
725
 
        } while (! reply);
726
 
 
727
 
        /* Send the reply, appending it to the outgoing queue. */
728
 
        NIH_MUST (dbus_connection_send (message->connection, reply, NULL));
729
 
 
730
 
        dbus_message_unref (reply);
731
 
 
732
 
        return DBUS_HANDLER_RESULT_HANDLED;
733
 
}
734
 
 
735
 
 
736
 
int
737
 
my_foo_emit_new_result (DBusConnection *connection,
738
 
                        const char *    origin_path)
739
 
{
740
 
        DBusMessage *   signal;
741
 
        DBusMessageIter iter;
742
 
 
743
 
        nih_assert (connection != NULL);
744
 
        nih_assert (origin_path != NULL);
745
 
 
746
 
        /* Construct the message. */
747
 
        signal = dbus_message_new_signal (origin_path, "com.netsplit.Nih.Foo", "NewResult");
748
 
        if (! signal)
749
 
                return -1;
750
 
 
751
 
        dbus_message_iter_init_append (signal, &iter);
752
 
 
753
 
        /* Send the signal, appending it to the outgoing queue. */
754
 
        if (! dbus_connection_send (connection, signal, NULL)) {
755
 
                dbus_message_unref (signal);
756
 
                return -1;
757
 
        }
758
 
 
759
 
        dbus_message_unref (signal);
760
 
 
761
 
        return 0;
762
 
}