Class: DBus::DBusCallable
- Inherits:
-
Object
- Object
- DBus::DBusCallable
- Defined in:
- lib/dbus.rb
Overview
Base class for objects that support D-BUS invocation messages
Direct Known Subclasses
Instance Method Summary collapse
-
#dispatch(name, args, source_message) ⇒ Object
Invoke the method
name
, with argumentsargs
, and source invocation request messagesource_message
, returning the reply message. -
#dispatch_message(message) ⇒ Object
Process the method invocation message given in
message
. -
#initialize(connection, dbus_methods = []) ⇒ DBusCallable
constructor
Create a new DBusCallable instance on the specified
connection
. -
#new_error_reply(message, error_message) ⇒ Object
Generate a new error reply from source message
message
, and error stringerror_message
. -
#on_message(connection, message) ⇒ Object
Called when a message arrives on the connection for this object.
-
#on_unregister(connection) ⇒ Object
Called when this object is unregistered from the connection.
Constructor Details
#initialize(connection, dbus_methods = []) ⇒ DBusCallable
Create a new DBusCallable instance on the specified connection
. dbus_methods
is an Array containing a list of symbols for the methods which may be invoked remotely.
214 215 216 217 |
# File 'lib/dbus.rb', line 214 def initialize(connection, dbus_methods=[]) @connection = connection @dbus_methods = dbus_methods end |
Instance Method Details
#dispatch(name, args, source_message) ⇒ Object
Invoke the method name
, with arguments args
, and source invocation request message source_message
, returning the reply message.
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/dbus.rb', line 227 def dispatch(name, args, ) unless @dbus_methods.include?(name.to_sym) return new_error_reply(, "Method '#{name}' not in allowed list") end unless self.respond_to?(name) return new_error_reply(, "No such method '#{name}'") end ret = nil begin args = [, *args] ret = self.send(name, *args) rescue return new_error_reply(, $!.to_s) end reply = DBus::Binding::DBusMessage.new_method_return() iter = reply.get_iter iter.append(ret) reply end |
#dispatch_message(message) ⇒ Object
Process the method invocation message given in message
. Returns the reply message.
221 222 223 |
# File 'lib/dbus.rb', line 221 def () dispatch(.get_member, .to_a, ) end |
#new_error_reply(message, error_message) ⇒ Object
Generate a new error reply from source message message
, and error string error_message
.
249 250 251 252 253 |
# File 'lib/dbus.rb', line 249 def new_error_reply(, ) error_name = self.class.to_s.gsub(/::/, '.') error_name += '.ERROR' DBus::Binding::DBusMessage.new_error(, error_name, ) end |
#on_message(connection, message) ⇒ Object
Called when a message arrives on the connection for this object
260 261 262 263 264 |
# File 'lib/dbus.rb', line 260 def (connection, ) reply = () @connection.send(reply) HANDLER_RESULT_HANDLED end |
#on_unregister(connection) ⇒ Object
Called when this object is unregistered from the connection
256 257 |
# File 'lib/dbus.rb', line 256 def on_unregister(connection) end |