dbus 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/examples/example-client.rb +11 -0
- data/examples/example-service.rb +19 -0
- data/examples/example-signal-emitter.rb +18 -0
- data/examples/example-signal-recipient.rb +17 -0
- data/examples/gconf-proxy-client.rb +11 -0
- data/examples/gconf-proxy-service.rb +39 -0
- data/examples/list-session-services.rb +26 -0
- data/examples/list-system-services.rb +26 -0
- data/examples/volumed.rb +151 -0
- data/ext/MANIFEST +0 -0
- data/ext/extconf.rb +19 -0
- data/ext/ruby-dbus-bus.c +145 -0
- data/ext/ruby-dbus-common.c +105 -0
- data/ext/ruby-dbus-connection.c +704 -0
- data/ext/ruby-dbus-message-iter.c +661 -0
- data/ext/ruby-dbus-message.c +641 -0
- data/ext/ruby-dbus-pending-call.c +98 -0
- data/ext/ruby-dbus-server.c +126 -0
- data/ext/ruby-dbus.h +127 -0
- data/lib/dbus.rb +359 -0
- data/lib/dbus/binding.rb +259 -0
- data/lib/dbus/version.rb +21 -0
- data/test/tc_all.rb +10 -0
- data/test/tc_connection.rb +49 -0
- data/test/tc_message.rb +82 -0
- data/test/tc_server.rb +10 -0
- data/tools/genrdoc +6 -0
- metadata +67 -0
@@ -0,0 +1,661 @@
|
|
1
|
+
/*--------------------------------------------------
|
2
|
+
* D-BUS bindings for Ruby
|
3
|
+
* (C) Copyright 2004 Leon Breedt
|
4
|
+
* (C) Copyright 2004 Provenco Group Ltd
|
5
|
+
*
|
6
|
+
* Licensed under the same terms as the D-BUS library
|
7
|
+
*--------------------------------------------------*/
|
8
|
+
|
9
|
+
#include <stdlib.h>
|
10
|
+
#include "ruby-dbus.h"
|
11
|
+
|
12
|
+
/* NB: We wrap DBusMessageIter so that we are able to unref the associated message (if any)
|
13
|
+
* when the DBusMessageIter instance is GC'd. */
|
14
|
+
struct _RubyDBusMessageIter {
|
15
|
+
DBusMessageIter *real_iter;
|
16
|
+
DBusMessage *message;
|
17
|
+
};
|
18
|
+
|
19
|
+
VALUE cDBusMessageIter;
|
20
|
+
|
21
|
+
static void _free_message_iter(RubyDBusMessageIter *iter);
|
22
|
+
static void _ensure_arg_type(DBusMessageIter *iter, int type);
|
23
|
+
|
24
|
+
RDBUS_GENERATE_NEW(cDBusMessageIter, RubyDBusMessageIter *, _free_message_iter)
|
25
|
+
RDBUS_GENERATE_GET(RubyDBusMessageIter)
|
26
|
+
|
27
|
+
static RubyDBusMessageIter *
|
28
|
+
_alloc_message_iter(DBusMessage *message, DBusMessageIter *real_iter)
|
29
|
+
{
|
30
|
+
RubyDBusMessageIter *iter;
|
31
|
+
|
32
|
+
iter = NULL;
|
33
|
+
iter = ALLOC(RubyDBusMessageIter);
|
34
|
+
if (iter == NULL)
|
35
|
+
rb_raise(eDBusError, "unable to allocate DBusMessageIter");
|
36
|
+
|
37
|
+
if (real_iter != NULL)
|
38
|
+
iter->real_iter = real_iter;
|
39
|
+
else
|
40
|
+
iter->real_iter = ALLOC(DBusMessageIter);
|
41
|
+
|
42
|
+
if (iter->real_iter == NULL) {
|
43
|
+
ruby_xfree(iter);
|
44
|
+
rb_raise(eDBusError, "unable to allocate real DBusMessageIter");
|
45
|
+
}
|
46
|
+
|
47
|
+
iter->message = message;
|
48
|
+
if (iter->message != NULL)
|
49
|
+
dbus_message_ref(iter->message);
|
50
|
+
|
51
|
+
return iter;
|
52
|
+
}
|
53
|
+
|
54
|
+
RubyDBusMessageIter *
|
55
|
+
rdbus_message_iter_new(DBusMessage *message, short is_append_iter)
|
56
|
+
{
|
57
|
+
RubyDBusMessageIter *iter;
|
58
|
+
|
59
|
+
iter = _alloc_message_iter(message, NULL);
|
60
|
+
if (is_append_iter) {
|
61
|
+
dbus_message_append_iter_init(iter->message, iter->real_iter);
|
62
|
+
} else
|
63
|
+
dbus_message_iter_init(iter->message, iter->real_iter);
|
64
|
+
return iter;
|
65
|
+
}
|
66
|
+
|
67
|
+
static void
|
68
|
+
_free_message_iter(RubyDBusMessageIter *iter)
|
69
|
+
{
|
70
|
+
if (iter->message != NULL)
|
71
|
+
dbus_message_unref(iter->message);
|
72
|
+
ruby_xfree(iter->real_iter);
|
73
|
+
iter->message = NULL;
|
74
|
+
iter->real_iter = NULL;
|
75
|
+
ruby_xfree(iter);
|
76
|
+
}
|
77
|
+
|
78
|
+
static void
|
79
|
+
_ensure_arg_type(DBusMessageIter *iter, int type)
|
80
|
+
{
|
81
|
+
if (dbus_message_iter_get_arg_type(iter) != type)
|
82
|
+
rb_raise(eDBusError, "argument type mismatch");
|
83
|
+
}
|
84
|
+
|
85
|
+
/*
|
86
|
+
* call-seq:
|
87
|
+
* has_next => true|false
|
88
|
+
*
|
89
|
+
* Returns true if there are additional arguments after the current
|
90
|
+
* iterator argument.
|
91
|
+
*/
|
92
|
+
static VALUE
|
93
|
+
cDBusMessageIter_has_next(VALUE self)
|
94
|
+
{
|
95
|
+
if (dbus_message_iter_has_next(ITER_GET(self)))
|
96
|
+
return Qtrue;
|
97
|
+
return Qfalse;
|
98
|
+
}
|
99
|
+
|
100
|
+
/*
|
101
|
+
* call-seq:
|
102
|
+
* next => true|false
|
103
|
+
*
|
104
|
+
* Moves the iterator to the next argument.
|
105
|
+
*/
|
106
|
+
static VALUE
|
107
|
+
cDBusMessageIter_next(VALUE self)
|
108
|
+
{
|
109
|
+
if (dbus_message_iter_next(ITER_GET(self)))
|
110
|
+
return Qtrue;
|
111
|
+
return Qfalse;
|
112
|
+
}
|
113
|
+
|
114
|
+
/*
|
115
|
+
* call-seq:
|
116
|
+
* get_arg_type => typecode
|
117
|
+
*
|
118
|
+
* Returns the argument type of the argument that the iterator
|
119
|
+
* currently points at. This is one of the TYPE_xxx codes.
|
120
|
+
*/
|
121
|
+
static VALUE
|
122
|
+
cDBusMessageIter_get_arg_type(VALUE self)
|
123
|
+
{
|
124
|
+
return INT2FIX(dbus_message_iter_get_arg_type(ITER_GET(self)));
|
125
|
+
}
|
126
|
+
|
127
|
+
/*
|
128
|
+
* call-seq:
|
129
|
+
* get_array_type => typecode
|
130
|
+
*
|
131
|
+
* Returns the element type of the array argument that the iterator currently
|
132
|
+
* points at.
|
133
|
+
*/
|
134
|
+
static VALUE
|
135
|
+
cDBusMessageIter_get_array_type(VALUE self)
|
136
|
+
{
|
137
|
+
return INT2FIX(dbus_message_iter_get_array_type(ITER_GET(self)));
|
138
|
+
}
|
139
|
+
|
140
|
+
/*
|
141
|
+
* call-seq:
|
142
|
+
* get_byte => byte
|
143
|
+
*
|
144
|
+
* Returns the byte value of the argument that the iterator currently
|
145
|
+
* points at. As Ruby does not have a byte type, the returned value is
|
146
|
+
* a Fixnum.
|
147
|
+
*/
|
148
|
+
static VALUE
|
149
|
+
cDBusMessageIter_get_byte(VALUE self)
|
150
|
+
{
|
151
|
+
_ensure_arg_type(ITER_GET(self), DBUS_TYPE_BYTE);
|
152
|
+
return INT2FIX(dbus_message_iter_get_byte(ITER_GET(self)) & 0xff);
|
153
|
+
}
|
154
|
+
|
155
|
+
/*
|
156
|
+
* call-seq:
|
157
|
+
* get_boolean => true|false
|
158
|
+
*
|
159
|
+
* Returns the boolean value of the argument that the iterator currently
|
160
|
+
* points at.
|
161
|
+
*/
|
162
|
+
static VALUE
|
163
|
+
cDBusMessageIter_get_boolean(VALUE self)
|
164
|
+
{
|
165
|
+
_ensure_arg_type(ITER_GET(self), DBUS_TYPE_BOOLEAN);
|
166
|
+
if (dbus_message_iter_get_boolean(ITER_GET(self)))
|
167
|
+
return Qtrue;
|
168
|
+
return Qfalse;
|
169
|
+
}
|
170
|
+
|
171
|
+
/*
|
172
|
+
* call-seq:
|
173
|
+
* get_int32 => integer
|
174
|
+
*
|
175
|
+
* Returns the 32-bit integer value of the argument that the iterator
|
176
|
+
* currently points at.
|
177
|
+
*/
|
178
|
+
static VALUE
|
179
|
+
cDBusMessageIter_get_int32(VALUE self)
|
180
|
+
{
|
181
|
+
_ensure_arg_type(ITER_GET(self), DBUS_TYPE_INT32);
|
182
|
+
return INT2NUM(dbus_message_iter_get_int32(ITER_GET(self)));
|
183
|
+
}
|
184
|
+
|
185
|
+
/*
|
186
|
+
* call-seq:
|
187
|
+
* get_uint32 => integer
|
188
|
+
*
|
189
|
+
* Returns the unsigned 32-bit integer value of the argument that the
|
190
|
+
* iterator currently points at.
|
191
|
+
*/
|
192
|
+
static VALUE
|
193
|
+
cDBusMessageIter_get_uint32(VALUE self)
|
194
|
+
{
|
195
|
+
_ensure_arg_type(ITER_GET(self), DBUS_TYPE_UINT32);
|
196
|
+
return INT2NUM(dbus_message_iter_get_uint32(ITER_GET(self)));
|
197
|
+
}
|
198
|
+
|
199
|
+
#ifdef DBUS_HAVE_INT64
|
200
|
+
#if HAVE_LONG_LONG
|
201
|
+
/*
|
202
|
+
* call-seq:
|
203
|
+
* get_int64 => integer
|
204
|
+
*
|
205
|
+
* Returns the 64-bit integer value of the argument that the
|
206
|
+
* iterator currently points at.
|
207
|
+
*/
|
208
|
+
static VALUE
|
209
|
+
cDBusMessageIter_get_int64(VALUE self)
|
210
|
+
{
|
211
|
+
_ensure_arg_type(ITER_GET(self), DBUS_TYPE_INT64);
|
212
|
+
return LL2NUM(dbus_message_iter_get_int64(ITER_GET(self)));
|
213
|
+
}
|
214
|
+
|
215
|
+
/*
|
216
|
+
* call-seq:
|
217
|
+
* get_uint64 => integer
|
218
|
+
*
|
219
|
+
* Returns the unsigned 64-bit integer value of the argument that the
|
220
|
+
* iterator currently points at.
|
221
|
+
*/
|
222
|
+
static VALUE
|
223
|
+
cDBusMessageIter_get_uint64(VALUE self)
|
224
|
+
{
|
225
|
+
_ensure_arg_type(ITER_GET(self), DBUS_TYPE_UINT64);
|
226
|
+
return ULL2NUM(dbus_message_iter_get_uint64(ITER_GET(self)));
|
227
|
+
}
|
228
|
+
#endif
|
229
|
+
#endif
|
230
|
+
|
231
|
+
/*
|
232
|
+
* call-seq:
|
233
|
+
* get_double => float
|
234
|
+
*
|
235
|
+
* Returns the floating point value of the argument that the
|
236
|
+
* iterator currently points at.
|
237
|
+
*/
|
238
|
+
static VALUE
|
239
|
+
cDBusMessageIter_get_double(VALUE self)
|
240
|
+
{
|
241
|
+
_ensure_arg_type(ITER_GET(self), DBUS_TYPE_DOUBLE);
|
242
|
+
return rb_float_new(dbus_message_iter_get_double(ITER_GET(self)));
|
243
|
+
}
|
244
|
+
|
245
|
+
/*
|
246
|
+
* call-seq:
|
247
|
+
* get_string => string
|
248
|
+
*
|
249
|
+
* Returns the string value of the argument that the iterator currently
|
250
|
+
* points at.
|
251
|
+
*/
|
252
|
+
static VALUE
|
253
|
+
cDBusMessageIter_get_string(VALUE self)
|
254
|
+
{
|
255
|
+
_ensure_arg_type(ITER_GET(self), DBUS_TYPE_STRING);
|
256
|
+
return rb_str_new2(dbus_message_iter_get_string(ITER_GET(self)));
|
257
|
+
}
|
258
|
+
|
259
|
+
/*
|
260
|
+
* call-seq:
|
261
|
+
* get_object_path => string
|
262
|
+
*
|
263
|
+
* Returns the object path value of the argument that the iterator currently
|
264
|
+
* points at. An object path value is a String.
|
265
|
+
*/
|
266
|
+
static VALUE
|
267
|
+
cDBusMessageIter_get_object_path(VALUE self)
|
268
|
+
{
|
269
|
+
_ensure_arg_type(ITER_GET(self), DBUS_TYPE_OBJECT_PATH);
|
270
|
+
return rb_str_new2(dbus_message_iter_get_object_path(ITER_GET(self)));
|
271
|
+
}
|
272
|
+
|
273
|
+
/*
|
274
|
+
* call-seq:
|
275
|
+
* get_dict_key => string
|
276
|
+
*
|
277
|
+
* Returns the dictionary key for a dictionary entry that the
|
278
|
+
* iteratory currently points to. This will only work on iterators
|
279
|
+
* returned by DBusMessageIter#dict_iter.
|
280
|
+
*/
|
281
|
+
static VALUE
|
282
|
+
cDBusMessageIter_get_dict_key(VALUE self)
|
283
|
+
{
|
284
|
+
return rb_str_new2(dbus_message_iter_get_dict_key(ITER_GET(self)));
|
285
|
+
}
|
286
|
+
|
287
|
+
/*
|
288
|
+
* call-seq:
|
289
|
+
* array_iter => iterator
|
290
|
+
*
|
291
|
+
* Returns an array iterator for the array argument that this iterator
|
292
|
+
* currently points to.
|
293
|
+
*
|
294
|
+
* See DBusMessageIter#get_array for an example of usage.
|
295
|
+
*/
|
296
|
+
static VALUE
|
297
|
+
cDBusMessageIter_array_iter_new(VALUE self)
|
298
|
+
{
|
299
|
+
RubyDBusMessageIter *self_iter = NULL;
|
300
|
+
RubyDBusMessageIter *ary_iter = NULL;
|
301
|
+
int array_type = DBUS_TYPE_INVALID;
|
302
|
+
|
303
|
+
self_iter = RDBUS_GET(RubyDBusMessageIter, self);
|
304
|
+
_ensure_arg_type(self_iter->real_iter, DBUS_TYPE_ARRAY);
|
305
|
+
ary_iter = _alloc_message_iter(self_iter->message, NULL);
|
306
|
+
dbus_message_iter_init_array_iterator(self_iter->real_iter, ary_iter->real_iter, &array_type);
|
307
|
+
return RDBUS_NEW(cDBusMessageIter, ary_iter);
|
308
|
+
}
|
309
|
+
|
310
|
+
/*
|
311
|
+
* call-seq:
|
312
|
+
* dict_iter => iterator
|
313
|
+
*
|
314
|
+
* Returns a dictionary iterator for the dictionary argument that this
|
315
|
+
* iterator currently points to.
|
316
|
+
*
|
317
|
+
* See DBusMessageIter#get_dict for an example of usage.
|
318
|
+
*/
|
319
|
+
static VALUE
|
320
|
+
cDBusMessageIter_dict_iter_new(VALUE self)
|
321
|
+
{
|
322
|
+
RubyDBusMessageIter *self_iter = NULL;
|
323
|
+
RubyDBusMessageIter *dict_iter = NULL;
|
324
|
+
|
325
|
+
self_iter = RDBUS_GET(RubyDBusMessageIter, self);
|
326
|
+
_ensure_arg_type(self_iter->real_iter, DBUS_TYPE_DICT);
|
327
|
+
dict_iter = _alloc_message_iter(self_iter->message, NULL);
|
328
|
+
dbus_message_iter_init_dict_iterator(self_iter->real_iter, dict_iter->real_iter);
|
329
|
+
return RDBUS_NEW(cDBusMessageIter, dict_iter);
|
330
|
+
}
|
331
|
+
|
332
|
+
/*
|
333
|
+
* call-seq:
|
334
|
+
* append_nil => true|false
|
335
|
+
*
|
336
|
+
* Appends a nil argument value to this message.
|
337
|
+
*
|
338
|
+
* Returns +false+ if no memory.
|
339
|
+
*/
|
340
|
+
static VALUE
|
341
|
+
cDBusMessageIter_append_nil(VALUE self)
|
342
|
+
{
|
343
|
+
if (dbus_message_iter_append_nil(ITER_GET(self)))
|
344
|
+
return Qtrue;
|
345
|
+
return Qfalse;
|
346
|
+
}
|
347
|
+
|
348
|
+
/*
|
349
|
+
* call-seq:
|
350
|
+
* append_boolean(true|false|nil) => true|false
|
351
|
+
*
|
352
|
+
* Appends a boolean argument value to this message. +nil+ is
|
353
|
+
* regarded as a false value if passed through.
|
354
|
+
*
|
355
|
+
* Returns +false+ if no memory.
|
356
|
+
*/
|
357
|
+
static VALUE
|
358
|
+
cDBusMessageIter_append_boolean(VALUE self, VALUE value)
|
359
|
+
{
|
360
|
+
dbus_bool_t val;
|
361
|
+
if (TYPE(value) == T_FALSE || TYPE(value) == T_NIL)
|
362
|
+
val = FALSE;
|
363
|
+
else
|
364
|
+
val = TRUE;
|
365
|
+
if (dbus_message_iter_append_boolean(ITER_GET(self), val))
|
366
|
+
return Qtrue;
|
367
|
+
return Qfalse;
|
368
|
+
}
|
369
|
+
|
370
|
+
/*
|
371
|
+
* call-seq:
|
372
|
+
* append_byte(byte) => true|false
|
373
|
+
*
|
374
|
+
* Appends a byte value to this message. As Ruby has no byte type, providing
|
375
|
+
* an integer representing the byte value suffices. Note that the supplied
|
376
|
+
* value is clamped to 8 bits.
|
377
|
+
*
|
378
|
+
* Returns +false+ if no memory.
|
379
|
+
*/
|
380
|
+
static VALUE
|
381
|
+
cDBusMessageIter_append_byte(VALUE self, VALUE value)
|
382
|
+
{
|
383
|
+
unsigned char val;
|
384
|
+
val = NUM2UINT(value) & 0xff;
|
385
|
+
if (dbus_message_iter_append_byte(ITER_GET(self), val))
|
386
|
+
return Qtrue;
|
387
|
+
return Qfalse;
|
388
|
+
}
|
389
|
+
|
390
|
+
/*
|
391
|
+
* call-seq:
|
392
|
+
* append_int32(integer) => true|false
|
393
|
+
*
|
394
|
+
* Appends a signed 32-bit integer value to this message. Note that your
|
395
|
+
* value will be truncated if it is larger than the associated D-BUS
|
396
|
+
* type.
|
397
|
+
*
|
398
|
+
* Returns +false+ if no memory.
|
399
|
+
*/
|
400
|
+
static VALUE
|
401
|
+
cDBusMessageIter_append_int32(VALUE self, VALUE value)
|
402
|
+
{
|
403
|
+
dbus_int32_t val;
|
404
|
+
val = NUM2INT(value);
|
405
|
+
if (dbus_message_iter_append_int32(ITER_GET(self), val))
|
406
|
+
return Qtrue;
|
407
|
+
return Qfalse;
|
408
|
+
}
|
409
|
+
|
410
|
+
/*
|
411
|
+
* call-seq:
|
412
|
+
* append_uint32(integer) => true|false
|
413
|
+
*
|
414
|
+
* Appends an unsigned 32-bit integer value to this message. Note that your
|
415
|
+
* value will be truncated if it is larger than the associated D-BUS
|
416
|
+
* type.
|
417
|
+
*
|
418
|
+
* Returns +false+ if no memory.
|
419
|
+
*/
|
420
|
+
static VALUE
|
421
|
+
cDBusMessageIter_append_uint32(VALUE self, VALUE value)
|
422
|
+
{
|
423
|
+
dbus_uint32_t val;
|
424
|
+
val = NUM2UINT(value);
|
425
|
+
if (dbus_message_iter_append_uint32(ITER_GET(self), val))
|
426
|
+
return Qtrue;
|
427
|
+
return Qfalse;
|
428
|
+
}
|
429
|
+
|
430
|
+
#ifdef DBUS_HAVE_INT64
|
431
|
+
#if HAVE_LONG_LONG
|
432
|
+
/*
|
433
|
+
* call-seq:
|
434
|
+
* append_int64(integer) => true|false
|
435
|
+
*
|
436
|
+
* Appends a signed 64-bit integer value to this message. Note that your
|
437
|
+
* value will be truncated if it is larger than the associated D-BUS
|
438
|
+
* type.
|
439
|
+
*
|
440
|
+
* Returns +false+ if no memory.
|
441
|
+
*/
|
442
|
+
static VALUE
|
443
|
+
cDBusMessageIter_append_int64(VALUE self, VALUE value)
|
444
|
+
{
|
445
|
+
dbus_int64_t val;
|
446
|
+
val = NUM2LL(value);
|
447
|
+
if (dbus_message_iter_append_int64(ITER_GET(self), val))
|
448
|
+
return Qtrue;
|
449
|
+
return Qfalse;
|
450
|
+
}
|
451
|
+
|
452
|
+
/*
|
453
|
+
* call-seq:
|
454
|
+
* append_uint64(integer) => true|false
|
455
|
+
*
|
456
|
+
* Appends an unsigned 64-bit integer value to this message. Note that your
|
457
|
+
* value will be truncated if it is larger than the associated D-BUS
|
458
|
+
* type.
|
459
|
+
*
|
460
|
+
* Returns +false+ if no memory.
|
461
|
+
*/
|
462
|
+
static VALUE
|
463
|
+
cDBusMessageIter_append_uint64(VALUE self, VALUE value)
|
464
|
+
{
|
465
|
+
dbus_uint64_t val;
|
466
|
+
val = NUM2LL(value);
|
467
|
+
if (dbus_message_iter_append_uint64(ITER_GET(self), val))
|
468
|
+
return Qtrue;
|
469
|
+
return Qfalse;
|
470
|
+
}
|
471
|
+
#endif
|
472
|
+
#endif
|
473
|
+
|
474
|
+
/*
|
475
|
+
* call-seq:
|
476
|
+
* append_double(float) => true|false
|
477
|
+
*
|
478
|
+
* Appends a floating point value to this message. Note that your
|
479
|
+
* value will be truncated if it is larger than the associated D-BUS
|
480
|
+
* type.
|
481
|
+
*
|
482
|
+
* Returns +false+ if no memory.
|
483
|
+
*/
|
484
|
+
static VALUE
|
485
|
+
cDBusMessageIter_append_double(VALUE self, VALUE value)
|
486
|
+
{
|
487
|
+
double val;
|
488
|
+
val = NUM2DBL(value);
|
489
|
+
if (dbus_message_iter_append_double(ITER_GET(self), val))
|
490
|
+
return Qtrue;
|
491
|
+
return Qfalse;
|
492
|
+
}
|
493
|
+
|
494
|
+
/*
|
495
|
+
* call-seq:
|
496
|
+
* append_string(string) => true|false
|
497
|
+
*
|
498
|
+
* Appends a string value to this message.
|
499
|
+
*
|
500
|
+
* Returns +false+ if no memory.
|
501
|
+
*/
|
502
|
+
static VALUE
|
503
|
+
cDBusMessageIter_append_string(VALUE self, VALUE value)
|
504
|
+
{
|
505
|
+
if (dbus_message_iter_append_string(ITER_GET(self), StringValuePtr(value)))
|
506
|
+
return Qtrue;
|
507
|
+
return Qfalse;
|
508
|
+
}
|
509
|
+
|
510
|
+
/*
|
511
|
+
* call-seq:
|
512
|
+
* append_object_path(string) => true|false
|
513
|
+
*
|
514
|
+
* Appends an object path value to this message.
|
515
|
+
*
|
516
|
+
* Returns +false+ if no memory.
|
517
|
+
*/
|
518
|
+
static VALUE
|
519
|
+
cDBusMessageIter_append_object_path(VALUE self, VALUE value)
|
520
|
+
{
|
521
|
+
if (dbus_message_iter_append_object_path(ITER_GET(self), StringValuePtr(value)))
|
522
|
+
return Qtrue;
|
523
|
+
return Qfalse;
|
524
|
+
}
|
525
|
+
|
526
|
+
/*
|
527
|
+
* call-seq:
|
528
|
+
* append_dict_key(string) => true|false
|
529
|
+
*
|
530
|
+
* Appends a dictionary key value to this message. Use in
|
531
|
+
* conjunction with another append call for the value to populate
|
532
|
+
* a dictionary.
|
533
|
+
*
|
534
|
+
* See DBusMessageIter#append for an example of usage.
|
535
|
+
*
|
536
|
+
* Returns +false+ if no memory.
|
537
|
+
*/
|
538
|
+
static VALUE
|
539
|
+
cDBusMessageIter_append_dict_key(VALUE self, VALUE value)
|
540
|
+
{
|
541
|
+
if (dbus_message_iter_append_dict_key(ITER_GET(self), StringValuePtr(value)))
|
542
|
+
return Qtrue;
|
543
|
+
return Qfalse;
|
544
|
+
}
|
545
|
+
|
546
|
+
/*
|
547
|
+
* call-seq:
|
548
|
+
* append_array(typecode) => iterator
|
549
|
+
*
|
550
|
+
* Appends an array of the specified type to this message, and returns an
|
551
|
+
* iterator for adding values to the new array.
|
552
|
+
*
|
553
|
+
* See DBusMessageIter#append for an example of usage.
|
554
|
+
*
|
555
|
+
* Returns +nil+ if no memory.
|
556
|
+
*/
|
557
|
+
static VALUE
|
558
|
+
cDBusMessageIter_append_array(VALUE self, VALUE type)
|
559
|
+
{
|
560
|
+
RubyDBusMessageIter *parent = NULL;
|
561
|
+
RubyDBusMessageIter *child = NULL;
|
562
|
+
|
563
|
+
parent = RDBUS_GET(RubyDBusMessageIter, self);
|
564
|
+
child = _alloc_message_iter(parent->message, NULL);
|
565
|
+
if (dbus_message_iter_append_array(parent->real_iter, child->real_iter, NUM2INT(type)))
|
566
|
+
return RDBUS_NEW(cDBusMessageIter, child);
|
567
|
+
_free_message_iter(child);
|
568
|
+
return Qnil;
|
569
|
+
}
|
570
|
+
|
571
|
+
/*
|
572
|
+
* call-seq:
|
573
|
+
* append_dict => iterator
|
574
|
+
*
|
575
|
+
* Appends a dictionary to this message, and returns an iterator for adding
|
576
|
+
* values to the new dictionary. Use DBusMessageIter#append_dict_key in
|
577
|
+
* conjunction with another append method to add <tt>key=>value</tt> pairs
|
578
|
+
* to the dictionary.
|
579
|
+
*
|
580
|
+
* See DBusMessageIter#append for an example of usage.
|
581
|
+
*
|
582
|
+
* Returns +nil+ if no memory.
|
583
|
+
*/
|
584
|
+
static VALUE
|
585
|
+
cDBusMessageIter_append_dict(VALUE self)
|
586
|
+
{
|
587
|
+
RubyDBusMessageIter *parent = NULL;
|
588
|
+
RubyDBusMessageIter *child = NULL;
|
589
|
+
|
590
|
+
parent = RDBUS_GET(RubyDBusMessageIter, self);
|
591
|
+
child = _alloc_message_iter(parent->message, NULL);
|
592
|
+
if (dbus_message_iter_append_dict(parent->real_iter, child->real_iter))
|
593
|
+
return RDBUS_NEW(cDBusMessageIter, child);
|
594
|
+
_free_message_iter(child);
|
595
|
+
return Qnil;
|
596
|
+
}
|
597
|
+
|
598
|
+
/*
|
599
|
+
* Document-class: DBus::Binding::DBusMessageIter
|
600
|
+
*
|
601
|
+
* The DBusMessageIter class is an iterator abstraction for accessing the
|
602
|
+
* argument values of a DBusMessage.
|
603
|
+
*
|
604
|
+
* This abstraction is quite low-level, and it is recommended that you use
|
605
|
+
* the Enumerable and Array-like methods on DBusMessage to access message
|
606
|
+
* argument values instead, as they perform the necessary integration with
|
607
|
+
* DBusMessageIter, and will ensure that the values you get have been
|
608
|
+
* converted to the correct Ruby types.
|
609
|
+
*/
|
610
|
+
void Init_dbus_message_iter()
|
611
|
+
{
|
612
|
+
cDBusMessageIter = rb_define_class_under(mDBusBinding, "DBusMessageIter", rb_cObject);
|
613
|
+
|
614
|
+
rb_define_singleton_method(cDBusMessageIter, "new", rdbus_private_method, 0);
|
615
|
+
|
616
|
+
rb_define_method(cDBusMessageIter, "has_next", cDBusMessageIter_has_next, 0);
|
617
|
+
rb_define_method(cDBusMessageIter, "next", cDBusMessageIter_next, 0);
|
618
|
+
|
619
|
+
rb_define_method(cDBusMessageIter, "get_arg_type", cDBusMessageIter_get_arg_type, 0);
|
620
|
+
rb_define_method(cDBusMessageIter, "get_array_type", cDBusMessageIter_get_array_type, 0);
|
621
|
+
|
622
|
+
rb_define_method(cDBusMessageIter, "get_byte", cDBusMessageIter_get_byte, 0);
|
623
|
+
rb_define_method(cDBusMessageIter, "get_boolean", cDBusMessageIter_get_boolean, 0);
|
624
|
+
rb_define_method(cDBusMessageIter, "get_int32", cDBusMessageIter_get_int32, 0);
|
625
|
+
rb_define_method(cDBusMessageIter, "get_uint32", cDBusMessageIter_get_uint32, 0);
|
626
|
+
|
627
|
+
#ifdef DBUS_HAVE_INT64
|
628
|
+
#if HAVE_LONG_LONG
|
629
|
+
rb_define_method(cDBusMessageIter, "get_int64", cDBusMessageIter_get_int64, 0);
|
630
|
+
rb_define_method(cDBusMessageIter, "get_uint64", cDBusMessageIter_get_uint64, 0);
|
631
|
+
#endif
|
632
|
+
#endif
|
633
|
+
|
634
|
+
rb_define_method(cDBusMessageIter, "get_double", cDBusMessageIter_get_double, 0);
|
635
|
+
rb_define_method(cDBusMessageIter, "get_string", cDBusMessageIter_get_string, 0);
|
636
|
+
rb_define_method(cDBusMessageIter, "get_object_path", cDBusMessageIter_get_object_path, 0);
|
637
|
+
rb_define_method(cDBusMessageIter, "get_dict_key", cDBusMessageIter_get_dict_key, 0);
|
638
|
+
|
639
|
+
rb_define_method(cDBusMessageIter, "array_iter", cDBusMessageIter_array_iter_new, 0);
|
640
|
+
rb_define_method(cDBusMessageIter, "dict_iter", cDBusMessageIter_dict_iter_new, 0);
|
641
|
+
|
642
|
+
rb_define_method(cDBusMessageIter, "append_nil", cDBusMessageIter_append_nil, 0);
|
643
|
+
rb_define_method(cDBusMessageIter, "append_boolean", cDBusMessageIter_append_boolean, 1);
|
644
|
+
rb_define_method(cDBusMessageIter, "append_byte", cDBusMessageIter_append_byte, 1);
|
645
|
+
rb_define_method(cDBusMessageIter, "append_int32", cDBusMessageIter_append_int32, 1);
|
646
|
+
rb_define_method(cDBusMessageIter, "append_uint32", cDBusMessageIter_append_uint32, 1);
|
647
|
+
|
648
|
+
#ifdef DBUS_HAVE_INT64
|
649
|
+
#if HAVE_LONG_LONG
|
650
|
+
rb_define_method(cDBusMessageIter, "append_int64", cDBusMessageIter_append_int64, 1);
|
651
|
+
rb_define_method(cDBusMessageIter, "append_uint64", cDBusMessageIter_append_uint64, 1);
|
652
|
+
#endif
|
653
|
+
#endif
|
654
|
+
|
655
|
+
rb_define_method(cDBusMessageIter, "append_double", cDBusMessageIter_append_double, 1);
|
656
|
+
rb_define_method(cDBusMessageIter, "append_string", cDBusMessageIter_append_string, 1);
|
657
|
+
rb_define_method(cDBusMessageIter, "append_object_path", cDBusMessageIter_append_object_path, 1);
|
658
|
+
rb_define_method(cDBusMessageIter, "append_dict_key", cDBusMessageIter_append_dict_key, 1);
|
659
|
+
rb_define_method(cDBusMessageIter, "append_array", cDBusMessageIter_append_array, 1);
|
660
|
+
rb_define_method(cDBusMessageIter, "append_dict", cDBusMessageIter_append_dict, 0);
|
661
|
+
}
|