Exported object type

Exportable D-Bus object class

Objects that are going to be exported by a D-Bus service should inherit from this class.

Methods
Classes and Modules
Class DBus::Object::UndefinedInterface
Attributes
[R] intfs The interfaces that the object supports.
[R] path The path of the object.
[W] service The service that the object is exported by.
Public Class methods
dbus_interface(s) {|| ...}

Select (and create) the interface that the following defined methods belong to.

    # File lib/dbus/export.rb, line 77
77:     def self.dbus_interface(s)
78:       @@intfs_mutex.synchronize do
79:         @@cur_intf = @@intfs[s] = Interface.new(s)
80:         yield
81:         @@cur_intf = nil
82:       end
83:     end
dbus_method(sym, protoype = "", &block)

Defines an exportable method on the object with the given name sym, prototype and the code in a block.

    # File lib/dbus/export.rb, line 91
91:     def self.dbus_method(sym, protoype = "", &block)
92:       raise UndefinedInterface if @@cur_intf.nil?
93:       @@cur_intf.define(Method.new(sym.to_s).from_prototype(protoype))
94:       define_method(Object.make_method_name(@@cur_intf.name, sym.to_s), &block) 
95:     end
dbus_signal(sym, protoype = "")

Defines a signal for the object with a given name sym and prototype.

     # File lib/dbus/export.rb, line 104
104:     def self.dbus_signal(sym, protoype = "")
105:       raise UndefinedInterface if @@cur_intf.nil?
106:       cur_intf = @@cur_intf
107:       signal = Signal.new(sym.to_s).from_prototype(protoype)
108:       cur_intf.define(Signal.new(sym.to_s).from_prototype(protoype))
109:       define_method(sym.to_s) do |*args|
110:         emit(cur_intf, signal, *args)
111:       end
112:     end
new(path)

Create a new object with a given path.

    # File lib/dbus/export.rb, line 44
44:     def initialize(path)
45:       @path = path
46:       @intfs = @@intfs.dup
47:       @service = nil
48:     end
Public Instance methods
dispatch(msg)

Dispatch a message msg.

    # File lib/dbus/export.rb, line 56
56:     def dispatch(msg)
57:       case msg.message_type
58:       when Message::METHOD_CALL
59:         if not @intfs[msg.interface]
60:           raise InterfaceNotInObject, msg.interface
61:         end
62:         meth = @intfs[msg.interface].methods[msg.member.to_sym]
63:         raise MethodNotInInterface if not meth
64:         methname = Object.make_method_name(msg.interface, msg.member)
65:         retdata = method(methname).call(*msg.params).to_a
66: 
67:         reply = Message.new.reply_to(msg)
68:         meth.rets.zip(retdata).each do |rsig, rdata|
69:           reply.add_param(rsig[1], rdata)
70:         end
71:         @service.bus.send(reply.marshall)
72:       end
73:     end
emit(intf, sig, *args)

Emits a signal from the object with the given interface, signal sig and arguments args.

     # File lib/dbus/export.rb, line 99
 99:     def emit(intf, sig, *args)
100:       @service.bus.emit(@service, self, intf, sig, *args)
101:     end
implements(intf)

State that the object implements the given intf.

    # File lib/dbus/export.rb, line 51
51:     def implements(intf)
52:       @intfs[intf.name] = intf
53:     end