# 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[R]

@return [Hash{String => `DBus::Method`}]

name[R]

@return [String] The name of the interface.

object[R]

@return [ProxyObject] The proxy object to which this interface belongs.

properties[R]

@return [Hash{Symbol => Property}]

signals[R]

@return [Hash{String => Signal}]

### 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
    32 def initialize(object, name)
    33   @object = object
    34   @name = name
    35   @methods = {}
    36   @signals = {}
    37   @properties = {}
    38 end

### Public Instance Methods

[](propname) click to toggle source

Read a property. @param propname [String]

        # File lib/dbus/proxy_object_interface.rb
    133 def [](propname)
    134   ret = object[PROPERTY_INTERFACE].Get(name, propname)
    135   # this method always returns the single property
    136   if @object.api.proxy_method_returns_array
    137     ret[0]
    138   else
    139     ret
    140   end
    141 end

[]=(property_name, value) click to toggle source

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

        # File lib/dbus/proxy_object_interface.rb
    146 def []=(property_name, value)
    147   property = properties[property_name.to_sym]
    148   if !property
    149     raise DBus.error("org.freedesktop.DBus.Error.UnknownProperty"),
    150           "Property '#{name}.#{property_name}' (on object '#{object.path}') not found"
    151   end
    152
    153   case value
    154   # accommodate former need to explicitly make a variant with the right type
    155   when Data::Variant
    156     variant = value
    157   else
    158     type = property.type
    159     typed_value = Data.make_typed(type, value)
    160     variant = Data::Variant.new(typed_value, member_type: type)
    161   end
    162
    163   object[PROPERTY_INTERFACE].Set(name, property_name, variant)
    164 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
    168 def all_properties
    169   ret = object[PROPERTY_INTERFACE].GetAll(name)
    170   # this method always returns the single property
    171   if @object.api.proxy_method_returns_array
    172     ret[0]
    173   else
    174     ret
    175   end
    176 end

define(ifc_el) click to toggle source

Defines a signal or method based on the descriptor ifc_el. @param ifc_el [DBus::Method,Signal,Property]

        # File lib/dbus/proxy_object_interface.rb
     95 def define(ifc_el)
     96   case ifc_el
     97   when Method
     98     define_method_from_descriptor(ifc_el)
     99   when Signal
    100     define_signal_from_descriptor(ifc_el)
    101   when Property
    102     define_property_from_descriptor(ifc_el)
    103   end
    104 end

define_method(methodname, prototype) click to toggle source

Defines a proxied method on the interface.

        # File lib/dbus/proxy_object_interface.rb
    107 def define_method(methodname, prototype)
    108   m = Method.new(methodname)
    109   m.from_prototype(prototype)
    110   define(m)
    111 end

define_method_from_descriptor(method) click to toggle source

Defines a method on the interface from the `Method` descriptor method. @param method [Method]

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

define_property_from_descriptor(prop) click to toggle source

@param prop [Property]

       # File lib/dbus/proxy_object_interface.rb
    89 def define_property_from_descriptor(prop)
    90   @properties[prop.name] = prop
    91 end

define_signal_from_descriptor(sig) click to toggle source

Defines a signal from the descriptor sig. @param sig [Signal]

       # File lib/dbus/proxy_object_interface.rb
    84 def define_signal_from_descriptor(sig)
    85   @signals[sig.name] = sig
    86 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
    120 def on_signal(bus = @object.bus, name, &block)
    121   mr = DBus::MatchRule.new.from_signal(self, name)
    122   if block.nil?
    123     bus.remove_match(mr)
    124   else
    125     bus.add_match(mr) { |msg| block.call(*msg.params) }
    126   end
    127 end

to_str() click to toggle source

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

       # File lib/dbus/proxy_object_interface.rb
    41 def to_str
    42   @name
    43 end