ruby-dbus 0.9.3 → 0.10.0

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d85683483eaee12e0221cc19843e3887a858269a
4
+ data.tar.gz: 8aa3af094fe0068807269591395d29d7eb37c7cf
5
+ SHA512:
6
+ metadata.gz: 0493a1b55563d87d202b8cfda861a817d4ab63baa42724505976e64568fad392c2bdcf9a570ea99fe4c32c11ead7dfdc885fbe887e4fc9c7b67540d45c4b0b0d
7
+ data.tar.gz: 6d0f2704d4a30ef90b08b93c2e5f9f69750312914dfb7904ad5c9cb13aaaa6cef067dc0484d12b952c1885e747b831731b995526eeb9b39ef6c005ab29315124
data/NEWS CHANGED
@@ -5,6 +5,15 @@ Note about bug numbers:
5
5
  Issue#1 - http://github.com/mvidner/ruby-dbus/issues#issue/1
6
6
  bnc#1 - https://bugzilla.novell.com/show_bug.cgi?id=1
7
7
 
8
+ == Ruby D-Bus 0.10.0 - 2014-01-10
9
+
10
+ Bug fixes:
11
+ * fixed "Interfaces added with singleton_class.instance_eval aren't
12
+ exported" (Issue#22, by miaoufkirsh)
13
+
14
+ Requirements:
15
+ * Require ruby 1.9.3, stopped supporting 1.8.7.
16
+
8
17
  == Ruby D-Bus 0.9.3 - 2014-01-02
9
18
 
10
19
  Bug fixes:
data/README.md CHANGED
@@ -5,7 +5,9 @@ D-Bus system can be used in the Ruby programming language.
5
5
 
6
6
  ## Requirements
7
7
 
