Skip to content

Commit

Permalink
Use class_attribute to properly inherit interfaces (Ticket#36 aka Iss…
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidner committed Aug 17, 2010
1 parent 3877d57 commit 986be02
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/dbus.rb
Expand Up @@ -8,6 +8,7 @@
# License, version 2.1 as published by the Free Software Foundation.
# See the file "COPYING" for the exact licensing terms.

require 'dbus/core_ext/class/attribute'
require 'dbus/type'
require 'dbus/introspect'
require 'dbus/export'
Expand Down
14 changes: 7 additions & 7 deletions lib/dbus/export.rb
Expand Up @@ -32,34 +32,33 @@ class Object
# The path of the object.
attr_reader :path
# The interfaces that the object supports.
attr_reader :intfs
class_attribute :intfs
# The service that the object is exported by.
attr_writer :service

@@intfs = Hash.new
@@cur_intf = nil
@@intfs_mutex = Mutex.new

# Create a new object with a given _path_.
def initialize(path)
@path = path
@intfs = @@intfs.dup
@service = nil
end

# State that the object implements the given _intf_.
def implements(intf)
@intfs[intf.name] = intf
# use a setter
self.intfs = (self.intfs || {}).merge({intf.name => intf})
end

# Dispatch a message _msg_.
def dispatch(msg)
case msg.message_type
when Message::METHOD_CALL
if not @intfs[msg.interface]
if not self.intfs[msg.interface]
raise InterfaceNotInObject, msg.interface
end
meth = @intfs[msg.interface].methods[msg.member.to_sym]
meth = self.intfs[msg.interface].methods[msg.member.to_sym]
raise MethodNotInInterface if not meth
methname = Object.make_method_name(msg.interface, msg.member)
reply = nil
Expand All @@ -83,7 +82,8 @@ def dispatch(msg)
# belong to.
def self.dbus_interface(s)
@@intfs_mutex.synchronize do
@@cur_intf = @@intfs[s] = Interface.new(s)
@@cur_intf = Interface.new(s)
self.intfs = (self.intfs || {}).merge({s => @@cur_intf})
yield
@@cur_intf = nil
end
Expand Down

0 comments on commit 986be02

Please sign in to comment.