dbus 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,37 +8,72 @@
8
8
 
9
9
  #include "ruby-dbus.h"
10
10
 
11
+ typedef struct _RubyDBusConnection {
12
+ DBusConnection *conn;
13
+ VALUE callbacks;
14
+ } RubyDBusConnection;
15
+
11
16
  VALUE cDBusConnection;
12
17
 
13
18
  static void
14
- rdbus_free_connection(void *conn)
19
+ rdbus_mark_connection(RubyDBusConnection *wrapper)
20
+ {
21
+ DEBUG("DBusConnection.mark <%p>", wrapper->conn);
22
+ rb_gc_mark(wrapper->callbacks);
23
+ }
24
+
25
+ static void
26
+ rdbus_free_connection(RubyDBusConnection *wrapper)
15
27
  {
16
- DEBUG("DBusConnection.free <%p>", conn);
17
- dbus_connection_unref((DBusConnection *)conn);
28
+ DEBUG("DBusConnection.free <%p>", wrapper->conn);
29
+ dbus_connection_unref(wrapper->conn);
30
+ rb_ary_clear(wrapper->callbacks);
31
+ wrapper->conn = NULL;
32
+ wrapper->callbacks = Qnil;
33
+ ruby_xfree(wrapper);
34
+ }
35
+
36
+ static RubyDBusConnection *
37
+ rdbus_get_connection_wrapper(VALUE obj)
38
+ {
39
+ RubyDBusConnection *wrapper;
40
+
41
+ wrapper = NULL;
42
+ Data_Get_Struct(obj, RubyDBusConnection, wrapper);
43
+ if (wrapper == NULL)
44
+ rb_raise(eDBusError, "Failed to retrieve DATA object for DBusConnection");
45
+ return wrapper;
18
46
  }
19
47
 
20
48
  VALUE
21
49
  rdbus_new_connection(DBusConnection *conn, gboolean owner)
22
50
  {
51
+ RubyDBusConnection *wrapper;
52
+
53
+ wrapper = ALLOC(RubyDBusConnection);
54
+ wrapper->conn = conn;
55
+ wrapper->callbacks = rb_ary_new();
56
+
23
57
  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);
58
+ dbus_connection_ref(wrapper->conn);
59
+ DEBUG("DBusConnection.new <%p> owner=%d", wrapper->conn, owner);
60
+ return Data_Wrap_Struct(cDBusConnection, rdbus_mark_connection, rdbus_free_connection, wrapper);
27
61
  }
28
62
 
29
63
  DBusConnection *
30
64
  rdbus_get_connection(VALUE obj)
31
65
  {
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;
66
+ return rdbus_get_connection_wrapper(obj)->conn;
39
67
  }
40
68
 
41
- /* Helpers */
69
+ static void
70
+ rdbus_register_connection_callback(VALUE self, VALUE callback)
71
+ {
72
+ RubyDBusConnection *wrapper;
73
+
74
+ wrapper = rdbus_get_connection_wrapper(self);
75
+ rb_ary_push(wrapper->callbacks, callback);
76
+ }
42
77
 
43
78
  /*
44
79
  * call-seq:
@@ -440,9 +475,6 @@ _on_object_path_unregister(DBusConnection *conn, void *user_data)
440
475
  if (exc)
441
476
  rb_warn("Unregister callback raised exception (ignored)");
442
477
 
443
- rb_gc_unregister_address(&unregister_cb);
444
- rb_gc_unregister_address(&message_cb);
445
-
446
478
  ruby_xfree(data);
447
479
  }
448
480
 
@@ -517,8 +549,8 @@ cDBusConnection_register_object_path(VALUE self, VALUE path,
517
549
  if (dbus_connection_register_object_path(CONN_GET(self), StringValuePtr(path),
518
550
  &vtable, (void *)user_data))
519
551
  {
520
- rb_gc_register_address(&unregister_cb);
521
- rb_gc_register_address(&message_cb);
552
+ rdbus_register_connection_callback(self, unregister_cb);
553
+ rdbus_register_connection_callback(self, message_cb);
522
554
  return Qtrue;
523
555
  }
524
556
 
@@ -561,8 +593,8 @@ cDBusConnection_register_fallback(VALUE self, VALUE path,
561
593
  if (dbus_connection_register_fallback(CONN_GET(self), StringValuePtr(path),
562
594
  &vtable, (void *)user_data))
563
595
  {
564
- rb_gc_register_address(&unregister_cb);
565
- rb_gc_register_address(&message_cb);
596
+ rdbus_register_connection_callback(self, unregister_cb);
597
+ rdbus_register_connection_callback(self, message_cb);
566
598
  return Qtrue;
567
599
  }
568
600
 
@@ -573,10 +605,7 @@ cDBusConnection_register_fallback(VALUE self, VALUE path,
573
605
  static void
574
606
  _free_filter_data(void *user_data)
575
607
  {
576
- VALUE *data = (VALUE*)user_data;
577
- VALUE filter_cb = data[0];
578
- rb_gc_unregister_address(&filter_cb);
579
- ruby_xfree(data);
608
+ ruby_xfree(user_data);
580
609
  }
581
610
 
582
611
  static VALUE
@@ -645,7 +674,7 @@ cDBusConnection_add_filter(VALUE self, VALUE filter_cb)
645
674
  if (dbus_connection_add_filter(CONN_GET(self), _on_filter_message,
646
675
  (void*)data, _free_filter_data))
647
676
  {
648
- rb_gc_register_address(&filter_cb);
677
+ rdbus_register_connection_callback(self, filter_cb);
649
678
  return Qtrue;
650
679
  }
651
680
 
@@ -9,12 +9,10 @@
9
9
  #include <stdlib.h>
10
10
  #include "ruby-dbus.h"
11
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 {
12
+ typedef struct _RubyDBusMessageIter {
15
13
  DBusMessageIter *real_iter;
16
14
  DBusMessage *message;
17
- };
15
+ } RubyDBusMessageIter;
18
16
 
19
17
  VALUE cDBusMessageIter;
20
18
 
@@ -10,6 +10,7 @@
10
10
 
11
11
  VALUE cDBusMessage;
12
12
 
13
+ #ifdef RDBUS_DEBUG
13
14
  static const char *
14
15
  rdbus_message_type_string(DBusMessage *message)
15
16
  {
@@ -31,6 +32,7 @@ rdbus_message_type_string(DBusMessage *message)
31
32
  return "Unknown";
32
33
  }
33
34
  }
35
+ #endif
34
36
 
35
37
  static void
36
38
  rdbus_free_message(void *message)
@@ -81,8 +81,6 @@ extern VALUE cDBusMessageIter;
81
81
  extern VALUE cDBusPendingCall;
82
82
  extern VALUE eDBusError;
83
83
 
84
- typedef struct _RubyDBusMessageIter RubyDBusMessageIter;
85
-
86
84
  void Init_dbus_bus();
87
85
  void Init_dbus_connection();
88
86
  void Init_dbus_message();
@@ -13,7 +13,7 @@ module DBus
13
13
  module BindingVersion
14
14
  VERSION_MAJOR = 0
15
15
  VERSION_MINOR = 1
16
- VERSION_PATCH = 7
16
+ VERSION_PATCH = 8
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.7
7
- date: 2004-12-11
6
+ version: 0.1.8
7
+ date: 2004-12-12
8
8
  summary: Ruby bindings for D-BUS.
9
9
  require_paths:
10
10
  - lib