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.
@@ -0,0 +1,259 @@
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
+ #-----------------------------------------------------------------
10
+ # Native classes
11
+ #
12
+ # The classes below provide any additional implementation for
13
+ # the corresponding classes defined in dbus.so. Things which
14
+ # belong in here are string munging, convenience methods,
15
+ # to_string implementations, etc.
16
+ #
17
+ # Basically, anything which would be too much of a pain to
18
+ # implement in C.
19
+ #
20
+ #-----------------------------------------------------------------
21
+ module DBus
22
+ module Binding
23
+
24
+ class DBusConnection
25
+ #--
26
+ # TODO
27
+ #++
28
+ def set_watch_functions(add_func, remove_func, data) # :nodoc:
29
+ end
30
+ def set_timeout_functions(add_func, remove_func, data) # :nodoc:
31
+ end
32
+ def set_wakeup_main_function(add_func, remove_func, data) # :nodoc:
33
+ end
34
+ def set_data(slot, data) # :nodoc:
35
+ end
36
+ def get_data(slot, data) # :nodoc:
37
+ end
38
+ end
39
+
40
+ class DBusMessage
41
+ include Enumerable
42
+
43
+ # Yields each message argument value that was appended to the message to
44
+ # the given block, in sequence
45
+ def each
46
+ raise DBusError, "block expected" unless block_given?
47
+ iter = get_iter
48
+ begin
49
+ value = iter.value
50
+ rescue
51
+ return nil
52
+ end
53
+ yield value
54
+ have_value = iter.next
55
+ while have_value
56
+ yield iter.value
57
+ have_value = iter.next
58
+ end
59
+ nil
60
+ end
61
+
62
+ # Returns the message argument value at the given offset
63
+ def [](offset)
64
+ entries[offset]
65
+ end
66
+
67
+ # Appends each item in the given Array to the message
68
+ def append(ary)
69
+ iter = get_append_iter
70
+ ary.each{|value| iter.append(value)}
71
+ nil
72
+ end
73
+
74
+ # Appends the given value to the message. If you want to append more than
75
+ # one value, use DBusMessage#append instead, it will be more efficient.
76
+ def <<(value)
77
+ iter = get_append_iter
78
+ iter.append(value)
79
+ nil
80
+ end
81
+
82
+ # Returns an array containing the path segments of the message path
83
+ def get_path_decomposed
84
+ get_path.split("/")
85
+ end
86
+
87
+ def to_s
88
+ "#<#{self.class.to_s} path=\"#{get_path}\" interface=\"#{get_interface}\" member=\"#{get_member}\" sender=\"#{get_sender}\">"
89
+ end
90
+ end
91
+
92
+ class DBusMessageIter
93
+ # Appends the given value to the message this iterator is associated with.
94
+ # Ruby types are automatically converted to the closest matching D-BUS
95
+ # message argument type.
96
+ def append(value)
97
+ case
98
+ when value.nil?
99
+ append_nil
100
+ when value.is_a?(ObjectPath)
101
+ append_object_path(value)
102
+ when value.is_a?(String)
103
+ append_string(value)
104
+ when value.is_a?(Fixnum)
105
+ append_int32(value)
106
+ when value.is_a?(Bignum)
107
+ append_int64(value)
108
+ when value.is_a?(Float)
109
+ append_double(value)
110
+ when value.is_a?(TrueClass)
111
+ append_boolean(true)
112
+ when value.is_a?(FalseClass)
113
+ append_boolean(false)
114
+ when value.is_a?(Hash)
115
+ di = append_dict
116
+ value.each{|k,v| di.append_dict_key(k); di.append(v); }
117
+ true
118
+ when value.is_a?(Array)
119
+ raise ArgumentError, "empty arrays are not supported" if value.empty?
120
+ dtype = ruby_to_dbus_type(value[0])
121
+ ai = append_array(dtype)
122
+ value.each{|v| ai.append(v) if ruby_to_dbus_type(v) == dtype}
123
+ true
124
+ else
125
+ raise ArgumentError, "unsupported argument type #{value.class}"
126
+ end
127
+ end
128
+
129
+ # Returns the message argument value at the current position of the
130
+ # iterator. The value is converted from the D-BUS type to the closest
131
+ # matching Ruby type.
132
+ def value
133
+ case get_arg_type
134
+ when TYPE_NIL
135
+ nil
136
+ when TYPE_BYTE
137
+ get_byte
138
+ when TYPE_BOOLEAN
139
+ get_boolean
140
+ when TYPE_INT32
141
+ get_int32
142
+ when TYPE_UINT32
143
+ get_uint32
144
+ when TYPE_INT64
145
+ get_int64
146
+ when TYPE_UINT64
147
+ get_uint64
148
+ when TYPE_DOUBLE
149
+ get_double
150
+ when TYPE_STRING
151
+ get_string
152
+ when TYPE_ARRAY
153
+ get_array
154
+ when TYPE_DICT
155
+ get_dict
156
+ when TYPE_OBJECT_PATH
157
+ ObjectPath.new(get_object_path)
158
+ else
159
+ raise DBusError, "unsupported iter arg type '#{type_as_string(get_arg_type)}'"
160
+ end
161
+ end
162
+
163
+ # For compatibility with the other bindings
164
+ alias :get :value
165
+
166
+ # Returns the message argument value at the current position of the
167
+ # iterator as a Hash. For this to work, the argument value has to be
168
+ # of the D-BUS type TYPE_DICT.
169
+ def get_dict
170
+ iter = dict_iter
171
+ ret = {}
172
+ loop do
173
+ ret[iter.get_dict_key] = iter.value
174
+ break if !iter.has_next
175
+ iter.next
176
+ end
177
+ ret
178
+ end
179
+
180
+ # Returns the message argument value at the current position of the
181
+ # iterator as an Array. For this to work, the argument value has to be
182
+ # of the D-BUS type TYPE_ARRAY.
183
+ def get_array
184
+ iter = array_iter
185
+ ret = []
186
+ loop do
187
+ ret << iter.value
188
+ break if !iter.has_next
189
+ iter.next
190
+ end
191
+ ret
192
+ end
193
+
194
+ private
195
+ def type_as_string(arg_type)
196
+ case arg_type
197
+ when TYPE_INVALID
198
+ 'invalid'
199
+ when TYPE_NIL
200
+ 'nil'
201
+ when TYPE_BYTE
202
+ 'byte'
203
+ when TYPE_BOOLEAN
204
+ 'boolean'
205
+ when TYPE_INT32
206
+ 'int32'
207
+ when TYPE_UINT32
208
+ 'uint32'
209
+ when TYPE_INT64
210
+ 'int64'
211
+ when TYPE_UINT64
212
+ 'uint64'
213
+ when TYPE_DOUBLE
214
+ 'double'
215
+ when TYPE_STRING
216
+ 'string'
217
+ when TYPE_CUSTOM
218
+ 'custom'
219
+ when TYPE_ARRAY
220
+ 'array'
221
+ when TYPE_DICT
222
+ 'dict'
223
+ when TYPE_OBJECT_PATH
224
+ 'objectpath'
225
+ else
226
+ 'unknown'
227
+ end
228
+ end
229
+
230
+ def ruby_to_dbus_type(value)
231
+ case
232
+ when value.nil?
233
+ TYPE_NIL
234
+ when value.is_a?(ObjectPath)
235
+ TYPE_OBJECT_PATH
236
+ when value.is_a?(String)
237
+ TYPE_STRING
238
+ when value.is_a?(Fixnum)
239
+ TYPE_INT32
240
+ when value.is_a?(Bignum)
241
+ TYPE_INT64
242
+ when value.is_a?(Float)
243
+ TYPE_DOUBLE
244
+ when value.is_a?(TrueClass)
245
+ TYPE_BOOLEAN
246
+ when value.is_a?(FalseClass)
247
+ TYPE_BOOLEAN
248
+ when value.is_a?(Hash)
249
+ TYPE_DICT
250
+ when value.is_a?(Array)
251
+ TYPE_ARRAY
252
+ else
253
+ raise ArgumentError, "unsupported Ruby type #{value.class}"
254
+ end
255
+ end
256
+ end
257
+
258
+ end # Binding
259
+ end # DBus
@@ -0,0 +1,21 @@
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
+ module DBus
10
+
11
+ # Contains the version of the D-BUS bindings. This version is
12
+ # completely different from the D-BUS library itself.
13
+ module BindingVersion
14
+ VERSION_MAJOR = 0
15
+ VERSION_MINOR = 1
16
+ VERSION_PATCH = 4
17
+ end
18
+
19
+ # Contains the string version of the D-BUS bindings
20
+ BINDING_VERSION = "#{BindingVersion::VERSION_MAJOR}.#{BindingVersion::VERSION_MINOR}.#{BindingVersion::VERSION_PATCH}"
21
+ end
@@ -0,0 +1,10 @@
1
+ require 'pathname'
2
+ require 'test/unit'
3
+ basedir = Pathname.new($0).realpath.dirname.dirname.to_s
4
+ $:.unshift(File.join(basedir, 'ext'))
5
+ $:.unshift(File.join(basedir, 'lib'))
6
+ testdir = File.join(basedir, 'test')
7
+ $:.unshift(testdir)
8
+ Dir[File.join(testdir, '**', 'tc_*.rb')].each do |t|
9
+ require t
10
+ end
@@ -0,0 +1,49 @@
1
+ require 'dbus'
2
+ require 'test/unit'
3
+
4
+ class TC_DBusConnection < Test::Unit::TestCase
5
+ def setup
6
+ @server = DBus::Binding::DBusServer::listen("unix:tmpdir=#{Dir.getwd}")
7
+ @conn = DBus::Binding::DBusConnection.new(@server.get_address)
8
+ @server.setup_with_g_main
9
+ @conn.setup_with_g_main
10
+ end
11
+
12
+ def teardown
13
+ @server.disconnect
14
+ @conn.disconnect
15
+ @server = @conn = nil
16
+ end
17
+
18
+ def test_bus_get
19
+ conn = DBus::Binding::bus_get(DBus::BUS_SYSTEM)
20
+ assert(!conn.nil?)
21
+ assert(conn.is_a?(DBus::Binding::DBusConnection))
22
+ end
23
+
24
+ def test_conn_open_new
25
+ assert_raises(DBus::DBusError) do
26
+ DBus::Binding::DBusConnection.new("invalid dbus address")
27
+ end
28
+ assert_raises(DBus::DBusError) do
29
+ DBus::Binding::DBusConnection.new("unix:path=/nonexistent/socket/path")
30
+ end
31
+ end
32
+
33
+ def test_attr
34
+ conn = DBus::Binding::bus_get(DBus::BUS_SYSTEM)
35
+ assert(conn.get_max_message_size.is_a?(Numeric))
36
+ conn.set_max_message_size(5)
37
+ assert(conn.get_max_message_size == 5)
38
+ assert(conn.get_max_received_size.is_a?(Numeric))
39
+ conn.set_max_received_size(5)
40
+ assert(conn.get_max_received_size == 5)
41
+ assert(conn.get_outgoing_size.is_a?(Numeric))
42
+ end
43
+
44
+ def test_send
45
+ msg = DBus::Binding::DBusMessage.new_signal("/com/provenco/sync/FS", "com.provenco.sync.FS", "MediaChanged")
46
+ msg.get_iter.append_boolean(true)
47
+ ret, call = @conn.send_with_reply(msg, 5)
48
+ end
49
+ end
@@ -0,0 +1,82 @@
1
+ require 'dbus'
2
+ require 'test/unit'
3
+
4
+ class TC_DBusMessage < Test::Unit::TestCase
5
+ def test_new_variants
6
+ msg = DBus::Binding::DBusMessage.new_method_call("dummy", "fake", "fake", "fake")
7
+ assert(msg.get_type == DBus::MESSAGE_TYPE_METHOD_CALL)
8
+ msg = DBus::Binding::DBusMessage.new_method_return(msg)
9
+ assert(msg.get_type == DBus::MESSAGE_TYPE_METHOD_RETURN)
10
+ msg = DBus::Binding::DBusMessage.new_signal("path", "interface", "name")
11
+ assert(msg.get_type == DBus::MESSAGE_TYPE_SIGNAL)
12
+ msg = DBus::Binding::DBusMessage.new_error(msg, "com.provenco.Error", "default msg")
13
+ assert(msg.get_type == DBus::MESSAGE_TYPE_ERROR)
14
+ end
15
+
16
+ def test_attribute_getters_and_setters
17
+ msg = DBus::Binding::DBusMessage.new(DBus::MESSAGE_TYPE_SIGNAL)
18
+ str_attrs = %w[path interface member error_name destination sender]
19
+ str_attrs.each do |name|
20
+ assert(msg.send("get_#{name}").nil?)
21
+ value = name == 'path' ? "org/freedesktop/Fake/Value" : "org.freedesktop.Fake.Value"
22
+ assert(msg.send("set_#{name}", value) == true)
23
+ assert(msg.send("get_#{name}") == value)
24
+ end
25
+ assert(msg.get_no_reply == false)
26
+ msg.set_no_reply(true)
27
+ assert(msg.get_no_reply == true)
28
+ assert(msg.is_method_call("org.freedesktop.Fake.Interface", "FakeMethod") == false)
29
+ assert(msg.is_error("org.freedesktop.Fake.Error") == false)
30
+ assert(msg.has_destination("org.freedesktop.Fake.Destination") == false)
31
+ assert(msg.has_sender("org.freedesktop.Fake.Sender") == false)
32
+ assert(msg.has_signature("org.freedesktop.Fake.Signature") == false)
33
+ assert(msg.get_serial == 0) # XXX crap, what should this be?
34
+ assert(msg.get_signature == '') # XXX crap, what should this be?
35
+ msg.set_reply_serial(590232)
36
+ msg.get_reply_serial == 590232
37
+ assert(msg.get_auto_activation == false)
38
+ msg.set_auto_activation(true)
39
+ assert(msg.get_auto_activation == true)
40
+ assert(msg.get_path_decomposed == ["org", "freedesktop", "Fake", "Value"])
41
+ end
42
+
43
+ def test_iter
44
+ msg = DBus::Binding::DBusMessage.new(DBus::MESSAGE_TYPE_SIGNAL)
45
+ iter = msg.get_iter
46
+ iter.append_byte(0xfa)
47
+ iter.append_nil
48
+ iter.append_boolean(true)
49
+ iter.append_int32(0xfffff)
50
+ iter.append({'hello' => 5, 'bye' => 6})
51
+ iter.append([1, 2, 3, 4])
52
+ iter = msg.get_iter
53
+ assert(iter.has_next == true)
54
+ assert(iter.value == 0xfa)
55
+ iter.next
56
+ assert(iter.value.nil?)
57
+ iter.next
58
+ assert(iter.value == true)
59
+ assert(iter.next == true)
60
+ assert(iter.value == 0xfffff)
61
+ iter.next
62
+ assert(iter.value['hello'] == 5)
63
+ assert(iter.value['bye'] == 6)
64
+ iter.next
65
+ assert(iter.value[0] == 1)
66
+ assert(iter.value[1] == 2)
67
+ assert(iter.value[2] == 3)
68
+ assert(iter.value[3] == 4)
69
+ assert(iter.has_next == false)
70
+ assert(iter.next == false)
71
+ end
72
+
73
+ def test_enumerable
74
+ msg = DBus::Binding::DBusMessage.new(DBus::MESSAGE_TYPE_SIGNAL)
75
+ msg << "test"
76
+ msg << 0
77
+ msg.append([5, nil, false, 39932039, "test2"])
78
+ assert(msg[0] == "test")
79
+ assert(msg.collect {|x| x == 5} == [false, false, true, false, false, false, false])
80
+ assert(msg.entries.length == 7)
81
+ end
82
+ end
@@ -0,0 +1,10 @@
1
+ require 'dbus'
2
+ require 'test/unit'
3
+
4
+ class TC_Server < Test::Unit::TestCase
5
+ def test_server_listen
6
+ server = DBus::Binding::DBusServer::listen("unix:tmpdir=#{Dir.getwd}")
7
+ assert(server.get_is_connected == true)
8
+ assert(!server.get_address.nil?)
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ #!/bin/sh
2
+
3
+ # ugly, but rdoc doesn't maintain state between .c files.
4
+ cat ext/*.c >ruby-dbus.c
5
+ rdoc -t DBus/Ruby --line-numbers --inline-source -p -m DBus -x ext ruby-dbus.c lib
6
+ rm -f ruby-dbus.c
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.1
3
+ specification_version: 1
4
+ name: dbus
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.5
7
+ date: 2004-11-25
8
+ summary: Ruby bindings for D-BUS.
9
+ require_paths:
10
+ - lib
11
+ author: Leon Breedt
12
+ email: bitserf@gmail.com
13
+ homepage: http://rubyforge.org/projects/dbus-ruby
14
+ rubyforge_project: dbus-ruby
15
+ description: Ruby bindings for D-BUS. This module allows Ruby programs to interface with the D-BUS message bus installed on newer Unix operating systems.
16
+ autorequire: dbus
17
+ default_executable:
18
+ bindir: bin
19
+ has_rdoc: false
20
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
21
+ requirements:
22
+ -
23
+ - ">"
24
+ - !ruby/object:Gem::Version
25
+ version: 0.0.0
26
+ version:
27
+ platform: ruby
28
+ files:
29
+ - examples/example-signal-emitter.rb
30
+ - examples/list-session-services.rb
31
+ - examples/example-signal-recipient.rb
32
+ - examples/list-system-services.rb
33
+ - examples/gconf-proxy-client.rb
34
+ - examples/example-client.rb
35
+ - examples/gconf-proxy-service.rb
36
+ - examples/example-service.rb
37
+ - examples/volumed.rb
38
+ - ext/ruby-dbus-message-iter.c
39
+ - ext/ruby-dbus-message.c
40
+ - ext/ruby-dbus-pending-call.c
41
+ - ext/ruby-dbus-server.c
42
+ - ext/ruby-dbus.h
43
+ - ext/ruby-dbus-common.c
44
+ - ext/ruby-dbus-bus.c
45
+ - ext/MANIFEST
46
+ - ext/extconf.rb
47
+ - ext/ruby-dbus-connection.c
48
+ - lib/dbus
49
+ - lib/dbus.rb
50
+ - lib/dbus/version.rb
51
+ - lib/dbus/binding.rb
52
+ - test/tc_connection.rb
53
+ - test/tc_all.rb
54
+ - test/tc_message.rb
55
+ - test/tc_server.rb
56
+ - tools/genrdoc
57
+ test_files:
58
+ - test/tc_all.rb
59
+ rdoc_options: []
60
+ extra_rdoc_files: []
61
+ executables: []
62
+ extensions:
63
+ - ext/extconf.rb
64
+ requirements:
65
+ - The D-BUS library
66
+ - Ruby Glib2 bindings
67
+ dependencies: []