8
- - Ruby 1.8.7, 1.9 or 2.0
8
+ - Ruby 1.9.3 or 2.0
9
+
10
+ [![Build Status](https://travis-ci.org/mvidner/ruby-dbus.png)](https://travis-ci.org/mvidner/ruby-dbus)
9
11
 
10
12
  ## Installation
11
13
 
data/Rakefile CHANGED
@@ -13,6 +13,9 @@ Packaging.configuration do |conf|
13
13
  conf.obs_sr_project = "openSUSE:Factory"
14
14
  conf.skip_license_check << /^[^\/]*$/
15
15
  conf.skip_license_check << /^(doc|examples|test)\/.*/
16
+ # "Ruby on Rails is released under the MIT License."
17
+ # but the files are missing copyright headers
18
+ conf.skip_license_check << /^lib\/dbus\/core_ext\//
16
19
  end
17
20
 
18
21
  desc 'Default: run tests in the proper environment'
@@ -20,7 +23,7 @@ task :default => :test
20
23
 
21
24
  def common_test_task(t)
22
25
  t.libs << "lib"
23
- t.test_files = FileList['test/*_test.rb', 'test/t[0-9]*.rb']
26
+ t.test_files = FileList['test/*_test.rb']
24
27
  t.verbose = true
25
28
  end
26
29
  Rake::TestTask.new("bare:test") {|t| common_test_task t }
@@ -35,7 +38,7 @@ end
35
38
  %w(test rcov).each do |tname|
36
39
  desc "Run bare:#{tname} in the proper environment"
37
40
  task tname do |t|
38
- cd "test" do
41
+ cd "test/tools" do
39
42
  sh "./test_env rake bare:#{tname}"
40
43
  end
41
44
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.3
1
+ 0.10.0
@@ -8,6 +8,7 @@
8
8
  # License, version 2.1 as published by the Free Software Foundation.
9
9
  # See the file "COPYING" for the exact licensing terms.
10
10
 
11
+ require 'dbus/core_ext/class/attribute'
11
12
  require 'dbus/type'
12
13
  require 'dbus/introspect'
13
14
  require 'dbus/error'
@@ -23,13 +24,6 @@ require 'dbus/xml'
23
24
  require 'socket'
24
25
  require 'thread'
25
26
 
26
- unless 0.respond_to?(:ord)
27
- # Backward compatibility with Ruby 1.8.6, see http://www.pubbs.net/ruby/200907/65871/
28
- class Integer
29
- def ord; self; end
30
- end
31
- end
32
-
33
27
  # = D-Bus main module
34
28
  #
35
29
  # Module containing all the D-Bus modules and classes.
@@ -247,7 +247,8 @@ module DBus
247
247
  @socket.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
248
248
  init_connection
249
249
  @is_tcp = true
250
- rescue
250
+ rescue Exception => e
251
+ puts "Oops:", e
251
252
  puts "Error: Could not establish connection to: #{@path}, will now exit."
252
253
  exit(1) #a little harsh
253
254
  end
@@ -0,0 +1,31 @@
1
+ # copied from activesupport/core_ext from Rails, MIT license
2
+ # https://github.com/rails/rails/tree/5aa869861c192daceafe3a3ee50eb93f5a2b7bd2/activesupport/lib/active_support/core_ext
3
+ class Hash
4
+ # By default, only instances of Hash itself are extractable.
5
+ # Subclasses of Hash may implement this method and return
6
+ # true to declare themselves as extractable. If a Hash
7
+ # is extractable, Array#extract_options! pops it from
8
+ # the Array when it is the last element of the Array.
9
+ def extractable_options?
10
+ instance_of?(Hash)
11
+ end
12
+ end
13
+
14
+ class Array
15
+ # Extracts options from a set of arguments. Removes and returns the last
16
+ # element in the array if it's a hash, otherwise returns a blank hash.
17
+ #
18
+ # def options(*args)
19
+ # args.extract_options!
20
+ # end
21
+ #
22
+ # options(1, 2) # => {}
23
+ # options(1, 2, a: :b) # => {:a=>:b}
24
+ def extract_options!
25
+ if last.is_a?(Hash) && last.extractable_options?
26
+ pop
27
+ else
28
+ {}
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,129 @@
1
+ # copied from activesupport/core_ext from Rails, MIT license
2
+ # https://github.com/rails/rails/tree/5aa869861c192daceafe3a3ee50eb93f5a2b7bd2/activesupport/lib/active_support/core_ext
3
+ require 'dbus/core_ext/kernel/singleton_class'
4
+ require 'dbus/core_ext/module/remove_method'
5
+ require 'dbus/core_ext/array/extract_options'
6
+
7
+ class Class
8
+ # Declare a class-level attribute whose value is inheritable by subclasses.
9
+ # Subclasses can change their own value and it will not impact parent class.
10
+ #
11
+ # class Base
12
+ # class_attribute :setting
13
+ # end
14
+ #
15
+ # class Subclass < Base
16
+ # end
17
+ #
18
+ # Base.setting = true
19
+ # Subclass.setting # => true
20
+ # Subclass.setting = false
21
+ # Subclass.setting # => false
22
+ # Base.setting # => true
23
+ #
24
+ # In the above case as long as Subclass does not assign a value to setting
25
+ # by performing <tt>Subclass.setting = _something_ </tt>, <tt>Subclass.setting</tt>
26
+ # would read value assigned to parent class. Once Subclass assigns a value then
27
+ # the value assigned by Subclass would be returned.
28
+ #
29
+ # This matches normal Ruby method inheritance: think of writing an attribute
30
+ # on a subclass as overriding the reader method. However, you need to be aware
31
+ # when using +class_attribute+ with mutable structures as +Array+ or +Hash+.
32
+ # In such cases, you don't want to do changes in places but use setters:
33
+ #
34
+ # Base.setting = []
35
+ # Base.setting # => []
36
+ # Subclass.setting # => []
37
+ #
38
+ # # Appending in child changes both parent and child because it is the same object:
39
+ # Subclass.setting << :foo
40
+ # Base.setting # => [:foo]
41
+ # Subclass.setting # => [:foo]
42
+ #
43
+ # # Use setters to not propagate changes:
44
+ # Base.setting = []
45
+ # Subclass.setting += [:foo]
46
+ # Base.setting # => []
47
+ # Subclass.setting # => [:foo]
48
+ #
49
+ # For convenience, an instance predicate method is defined as well.
50
+ # To skip it, pass <tt>instance_predicate: false</tt>.
51
+ #
52
+ # Subclass.setting? # => false
53
+ #
54
+ # Instances may overwrite the class value in the same way:
55
+ #
56
+ # Base.setting = true
57
+ # object = Base.new
58
+ # object.setting # => true
59
+ # object.setting = false
60
+ # object.setting # => false
61
+ # Base.setting # => true
62
+ #
63
+ # To opt out of the instance reader method, pass <tt>instance_reader: false</tt>.
64
+ #
65
+ # object.setting # => NoMethodError
66
+ # object.setting? # => NoMethodError
67
+ #
68
+ # To opt out of the instance writer method, pass <tt>instance_writer: false</tt>.
69
+ #
70
+ # object.setting = false # => NoMethodError
71
+ #
72
+ # To opt out of both instance methods, pass <tt>instance_accessor: false</tt>.
73
+ def class_attribute(*attrs)
74
+ options = attrs.extract_options!
75
+ instance_reader = options.fetch(:instance_accessor, true) && options.fetch(:instance_reader, true)
76
+ instance_writer = options.fetch(:instance_accessor, true) && options.fetch(:instance_writer, true)
77
+ instance_predicate = options.fetch(:instance_predicate, true)
78
+
79
+ attrs.each do |name|
80
+ define_singleton_method(name) { nil }
81
+ define_singleton_method("#{name}?") { !!public_send(name) } if instance_predicate
82
+
83
+ ivar = "@#{name}"
84
+
85
+ define_singleton_method("#{name}=") do |val|
86
+ singleton_class.class_eval do
87
+ remove_possible_method(name)
88
+ define_method(name) { val }
89
+ end
90
+
91
+ if singleton_class?
92
+ class_eval do
93
+ remove_possible_method(name)
94
+ define_method(name) do
95
+ if instance_variable_defined? ivar
96
+ instance_variable_get ivar
97
+ else
98
+ singleton_class.send name
99
+ end
100
+ end
101
+ end
102
+ end
103
+ val
104
+ end
105
+
106
+ if instance_reader
107
+ remove_possible_method name
108
+ define_method(name) do
109
+ if instance_variable_defined?(ivar)
110
+ instance_variable_get ivar
111
+ else
112
+ self.class.public_send name
113
+ end
114
+ end
115
+ define_method("#{name}?") { !!public_send(name) } if instance_predicate
116
+ end
117
+
118
+ attr_writer name if instance_writer
119
+ end
120
+ end
121
+
122
+ private
123
+
124
+ unless respond_to?(:singleton_class?)
125
+ def singleton_class?
126
+ ancestors.first != self
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,8 @@
1
+ # copied from activesupport/core_ext from Rails, MIT license
2
+ # https://github.com/rails/rails/tree/5aa869861c192daceafe3a3ee50eb93f5a2b7bd2/activesupport/lib/active_support/core_ext
3
+ module Kernel
4
+ # class_eval on an object acts like singleton_class.class_eval.
5
+ def class_eval(*args, &block)
6
+ singleton_class.class_eval(*args, &block)
7
+ end
8
+ end
@@ -0,0 +1,14 @@
1
+ # copied from activesupport/core_ext from Rails, MIT license
2
+ # https://github.com/rails/rails/tree/5aa869861c192daceafe3a3ee50eb93f5a2b7bd2/activesupport/lib/active_support/core_ext
3
+ class Module
4
+ def remove_possible_method(method)
5
+ if method_defined?(method) || private_method_defined?(method)
6
+ undef_method(method)
7
+ end
8
+ end
9
+
10
+ def redefine_method(method, &block)
11
+ remove_possible_method(method)
12
+ define_method(method, &block)
13
+ end
14
+ end
@@ -19,10 +19,8 @@ module DBus
19
19
  class Object
20
20
  # The path of the object.
21
21
  attr_reader :path
22
- # The interfaces that the object supports.
23
- # intfs: Hash: String => Interface
24
- # @@intfs_hash simulates a class attribute by being a hash Class => intfs
25
- @@intfs_hash = {DBus::Object => nil}
22
+ # The interfaces that the object supports. Hash: String => Interface
23
+ class_attribute :intfs
26
24
  # The service that the object is exported by.
27
25
  attr_writer :service
28
26
 
@@ -36,26 +34,6 @@ module DBus
36
34
  @service = nil
37
35
  end
38
36
 
39
- def self.intfs
40
- if self.equal? DBus::Object
41
- @@intfs_hash[DBus::Object]
42
- else
43
- @@intfs_hash[self] || self.superclass.intfs
44
- end
45
- end
46
-
47
- def self.intfs= param
48
- @@intfs_hash[self] = param
49
- end
50
-
51
- def intfs
52
- self.class.intfs
53
- end
54
-
55
- def intfs= param
56
- self.class.intfs = param
57
- end
58
-
59
37
  # State that the object implements the given _intf_.
60
38
  def implements(intf)
61
39
  # use a setter
@@ -306,18 +306,7 @@ module DBus
306
306
  # Note that specifying _bus_ is discouraged and the option is kept only for
307
307
  # backward compatibility.
308
308
  # @return [void]
309
- def on_signal(*args, &block)
310
- # Since we must function under ruby 1.8.7, it isn't possible to define the
311
- # function as on_signal(bus = nil, name, &block)
312
- bus = case args.size
313
- when 1
314
- @object.bus
315
- when 2
316
- args.shift
317
- else
318
- raise ArgumentError, "wrong number of arguments (#{args.size} for 1-2)"
319
- end
320
- name = args.shift
309
+ def on_signal(bus = @object.bus, name, &block)
321
310
  mr = DBus::MatchRule.new.from_signal(self, name)
322
311
  if block.nil?
323
312
  bus.remove_match(mr)
@@ -90,15 +90,6 @@ module DBus
90
90
  ret
91
91
  end
92
92
 
93
- # Retrieve the series of bytes until the next NULL (\0) byte.
94
- def get_nul_terminated
95
- raise IncompleteBufferException if not @buffy[@idx..-1] =~ /^([^\0]*)\0/
96
- str = $1
97
- raise IncompleteBufferException if @idx + str.bytesize + 1 > @buffy.bytesize
98
- @idx += str.bytesize + 1
99
- str
100
- end
101
-
102
93
  # Get the string length and string itself from the buffer.
103
94
  # Return the string.
104
95
  def get_string
@@ -301,11 +292,6 @@ module DBus
301
292
  yield
302
293
  end
303
294
 
304
- # Append a string of bytes without type.
305
- def append_simple_string(s)
306
- @packet += s + "\0"
307
- end
308
-
309
295
  # Append a value _val_ to the packet based on its _type_.
310
296
  #
311
297
  # Host native endianness is used, declared in Message#marshall
@@ -14,6 +14,6 @@ GEMSPEC = Gem::Specification.new do |s|
14
14
  s.homepage = "https://trac.luon.net/ruby-dbus"
15
15
  s.files = FileList["{doc,examples,lib,test}/**/*", "COPYING", "NEWS", "Rakefile", "README.md", "ruby-dbus.gemspec", "VERSION"].to_a.sort
16
16
  s.require_path = "lib"
17
- s.required_ruby_version = ">= 1.8.7"
17
+ s.required_ruby_version = ">= 1.9.3"
18
18
  s.add_development_dependency("packaging_rake_tasks")
19
19
  end
@@ -54,4 +54,23 @@ class BindingTest < Test::Unit::TestCase
54
54
  assert_equal "org.freedesktop.DBus.Error.Failed", e.name
55
55
  assert_equal "failed as designed", e.message
56
56
  end
57
+
58
+ def test_dynamic_interface_definition
59
+ # interfaces can be defined dynamicaly
60
+ derived = DBus::Object.new "/org/ruby/MyDerivedInstance"
61
+
62
+ #define a new interface
63
+ derived.singleton_class.instance_eval do
64
+ dbus_interface "org.ruby.DynamicInterface" do
65
+ dbus_method :hello2, "in name:s, in name2:s" do |name, name2|
66
+ puts "hello(#{name}, #{name2})"
67
+ end
68
+ end
69
+ end
70
+
71
+ # the object should have the new iface
72
+ ifaces = derived.intfs
73
+ assert ifaces and ifaces.include?("org.ruby.DynamicInterface")
74
+ end
75
+
57
76
  end
File without changes
@@ -7,7 +7,7 @@
7
7
  #export RUBYOPT="-d"
8
8
  export RUBYOPT="$RUBYOPT -w"
9
9
  ./test_server \
10
- ./service_newapi.rb \
10
+ ../service_newapi.rb \
11
11
  -- \
12
12
  ./dbus-launch-simple \
13
13
  "$@"
File without changes
@@ -13,6 +13,15 @@ class ValueTest < Test::Unit::TestCase
13
13
  @obj.default_iface = "org.ruby.SampleInterface"
14
14
  end
15
15
 
16
+ def test_passing_an_array_of_structs_through_a_variant
17
+ triple = ['a(uuu)', []]
18
+ @obj.test_variant(triple)
19
+ quadruple = ['a(uuuu)', []] # a(uuu) works fine
20
+ # The bus disconnects us because of malformed message,
21
+ # code 12: DBUS_INVALID_TOO_MUCH_DATA
22
+ @obj.test_variant(quadruple)
23
+ end
24
+
16
25
  def test_passing_an_array_through_a_variant
17
26
  # old explicit typing
18
27
  @obj.test_variant(["as", ["coucou", "kuku"]])
metadata CHANGED
@@ -1,30 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-dbus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
5
- prerelease:
4
+ version: 0.10.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ruby DBus Team
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-01-02 00:00:00.000000000 Z
11
+ date: 2014-01-10 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: packaging_rake_tasks
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  description: Pure Ruby module for interaction with D-Bus IPC system
@@ -63,6 +60,10 @@ files:
63
60
  - lib/dbus.rb
64
61
  - lib/dbus/auth.rb
65
62
  - lib/dbus/bus.rb
63
+ - lib/dbus/core_ext/array/extract_options.rb
64
+ - lib/dbus/core_ext/class/attribute.rb
65
+ - lib/dbus/core_ext/kernel/singleton_class.rb
66
+ - lib/dbus/core_ext/module/remove_method.rb
66
67
  - lib/dbus/error.rb
67
68
  - lib/dbus/export.rb
68
69
  - lib/dbus/introspect.rb
@@ -79,51 +80,48 @@ files:
79
80
  - test/bus_driver_test.rb
80
81
  - test/bus_test.rb
81
82
  - test/byte_array_test.rb
82
- - test/dbus-launch-simple
83
- - test/dbus-limited-session.conf
83
+ - test/err_msg_test.rb
84
84
  - test/introspect_xml_parser_test.rb
85
85
  - test/introspection_test.rb
86
+ - test/main_loop_test.rb
86
87
  - test/property_test.rb
87
88
  - test/server_robustness_test.rb
88
89
  - test/server_test.rb
89
90
  - test/service_newapi.rb
90
91
  - test/session_bus_test_manual.rb
91
92
  - test/signal_test.rb
92
- - test/t1
93
- - test/t2.rb
94
- - test/t3-ticket27.rb
95
- - test/t5-report-dbus-interface.rb
96
- - test/t6-loop.rb
97
- - test/test_env
98
93
  - test/test_helper.rb
99
- - test/test_server
100
94
  - test/thread_safety_test.rb
95
+ - test/tools/dbus-launch-simple
96
+ - test/tools/dbus-limited-session.conf
97
+ - test/tools/test_env
98
+ - test/tools/test_server
101
99
  - test/type_test.rb
100
+ - test/value_test.rb
102
101
  - test/variant_test.rb
103
102
  homepage: https://trac.luon.net/ruby-dbus
104
103
  licenses:
105
104
  - LGPL v2.1
105
+ metadata: {}
106
106
  post_install_message:
107
107
  rdoc_options: []
108
108
  require_paths:
109
109
  - lib
110
110
  required_ruby_version: !ruby/object:Gem::Requirement
111
- none: false
112
111
  requirements:
113
- - - ! '>='
112
+ - - '>='
114
113
  - !ruby/object:Gem::Version
115
- version: 1.8.7
114
+ version: 1.9.3
116
115
  required_rubygems_version: !ruby/object:Gem::Requirement
117
- none: false
118
116
  requirements:
119
- - - ! '>='
117
+ - - '>='
120
118
  - !ruby/object:Gem::Version
121
119
  version: '0'
122
120
  requirements: []
123
121
  rubyforge_project:
124
- rubygems_version: 1.8.23
122
+ rubygems_version: 2.0.3
125
123
  signing_key:
126
- specification_version: 3
124
+ specification_version: 4
127
125
  summary: Ruby module for interaction with D-Bus
128
126
  test_files: []
129
127
  has_rdoc:
data/test/t1 DELETED
@@ -1,4 +0,0 @@
1
- #! /bin/sh
2
- SEND0="dbus-send --session --dest=org.ruby.service"
3
- CALL="$SEND0 --type=method_call --print-reply"
4
- $CALL /org/ruby/MyInstance org.ruby.AnotherInterface.Reverse string:Hello
@@ -1,19 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Test passing a particular struct array through a variant
3
- # https://trac.luon.net/ruby-dbus/ticket/27
4
- require File.expand_path("../test_helper", __FILE__)
5
- require "dbus"
6
- session_bus = DBus::ASessionBus.new
7
- svc = session_bus.service("org.ruby.service")
8
- obj = svc.object("/org/ruby/MyInstance")
9
- obj.introspect # necessary
10
- obj.default_iface = "org.ruby.SampleInterface"
11
- # The bug is probably alignment related so whether it triggers
12
- # depends also on the combined length of service, interface,
13
- # and method names. Luckily here it works out.
14
- triple = ['a(uuu)', []]
15
- obj.test_variant(triple)
16
- quadruple = ['a(uuuu)', []] # a(uuu) works fine
17
- # The bus disconnects us because of malformed message,
18
- # code 12: DBUS_INVALID_TOO_MUCH_DATA
19
- obj.test_variant(quadruple)