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.
194 195 196 197 |
# File 'lib/dbus.rb', line 194 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.
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/dbus.rb', line 207 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.
201 202 203 |
# File 'lib/dbus.rb', line 201 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.
229 230 231 232 233 |
# File 'lib/dbus.rb', line 229 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
240 241 242 243 244 |
# File 'lib/dbus.rb', line 240 def (connection, ) reply = () @connection.send(reply) HANDLER_RESULT_HANDLED end |
#on_unregister(connection) ⇒ Object
Called when this object is unregistered from the connection
236 237 |
# File 'lib/dbus.rb', line 236 def on_unregister(connection) end |