ruby-dbus 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/doc/Reference.md +14 -3
- data/lib/dbus/marshall.rb +6 -2
- data/lib/dbus/xml.rb +8 -5
- data/test/async_test.rb +1 -0
- data/test/binding_test.rb +1 -0
- data/test/bus_and_xml_backend_test.rb +1 -0
- data/test/bus_driver_test.rb +1 -0
- data/test/bus_test.rb +1 -0
- data/test/byte_array_test.rb +42 -0
- data/test/dbus-limited-session.conf +1 -1
- data/test/introspect_xml_parser_test.rb +27 -0
- data/test/introspection_test.rb +1 -0
- data/test/property_test.rb +1 -0
- data/test/server_robustness_test.rb +1 -0
- data/test/server_test.rb +1 -0
- data/test/service_newapi.rb +7 -1
- data/test/session_bus_test_manual.rb +1 -0
- data/test/signal_test.rb +1 -0
- data/test/t2.rb +1 -0
- data/test/t3-ticket27.rb +1 -0
- data/test/t5-report-dbus-interface.rb +1 -0
- data/test/t6-loop.rb +1 -0
- data/test/test_helper.rb +14 -0
- data/test/thread_safety_test.rb +1 -0
- data/test/type_test.rb +1 -0
- data/test/variant_test.rb +1 -0
- metadata +5 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.2
|
data/doc/Reference.md
CHANGED
@@ -108,7 +108,11 @@ Variants are simply unpacked to become their contained type.
|
|
108
108
|
|
109
109
|
D-Bus has stricter typing than Ruby, so the library must decide
|
110
110
|
which D-Bus type to choose. Most of the time the choice is dictated
|
111
|
-
by the D-Bus signature.
|
111
|
+
by the D-Bus signature.
|
112
|
+
|
113
|
+
##### Variants
|
114
|
+
|
115
|
+
If the signature expects a Variant
|
112
116
|
(which is the case for all Properties!) then an explicit mechanism is needed.
|
113
117
|
|
114
118
|
1. A pair [{DBus::Type::Type}, value] specifies to marshall *value* as
|
@@ -119,6 +123,8 @@ by the D-Bus signature. However if the signature expects a Variant
|
|
119
123
|
ISSUE: using something else than cryptic signatures is even more painful
|
120
124
|
than remembering the signatures!
|
121
125
|
|
126
|
+
foo_i['Bar'] = DBus.variant("au", [0, 1, 1, 2, 3, 5, 8])
|
127
|
+
|
122
128
|
2. Other values are tried to fit one of these:
|
123
129
|
Boolean, Double, Array of Variants, Hash of String keyed Variants,
|
124
130
|
String, Int32, Int64.
|
@@ -128,12 +134,17 @@ by the D-Bus signature. However if the signature expects a Variant
|
|
128
134
|
type. This will hit you when you rely on method (2) but happen to have
|
129
135
|
a particular string value in an array.
|
130
136
|
|
137
|
+
##### Byte Arrays
|
138
|
+
|
139
|
+
If a byte array (`ay`) is expected you can pass a String too.
|
140
|
+
The bytes sent are according to the string's
|
141
|
+
[encoding](http://ruby-doc.org/core-1.9.3/Encoding.html).
|
142
|
+
|
143
|
+
##### nil
|
131
144
|
|
132
145
|
`nil` is not allowed by D-Bus and attempting to send it raises an exception
|
133
146
|
(but see [I#16](https://github.com/mvidner/ruby-dbus/issues/16)).
|
134
147
|
|
135
|
-
foo_i['Bar'] = DBus.variant("au", [0, 1, 1, 2, 3, 5, 8])
|
136
|
-
|
137
148
|
|
138
149
|
#### Errors
|
139
150
|
|
data/lib/dbus/marshall.rb
CHANGED
@@ -382,8 +382,12 @@ module DBus
|
|
382
382
|
# Damn ruby rocks here
|
383
383
|
val = val.to_a
|
384
384
|
end
|
385
|
-
|
386
|
-
|
385
|
+
# If string is recieved and ay is expected, explode the string
|
386
|
+
if val.kind_of?(String) && type.child.sigtype == Type::BYTE
|
387
|
+
val = val.bytes
|
388
|
+
end
|
389
|
+
if not val.kind_of?(Enumerable)
|
390
|
+
raise TypeException, "Expected an Enumerable of #{type.child.inspect} but got a #{val.class}"
|
387
391
|
end
|
388
392
|
array(type.child) do
|
389
393
|
val.each do |elem|
|
data/lib/dbus/xml.rb
CHANGED
@@ -97,8 +97,12 @@ module DBus
|
|
97
97
|
|
98
98
|
# return a pair: [list of Interfaces, list of direct subnode names]
|
99
99
|
def parse
|
100
|
-
|
101
|
-
|
100
|
+
# Using a Hash instead of a list helps merge split-up interfaces,
|
101
|
+
# a quirk observed in ModemManager (I#41).
|
102
|
+
interfaces = Hash.new do |hash, missing_key|
|
103
|
+
hash[missing_key] = Interface.new(missing_key)
|
104
|
+
end
|
105
|
+
subnodes = []
|
102
106
|
t = Time.now
|
103
107
|
|
104
108
|
|
@@ -107,7 +111,7 @@ module DBus
|
|
107
111
|
subnodes << e["name"]
|
108
112
|
end
|
109
113
|
d.each("node/interface") do |e|
|
110
|
-
i =
|
114
|
+
i = interfaces[e["name"]]
|
111
115
|
e.each("method") do |me|
|
112
116
|
m = Method.new(me["name"])
|
113
117
|
parse_methsig(me, m)
|
@@ -118,13 +122,12 @@ module DBus
|
|
118
122
|
parse_methsig(se, s)
|
119
123
|
i << s
|
120
124
|
end
|
121
|
-
interfaces << i
|
122
125
|
end
|
123
126
|
d = Time.now - t
|
124
127
|
if d > 2
|
125
128
|
DBus.logger.debug "Some XML took more that two secs to parse. Optimize me!"
|
126
129
|
end
|
127
|
-
[interfaces, subnodes]
|
130
|
+
[interfaces.values, subnodes]
|
128
131
|
end
|
129
132
|
|
130
133
|
######################################################################
|
data/test/async_test.rb
CHANGED
data/test/binding_test.rb
CHANGED
data/test/bus_driver_test.rb
CHANGED
data/test/bus_test.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require File.expand_path("../test_helper", __FILE__)
|
3
|
+
require "test/unit"
|
4
|
+
require "dbus"
|
5
|
+
|
6
|
+
class ByteArrayTest < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@bus = DBus::ASessionBus.new
|
9
|
+
@svc = @bus.service("org.ruby.service")
|
10
|
+
@obj = @svc.object("/org/ruby/MyInstance")
|
11
|
+
@obj.introspect
|
12
|
+
@obj.default_iface = "org.ruby.SampleInterface"
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
def test_passing_byte_array
|
17
|
+
data = [0, 77, 255]
|
18
|
+
result = @obj.mirror_byte_array(data).first
|
19
|
+
assert_equal data, result
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_passing_byte_array_from_string
|
23
|
+
data = "AAA"
|
24
|
+
result = @obj.mirror_byte_array(data).first
|
25
|
+
assert_equal [65, 65, 65], result
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_passing_byte_array_from_hash
|
29
|
+
# Hash is an Enumerable, but is caught earlier
|
30
|
+
data = { "this will" => "fail" }
|
31
|
+
assert_raises DBus::TypeException do
|
32
|
+
@obj.mirror_byte_array(data).first
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_passing_byte_array_from_nonenumerable
|
37
|
+
data = Time.now
|
38
|
+
assert_raises DBus::TypeException do
|
39
|
+
@obj.mirror_byte_array(data).first
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require File.expand_path("../test_helper", __FILE__)
|
3
|
+
require "test/unit"
|
4
|
+
require "dbus"
|
5
|
+
|
6
|
+
class IntrospectXMLParserTest < Test::Unit::TestCase
|
7
|
+
def test_split_interfaces
|
8
|
+
xml = <<EOS
|
9
|
+
<node>
|
10
|
+
<interface name="org.example.Foo">
|
11
|
+
<method name="Dwim"/>
|
12
|
+
</interface>
|
13
|
+
<interface name="org.example.Bar">
|
14
|
+
<method name="Drink"/>
|
15
|
+
</interface>
|
16
|
+
<interface name="org.example.Foo">
|
17
|
+
<method name="Smurf"/>
|
18
|
+
</interface>
|
19
|
+
</node>
|
20
|
+
EOS
|
21
|
+
|
22
|
+
interfaces, _ = DBus::IntrospectXMLParser.new(xml).parse
|
23
|
+
|
24
|
+
foo = interfaces.find {|i| i.name == "org.example.Foo" }
|
25
|
+
assert_equal 2, foo.methods.keys.size
|
26
|
+
end
|
27
|
+
end
|
data/test/introspection_test.rb
CHANGED
data/test/property_test.rb
CHANGED
data/test/server_test.rb
CHANGED
data/test/service_newapi.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# -*- coding: utf-8 -*-
|
3
3
|
|
4
|
+
require File.expand_path("../test_helper", __FILE__)
|
5
|
+
SimpleCov.command_name "Service Tests" if Object.const_defined? "SimpleCov"
|
4
6
|
# find the library without external help
|
5
7
|
$:.unshift File.expand_path("../../lib", __FILE__)
|
6
8
|
|
@@ -23,7 +25,7 @@ class Test < DBus::Object
|
|
23
25
|
end
|
24
26
|
|
25
27
|
dbus_method :test_variant, "in stuff:v" do |variant|
|
26
|
-
|
28
|
+
DBus.logger.debug variant.inspect
|
27
29
|
end
|
28
30
|
|
29
31
|
dbus_method :bounce_variant, "in stuff:v, out chaff:v" do |variant|
|
@@ -53,6 +55,10 @@ class Test < DBus::Object
|
|
53
55
|
dbus_method :Error, "in name:s, in description:s" do |name, description|
|
54
56
|
raise DBus.error(name), description
|
55
57
|
end
|
58
|
+
|
59
|
+
dbus_method :mirror_byte_array, "in bytes:ay, out mirrored:ay" do |bytes|
|
60
|
+
[bytes]
|
61
|
+
end
|
56
62
|
end
|
57
63
|
|
58
64
|
# closing and reopening the same interface
|
data/test/signal_test.rb
CHANGED
data/test/t2.rb
CHANGED
data/test/t3-ticket27.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# Test passing a particular struct array through a variant
|
3
3
|
# https://trac.luon.net/ruby-dbus/ticket/27
|
4
|
+
require File.expand_path("../test_helper", __FILE__)
|
4
5
|
require "dbus"
|
5
6
|
session_bus = DBus::ASessionBus.new
|
6
7
|
svc = session_bus.service("org.ruby.service")
|
data/test/t6-loop.rb
CHANGED
data/test/test_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
if ENV["COVERAGE"]
|
2
|
+
coverage = ENV["COVERAGE"] == "true"
|
3
|
+
else
|
4
|
+
# heuristics: enable for interactive builds but not in Travis or OBS
|
5
|
+
coverage = !!ENV["DISPLAY"]
|
6
|
+
end
|
7
|
+
|
8
|
+
if coverage && RUBY_VERSION >= "1.9" # SimpleCov does not work with 1.8
|
9
|
+
require 'simplecov'
|
10
|
+
SimpleCov.root File.expand_path("../..", __FILE__)
|
11
|
+
SimpleCov.start
|
12
|
+
end
|
13
|
+
|
14
|
+
$:.unshift File.expand_path("../../lib", __FILE__)
|
data/test/thread_safety_test.rb
CHANGED
data/test/type_test.rb
CHANGED
data/test/variant_test.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-dbus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-08 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Pure Ruby module for interaction with D-Bus IPC system
|
15
15
|
email: ruby-dbus-devel@lists.luon.net
|
@@ -59,8 +59,10 @@ files:
|
|
59
59
|
- test/bus_and_xml_backend_test.rb
|
60
60
|
- test/bus_driver_test.rb
|
61
61
|
- test/bus_test.rb
|
62
|
+
- test/byte_array_test.rb
|
62
63
|
- test/dbus-launch-simple
|
63
64
|
- test/dbus-limited-session.conf
|
65
|
+
- test/introspect_xml_parser_test.rb
|
64
66
|
- test/introspection_test.rb
|
65
67
|
- test/property_test.rb
|
66
68
|
- test/server_robustness_test.rb
|
@@ -74,6 +76,7 @@ files:
|
|
74
76
|
- test/t5-report-dbus-interface.rb
|
75
77
|
- test/t6-loop.rb
|
76
78
|
- test/test_env
|
79
|
+
- test/test_helper.rb
|
77
80
|
- test/test_server
|
78
81
|
- test/thread_safety_test.rb
|
79
82
|
- test/type_test.rb
|