Parent

Files

DBus::Object

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. At the client side, use ProxyObject.

Attributes

path[R]

The path of the object.

service[W]

The service that the object is exported by.

Public Class Methods

dbus_interface(s) click to toggle source

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

# File lib/dbus/export.rb, line 97
def self.dbus_interface(s)
  @@intfs_mutex.synchronize do
    unless @@cur_intf = (self.intfs && self.intfs[s])
      @@cur_intf = Interface.new(s)
      self.intfs = (self.intfs || {}).merge({s => @@cur_intf})
    end
    yield
    @@cur_intf = nil
  end
end
dbus_method(sym, protoype = "", &block) click to toggle source

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 117
def self.dbus_method(sym, protoype = "", &block)
  raise UndefinedInterface, sym if @@cur_intf.nil?
  @@cur_intf.define(Method.new(sym.to_s).from_prototype(protoype))
  define_method(Object.make_method_name(@@cur_intf.name, sym.to_s), &block) 
end
dbus_signal(sym, protoype = "") click to toggle source

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

# File lib/dbus/export.rb, line 130
def self.dbus_signal(sym, protoype = "")
  raise UndefinedInterface, sym if @@cur_intf.nil?
  cur_intf = @@cur_intf
  signal = Signal.new(sym.to_s).from_prototype(protoype)
  cur_intf.define(Signal.new(sym.to_s).from_prototype(protoype))
  define_method(sym.to_s) do |*args|
    emit(cur_intf, signal, *args)
  end
end
intfs() click to toggle source
# File lib/dbus/export.rb, line 39
def self.intfs
  if self.equal? DBus::Object
    @@intfs_hash[DBus::Object]
  else
    @@intfs_hash[self] || self.superclass.intfs
  end
end
intfs=(param) click to toggle source
# File lib/dbus/export.rb, line 47
def self.intfs= param
  @@intfs_hash[self] = param
end
new(path) click to toggle source

Create a new object with a given path. Use Service#export to export it.

# File lib/dbus/export.rb, line 34
def initialize(path)
  @path = path
  @service = nil
end

Public Instance Methods

dispatch(msg) click to toggle source

Dispatch a message msg to call exported methods

# File lib/dbus/export.rb, line 66
def dispatch(msg)
  case msg.message_type
  when Message::METHOD_CALL
    reply = nil
    begin
      if not self.intfs[msg.interface]
        raise DBus.error("org.freedesktop.DBus.Error.UnknownMethod"),
        "Interface \"#{msg.interface}\" of object \"#{msg.path}\" doesn't exist"
      end
      meth = self.intfs[msg.interface].methods[msg.member.to_sym]
      if not meth
        raise DBus.error("org.freedesktop.DBus.Error.UnknownMethod"),
        "Method \"#{msg.member}\" on interface \"#{msg.interface}\" of object \"#{msg.path}\" doesn't exist"
      end
      methname = Object.make_method_name(msg.interface, msg.member)
      retdata = method(methname).call(*msg.params)
      retdata =  [*retdata]

      reply = Message.method_return(msg)
      meth.rets.zip(retdata).each do |rsig, rdata|
        reply.add_param(rsig.type, rdata)
      end
    rescue => ex
      reply = ErrorMessage.from_exception(ex).reply_to(msg)
    end
    @service.bus.send(reply.marshall)
  end
end
emit(intf, sig, *args) click to toggle source

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

# File lib/dbus/export.rb, line 125
def emit(intf, sig, *args)
  @service.bus.emit(@service, self, intf, sig, *args)
end
implements(intf) click to toggle source

State that the object implements the given intf.

# File lib/dbus/export.rb, line 60
def implements(intf)
  # use a setter
  self.intfs = (self.intfs || {}).merge({intf.name => intf})
end
intfs() click to toggle source
# File lib/dbus/export.rb, line 51
def intfs
  self.class.intfs
end
intfs=(param) click to toggle source
# File lib/dbus/export.rb, line 55
def intfs= param
  self.class.intfs = param
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.