rbus 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/CHANGELOG.txt +9 -0
  2. data/COPYING.txt +341 -0
  3. data/HACKING.txt +104 -0
  4. data/Manifest.txt +58 -0
  5. data/README.txt +17 -0
  6. data/Rakefile +97 -0
  7. data/TUTORIAL.txt +303 -0
  8. data/bin/rbus-send +165 -0
  9. data/examples/async_rb_and_notify.rb +56 -0
  10. data/examples/async_rb_loop.rb +52 -0
  11. data/examples/glib_async_rb_loop.rb +57 -0
  12. data/examples/glib_rhythmbox.rb +54 -0
  13. data/examples/hal_device_info.rb +54 -0
  14. data/examples/listnames.rb +37 -0
  15. data/examples/network_manager_get_properties.rb +50 -0
  16. data/examples/notification_bubble.rb +46 -0
  17. data/examples/rhythmbox_print_playing_uri.rb +41 -0
  18. data/examples/rhythmbox_signal_print_playing.rb +54 -0
  19. data/examples/rhythmbox_start_service.rb +39 -0
  20. data/examples/rhythmbox_toggle_playing.rb +46 -0
  21. data/lib/rbus.rb +25 -0
  22. data/lib/rbus/auth/auth.rb +53 -0
  23. data/lib/rbus/auth/dbus_cookie_sha1.rb +66 -0
  24. data/lib/rbus/auth/dummy.rb +37 -0
  25. data/lib/rbus/auth/external.rb +34 -0
  26. data/lib/rbus/auth/state_machine.rb +168 -0
  27. data/lib/rbus/bus/bus.rb +101 -0
  28. data/lib/rbus/bus/proxy.rb +137 -0
  29. data/lib/rbus/bus/transport.rb +125 -0
  30. data/lib/rbus/default.rb +29 -0
  31. data/lib/rbus/etc/exception.rb +44 -0
  32. data/lib/rbus/etc/log.rb +100 -0
  33. data/lib/rbus/etc/types.rb +56 -0
  34. data/lib/rbus/etc/version.rb +34 -0
  35. data/lib/rbus/glib.rb +29 -0
  36. data/lib/rbus/mainloop/glib.rb +77 -0
  37. data/lib/rbus/mainloop/mainloop.rb +84 -0
  38. data/lib/rbus/mainloop/observers.rb +149 -0
  39. data/lib/rbus/mainloop/thread.rb +78 -0
  40. data/lib/rbus/message/constants.rb +51 -0
  41. data/lib/rbus/message/marshal.rb +139 -0
  42. data/lib/rbus/message/message.rb +110 -0
  43. data/lib/rbus/message/reader.rb +108 -0
  44. data/lib/rbus/message/serial_generator.rb +48 -0
  45. data/lib/rbus/message/unmarshal.rb +171 -0
  46. data/lib/rbus/message/writer.rb +69 -0
  47. data/setup.rb +1608 -0
  48. data/spec/auth_spec.rb +123 -0
  49. data/spec/bus_spec.rb +178 -0
  50. data/spec/helpers/bus_mocks.rb +64 -0
  51. data/spec/helpers/spec_helper.rb +24 -0
  52. data/spec/mainloop_spec.rb +74 -0
  53. data/spec/marshal_spec.rb +91 -0
  54. data/spec/message_spec.rb +61 -0
  55. data/spec/observers_spec.rb +28 -0
  56. data/spec/proxy_spec.rb +120 -0
  57. data/spec/transport_spec.rb +187 -0
  58. data/spec/unmarshal_spec.rb +186 -0
  59. metadata +118 -0
