class DBus::ProxyObjectInterface

D-Bus proxy object interface class

A class similar to the normal Interface used as a proxy for remote object interfaces.

Constants

PROPERTY_INTERFACE

Attributes

methods[RW]

The proxied methods contained in the interface.

name[R]

The name of the interface.

object[R]

The proxy object to which this interface belongs.

signals[RW]

The proxied signals contained in the interface.

Public Class Methods

new(object, name) click to toggle source

Creates a new proxy interface for the given proxy object and the given name.

   # File lib/dbus/proxy_object_interface.rb
27 def initialize(object, name)
28   @object = object
29   @name = name
30   @methods = {}
31   @signals = {}
32 end

Public Instance Methods

[](propname) click to toggle source

Read a property. @param propname [String]

    # File lib/dbus/proxy_object_interface.rb
116 def [](propname)
117   ret = object[PROPERTY_INTERFACE].Get(name, propname)
118   # this method always returns the single property
119   if @object.api.proxy_method_returns_array
120     ret[0]
121   else
122     ret
123   end
124 end
[]=(propname, value) click to toggle source

Write a property. @param propname [String] @param value [Object]

    # File lib/dbus/proxy_object_interface.rb
129 def []=(propname, value)
130   object[PROPERTY_INTERFACE].Set(name, propname, value)
131 end
all_properties() click to toggle source

Read all properties at once, as a hash. @return [Hash{String}]

    # File lib/dbus/proxy_object_interface.rb
135 def all_properties
136   ret = object[PROPERTY_INTERFACE].GetAll(name)
137   # this method always returns the single property
138   if @object.api.proxy_method_returns_array
139     ret[0]
140   else
141     ret
142   end
143 end
define(m) click to toggle source

Defines a signal or method based on the descriptor m.

   # File lib/dbus/proxy_object_interface.rb
81 def define(m)
82   if m.is_a?(Method)
83     define_method_from_descriptor(m)
84   elsif m.is_a?(Signal)
85     define_signal_from_descriptor(m)
86   end
87 end
define_method(methodname, prototype) click to toggle source

Defines a proxied method on the interface.

   # File lib/dbus/proxy_object_interface.rb
90 def define_method(methodname, prototype)
91   m = Method.new(methodname)
92   m.from_prototype(prototype)
93   define(m)
94 end
define_method_from_descriptor(m) click to toggle source

Defines a method on the interface from the Method descriptor m.

   # File lib/dbus/proxy_object_interface.rb
40 def define_method_from_descriptor(m)
41   m.params.each do |fpar|
42     par = fpar.type
43     # This is the signature validity check
44     Type::Parser.new(par).parse
45   end
46 
47   singleton_class.class_eval do
48     define_method m.name do |*args, &reply_handler|
49       if m.params.size != args.size
50         raise ArgumentError, "wrong number of arguments (#{args.size} for #{m.params.size})"
51       end
52 
53       msg = Message.new(Message::METHOD_CALL)
54       msg.path = @object.path
55       msg.interface = @name
56       msg.destination = @object.destination
57       msg.member = m.name
58       msg.sender = @object.bus.unique_name
59       m.params.each do |fpar|
60         par = fpar.type
61         msg.add_param(par, args.shift)
62       end
63       ret = @object.bus.send_sync_or_async(msg, &reply_handler)
64       if ret.nil? || @object.api.proxy_method_returns_array
65         ret
66       else
67         m.rets.size == 1 ? ret.first : ret
68       end
69     end
70   end
71 
72   @methods[m.name] = m
73 end
define_signal_from_descriptor(s) click to toggle source

Defines a signal from the descriptor s.

   # File lib/dbus/proxy_object_interface.rb
76 def define_signal_from_descriptor(s)
77   @signals[s.name] = s
78 end
on_signal(bus = @object.bus, name, &block) click to toggle source

@overload on_signal(name, &block) @overload on_signal(bus, name, &block) Registers a handler (code block) for a signal with name arriving over the given bus. If no block is given, the signal is unregistered. Note that specifying bus is discouraged and the option is kept only for backward compatibility. @return [void]

    # File lib/dbus/proxy_object_interface.rb
103 def on_signal(bus = @object.bus, name, &block)
104   mr = DBus::MatchRule.new.from_signal(self, name)
105   if block.nil?
106     bus.remove_match(mr)
107   else
108     bus.add_match(mr) { |msg| block.call(*msg.params) }
109   end
110 end
to_str() click to toggle source

Returns the string representation of the interface (the name).

   # File lib/dbus/proxy_object_interface.rb
35 def to_str
36   @name
37 end