Class: DBus::ProxyObjectInterface
- Inherits:
-
Object
- Object
- DBus::ProxyObjectInterface
- Defined in:
- lib/dbus/introspect.rb
Overview
D-Bus proxy object interface class
A class similar to the normal Interface used as a proxy for remote object interfaces.
Instance Attribute Summary collapse
-
#methods ⇒ Object
The proxied methods contained in the interface.
-
#name ⇒ Object
readonly
The name of the interface.
-
#object ⇒ Object
readonly
The proxy object to which this interface belongs.
-
#signals ⇒ Object
The proxied signals contained in the interface.
Instance Method Summary collapse
-
#check_for_eval(s) ⇒ Object
FIXME.
-
#check_for_quoted_eval(s) ⇒ Object
FIXME.
-
#define(m) ⇒ Object
Defines a signal or method based on the descriptor m.
-
#define_method(methodname, prototype) ⇒ Object
Defines a proxied method on the interface.
-
#define_method_from_descriptor(m) ⇒ Object
Defines a method on the interface from the descriptor m.
-
#define_signal_from_descriptor(s) ⇒ Object
Defines a signal from the descriptor s.
-
#initialize(object, name) ⇒ ProxyObjectInterface
constructor
Creates a new proxy interface for the given proxy object and the given name.
-
#on_signal(bus, name, &block) ⇒ Object
Registers a handler (code block) for a signal with name arriving over the given bus.
-
#singleton_class ⇒ Object
Returns the singleton class of the interface.
-
#to_str ⇒ Object
Returns the string representation of the interface (the name).
Constructor Details
#initialize(object, name) ⇒ ProxyObjectInterface
Creates a new proxy interface for the given proxy object and the given name.
348 349 350 351 |
# File 'lib/dbus/introspect.rb', line 348 def initialize(object, name) @object, @name = object, name @methods, @signals = Hash.new, Hash.new end |
Instance Attribute Details
#methods ⇒ Object
The proxied methods contained in the interface.
338 339 340 |
# File 'lib/dbus/introspect.rb', line 338 def methods @methods end |
#name ⇒ Object (readonly)
The name of the interface.
344 345 346 |
# File 'lib/dbus/introspect.rb', line 344 def name @name end |
#object ⇒ Object (readonly)
The proxy object to which this interface belongs.
342 343 344 |
# File 'lib/dbus/introspect.rb', line 342 def object @object end |
#signals ⇒ Object
The proxied signals contained in the interface.
340 341 342 |
# File 'lib/dbus/introspect.rb', line 340 def signals @signals end |
Instance Method Details
#check_for_eval(s) ⇒ Object
FIXME
364 365 366 |
# File 'lib/dbus/introspect.rb', line 364 def check_for_eval(s) raise RuntimeException, "invalid internal data" if not s.to_s =~ /^[A-Za-z0-9_]*$/ end |
#check_for_quoted_eval(s) ⇒ Object
FIXME
369 370 371 |
# File 'lib/dbus/introspect.rb', line 369 def check_for_quoted_eval(s) raise RuntimeException, "invalid internal data" if not s.to_s =~ /^[^"]+$/ end |
#define(m) ⇒ Object
Defines a signal or method based on the descriptor m.
435 436 437 438 439 440 441 |
# File 'lib/dbus/introspect.rb', line 435 def define(m) if m.kind_of?(Method) define_method_from_descriptor(m) elsif m.kind_of?(Signal) define_signal_from_descriptor(m) end end |
#define_method(methodname, prototype) ⇒ Object
Defines a proxied method on the interface.
444 445 446 447 448 |
# File 'lib/dbus/introspect.rb', line 444 def define_method(methodname, prototype) m = Method.new(methodname) m.from_prototype(prototype) define(m) end |
#define_method_from_descriptor(m) ⇒ Object
Defines a method on the interface from the descriptor m.
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
# File 'lib/dbus/introspect.rb', line 374 def define_method_from_descriptor(m) check_for_eval(m.name) check_for_quoted_eval(@name) methdef = "def #{m.name}(" methdef += (0..(m.params.size - 1)).to_a.collect { |n| "arg#{n}" }.join(", ") methdef += %{) msg = Message.new(Message::METHOD_CALL) msg.path = @object.path msg.interface = "#{@name}" msg.destination = @object.destination msg.member = "#{m.name}" msg.sender = @object.bus.unique_name } idx = 0 m.params.each do |npar| paramname, par = npar check_for_quoted_eval(par) # This is the signature validity check Type::Parser.new(par).parse methdef += %{ msg.add_param("#{par}", arg#{idx}) } idx += 1 end methdef += " ret = nil if block_given? @object.bus.on_return(msg) do |rmsg| if rmsg.is_a?(Error) yield(rmsg) else yield(rmsg, *rmsg.params) end end @object.bus.send(msg.marshall) else @object.bus.send_sync(msg) do |rmsg| if rmsg.is_a?(Error) raise rmsg else ret = rmsg.params end end end ret end " singleton_class.class_eval(methdef) @methods[m.name] = m end |
#define_signal_from_descriptor(s) ⇒ Object
Defines a signal from the descriptor s.
430 431 432 |
# File 'lib/dbus/introspect.rb', line 430 def define_signal_from_descriptor(s) @signals[s.name] = s end |
#on_signal(bus, name, &block) ⇒ Object
Registers a handler (code block) for a signal with name arriving over the given bus.
452 453 454 455 |
# File 'lib/dbus/introspect.rb', line 452 def on_signal(bus, name, &block) mr = DBus::MatchRule.new.from_signal(self, name) bus.add_match(mr) { |msg| block.call(*msg.params) } end |
#singleton_class ⇒ Object
Returns the singleton class of the interface.
359 360 361 |
# File 'lib/dbus/introspect.rb', line 359 def singleton_class (class << self ; self ; end) end |
#to_str ⇒ Object
Returns the string representation of the interface (the name).
354 355 356 |
# File 'lib/dbus/introspect.rb', line 354 def to_str @name end |