@@ -0,0 +1,186 @@
1
+ #--
2
+ #
3
+ # R-Bus is a native Ruby implementation of the D-Bus protocol.
4
+ # Copyright (C) 2007 Kristoffer Lundén (kristoffer.lunden@gmail.com)
5
+ #
6
+ # This program is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
+ # MA 02110-1301, USA. A copy of the GNU General Public License is
20
+ # also available at http://www.gnu.org/copyleft/gpl.html.
21
+ #
22
+ #++
23
+ #
24
+ require File.dirname(__FILE__) + '/helpers/spec_helper'
25
+
26
+ module RBus
27
+ context "Byte" do
28
+ specify "should decode byte" do
29
+ num = rand(255)
30
+ [num].pack('C').dbus_unmarshal('y').should == num
31
+ end
32
+ end
33
+
34
+ context "Boolean" do
35
+ specify "should decode true" do
36
+ "\1\0\0\0".dbus_unmarshal('b').should == true
37
+ end
38
+ specify "should decode true in big endian" do
39
+ "\0\0\0\1".dbus_unmarshal('b', ?B).should == true
40
+ end
41
+ specify "should decode false" do
42
+ "\0\0\0\0".dbus_unmarshal('b').should == false
43
+ end
44
+ specify "should raise on illegal value" do
45
+ lambda{[rand(255)+1].pack('V').dbus_unmarshal('b')}.should_raise(TypeException)
46
+ end
47
+ end
48
+
49
+ context "Numbers" do
50
+ specify "should decode uint32 in implicit little endian" do
51
+ num = rand(32768)
52
+ [num].pack('V').dbus_unmarshal('u').should == num
53
+ end
54
+ specify "should decode uint32 in explicit little endian" do
55
+ num = rand(32768)
56
+ [num].pack('V').dbus_unmarshal('u', ?l).should == num
57
+ end
58
+ specify "should decode uint32 in explicit big endian" do
59
+ num = rand(32768)
60
+ [num].pack('N').dbus_unmarshal('u', ?B).should == num
61
+ end
62
+ specify "should should decode negative int64" do
63
+ "\377\377\377\377\377\377\377\377".dbus_unmarshal('x').should == -1
64
+ end
65
+ #specify "should should decode positive int64" do
66
+ # "\1\0\0\0\0\0\0\0\0".dbus_unmarshal('x').should == 1
67
+ #end
68
+
69
+ end
70
+
71
+ context "Strings/Paths" do
72
+ specify "should decode string in implicit little endian" do
73
+ str = "\12\0\0\0teststring\0"
74
+ str.dbus_unmarshal('s').should == 'teststring'
75
+ end
76
+ specify "should decode string in explicit little endian" do
77
+ str = "\12\0\0\0teststring\0"
78
+ str.dbus_unmarshal('s', ?l).should == 'teststring'
79
+ end
80
+ specify "should decode string in explicit big endian" do
81
+ str = "\0\0\0\12teststring\0"
82
+ str.dbus_unmarshal('s', ?B).should == 'teststring'
83
+ end
84
+ specify "should decode object path" do
85
+ str = "\12\0\0\0teststring\0"
86
+ str.dbus_unmarshal('o').should == 'teststring'
87
+ end
88
+ specify "should decode object path in big endian" do
89
+ str = "\0\0\0\12teststring\0"
90
+ str.dbus_unmarshal('o', ?B).should == 'teststring'
91
+ end
92
+ end
93
+
94
+ context "Variant" do
95
+ specify "should decode with string" do
96
+ #str_var = "teststring".to_dbus_variant
97
+ str_var = "\1s\0\0\12\0\0\0teststring\0"
98
+ str_var.dbus_unmarshal('v').object.should == 'teststring'
99
+ end
100
+ specify "should decode with string in big endian" do
101
+ str_var = "\1s\0\0\0\0\0\12teststring\0"
102
+ str_var.dbus_unmarshal('v', ?B).object.should == 'teststring'
103
+ end
104
+ end
105
+
106
+ context "Array" do
107
+ specify "should decode with one byte" do
108
+ "\1\0\0\0\1".dbus_unmarshal('ay').should == [1]
109
+ end
110
+ specify "should decode with bytes" do
111
+ "\3\0\0\0\1\2\3".dbus_unmarshal('ay').should == [1,2,3]
112
+ end
113
+ specify "should decode double with bytes" do
114
+ "\3\0\0\0\1\2\3\0\3\0\0\0\1\2\3".dbus_unmarshal('ayay').should == [[1,2,3],[1,2,3]]
115
+ end
116
+ specify "should decode with strings" do
117
+ "\021\0\0\0\3\0\0\0abc\0\4\0\0\0defg\0".dbus_unmarshal('as').should == ['abc','defg']
118
+ end
119
+ end
120
+
121
+ context "Struct" do
122
+ specify "should decode struct with one byte" do
123
+ "\1".dbus_unmarshal('(y)').should == [1]
124
+ end
125
+ specify "should decode struct with two bytes" do
126
+ "\1\2".dbus_unmarshal('(yy)').should == [1,2]
127
+ end
128
+
129
+ end
130
+
131
+ context "Dict" do
132
+ setup do
133
+
134
+ end
135
+ specify "should decode array with one dict of string, string" do
136
+ d_str = "\22\0\0\0\0\0\0\0" + "\3\0\0\0key\0" + "\5\0\0\0value\0"
137
+ d_str.dbus_unmarshal('a{ss}').should == {'key' => 'value'}
138
+ end
139
+ #specify "should decode array with two dict of string, string" do
140
+ # TODO: get real examples instead, this ain't real
141
+ #d_str = "\0\0\0\0" + "\3\0\0\0key\0" + "\5\0\0\0value\0"
142
+ #d_str += "\0\0" + "\3\0\0\0ke2\0" + "\5\0\0\0value\0"
143
+ #d_str = [d_str.length].pack('V') + d_str
144
+ #d_str.dbus_unmarshal('a{ss}').should == {'key' => 'value', 'ke2' => 'value'}
145
+ #end
146
+ end
147
+
148
+ context "Mixed" do
149
+ specify "should decode yu" do
150
+ "\3\0\0\0\4\0\0\0".dbus_unmarshal('yu').should == [3,4]
151
+ end
152
+ specify "should decode uy" do
153
+ "\3\0\0\0\4".dbus_unmarshal('uy').should == [3,4]
154
+ end
155
+ end
156
+
157
+ context "Real examples" do
158
+ specify "hello header fields" do
159
+ hello = "n\000\000\000\000\000\000\000\006\001s\000\024\000\000\000org.freedesktop.DBus\000\000\000\000\001\001o\000\025\000\000\000/org/freedesktop/DBus\000\000\000\002\001s\000\024\000\000\000org.freedesktop.DBus\000\000\000\000\003\001s\000\005\000\000\000Hello\000\000\000"
160
+
161
+ f1 = [6, Variant.new("org.freedesktop.DBus", 's')]
162
+ f2 = [1, Variant.new("/org/freedesktop/DBus", 'o')]
163
+ f3 = [2, Variant.new("org.freedesktop.DBus", 's')]
164
+ f4 = [3, Variant.new("Hello", 's')]
165
+
166
+ # Outer Array = the arguments array
167
+ # Inner Array = the D-Bus array
168
+ # Innermost Arrays = Structs
169
+ hello.dbus_unmarshal('a(yv)').should == [f1,f2,f3,f4]
170
+ end
171
+
172
+ specify "hello server reply header fields" do
173
+ hf = "=\000\000\000\000\000\000\000\006\001s\000\005\000\000\000:1.25\000\000\000\005\001u\000\001\000\000\000\010\001g\000\001s\000\000\a\001s\000\024\000\000\000org.freedesktop.DBus\000"
174
+
175
+ f1 = [6, Variant.new(":1.25", 's')]
176
+ f2 = [5, Variant.new(1, 'u')]
177
+ f3 = [8, Variant.new("s", 'g')]
178
+ f4 = [7, Variant.new("org.freedesktop.DBus", 's')]
179
+
180
+ hf.dbus_unmarshal('a(yv)').should == [f1,f2,f3,f4]
181
+ end
182
+ end
183
+
184
+
185
+
186
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.2
3
+ specification_version: 1
4
+ name: rbus
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.0
7
+ date: 2007-03-28 00:00:00 +02:00
8
+ summary: A native implementation of the D-Bus protocol.
9
+ require_paths:
10
+ - lib
11
+ email: kristoffer.lunden@gmail.com
12
+ homepage: http://rbus.rubyforge.org
13
+ rubyforge_project: rbus
14
+ description: A native implementation of the D-Bus protocol.
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - "Kristoffer Lund\xC3\xA9n"
31
+ files:
32
+ - CHANGELOG.txt
33
+ - COPYING.txt
34
+ - HACKING.txt
35
+ - Manifest.txt
36
+ - README.txt
37
+ - Rakefile
38
+ - TUTORIAL.txt
39
+ - bin/rbus-send
40
+ - examples/async_rb_and_notify.rb
41
+ - examples/async_rb_loop.rb
42
+ - examples/glib_async_rb_loop.rb
43
+ - examples/glib_rhythmbox.rb
44
+ - examples/hal_device_info.rb
45
+ - examples/listnames.rb
46
+ - examples/network_manager_get_properties.rb
47
+ - examples/notification_bubble.rb
48
+ - examples/rhythmbox_print_playing_uri.rb
49
+ - examples/rhythmbox_signal_print_playing.rb
50
+ - examples/rhythmbox_start_service.rb
51
+ - examples/rhythmbox_toggle_playing.rb
52
+ - lib/rbus.rb
53
+ - lib/rbus/auth/auth.rb
54
+ - lib/rbus/auth/dbus_cookie_sha1.rb
55
+ - lib/rbus/auth/dummy.rb
56
+ - lib/rbus/auth/external.rb
57
+ - lib/rbus/auth/state_machine.rb
58
+ - lib/rbus/bus/bus.rb
59
+ - lib/rbus/bus/proxy.rb
60
+ - lib/rbus/bus/transport.rb
61
+ - lib/rbus/default.rb
62
+ - lib/rbus/etc/exception.rb
63
+ - lib/rbus/etc/log.rb
64
+ - lib/rbus/etc/types.rb
65
+ - lib/rbus/etc/version.rb
66
+ - lib/rbus/glib.rb
67
+ - lib/rbus/mainloop/glib.rb
68
+ - lib/rbus/mainloop/mainloop.rb
69
+ - lib/rbus/mainloop/observers.rb
70
+ - lib/rbus/mainloop/thread.rb
71
+ - lib/rbus/message/constants.rb
72
+ - lib/rbus/message/marshal.rb
73
+ - lib/rbus/message/message.rb
74
+ - lib/rbus/message/reader.rb
75
+ - lib/rbus/message/serial_generator.rb
76
+ - lib/rbus/message/unmarshal.rb
77
+ - lib/rbus/message/writer.rb
78
+ - setup.rb
79
+ - spec/auth_spec.rb
80
+ - spec/bus_spec.rb
81
+ - spec/helpers/bus_mocks.rb
82
+ - spec/helpers/spec_helper.rb
83
+ - spec/mainloop_spec.rb
84
+ - spec/marshal_spec.rb
85
+ - spec/message_spec.rb
86
+ - spec/observers_spec.rb
87
+ - spec/proxy_spec.rb
88
+ - spec/transport_spec.rb
89
+ - spec/unmarshal_spec.rb
90
+ test_files: []
91
+
92
+ rdoc_options:
93
+ - --quiet
94
+ - --title
95
+ - R-Bus documentation
96
+ - --opname
97
+ - index.html
98
+ - --line-numbers
99
+ - --main
100
+ - README.txt
101
+ - --charset
102
+ - utf-8
103
+ - --inline-source
104
+ extra_rdoc_files:
105
+ - README.txt
106
+ - TUTORIAL.txt
107
+ - HACKING.txt
108
+ - COPYING.txt
109
+ - CHANGELOG.txt
110
+ - bin/rbus-send
111
+ executables:
112
+ - rbus-send
113
+ extensions: []
114
+
115
+ requirements: []
116
+
117
+ dependencies: []
118
+