dbus 0.1.5 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/extconf.rb +7 -0
- data/ext/ruby-dbus-bus.c +1 -1
- data/ext/ruby-dbus-connection.c +76 -37
- data/ext/ruby-dbus-message-iter.c +54 -31
- data/ext/ruby-dbus-message.c +61 -9
- data/ext/ruby-dbus-pending-call.c +27 -3
- data/ext/ruby-dbus-server.c +25 -9
- data/ext/ruby-dbus.h +40 -53
- data/lib/dbus/version.rb +1 -1
- metadata +2 -2
data/ext/extconf.rb
CHANGED
@@ -8,6 +8,7 @@ end
|
|
8
8
|
PKGConfig.have_package('dbus-1')
|
9
9
|
PKGConfig.have_package('dbus-glib-1')
|
10
10
|
PKGConfig.have_package('glib-2.0')
|
11
|
+
PKGConfig.have_package('gthread-2.0')
|
11
12
|
|
12
13
|
%w[dbus_connection_setup_with_g_main dbus_server_setup_with_g_main dbus_bus_get].each do |f|
|
13
14
|
unless have_func(f)
|
@@ -16,4 +17,10 @@ PKGConfig.have_package('glib-2.0')
|
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
20
|
+
debug = ARGV.shift
|
21
|
+
if debug == "--debug"
|
22
|
+
$CPPFLAGS << " -DRDBUS_DEBUG"
|
23
|
+
$CFLAGS << " -g"
|
24
|
+
end
|
25
|
+
|
19
26
|
create_makefile('dbus')
|
data/ext/ruby-dbus-bus.c
CHANGED
@@ -40,7 +40,7 @@ mDBusBinding_bus_get(int argc, VALUE *argv)
|
|
40
40
|
conn = NULL;
|
41
41
|
RDBUS_TRY(conn = dbus_bus_get(bus_type, &error));
|
42
42
|
RDBUS_RAISE_IF(conn == NULL, "failed to open D-BUS connection");
|
43
|
-
return
|
43
|
+
return CONN_NEW(conn);
|
44
44
|
}
|
45
45
|
|
46
46
|
/*
|
data/ext/ruby-dbus-connection.c
CHANGED
@@ -8,22 +8,38 @@
|
|
8
8
|
|
9
9
|
#include "ruby-dbus.h"
|
10
10
|
|
11
|
-
static void _free_connection(DBusConnection *conn);
|
12
|
-
|
13
11
|
VALUE cDBusConnection;
|
14
12
|
|
15
|
-
|
16
|
-
|
13
|
+
static void
|
14
|
+
rdbus_free_connection(void *conn)
|
15
|
+
{
|
16
|
+
DEBUG("DBusConnection.free <%p>", conn);
|
17
|
+
dbus_connection_unref((DBusConnection *)conn);
|
18
|
+
}
|
17
19
|
|
18
|
-
|
20
|
+
VALUE
|
21
|
+
rdbus_new_connection(DBusConnection *conn, gboolean owner)
|
22
|
+
{
|
23
|
+
if (!owner)
|
24
|
+
dbus_connection_ref(conn);
|
25
|
+
DEBUG("DBusConnection.new <%p> owner=%d", conn, owner);
|
26
|
+
return Data_Wrap_Struct(cDBusConnection, NULL, rdbus_free_connection, conn);
|
27
|
+
}
|
19
28
|
|
20
|
-
|
21
|
-
|
29
|
+
DBusConnection *
|
30
|
+
rdbus_get_connection(VALUE obj)
|
22
31
|
{
|
23
|
-
|
24
|
-
|
32
|
+
DBusConnection *conn;
|
33
|
+
|
34
|
+
conn = NULL;
|
35
|
+
Data_Get_Struct(obj, DBusConnection, conn);
|
36
|
+
if (conn == NULL)
|
37
|
+
rb_raise(eDBusError, "Failed to retrieve DATA object for DBusConnection");
|
38
|
+
return conn;
|
25
39
|
}
|
26
40
|
|
41
|
+
/* Helpers */
|
42
|
+
|
27
43
|
/*
|
28
44
|
* call-seq:
|
29
45
|
* new(address) => connection
|
@@ -45,7 +61,7 @@ cDBusConnection_open(VALUE klass, VALUE address)
|
|
45
61
|
conn = NULL;
|
46
62
|
RDBUS_TRY(conn = dbus_connection_open(StringValuePtr(address), &error));
|
47
63
|
RDBUS_RAISE_IF(conn == NULL, "failed to open D-BUS connection");
|
48
|
-
return
|
64
|
+
return CONN_NEW_TAKE_OWNERSHIP(conn);
|
49
65
|
}
|
50
66
|
|
51
67
|
/*
|
@@ -150,7 +166,7 @@ cDBusConnection_borrow_message(VALUE self)
|
|
150
166
|
message = dbus_connection_borrow_message(CONN_GET(self));
|
151
167
|
if (message == NULL)
|
152
168
|
return Qnil;
|
153
|
-
return
|
169
|
+
return MSG_NEW(message);
|
154
170
|
}
|
155
171
|
|
156
172
|
/*
|
@@ -167,7 +183,7 @@ cDBusConnection_return_message(VALUE self, VALUE message)
|
|
167
183
|
{
|
168
184
|
dbus_connection_return_message(
|
169
185
|
CONN_GET(self),
|
170
|
-
|
186
|
+
MSG_GET(message)
|
171
187
|
);
|
172
188
|
return Qnil;
|
173
189
|
}
|
@@ -187,7 +203,7 @@ cDBusConnection_steal_borrowed_message(VALUE self, VALUE message)
|
|
187
203
|
{
|
188
204
|
dbus_connection_steal_borrowed_message(
|
189
205
|
CONN_GET(self),
|
190
|
-
|
206
|
+
MSG_GET(message)
|
191
207
|
);
|
192
208
|
return Qnil;
|
193
209
|
}
|
@@ -211,7 +227,7 @@ cDBusConnection_pop_message(VALUE self)
|
|
211
227
|
message = dbus_connection_pop_message(CONN_GET(self));
|
212
228
|
if (message == NULL)
|
213
229
|
return Qnil;
|
214
|
-
return
|
230
|
+
return MSG_NEW(message);
|
215
231
|
}
|
216
232
|
|
217
233
|
/*
|
@@ -261,7 +277,7 @@ cDBusConnection_dispatch(VALUE self)
|
|
261
277
|
static VALUE
|
262
278
|
cDBusConnection_send(VALUE self, VALUE message)
|
263
279
|
{
|
264
|
-
if (dbus_connection_send(CONN_GET(self),
|
280
|
+
if (dbus_connection_send(CONN_GET(self), MSG_GET(message), NULL))
|
265
281
|
return Qtrue;
|
266
282
|
return Qfalse;
|
267
283
|
}
|
@@ -294,10 +310,11 @@ cDBusConnection_send_with_reply(VALUE self, VALUE msg, VALUE timeout)
|
|
294
310
|
ret = Qtrue;
|
295
311
|
ary = rb_ary_new2(2);
|
296
312
|
rb_ary_push(ary, ret);
|
297
|
-
if (call != NULL)
|
298
|
-
rb_ary_push(ary,
|
299
|
-
else
|
313
|
+
if (call != NULL) {
|
314
|
+
rb_ary_push(ary, CALL_NEW(call));
|
315
|
+
} else {
|
300
316
|
rb_ary_push(ary, Qnil);
|
317
|
+
}
|
301
318
|
return ary;
|
302
319
|
}
|
303
320
|
|
@@ -321,7 +338,7 @@ cDBusConnection_send_with_reply_and_block(VALUE self, VALUE msg, VALUE timeout)
|
|
321
338
|
)
|
322
339
|
if (return_msg == NULL)
|
323
340
|
return Qnil;
|
324
|
-
return
|
341
|
+
return MSG_NEW(return_msg);
|
325
342
|
}
|
326
343
|
|
327
344
|
/*
|
@@ -397,9 +414,9 @@ cDBusConnection_get_outgoing_size(VALUE self)
|
|
397
414
|
static VALUE
|
398
415
|
_real_call_unregister_cb(VALUE args)
|
399
416
|
{
|
400
|
-
VALUE *
|
401
|
-
VALUE unregister_cb =
|
402
|
-
return
|
417
|
+
VALUE *argv = (VALUE*)args;
|
418
|
+
VALUE unregister_cb = argv[0];
|
419
|
+
return rb_funcall(unregister_cb, rb_intern("call"), 1, argv[1]);
|
403
420
|
}
|
404
421
|
|
405
422
|
static void
|
@@ -415,24 +432,26 @@ _on_object_path_unregister(DBusConnection *conn, void *user_data)
|
|
415
432
|
unregister_cb = data[0];
|
416
433
|
message_cb = data[1];
|
417
434
|
args[0] = unregister_cb;
|
418
|
-
args[1] =
|
435
|
+
args[1] = CONN_NEW(conn);
|
419
436
|
|
420
437
|
exc = 0;
|
421
438
|
rb_protect(_real_call_unregister_cb, (VALUE)args, &exc);
|
422
439
|
|
423
440
|
if (exc)
|
424
441
|
rb_warn("Unregister callback raised exception (ignored)");
|
442
|
+
|
425
443
|
rb_gc_unregister_address(&unregister_cb);
|
426
444
|
rb_gc_unregister_address(&message_cb);
|
445
|
+
|
427
446
|
ruby_xfree(data);
|
428
447
|
}
|
429
448
|
|
430
449
|
static VALUE
|
431
450
|
_real_call_message_cb(VALUE args)
|
432
451
|
{
|
433
|
-
VALUE *
|
434
|
-
VALUE message_cb =
|
435
|
-
return
|
452
|
+
VALUE *argv = (VALUE*)args;
|
453
|
+
VALUE message_cb = argv[0];
|
454
|
+
return rb_funcall(message_cb, rb_intern("call"), 2, argv[1], argv[2]);
|
436
455
|
}
|
437
456
|
|
438
457
|
static DBusHandlerResult
|
@@ -443,21 +462,24 @@ _on_object_path_message(DBusConnection *conn, DBusMessage *msg, void *user_data)
|
|
443
462
|
VALUE ret;
|
444
463
|
VALUE args[3];
|
445
464
|
int exc;
|
465
|
+
DBusHandlerResult result;
|
446
466
|
|
447
467
|
data = (VALUE *)user_data;
|
448
468
|
message_cb = data[1];
|
449
469
|
args[0] = message_cb;
|
450
|
-
args[1] =
|
451
|
-
args[2] =
|
470
|
+
args[1] = CONN_NEW(conn);
|
471
|
+
args[2] = MSG_NEW(msg);
|
452
472
|
|
453
473
|
exc = 0;
|
454
474
|
ret = rb_protect(_real_call_message_cb, (VALUE)args, &exc);
|
455
475
|
|
456
476
|
if (exc)
|
457
477
|
rb_warn("Message callback raised exception (ignored)");
|
478
|
+
|
458
479
|
if (ret == Qnil)
|
459
|
-
|
460
|
-
|
480
|
+
result = DBUS_HANDLER_RESULT_HANDLED;
|
481
|
+
result = NUM2INT(ret);
|
482
|
+
return result;
|
461
483
|
}
|
462
484
|
|
463
485
|
/*
|
@@ -482,6 +504,9 @@ cDBusConnection_register_object_path(VALUE self, VALUE path,
|
|
482
504
|
DBusObjectPathVTable vtable;
|
483
505
|
VALUE *user_data;
|
484
506
|
|
507
|
+
if (NIL_P(unregister_cb) || NIL_P(message_cb))
|
508
|
+
rb_raise(eDBusError, "Both unregister and message callbacks have to be supplied");
|
509
|
+
|
485
510
|
vtable.unregister_function = _on_object_path_unregister;
|
486
511
|
vtable.message_function = _on_object_path_message;
|
487
512
|
|
@@ -496,6 +521,7 @@ cDBusConnection_register_object_path(VALUE self, VALUE path,
|
|
496
521
|
rb_gc_register_address(&message_cb);
|
497
522
|
return Qtrue;
|
498
523
|
}
|
524
|
+
|
499
525
|
ruby_xfree(user_data);
|
500
526
|
return Qfalse;
|
501
527
|
}
|
@@ -522,12 +548,16 @@ cDBusConnection_register_fallback(VALUE self, VALUE path,
|
|
522
548
|
DBusObjectPathVTable vtable;
|
523
549
|
VALUE *user_data;
|
524
550
|
|
551
|
+
if (NIL_P(unregister_cb) || NIL_P(message_cb))
|
552
|
+
rb_raise(eDBusError, "Both unregister and message callbacks have to be supplied");
|
553
|
+
|
525
554
|
vtable.unregister_function = _on_object_path_unregister;
|
526
555
|
vtable.message_function = _on_object_path_message;
|
527
556
|
|
528
557
|
user_data = ALLOC_N(VALUE, 2);
|
529
558
|
user_data[0] = unregister_cb;
|
530
559
|
user_data[1] = message_cb;
|
560
|
+
|
531
561
|
if (dbus_connection_register_fallback(CONN_GET(self), StringValuePtr(path),
|
532
562
|
&vtable, (void *)user_data))
|
533
563
|
{
|
@@ -535,6 +565,7 @@ cDBusConnection_register_fallback(VALUE self, VALUE path,
|
|
535
565
|
rb_gc_register_address(&message_cb);
|
536
566
|
return Qtrue;
|
537
567
|
}
|
568
|
+
|
538
569
|
ruby_xfree(user_data);
|
539
570
|
return Qfalse;
|
540
571
|
}
|
@@ -551,9 +582,9 @@ _free_filter_data(void *user_data)
|
|
551
582
|
static VALUE
|
552
583
|
_real_call_filter_cb(VALUE args)
|
553
584
|
{
|
554
|
-
VALUE *
|
555
|
-
VALUE filter_cb =
|
556
|
-
return
|
585
|
+
VALUE *argv = (VALUE*)args;
|
586
|
+
VALUE filter_cb = argv[0];
|
587
|
+
return rb_funcall(filter_cb, rb_intern("call"), 2, argv[1], argv[2]);
|
557
588
|
}
|
558
589
|
|
559
590
|
static DBusHandlerResult
|
@@ -564,21 +595,24 @@ _on_filter_message(DBusConnection *conn, DBusMessage *msg, void *user_data)
|
|
564
595
|
VALUE ret;
|
565
596
|
VALUE args[3];
|
566
597
|
int exc;
|
598
|
+
DBusHandlerResult result;
|
567
599
|
|
568
600
|
data = (VALUE*)user_data;
|
569
601
|
filter_cb = data[0];
|
570
602
|
args[0] = filter_cb;
|
571
|
-
args[1] =
|
572
|
-
args[2] =
|
603
|
+
args[1] = CONN_NEW(conn);
|
604
|
+
args[2] = MSG_NEW(msg);
|
573
605
|
|
574
606
|
exc = 0;
|
575
607
|
ret = rb_protect(_real_call_filter_cb, (VALUE)args, &exc);
|
576
608
|
|
577
609
|
if (exc)
|
578
610
|
rb_warn("Filter callback raised exception (ignored)");
|
611
|
+
|
579
612
|
if (ret == Qnil)
|
580
|
-
|
581
|
-
|
613
|
+
result = DBUS_HANDLER_RESULT_HANDLED;
|
614
|
+
result = NUM2INT(ret);
|
615
|
+
return result;
|
582
616
|
}
|
583
617
|
|
584
618
|
/*
|
@@ -602,14 +636,19 @@ cDBusConnection_add_filter(VALUE self, VALUE filter_cb)
|
|
602
636
|
{
|
603
637
|
VALUE *data;
|
604
638
|
|
639
|
+
if (NIL_P(filter_cb))
|
640
|
+
rb_raise(eDBusError, "Callback must be supplied");
|
641
|
+
|
605
642
|
data = ALLOC_N(VALUE, 1);
|
606
643
|
data[0] = filter_cb;
|
644
|
+
|
607
645
|
if (dbus_connection_add_filter(CONN_GET(self), _on_filter_message,
|
608
646
|
(void*)data, _free_filter_data))
|
609
647
|
{
|
610
648
|
rb_gc_register_address(&filter_cb);
|
611
649
|
return Qtrue;
|
612
650
|
}
|
651
|
+
|
613
652
|
ruby_xfree(data);
|
614
653
|
return Qfalse;
|
615
654
|
}
|
@@ -18,12 +18,8 @@ struct _RubyDBusMessageIter {
|
|
18
18
|
|
19
19
|
VALUE cDBusMessageIter;
|
20
20
|
|
21
|
-
static void _free_message_iter(RubyDBusMessageIter *iter);
|
22
21
|
static void _ensure_arg_type(DBusMessageIter *iter, int type);
|
23
22
|
|
24
|
-
RDBUS_GENERATE_NEW(cDBusMessageIter, RubyDBusMessageIter *, _free_message_iter)
|
25
|
-
RDBUS_GENERATE_GET(RubyDBusMessageIter)
|
26
|
-
|
27
23
|
static RubyDBusMessageIter *
|
28
24
|
_alloc_message_iter(DBusMessage *message, DBusMessageIter *real_iter)
|
29
25
|
{
|
@@ -45,43 +41,70 @@ _alloc_message_iter(DBusMessage *message, DBusMessageIter *real_iter)
|
|
45
41
|
}
|
46
42
|
|
47
43
|
iter->message = message;
|
48
|
-
if (iter->message != NULL)
|
44
|
+
if (iter->message != NULL) {
|
49
45
|
dbus_message_ref(iter->message);
|
46
|
+
}
|
50
47
|
|
51
48
|
return iter;
|
52
49
|
}
|
53
50
|
|
54
|
-
|
55
|
-
|
51
|
+
static void
|
52
|
+
_ensure_arg_type(DBusMessageIter *iter, int type)
|
56
53
|
{
|
57
|
-
|
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;
|
54
|
+
if (dbus_message_iter_get_arg_type(iter) != type)
|
55
|
+
rb_raise(eDBusError, "argument type mismatch");
|
65
56
|
}
|
66
57
|
|
67
58
|
static void
|
68
|
-
|
59
|
+
rdbus_free_message_iter(void *iterp)
|
69
60
|
{
|
70
|
-
|
61
|
+
RubyDBusMessageIter *iter = (RubyDBusMessageIter *)iterp;
|
62
|
+
|
63
|
+
if (iter->message != NULL) {
|
71
64
|
dbus_message_unref(iter->message);
|
65
|
+
}
|
72
66
|
ruby_xfree(iter->real_iter);
|
73
67
|
iter->message = NULL;
|
74
68
|
iter->real_iter = NULL;
|
75
69
|
ruby_xfree(iter);
|
76
70
|
}
|
77
71
|
|
78
|
-
|
79
|
-
|
72
|
+
VALUE
|
73
|
+
rdbus_new_message_iter(DBusMessage *message, gboolean is_append)
|
80
74
|
{
|
81
|
-
|
82
|
-
|
75
|
+
RubyDBusMessageIter *iter;
|
76
|
+
|
77
|
+
iter = _alloc_message_iter(message, NULL);
|
78
|
+
if (is_append) {
|
79
|
+
dbus_message_append_iter_init(iter->message, iter->real_iter);
|
80
|
+
} else {
|
81
|
+
dbus_message_iter_init(iter->message, iter->real_iter);
|
82
|
+
}
|
83
|
+
return Data_Wrap_Struct(cDBusMessageIter, NULL, rdbus_free_message_iter, iter);
|
83
84
|
}
|
84
85
|
|
86
|
+
#define ITER_WRAPPER_GET(obj) \
|
87
|
+
rdbus_get_wrapping_message_iter(obj)
|
88
|
+
|
89
|
+
RubyDBusMessageIter *
|
90
|
+
rdbus_get_wrapping_message_iter(VALUE obj)
|
91
|
+
{
|
92
|
+
RubyDBusMessageIter *iter;
|
93
|
+
|
94
|
+
iter = NULL;
|
95
|
+
Data_Get_Struct(obj, RubyDBusMessageIter, iter);
|
96
|
+
if (iter == NULL)
|
97
|
+
rb_raise(eDBusError, "Failed to retrieve DATA object for RubyDBusMessageIter");
|
98
|
+
return iter;
|
99
|
+
}
|
100
|
+
|
101
|
+
DBusMessageIter *
|
102
|
+
rdbus_get_message_iter(VALUE obj)
|
103
|
+
{
|
104
|
+
return rdbus_get_wrapping_message_iter(obj)->real_iter;
|
105
|
+
}
|
106
|
+
|
107
|
+
|
85
108
|
/*
|
86
109
|
* call-seq:
|
87
110
|
* has_next => true|false
|
@@ -300,11 +323,11 @@ cDBusMessageIter_array_iter_new(VALUE self)
|
|
300
323
|
RubyDBusMessageIter *ary_iter = NULL;
|
301
324
|
int array_type = DBUS_TYPE_INVALID;
|
302
325
|
|
303
|
-
self_iter =
|
326
|
+
self_iter = ITER_WRAPPER_GET(self);
|
304
327
|
_ensure_arg_type(self_iter->real_iter, DBUS_TYPE_ARRAY);
|
305
328
|
ary_iter = _alloc_message_iter(self_iter->message, NULL);
|
306
329
|
dbus_message_iter_init_array_iterator(self_iter->real_iter, ary_iter->real_iter, &array_type);
|
307
|
-
return
|
330
|
+
return Data_Wrap_Struct(cDBusMessageIter, NULL, rdbus_free_message_iter, ary_iter);
|
308
331
|
}
|
309
332
|
|
310
333
|
/*
|
@@ -322,11 +345,11 @@ cDBusMessageIter_dict_iter_new(VALUE self)
|
|
322
345
|
RubyDBusMessageIter *self_iter = NULL;
|
323
346
|
RubyDBusMessageIter *dict_iter = NULL;
|
324
347
|
|
325
|
-
self_iter =
|
348
|
+
self_iter = ITER_WRAPPER_GET(self);
|
326
349
|
_ensure_arg_type(self_iter->real_iter, DBUS_TYPE_DICT);
|
327
350
|
dict_iter = _alloc_message_iter(self_iter->message, NULL);
|
328
351
|
dbus_message_iter_init_dict_iterator(self_iter->real_iter, dict_iter->real_iter);
|
329
|
-
return
|
352
|
+
return Data_Wrap_Struct(cDBusMessageIter, NULL, rdbus_free_message_iter, dict_iter);
|
330
353
|
}
|
331
354
|
|
332
355
|
/*
|
@@ -560,11 +583,11 @@ cDBusMessageIter_append_array(VALUE self, VALUE type)
|
|
560
583
|
RubyDBusMessageIter *parent = NULL;
|
561
584
|
RubyDBusMessageIter *child = NULL;
|
562
585
|
|
563
|
-
parent =
|
586
|
+
parent = ITER_WRAPPER_GET(self);
|
564
587
|
child = _alloc_message_iter(parent->message, NULL);
|
565
588
|
if (dbus_message_iter_append_array(parent->real_iter, child->real_iter, NUM2INT(type)))
|
566
|
-
return
|
567
|
-
|
589
|
+
return Data_Wrap_Struct(cDBusMessageIter, NULL, rdbus_free_message_iter, child);
|
590
|
+
rdbus_free_message_iter(child);
|
568
591
|
return Qnil;
|
569
592
|
}
|
570
593
|
|
@@ -587,11 +610,11 @@ cDBusMessageIter_append_dict(VALUE self)
|
|
587
610
|
RubyDBusMessageIter *parent = NULL;
|
588
611
|
RubyDBusMessageIter *child = NULL;
|
589
612
|
|
590
|
-
parent =
|
613
|
+
parent = ITER_WRAPPER_GET(self);
|
591
614
|
child = _alloc_message_iter(parent->message, NULL);
|
592
615
|
if (dbus_message_iter_append_dict(parent->real_iter, child->real_iter))
|
593
|
-
return
|
594
|
-
|
616
|
+
return Data_Wrap_Struct(cDBusMessageIter, NULL, rdbus_free_message_iter, child);
|
617
|
+
rdbus_free_message_iter(child);
|
595
618
|
return Qnil;
|
596
619
|
}
|
597
620
|
|
data/ext/ruby-dbus-message.c
CHANGED
@@ -10,8 +10,60 @@
|
|
10
10
|
|
11
11
|
VALUE cDBusMessage;
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
static const char *
|
14
|
+
rdbus_message_type_string(DBusMessage *message)
|
15
|
+
{
|
16
|
+
int type;
|
17
|
+
|
18
|
+
type = dbus_message_get_type(message);
|
19
|
+
switch (type) {
|
20
|
+
case DBUS_MESSAGE_TYPE_INVALID:
|
21
|
+
return "Invalid";
|
22
|
+
case DBUS_MESSAGE_TYPE_METHOD_CALL:
|
23
|
+
return "MethodCall";
|
24
|
+
case DBUS_MESSAGE_TYPE_METHOD_RETURN:
|
25
|
+
return "MethodReturn";
|
26
|
+
case DBUS_MESSAGE_TYPE_ERROR:
|
27
|
+
return "Error";
|
28
|
+
case DBUS_MESSAGE_TYPE_SIGNAL:
|
29
|
+
return "Signal";
|
30
|
+
default:
|
31
|
+
return "Unknown";
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
static void
|
36
|
+
rdbus_free_message(void *message)
|
37
|
+
{
|
38
|
+
DEBUG("DBusMessage.free <%p>", message);
|
39
|
+
dbus_message_unref((DBusMessage *)message);
|
40
|
+
}
|
41
|
+
|
42
|
+
VALUE
|
43
|
+
rdbus_new_message(DBusMessage *message, gboolean owner)
|
44
|
+
{
|
45
|
+
#ifdef RDBUS_DEBUG
|
46
|
+
const char *path;
|
47
|
+
path = dbus_message_get_path(message);
|
48
|
+
#endif
|
49
|
+
|
50
|
+
if (!owner)
|
51
|
+
dbus_message_ref(message);
|
52
|
+
DEBUG("DBusMessage.new <%p> owner=%d type=%s path=%s", message, owner, rdbus_message_type_string(message), path ? path : "<NULL>");
|
53
|
+
return Data_Wrap_Struct(cDBusMessage, NULL, rdbus_free_message, message);
|
54
|
+
}
|
55
|
+
|
56
|
+
DBusMessage *
|
57
|
+
rdbus_get_message(VALUE obj)
|
58
|
+
{
|
59
|
+
DBusMessage *msg;
|
60
|
+
|
61
|
+
msg = NULL;
|
62
|
+
Data_Get_Struct(obj, DBusMessage, msg);
|
63
|
+
if (msg == NULL)
|
64
|
+
rb_raise(eDBusError, "Failed to retrieve DATA object for DBusMessage");
|
65
|
+
return msg;
|
66
|
+
}
|
15
67
|
|
16
68
|
/*
|
17
69
|
* call-seq:
|
@@ -41,7 +93,7 @@ cDBusMessage_new(VALUE klass, VALUE type)
|
|
41
93
|
message = NULL;
|
42
94
|
message = dbus_message_new(message_type);
|
43
95
|
RDBUS_RAISE_IF(message == NULL, "failed to create DBusMessage");
|
44
|
-
return
|
96
|
+
return MSG_NEW_TAKE_OWNERSHIP(message);
|
45
97
|
}
|
46
98
|
|
47
99
|
/*
|
@@ -72,7 +124,7 @@ cDBusMessage_new_method_call(VALUE klass, VALUE service, VALUE path,
|
|
72
124
|
StringValuePtr(method)
|
73
125
|
);
|
74
126
|
RDBUS_RAISE_IF(message == NULL, "failed to create DBusMessage");
|
75
|
-
return
|
127
|
+
return MSG_NEW_TAKE_OWNERSHIP(message);
|
76
128
|
}
|
77
129
|
|
78
130
|
/*
|
@@ -92,7 +144,7 @@ cDBusMessage_new_method_return(VALUE klass, VALUE method_call_msg)
|
|
92
144
|
message = NULL;
|
93
145
|
message = dbus_message_new_method_return(MSG_GET(method_call_msg));
|
94
146
|
RDBUS_RAISE_IF(!message, "failed to create DBusMessage");
|
95
|
-
return
|
147
|
+
return MSG_NEW_TAKE_OWNERSHIP(message);
|
96
148
|
}
|
97
149
|
|
98
150
|
/*
|
@@ -120,7 +172,7 @@ cDBusMessage_new_signal(VALUE klass, VALUE path, VALUE interface, VALUE name)
|
|
120
172
|
StringValuePtr(name)
|
121
173
|
);
|
122
174
|
RDBUS_RAISE_IF(!message, "failed to create DBusMessage");
|
123
|
-
return
|
175
|
+
return MSG_NEW_TAKE_OWNERSHIP(message);
|
124
176
|
}
|
125
177
|
|
126
178
|
/*
|
@@ -146,7 +198,7 @@ cDBusMessage_new_error(VALUE klass, VALUE reply_to, VALUE error_name,
|
|
146
198
|
StringValuePtr(error_message)
|
147
199
|
);
|
148
200
|
RDBUS_RAISE_IF(!message, "failed to create DBusMessage");
|
149
|
-
return
|
201
|
+
return MSG_NEW_TAKE_OWNERSHIP(message);
|
150
202
|
}
|
151
203
|
|
152
204
|
/*
|
@@ -566,7 +618,7 @@ cDBusMessage_get_auto_activation(VALUE self)
|
|
566
618
|
static VALUE
|
567
619
|
cDBusMessage_get_iter(VALUE self)
|
568
620
|
{
|
569
|
-
return
|
621
|
+
return ITER_NEW(MSG_GET(self), FALSE);
|
570
622
|
}
|
571
623
|
|
572
624
|
/*
|
@@ -580,7 +632,7 @@ cDBusMessage_get_iter(VALUE self)
|
|
580
632
|
static VALUE
|
581
633
|
cDBusMessage_get_append_iter(VALUE self)
|
582
634
|
{
|
583
|
-
return
|
635
|
+
return ITER_NEW(MSG_GET(self), TRUE);
|
584
636
|
}
|
585
637
|
|
586
638
|
/*
|
@@ -10,8 +10,32 @@
|
|
10
10
|
|
11
11
|
VALUE cDBusPendingCall;
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
static void
|
14
|
+
rdbus_free_pending_call(void *call)
|
15
|
+
{
|
16
|
+
DEBUG("DBusPendingCall.free <%p>", call);
|
17
|
+
dbus_pending_call_unref((DBusPendingCall *)call);
|
18
|
+
}
|
19
|
+
|
20
|
+
VALUE
|
21
|
+
rdbus_new_pending_call(DBusPendingCall *call)
|
22
|
+
{
|
23
|
+
dbus_pending_call_ref(call);
|
24
|
+
DEBUG("DBusPendingCall.new <%p>", call);
|
25
|
+
return Data_Wrap_Struct(cDBusPendingCall, NULL, rdbus_free_pending_call, call);
|
26
|
+
}
|
27
|
+
|
28
|
+
DBusPendingCall *
|
29
|
+
rdbus_get_pending_call(VALUE obj)
|
30
|
+
{
|
31
|
+
DBusPendingCall *call;
|
32
|
+
|
33
|
+
call = NULL;
|
34
|
+
Data_Get_Struct(obj, DBusPendingCall, call);
|
35
|
+
if (call == NULL)
|
36
|
+
rb_raise(eDBusError, "Failed to retrieve DATA object for DBusPendingCall");
|
37
|
+
return call;
|
38
|
+
}
|
15
39
|
|
16
40
|
/*
|
17
41
|
* call-seq:
|
@@ -55,7 +79,7 @@ cDBusPendingCall_get_reply(VALUE self)
|
|
55
79
|
|
56
80
|
msg = dbus_pending_call_get_reply(CALL_GET(self));
|
57
81
|
if (msg != NULL)
|
58
|
-
return
|
82
|
+
return MSG_NEW(msg);
|
59
83
|
return Qnil;
|
60
84
|
}
|
61
85
|
|
data/ext/ruby-dbus-server.c
CHANGED
@@ -8,18 +8,34 @@
|
|
8
8
|
|
9
9
|
#include "ruby-dbus.h"
|
10
10
|
|
11
|
-
static void _server_free(DBusServer *server);
|
12
|
-
|
13
11
|
VALUE cDBusServer;
|
14
12
|
|
15
|
-
RDBUS_GENERATE_NEW(cDBusServer, DBusServer *, _server_free)
|
16
|
-
RDBUS_GENERATE_GET(DBusServer)
|
17
|
-
|
18
13
|
static void
|
19
|
-
|
14
|
+
rdbus_free_server(void *server)
|
15
|
+
{
|
16
|
+
DEBUG("DBusServer.free <%p>", server);
|
17
|
+
dbus_server_unref((DBusServer *)server);
|
18
|
+
}
|
19
|
+
|
20
|
+
VALUE
|
21
|
+
rdbus_new_server(DBusServer *server, gboolean owner)
|
20
22
|
{
|
21
|
-
|
22
|
-
|
23
|
+
if (!owner)
|
24
|
+
dbus_server_ref(server);
|
25
|
+
DEBUG("DBusServer.new <%p> owner=%d", server, owner);
|
26
|
+
return Data_Wrap_Struct(cDBusServer, NULL, rdbus_free_server, server);
|
27
|
+
}
|
28
|
+
|
29
|
+
DBusServer *
|
30
|
+
rdbus_get_server(VALUE obj)
|
31
|
+
{
|
32
|
+
DBusServer *server;
|
33
|
+
|
34
|
+
server = NULL;
|
35
|
+
Data_Get_Struct(obj, DBusServer, server);
|
36
|
+
if (server == NULL)
|
37
|
+
rb_raise(eDBusError, "Failed to retrieve DATA object for DBusServer");
|
38
|
+
return server;
|
23
39
|
}
|
24
40
|
|
25
41
|
/*
|
@@ -38,7 +54,7 @@ cDBusServer_listen(VALUE klass, VALUE address)
|
|
38
54
|
|
39
55
|
RDBUS_TRY(server = dbus_server_listen(StringValuePtr(address), &error));
|
40
56
|
RDBUS_RAISE_IF(server == NULL, "failed to create DBusServer");
|
41
|
-
return
|
57
|
+
return SERVER_NEW_TAKE_OWNERSHIP(server);
|
42
58
|
}
|
43
59
|
|
44
60
|
/*
|
data/ext/ruby-dbus.h
CHANGED
@@ -10,36 +10,16 @@
|
|
10
10
|
#ifndef RUBY_DBUS_H
|
11
11
|
#define RUBY_DBUS_H
|
12
12
|
|
13
|
-
|
14
13
|
#define DBUS_API_SUBJECT_TO_CHANGE 1
|
15
14
|
#include <dbus/dbus.h>
|
16
15
|
#include <dbus/dbus-glib.h>
|
17
16
|
#include "ruby.h"
|
18
17
|
|
19
|
-
#
|
20
|
-
|
21
|
-
|
22
|
-
#define
|
23
|
-
|
24
|
-
|
25
|
-
#define RDBUS_GENERATE_NEW(klass, ctype, free) \
|
26
|
-
RDBUS_GENERATE_NEW_WITH_MARK(klass, ctype, NULL, free)
|
27
|
-
|
28
|
-
#define RDBUS_GENERATE_NEW_WITH_MARK(klass, ctype, mark, free) \
|
29
|
-
RDBUS_GENERATE_PROTO_NEW(klass, ctype) \
|
30
|
-
{ \
|
31
|
-
return Data_Wrap_Struct(klass, mark, free, obj); \
|
32
|
-
}
|
33
|
-
|
34
|
-
#define RDBUS_GENERATE_GET(ctype) \
|
35
|
-
RDBUS_GENERATE_PROTO_GET(ctype) \
|
36
|
-
{ \
|
37
|
-
ctype *obj = NULL; \
|
38
|
-
Data_Get_Struct(value, ctype, obj); \
|
39
|
-
if (obj == NULL) \
|
40
|
-
rb_raise(eDBusError, "failed to retrieve " #ctype); \
|
41
|
-
return obj; \
|
42
|
-
}
|
18
|
+
#ifdef RDBUS_DEBUG
|
19
|
+
#define DEBUG(fmt, x...) fprintf(stderr, "[RDBUS] " fmt "\n", ##x)
|
20
|
+
#else
|
21
|
+
#define DEBUG(fmt, x...)
|
22
|
+
#endif
|
43
23
|
|
44
24
|
#define RDBUS_TRY_ERR(expr, klass) \
|
45
25
|
do { \
|
@@ -53,33 +33,44 @@
|
|
53
33
|
#define RDBUS_TRY(expr) \
|
54
34
|
RDBUS_TRY_ERR((expr), eDBusError)
|
55
35
|
|
56
|
-
#define RDBUS_NEW(klass, obj) \
|
57
|
-
_rdbus_ ##klass## _new_from(obj)
|
58
|
-
|
59
|
-
#define RDBUS_GET(ctype, value) \
|
60
|
-
_rdbus_ ##ctype## _get_wrapped(value)
|
61
|
-
|
62
36
|
#define RDBUS_RAISE_IF(cond, message) \
|
63
37
|
if (cond) rb_raise(eDBusError, message)
|
64
38
|
|
39
|
+
#define CONN_GET(obj) \
|
40
|
+
rdbus_get_connection(obj)
|
65
41
|
|
42
|
+
#define CONN_NEW(obj) \
|
43
|
+
rdbus_new_connection(obj, FALSE)
|
66
44
|
|
67
|
-
#define
|
68
|
-
|
45
|
+
#define CONN_NEW_TAKE_OWNERSHIP(obj) \
|
46
|
+
rdbus_new_connection(obj, TRUE)
|
69
47
|
|
70
48
|
#define MSG_GET(obj) \
|
71
|
-
(
|
49
|
+
rdbus_get_message(obj)
|
50
|
+
|
51
|
+
#define MSG_NEW(obj) \
|
52
|
+
rdbus_new_message(obj, FALSE)
|
53
|
+
|
54
|
+
#define MSG_NEW_TAKE_OWNERSHIP(obj) \
|
55
|
+
rdbus_new_message(obj, TRUE)
|
72
56
|
|
73
57
|
#define ITER_GET(obj) \
|
74
|
-
(
|
58
|
+
rdbus_get_message_iter(obj)
|
59
|
+
|
60
|
+
#define ITER_NEW(msg, append) \
|
61
|
+
rdbus_new_message_iter(msg, append)
|
75
62
|
|
76
63
|
#define CALL_GET(obj) \
|
77
|
-
(
|
64
|
+
rdbus_get_pending_call(obj)
|
78
65
|
|
79
|
-
#define
|
80
|
-
(
|
66
|
+
#define CALL_NEW(obj) \
|
67
|
+
rdbus_new_pending_call(obj)
|
81
68
|
|
69
|
+
#define SERVER_GET(obj) \
|
70
|
+
rdbus_get_server(obj)
|
82
71
|
|
72
|
+
#define SERVER_NEW_TAKE_OWNERSHIP(obj) \
|
73
|
+
rdbus_new_server(obj, TRUE)
|
83
74
|
|
84
75
|
extern VALUE mDBus;
|
85
76
|
extern VALUE mDBusBinding;
|
@@ -92,8 +83,6 @@ extern VALUE eDBusError;
|
|
92
83
|
|
93
84
|
typedef struct _RubyDBusMessageIter RubyDBusMessageIter;
|
94
85
|
|
95
|
-
|
96
|
-
|
97
86
|
void Init_dbus_bus();
|
98
87
|
void Init_dbus_connection();
|
99
88
|
void Init_dbus_message();
|
@@ -101,21 +90,19 @@ void Init_dbus_message_iter();
|
|
101
90
|
void Init_dbus_pending_call();
|
102
91
|
void Init_dbus_server();
|
103
92
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
RDBUS_GENERATE_PROTO_GET(DBusConnection);
|
111
|
-
RDBUS_GENERATE_PROTO_GET(DBusMessage);
|
112
|
-
RDBUS_GENERATE_PROTO_GET(DBusMessageIter);
|
113
|
-
RDBUS_GENERATE_PROTO_GET(DBusPendingCall);
|
114
|
-
RDBUS_GENERATE_PROTO_GET(DBusServer);
|
93
|
+
VALUE rdbus_new_connection (DBusConnection *conn, gboolean is_owner);
|
94
|
+
VALUE rdbus_new_message (DBusMessage *msg, gboolean is_owner);
|
95
|
+
VALUE rdbus_new_message_iter (DBusMessage *msg, gboolean is_append);
|
96
|
+
VALUE rdbus_new_pending_call (DBusPendingCall *call);
|
97
|
+
VALUE rdbus_new_server (DBusServer *server, gboolean is_owner);
|
115
98
|
|
116
|
-
|
117
|
-
|
99
|
+
DBusConnection *rdbus_get_connection (VALUE obj);
|
100
|
+
DBusMessage *rdbus_get_message (VALUE obj);
|
101
|
+
DBusMessageIter *rdbus_get_message_iter (VALUE obj);
|
102
|
+
DBusPendingCall *rdbus_get_pending_call (VALUE obj);
|
103
|
+
DBusServer *rdbus_get_server (VALUE obj);
|
118
104
|
|
105
|
+
VALUE rdbus_private_method (VALUE klass);
|
119
106
|
|
120
107
|
/* --- Externals (copied from Python bindings) --- */
|
121
108
|
void dbus_connection_setup_with_g_main (DBusConnection *connection,
|
data/lib/dbus/version.rb
CHANGED