| Class | DBus::ObjectTree |
| In: |
lib/dbus.rb
|
| Parent: | DBusCallable |
An object tree allows you to register a handler for a tree of object paths. This means that literal Ruby objects do not need to be created for each object over the bus, but you can have a virtual tree of objects handled by a single Ruby object. There are two ways to handle method calls on virtual objects:
# File lib/dbus.rb, line 307
307: def initialize(base_path, service, dbus_methods=[])
308: @connection = service.get_bus.get_connection
309: super(@connection, dbus_methods)
310: @base_path = base_path
311: @service = service
312: @methods = dbus_methods
313: @service.get_bus.get_connection.register_fallback(base_path, method(:on_unregister),
314: method(:on_message))
315: end
Broadcast the signal signal_name for interface interface for the object identified by relative_path
# File lib/dbus.rb, line 324
324: def broadcast_signal(interface, signal_name, relative_path)
325: object_path = relative_path_to_object_path(relative_path)
326: message = DBus::Binding::DBusMessage.new_signal(object_path, interface, signal_name)
327: @connection.send(message)
328: end
# File lib/dbus.rb, line 330
330: def object_method_called
331: raise NotImplementedError, "Not implemented"
332: end
# File lib/dbus.rb, line 334
334: def on_message(connection, message)
335: target_object_full_path = message.get_path
336: n = @base_path.length
337: unless @base_path == target_object_full_path[0,n]
338: @connection.send(new_error_reply(message, "Invalid target path: #{target_object_full_path}"))
339: return HANDLER_RESULT_HANDLED
340: end
341: target_object_path = target_object_full_path[n..-1]
342: target_method = message.get_member
343: target_args = message.to_a
344: args = [target_object_path, *target_args]
345: @connection.send(dispatch(target_method, args, message))
346: HANDLER_RESULT_HANDLED
347: end
Create a new absolute ObjectPath for the given relative path
# File lib/dbus.rb, line 318
318: def relative_path_to_object_path(path)
319: ObjectPath.new(@base_path + path)
320: end