~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_no_signals.c

  • Committer: Scott James Remnant
  • Date: 2010-02-04 23:39:59 UTC
  • mfrom: (1182.1.45 upstart)
  • mto: This revision was merged to the branch mainline in revision 1250.
  • Revision ID: scott@netsplit.com-20100204233959-7kajqjnaoh7208ob
Tags: upstream-0.6.5
ImportĀ upstreamĀ versionĀ 0.6.5

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
 
static int
393
 
my_com_netsplit_Nih_Test_colour_get (NihDBusObject *  object,
394
 
                                     NihDBusMessage * message,
395
 
                                     DBusMessageIter *iter)
396
 
{
397
 
        DBusMessageIter variter;
398
 
        char *          value;
399
 
 
400
 
        nih_assert (object != NULL);
401
 
        nih_assert (message != NULL);
402
 
        nih_assert (iter != NULL);
403
 
 
404
 
        /* Call the handler function */
405
 
        if (my_test_get_colour (object->data, message, &value) < 0)
406
 
                return -1;
407
 
 
408
 
        /* Append a variant onto the message to contain the property value. */
409
 
        if (! dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "s", &variter)) {
410
 
                nih_error_raise_no_memory ();
411
 
                return -1;
412
 
        }
413
 
 
414
 
        /* Marshal a char * onto the message */
415
 
        if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &value)) {
416
 
                dbus_message_iter_abandon_container (iter, &variter);
417
 
                nih_error_raise_no_memory ();
418
 
                return -1;
419
 
        }
420
 
 
421
 
        /* Finish the variant */
422
 
        if (! dbus_message_iter_close_container (iter, &variter)) {
423
 
                nih_error_raise_no_memory ();
424
 
                return -1;
425
 
        }
426
 
 
427
 
        return 0;
428
 
}
429
 
 
430
 
static int
431
 
my_com_netsplit_Nih_Test_colour_set (NihDBusObject *  object,
432
 
                                     NihDBusMessage * message,
433
 
                                     DBusMessageIter *iter)
434
 
{
435
 
        DBusMessageIter variter;
436
 
        const char *    value_dbus;
437
 
        char *          value;
438
 
 
439
 
        nih_assert (object != NULL);
440
 
        nih_assert (message != NULL);
441
 
        nih_assert (iter != NULL);
442
 
 
443
 
        /* Recurse into the variant */
444
 
        if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_VARIANT) {
445
 
                nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
446
 
                                             "Invalid arguments to colour property");
447
 
                return -1;
448
 
        }
449
 
 
450
 
        dbus_message_iter_recurse (iter, &variter);
451
 
 
452
 
        /* Demarshal a char * from the message */
453
 
        if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) {
454
 
                nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
455
 
                                             "Invalid arguments to colour property");
456
 
                return -1;
457
 
        }
458
 
 
459
 
        dbus_message_iter_get_basic (&variter, &value_dbus);
460
 
 
461
 
        value = nih_strdup (message, value_dbus);
462
 
        if (! value) {
463
 
                nih_error_raise_no_memory ();
464
 
                return -1;
465
 
        }
466
 
 
467
 
        dbus_message_iter_next (&variter);
468
 
 
469
 
        dbus_message_iter_next (iter);
470
 
 
471
 
        if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_INVALID) {
472
 
                nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
473
 
                                             "Invalid arguments to colour property");
474
 
                return -1;
475
 
        }
476
 
 
477
 
        /* Call the handler function */
478
 
        if (my_test_set_colour (object->data, message, value) < 0)
479
 
                return -1;
480
 
 
481
 
        return 0;
482
 
}
483
 
 
484
 
 
485
 
static int
486
 
my_com_netsplit_Nih_Test_size_get (NihDBusObject *  object,
487
 
                                   NihDBusMessage * message,
488
 
                                   DBusMessageIter *iter)
489
 
{
490
 
        DBusMessageIter variter;
491
 
        uint32_t        value;
492
 
 
493
 
        nih_assert (object != NULL);
494
 
        nih_assert (message != NULL);
495
 
        nih_assert (iter != NULL);
496
 
 
497
 
        /* Call the handler function */
498
 
        if (my_test_get_size (object->data, message, &value) < 0)
499
 
                return -1;
500
 
 
501
 
        /* Append a variant onto the message to contain the property value. */
502
 
        if (! dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "u", &variter)) {
503
 
                nih_error_raise_no_memory ();
504
 
                return -1;
505
 
        }
506
 
 
507
 
        /* Marshal a uint32_t onto the message */
508
 
        if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_UINT32, &value)) {
509
 
                dbus_message_iter_abandon_container (iter, &variter);
510
 
                nih_error_raise_no_memory ();
511
 
                return -1;
512
 
        }
513
 
 
514
 
        /* Finish the variant */
515
 
        if (! dbus_message_iter_close_container (iter, &variter)) {
516
 
                nih_error_raise_no_memory ();
517
 
                return -1;
518
 
        }
519
 
 
520
 
        return 0;
521
 
}
522
 
 
523
 
 
524
 
static int
525
 
my_com_netsplit_Nih_Test_touch_set (NihDBusObject *  object,
526
 
                                    NihDBusMessage * message,
527
 
                                    DBusMessageIter *iter)
