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.
Constant Summary collapse
- PROPERTY_INTERFACE =
"org.freedesktop.DBus.Properties"
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
-
#[](propname) ⇒ Object
Read a property.
-
#[]=(propname, value) ⇒ Object
Write a property.
-
#all_properties ⇒ Hash{String}
Read all properties at once, as a hash.
-
#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 Method 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(*args, &block) ⇒ void
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.
235 236 237 238 |
# File 'lib/dbus/introspect.rb', line 235 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.
225 226 227 |
# File 'lib/dbus/introspect.rb', line 225 def methods @methods end |
#name ⇒ Object (readonly)
The name of the interface.
231 232 233 |
# File 'lib/dbus/introspect.rb', line 231 def name @name end |
#object ⇒ Object (readonly)
The proxy object to which this interface belongs.
229 230 231 |
# File 'lib/dbus/introspect.rb', line 229 def object @object end |
#signals ⇒ Object
The proxied signals contained in the interface.
227 228 229 |
# File 'lib/dbus/introspect.rb', line 227 def signals @signals end |
Instance Method Details
#[](propname) ⇒ Object
Read a property.
332 333 334 |
# File 'lib/dbus/introspect.rb', line 332 def [](propname) self.object[PROPERTY_INTERFACE].Get(self.name, propname)[0] end |
#[]=(propname, value) ⇒ Object
Write a property.
337 338 339 |
# File 'lib/dbus/introspect.rb', line 337 def []=(propname, value) self.object[PROPERTY_INTERFACE].Set(self.name, propname, value) end |
#all_properties ⇒ Hash{String}
Read all properties at once, as a hash.
343 344 345 |
# File 'lib/dbus/introspect.rb', line 343 def all_properties self.object[PROPERTY_INTERFACE].GetAll(self.name)[0] end |
#define(m) ⇒ Object
Defines a signal or method based on the descriptor m.
287 288 289 290 291 292 293 |
# File 'lib/dbus/introspect.rb', line 287 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.
296 297 298 299 300 |
# File 'lib/dbus/introspect.rb', line 296 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 Method descriptor m.
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/dbus/introspect.rb', line 251 def define_method_from_descriptor(m) m.params.each do |fpar| par = fpar.type # This is the signature validity check Type::Parser.new(par).parse end singleton_class.class_eval do define_method m.name do |*args, &reply_handler| if m.params.size != args.size raise ArgumentError, "wrong number of arguments (#{args.size} for #{m.params.size})" end 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 m.params.each do |fpar| par = fpar.type msg.add_param(par, args.shift) end @object.bus.send_sync_or_async(msg, &reply_handler) end end @methods[m.name] = m end |
#define_signal_from_descriptor(s) ⇒ Object
Defines a signal from the descriptor s.
282 283 284 |
# File 'lib/dbus/introspect.rb', line 282 def define_signal_from_descriptor(s) @signals[s.name] = s end |
#on_signal(name, &block) ⇒ void #on_signal(bus, name, &block) ⇒ void
This method returns an undefined value.
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.
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/dbus/introspect.rb', line 309 def on_signal(*args, &block) # Since we must function under ruby 1.8.7, it isn't possible to define the # function as on_signal(bus = nil, name, &block) bus = case args.size when 1 @object.bus when 2 args.shift else raise ArgumentError, "wrong number of arguments (#{args.size} for 1-2)" end name = args.shift mr = DBus::MatchRule.new.from_signal(self, name) if block.nil? bus.remove_match(mr) else bus.add_match(mr) { |msg| block.call(*msg.params) } end end |
#singleton_class ⇒ Object
Returns the singleton class of the interface.
246 247 248 |
# File 'lib/dbus/introspect.rb', line 246 def singleton_class (class << self ; self ; end) end |
#to_str ⇒ Object
Returns the string representation of the interface (the name).
241 242 243 |
# File 'lib/dbus/introspect.rb', line 241 def to_str @name end |