Class: DBus::ProxyObject
- Inherits:
-
Object
- Object
- DBus::ProxyObject
- Defined in:
- lib/dbus/introspect.rb
Overview
D-Bus proxy object class
Class representing a remote object in an external application. Typically, calling a method on an instance of a ProxyObject sends a message over the bus so that the method is executed remotely on the correctponding object.
Instance Attribute Summary collapse
-
#bus ⇒ Object
readonly
The bus the object is reachable via.
-
#default_iface ⇒ Object
The default interface of the object.
-
#destination ⇒ Object
readonly
The (remote) destination of the object.
-
#introspected ⇒ Object
Flag determining whether the object has been introspected.
-
#path ⇒ Object
readonly
The path to the object.
-
#subnodes ⇒ Object
The subnodes of the object in the tree.
Instance Method Summary collapse
-
#[](intfname) ⇒ Object
Retrieves an interface of the proxy object (ProxyObjectInterface instance).
-
#[]=(intfname, intf) ⇒ Object
Maps the given interface name intfname to the given interface _intf.
-
#has_iface?(name) ⇒ Boolean
Returns whether the object has an interface with the given name.
-
#initialize(bus, dest, path) ⇒ ProxyObject
constructor
Creates a new proxy object living on the given bus at destination dest on the given path.
-
#interfaces ⇒ Object
Returns the interfaces of the object.
-
#introspect ⇒ Object
Introspects the remote object.
-
#on_signal(name, &block) ⇒ Object
Registers a handler, the code block, for a signal with the given name.
Constructor Details
#initialize(bus, dest, path) ⇒ ProxyObject
Creates a new proxy object living on the given bus at destination dest on the given path.
480 481 482 483 484 |
# File 'lib/dbus/introspect.rb', line 480 def initialize(bus, dest, path) @bus, @destination, @path = bus, dest, path @interfaces = Hash.new @subnodes = Array.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object (private)
Handles all unkown methods, mostly to route method calls to the default interface.
530 531 532 533 534 535 536 537 538 |
# File 'lib/dbus/introspect.rb', line 530 def method_missing(name, *args) if @default_iface and has_iface?(@default_iface) @interfaces[@default_iface].method(name).call(*args) else dlog "interfaces: #{@interfaces.keys.inspect}" dlog "default_iface: #{@default_iface}" raise NoMethodError end end |
Instance Attribute Details
#bus ⇒ Object (readonly)
The bus the object is reachable via.
474 475 476 |
# File 'lib/dbus/introspect.rb', line 474 def bus @bus end |
#default_iface ⇒ Object
The default interface of the object.
476 477 478 |
# File 'lib/dbus/introspect.rb', line 476 def default_iface @default_iface end |
#destination ⇒ Object (readonly)
The (remote) destination of the object.
470 471 472 |
# File 'lib/dbus/introspect.rb', line 470 def destination @destination end |
#introspected ⇒ Object
Flag determining whether the object has been introspected.
468 469 470 |
# File 'lib/dbus/introspect.rb', line 468 def introspected @introspected end |
#path ⇒ Object (readonly)
The path to the object.
472 473 474 |
# File 'lib/dbus/introspect.rb', line 472 def path @path end |
#subnodes ⇒ Object
The subnodes of the object in the tree.
466 467 468 |
# File 'lib/dbus/introspect.rb', line 466 def subnodes @subnodes end |
Instance Method Details
#[](intfname) ⇒ Object
Retrieves an interface of the proxy object (ProxyObjectInterface instance).
492 493 494 |
# File 'lib/dbus/introspect.rb', line 492 def [](intfname) @interfaces[intfname] end |
#[]=(intfname, intf) ⇒ Object
Maps the given interface name intfname to the given interface _intf.
497 498 499 |
# File 'lib/dbus/introspect.rb', line 497 def []=(intfname, intf) @interfaces[intfname] = intf end |
#has_iface?(name) ⇒ Boolean
Returns whether the object has an interface with the given name.
511 512 513 514 |
# File 'lib/dbus/introspect.rb', line 511 def has_iface?(name) raise "Cannot call has_iface? is not introspected" if not @introspected @interfaces.member?(name) end |
#interfaces ⇒ Object
Returns the interfaces of the object.
487 488 489 |
# File 'lib/dbus/introspect.rb', line 487 def interfaces @interfaces.keys end |
#introspect ⇒ Object
Introspects the remote object. Allows you to find and select interfaces on the object.
503 504 505 506 507 508 |
# File 'lib/dbus/introspect.rb', line 503 def introspect # Synchronous call here. xml = @bus.introspect_data(@destination, @path) ProxyObjectFactory.introspect_into(self, xml) xml end |
#on_signal(name, &block) ⇒ Object
Registers a handler, the code block, for a signal with the given name.
517 518 519 520 521 522 523 |
# File 'lib/dbus/introspect.rb', line 517 def on_signal(name, &block) if @default_iface and has_iface?(@default_iface) @interfaces[@default_iface].on_signal(@bus, name, &block) else raise NoMethodError end end |