dbus 0.1.5 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -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')
@@ -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 RDBUS_NEW(cDBusConnection, conn);
43
+ return CONN_NEW(conn);
44
44
  }
45
45
 
46
46
  /*
@@ -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
- RDBUS_GENERATE_NEW(cDBusConnection, DBusConnection *, _free_connection)
16
- RDBUS_GENERATE_GET(DBusConnection)
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
- /* Helpers */
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
- static void
21
- _free_connection(DBusConnection *conn)
29
+ DBusConnection *
30
+ rdbus_get_connection(VALUE obj)
22
31
  {
23
- dbus_connection_disconnect(conn);
24
- dbus_connection_unref(conn);
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 RDBUS_NEW(cDBusConnection, conn);
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 RDBUS_NEW(cDBusMessage, message);
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
- RDBUS_GET(DBusMessage, message)
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
- RDBUS_GET(DBusMessage, message)
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 RDBUS_NEW(cDBusMessage, message);
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), RDBUS_GET(DBusMessage, message), NULL))
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, RDBUS_NEW(cDBusPendingCall, call));
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 RDBUS_NEW(cDBusMessage, return_msg);
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 *argp = (VALUE*)args;
401
- VALUE unregister_cb = argp[0];
402
- return rb_funcall2(unregister_cb, rb_intern("call"), 1, argp+1);
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] = RDBUS_NEW(cDBusConnection, conn);
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 *argp = (VALUE*)args;
434
- VALUE message_cb = argp[0];
435
- return rb_funcall2(message_cb, rb_intern("call"), 2, argp+1);
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] = RDBUS_NEW(cDBusConnection, conn);
451
- args[2] = RDBUS_NEW(cDBusMessage, msg);
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
- return DBUS_HANDLER_RESULT_HANDLED;
460
- return NUM2INT(ret);
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 *argp = (VALUE*)args;
555
- VALUE filter_cb = argp[0];
556
- return rb_funcall2(filter_cb, rb_intern("call"), 2, argp+1);
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] = RDBUS_NEW(cDBusConnection, conn);
572
- args[2] = RDBUS_NEW(cDBusMessage, msg);
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
- return DBUS_HANDLER_RESULT_HANDLED;
581
- return NUM2INT(ret);
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
- RubyDBusMessageIter *
55
- rdbus_message_iter_new(DBusMessage *message, short is_append_iter)
51
+ static void
52
+ _ensure_arg_type(DBusMessageIter *iter, int type)
56
53
  {
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;
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
- _free_message_iter(RubyDBusMessageIter *iter)
59
+ rdbus_free_message_iter(void *iterp)
69
60
  {
70
- if (iter->message != NULL)
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
- static void
79
- _ensure_arg_type(DBusMessageIter *iter, int type)
72
+ VALUE
73
+ rdbus_new_message_iter(DBusMessage *message, gboolean is_append)
80
74
  {
81
- if (dbus_message_iter_get_arg_type(iter) != type)
82
- rb_raise(eDBusError, "argument type mismatch");
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 = RDBUS_GET(RubyDBusMessageIter, self);
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 RDBUS_NEW(cDBusMessageIter, ary_iter);
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 = RDBUS_GET(RubyDBusMessageIter, self);
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 RDBUS_NEW(cDBusMessageIter, dict_iter);
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 = RDBUS_GET(RubyDBusMessageIter, self);
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 RDBUS_NEW(cDBusMessageIter, child);
567
- _free_message_iter(child);
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 = RDBUS_GET(RubyDBusMessageIter, self);
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 RDBUS_NEW(cDBusMessageIter, child);
594
- _free_message_iter(child);
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
 
@@ -10,8 +10,60 @@
10
10
 
11
11
  VALUE cDBusMessage;
12
12
 
13
- RDBUS_GENERATE_NEW(cDBusMessage, DBusMessage *, dbus_message_unref)
14
- RDBUS_GENERATE_GET(DBusMessage)
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 RDBUS_NEW(cDBusMessage, message);
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 RDBUS_NEW(cDBusMessage, message);
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 RDBUS_NEW(cDBusMessage, message);
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 RDBUS_NEW(cDBusMessage, message);
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 RDBUS_NEW(cDBusMessage, message);
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 RDBUS_NEW(cDBusMessageIter, rdbus_message_iter_new(MSG_GET(self), 0));
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 RDBUS_NEW(cDBusMessageIter, rdbus_message_iter_new(MSG_GET(self), 1));
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
- RDBUS_GENERATE_NEW(cDBusPendingCall, DBusPendingCall *, dbus_pending_call_unref)
14
- RDBUS_GENERATE_GET(DBusPendingCall)
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 RDBUS_NEW(cDBusMessage, msg);
82
+ return MSG_NEW(msg);
59
83
  return Qnil;
60
84
  }
61
85
 
@@ -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
- _server_free(DBusServer *server)
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
- dbus_server_disconnect(server);
22
- dbus_server_unref(server);
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 RDBUS_NEW(cDBusServer, server);
57
+ return SERVER_NEW_TAKE_OWNERSHIP(server);
42
58
  }
43
59
 
44
60
  /*
@@ -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
- #define RDBUS_GENERATE_PROTO_NEW(klass, ctype) \
20
- VALUE _rdbus_ ##klass## _new_from(ctype obj)
21
-
22
- #define RDBUS_GENERATE_PROTO_GET(ctype) \
23
- ctype * _rdbus_ ##ctype## _get_wrapped(VALUE value)
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 CONN_GET(obj) \
68
- RDBUS_GET(DBusConnection, obj)
45
+ #define CONN_NEW_TAKE_OWNERSHIP(obj) \
46
+ rdbus_new_connection(obj, TRUE)
69
47
 
70
48
  #define MSG_GET(obj) \
71
- (RDBUS_GET(DBusMessage, obj))
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
- (RDBUS_GET(RubyDBusMessageIter, obj)->real_iter)
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
- (RDBUS_GET(DBusPendingCall, obj))
64
+ rdbus_get_pending_call(obj)
78
65
 
79
- #define SERVER_GET(obj) \
80
- (RDBUS_GET(DBusServer, obj))
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
- RDBUS_GENERATE_PROTO_NEW(cDBusConnection, DBusConnection *);
105
- RDBUS_GENERATE_PROTO_NEW(cDBusMessage, DBusMessage *);
106
- RDBUS_GENERATE_PROTO_NEW(cDBusMessageIter, RubyDBusMessageIter *);
107
- RDBUS_GENERATE_PROTO_NEW(cDBusPendingCall, DBusPendingCall *);
108
- RDBUS_GENERATE_PROTO_NEW(cDBusServer, DBusServer *);
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
- RubyDBusMessageIter *rdbus_message_iter_new (DBusMessage *msg, short is_append_iter);
117
- VALUE rdbus_private_method (VALUE klass);
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,
@@ -13,7 +13,7 @@ module DBus
13
13
  module BindingVersion
14
14
  VERSION_MAJOR = 0
15
15
  VERSION_MINOR = 1
16
- VERSION_PATCH = 4
16
+ VERSION_PATCH = 7
17
17
  end
18
18
 
19
19
  # Contains the string version of the D-BUS bindings
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.1
3
3
  specification_version: 1
4
4
  name: dbus
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.5
7
- date: 2004-11-25
6
+ version: 0.1.7
7
+ date: 2004-12-11
8
8
  summary: Ruby bindings for D-BUS.
9
9
  require_paths:
10
10
  - lib