528
 
{
529
 
        DBusMessageIter variter;
530
 
        int             value;
531
 
 
532
 
        nih_assert (object != NULL);
533
 
        nih_assert (message != NULL);
534
 
        nih_assert (iter != NULL);
535
 
 
536
 
        /* Recurse into the variant */
537
 
        if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_VARIANT) {
538
 
                nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
539
 
                                             "Invalid arguments to touch property");
540
 
                return -1;
541
 
        }
542
 
 
543
 
        dbus_message_iter_recurse (iter, &variter);
544
 
 
545
 
        /* Demarshal a int from the message */
546
 
        if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_BOOLEAN) {
547
 
                nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
548
 
                                             "Invalid arguments to touch property");
549
 
                return -1;
550
 
        }
551
 
 
552
 
        dbus_message_iter_get_basic (&variter, &value);
553
 
 
554
 
        dbus_message_iter_next (&variter);
555
 
 
556
 
        dbus_message_iter_next (iter);
557
 
 
558
 
        if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_INVALID) {
559
 
                nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
560
 
                                             "Invalid arguments to touch property");
561
 
                return -1;
562
 
        }
563
 
 
564
 
        /* Call the handler function */
565
 
        if (my_test_set_touch (object->data, message, value) < 0)
566
 
                return -1;
567
 
 
568
 
        return 0;
569
 
}
570
 
 
571
 
 
572
 
static DBusHandlerResult
573
 
my_com_netsplit_Nih_Foo_Bing_method (NihDBusObject * object,
574
 
                                     NihDBusMessage *message)
575
 
{
576
 
        DBusMessageIter iter;
577
 
        DBusMessage *   reply;
578
 
 
579
 
        nih_assert (object != NULL);
580
 
        nih_assert (message != NULL);
581
 
 
582
 
        /* Iterate the arguments to the message and demarshal into arguments
583
 
         * for our own function call.
584
 
         */
585
 
        dbus_message_iter_init (message->message, &iter);
586
 
 
587
 
        if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) {
588
 
                reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS,
589
 
                                                "Invalid arguments to Bing method");
590
 
                if (! reply)
591
 
                        return DBUS_HANDLER_RESULT_NEED_MEMORY;
592
 
 
593
 
                if (! dbus_connection_send (message->connection, reply, NULL)) {
594
 
                        dbus_message_unref (reply);
595
 
                        return DBUS_HANDLER_RESULT_NEED_MEMORY;
596
 
                }
597
 
 
598
 
                dbus_message_unref (reply);
599
 
                return DBUS_HANDLER_RESULT_HANDLED;
600
 
        }
601
 
 
602
 
        /* Call the handler function */
603
 
        nih_error_push_context ();
604
 
        if (my_foo_bing (object->data, message) < 0) {
605
 
                NihError *err;
606
 
 
607
 
                err = nih_error_get ();
608
 
                if (err->number == ENOMEM) {
609
 
                        nih_free (err);
610
 
                        nih_error_pop_context ();
611
 
 
612
 
                        return DBUS_HANDLER_RESULT_NEED_MEMORY;
613
 
                } else if (err->number == NIH_DBUS_ERROR) {
614
 
                        NihDBusError *dbus_err = (NihDBusError *)err;
615
 
 
616
 
                        reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message));
617
 
                        nih_free (err);
618
 
                        nih_error_pop_context ();
619
 
 
620
 
                        NIH_MUST (dbus_connection_send (message->connection, reply, NULL));
621
 
 
622
 
                        dbus_message_unref (reply);
623
 
                        return DBUS_HANDLER_RESULT_HANDLED;
624
 
                } else {
625
 
                        reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message));
626
 
                        nih_free (err);
627
 
                        nih_error_pop_context ();
628
 
 
629
 
                        NIH_MUST (dbus_connection_send (message->connection, reply, NULL));
630
 
 
631
 
                        dbus_message_unref (reply);
632
 
                        return DBUS_HANDLER_RESULT_HANDLED;
633
 
                }
634
 
        }
635
 
        nih_error_pop_context ();
636
 
 
637
 
        /* If the sender doesn't care about a reply, don't bother wasting
638
 
         * effort constructing and sending one.
639
 
         */
640
 
        if (dbus_message_get_no_reply (message->message))
641
 
                return DBUS_HANDLER_RESULT_HANDLED;
642
 
 
643
 
        do {
644
 
                __label__ enomem;
645
 
 
646
 
                /* Construct the reply message. */
647
 
                reply = dbus_message_new_method_return (message->message);
648
 
                if (! reply)
649
 
                        goto enomem;
650
 
 
651
 
                dbus_message_iter_init_append (reply, &iter);
652
 
        enomem: __attribute__ ((unused));
653
 
        } while (! reply);
654
 
 
655
 
        /* Send the reply, appending it to the outgoing queue. */
656
 
        NIH_MUST (dbus_connection_send (message->connection, reply, NULL));
657
 
 
658
 
        dbus_message_unref (reply);
659
 
 
660
 
        return DBUS_HANDLER_RESULT_HANDLED;
661
 
}