Class: DBus::Binding::DBusMessage
- Inherits:
-
Object
- Object
- DBus::Binding::DBusMessage
- Includes:
- Enumerable
- Defined in:
- ext/ruby-dbus-message.c,
lib/dbus/binding.rb,
ext/ruby-dbus-message.c
Overview
Represents a message sent over or received from another application over the bus.
A message has a type (DBusMessage#get_type) field indicating the nature of the message, and this can be used to decide which additional fields will contain useful data.
In addition, a message can have application-specific values added to it, these are called values or arguments. The order and type of the appended values define the message type signature (see DBusMessage#get_signature).
Class Method Summary collapse
-
.new(type) ⇒ self
Creates a new DBusMessage of the specified type, which may be one of the DBus MESSAGE_TYPE constants.
-
.new_error(request_message, error_name, error_message) ⇒ Object
Creates a new DBusMessage of type MESSAGE_TYPE_ERROR.
-
.new_method_call(service, path, interface, method_name) ⇒ self
Creates a new DBusMessage representing a method call request on a remote object.
-
.new_method_return(invocation_message) ⇒ self
Creates a new DBusMessage representing a reply to a method call.
-
.new_signal(path, interface, signal_name) ⇒ self
Creates a new DBusMessage representing a signal emission.
Instance Method Summary collapse
-
#<<(value) ⇒ Object
Appends the given value to the message.
-
#[](offset) ⇒ Object
Returns the message argument value at the given offset.
-
#append(ary) ⇒ Object
Appends each item in the given Array to the message.
-
#each {|value| ... } ⇒ Object
Yields each message argument value that was appended to the message to the given block, in sequence.
-
#get_append_iter ⇒ Object
Returns a DBusMessageIter iterator instance for appending values to this message.
-
#get_auto_activation ⇒ Object
Returns
trueif the message will cause the addressed service to be auto-activated. -
#get_destination ⇒ Object
Gets the destination service of this message.
-
#get_error_name ⇒ Object
Gets the error name (for an error message).
-
#get_path ⇒ Object
Gets the interface this message is being sent to.
-
#get_iter ⇒ Object
Returns a DBusMessageIter iterator instance for this message.
-
#get_member ⇒ Object
Gets the interface member being invoked (for a method call), or emitted (for a signal).
-
#get_no_reply ⇒ Object
Returns
trueif the message sender is not expecting a reply message. -
#get_path ⇒ Object
Gets the object path this message is being sent to (for a method call), or being emitted from (for a signal).
-
#get_path_decomposed ⇒ Object
Returns an array containing the path segments of the message path.
-
#get_reply_serial ⇒ Object
Returns the serial number (see DbusMessage#get_serial) of the message that this message is a reply to.
-
#get_sender ⇒ Object
Gets the sending service of this message.
-
#get_serial ⇒ Object
Returns the client serial number of the message.
-
#get_signature ⇒ Object
Gets the type signature.
-
#get_type ⇒ Object
Returns an integer representing the message type.
-
#has_destination(service) ⇒ Object
Returns
trueif the message has a destination service with the given service name. -
#has_sender(service) ⇒ Object
Returns
trueif the message has the given service name as its sender. -
#has_signature(signature) ⇒ Object
Returns
trueif the message has the given type signature. -
#is_error(error_name) ⇒ Object
Returns
trueif the message is an error message with the given error name field. -
#is_method_call(interface, method_name) ⇒ Object
Returns
trueif the message is a method call message with the given method name and interface fields. -
#is_signal(interface, signal_name) ⇒ Object
Returns
trueif the message is a signal message with the given interface and signal name fields. -
#set_auto_activation(true|false) ⇒ nil
Indicates that the addressed service will be auto-activated before the message is delivered.
-
#set_destination(service) ⇒ Object
Sets the message’s destination service.
-
#set_error_name(name) ⇒ Object
Sets the name of the error (for an error message).
-
#set_interface(interface) ⇒ Object
Sets the interface this message is being sent to (for a method call), or the interface a signal is being emitted from (for a signal).
-
#set_member(member) ⇒ Object
Sets the interface member being invoked (for a method call), or emitted (for a signal).
-
#set_no_reply(true|false) ⇒ nil
Indicates whether or not the message wants a reply.
-
#set_path(object_path) ⇒ Object
Sets the object path this message is being sent to (for a method call), or the path a signal is being emitted from (for a signal).
-
#set_reply_serial(serial) ⇒ true
Sets the serial number (see DbusMessage#get_serial) of the message that this message is a reply to.
-
#set_sender(service) ⇒ Object
Sets the service sending this message.
- #to_s ⇒ Object
Class Method Details
.new(type) ⇒ self
Creates a new DBusMessage of the specified type, which may be one of the DBus MESSAGE_TYPE constants.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'ext/ruby-dbus-message.c', line 75 static VALUE cDBusMessage_new(VALUE klass, VALUE type) { DBusMessage *; int ; = NUM2INT(type); switch () { case DBUS_MESSAGE_TYPE_INVALID: case DBUS_MESSAGE_TYPE_METHOD_CALL: case DBUS_MESSAGE_TYPE_METHOD_RETURN: case DBUS_MESSAGE_TYPE_ERROR: case DBUS_MESSAGE_TYPE_SIGNAL: /* fall-through */ break; default: rb_raise(eDBusError, "unsupported DBusMessageType %d", ); } = NULL; = (); RDBUS_RAISE_IF( == NULL, "failed to create DBusMessage"); return MSG_NEW_TAKE_OWNERSHIP(); } |
.new_error(request_message, error_name, error_message) ⇒ Object
Creates a new DBusMessage of type MESSAGE_TYPE_ERROR.
Messages of this type are sent when a request fails for some reason. The error name has to be in a valid D-BUS error name format, meaning it has to contain at least one period.
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'ext/ruby-dbus-message.c', line 188 static VALUE cDBusMessage_new_error(VALUE klass, VALUE reply_to, VALUE error_name, VALUE ) { DBusMessage *; = NULL; = ( MSG_GET(reply_to), StringValuePtr(error_name), StringValuePtr() ); RDBUS_RAISE_IF(!, "failed to create DBusMessage"); return MSG_NEW_TAKE_OWNERSHIP(); } |
.new_method_call(service, path, interface, method_name) ⇒ self
Creates a new DBusMessage representing a method call request on a remote object.
-
servicemust contain the service to send the message to -
pathmust contain object path the message should be sent to -
interfacemust indicate the interface the method will be invoked on -
method_namemust contain the name of a method defined in the given interface
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'ext/ruby-dbus-message.c', line 113 static VALUE cDBusMessage_new_method_call(VALUE klass, VALUE service, VALUE path, VALUE interface, VALUE method) { DBusMessage *; = NULL; = ( StringValuePtr(service), StringValuePtr(path), StringValuePtr(interface), StringValuePtr(method) ); RDBUS_RAISE_IF( == NULL, "failed to create DBusMessage"); return MSG_NEW_TAKE_OWNERSHIP(); } |
.new_method_return(invocation_message) ⇒ self
Creates a new DBusMessage representing a reply to a method call.
The original method invocation request message must be provided in invocation_message.
139 140 141 142 143 144 145 146 147 148 |
# File 'ext/ruby-dbus-message.c', line 139 static VALUE cDBusMessage_new_method_return(VALUE klass, VALUE method_call_msg) { DBusMessage *; = NULL; = (MSG_GET(method_call_msg)); RDBUS_RAISE_IF(!, "failed to create DBusMessage"); return MSG_NEW_TAKE_OWNERSHIP(); } |
.new_signal(path, interface, signal_name) ⇒ self
Creates a new DBusMessage representing a signal emission.
The given path must be the path to the object emitting the signal, interface the interface the signal is being emitted from, and signal_name the name of the signal.
The signal name can subsequently be retrieved from the member field of the message.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'ext/ruby-dbus-message.c', line 163 static VALUE cDBusMessage_new_signal(VALUE klass, VALUE path, VALUE interface, VALUE name) { DBusMessage *; = NULL; = ( StringValuePtr(path), StringValuePtr(interface), StringValuePtr(name) ); RDBUS_RAISE_IF(!, "failed to create DBusMessage"); return MSG_NEW_TAKE_OWNERSHIP(); } |
Instance Method Details
#<<(value) ⇒ Object
Appends the given value to the message. If you want to append more than one value, use DBusMessage#append instead, it will be more efficient.
76 77 78 79 80 |
# File 'lib/dbus/binding.rb', line 76 def <<(value) iter = get_append_iter iter.append(value) nil end |
#[](offset) ⇒ Object
Returns the message argument value at the given offset
63 64 65 |
# File 'lib/dbus/binding.rb', line 63 def [](offset) entries[offset] end |
#append(ary) ⇒ Object
Appends each item in the given Array to the message
68 69 70 71 72 |
# File 'lib/dbus/binding.rb', line 68 def append(ary) iter = get_append_iter ary.each{|value| iter.append(value)} nil end |
#each {|value| ... } ⇒ Object
Yields each message argument value that was appended to the message to the given block, in sequence
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/dbus/binding.rb', line 45 def each raise DBusError, "block expected" unless block_given? iter = get_iter begin value = iter.value rescue return nil end yield value have_value = iter.next while have_value yield iter.value have_value = iter.next end nil end |
#get_append_iter ⇒ Object
Returns a DBusMessageIter iterator instance for appending values to this message. The position of the iterator is at the end of any existing values.
632 633 634 635 636 |
# File 'ext/ruby-dbus-message.c', line 632 static VALUE cDBusMessage_get_append_iter(VALUE self) { return ITER_NEW(MSG_GET(self), TRUE); } |
#get_auto_activation ⇒ Object
Returns true if the message will cause the addressed service to be auto-activated.
598 599 600 601 602 603 604 |
# File 'ext/ruby-dbus-message.c', line 598 static VALUE cDBusMessage_get_auto_activation(VALUE self) { if (!(MSG_GET(self))) return Qfalse; return Qtrue; } |
#get_destination ⇒ Object
Gets the destination service of this message.
372 373 374 375 376 |
# File 'ext/ruby-dbus-message.c', line 372 static VALUE cDBusMessage_get_destination(VALUE self) { MESSAGE_STR_GETTER_BODY(destination); } |
#get_error_name ⇒ Object
Gets the error name (for an error message).
360 361 362 363 364 |
# File 'ext/ruby-dbus-message.c', line 360 static VALUE cDBusMessage_get_error_name(VALUE self) { MESSAGE_STR_GETTER_BODY(error_name); } |
#get_path ⇒ Object
Gets the interface this message is being sent to.
335 336 337 338 339 |
# File 'ext/ruby-dbus-message.c', line 335 static VALUE cDBusMessage_get_interface(VALUE self) { MESSAGE_STR_GETTER_BODY(interface); } |
#get_iter ⇒ Object
Returns a DBusMessageIter iterator instance for this message. The iterator can be used to iterate over the values (arguments) appended to the message.
To append values to the message, use DBusMessage#get_append_iter instead, as its position will already be at the end, and by using it you will avoid D-BUS error messages.
618 619 620 621 622 |
# File 'ext/ruby-dbus-message.c', line 618 static VALUE cDBusMessage_get_iter(VALUE self) { return ITER_NEW(MSG_GET(self), FALSE); } |
#get_member ⇒ Object
Gets the interface member being invoked (for a method call), or emitted (for a signal).
348 349 350 351 352 |
# File 'ext/ruby-dbus-message.c', line 348 static VALUE cDBusMessage_get_member(VALUE self) { MESSAGE_STR_GETTER_BODY(member); } |
#get_no_reply ⇒ Object
Returns true if the message sender is not expecting a reply message.
431 432 433 434 435 436 437 |
# File 'ext/ruby-dbus-message.c', line 431 static VALUE cDBusMessage_get_no_reply(VALUE self) { if (!(MSG_GET(self))) return Qfalse; return Qtrue; } |
#get_path ⇒ Object
Gets the object path this message is being sent to (for a method call), or being emitted from (for a signal).
323 324 325 326 327 |
# File 'ext/ruby-dbus-message.c', line 323 static VALUE cDBusMessage_get_path(VALUE self) { MESSAGE_STR_GETTER_BODY(path); } |
#get_path_decomposed ⇒ Object
Returns an array containing the path segments of the message path
83 84 85 |
# File 'lib/dbus/binding.rb', line 83 def get_path_decomposed get_path.split("/") end |
#get_reply_serial ⇒ Object
Returns the serial number (see DbusMessage#get_serial) of the message that this message is a reply to.
549 550 551 552 553 |
# File 'ext/ruby-dbus-message.c', line 549 static VALUE cDBusMessage_get_reply_serial(VALUE self) { return INT2NUM((MSG_GET(self))); } |
#get_sender ⇒ Object
Gets the sending service of this message.
384 385 386 387 388 |
# File 'ext/ruby-dbus-message.c', line 384 static VALUE cDBusMessage_get_sender(VALUE self) { MESSAGE_STR_GETTER_BODY(sender); } |
#get_serial ⇒ Object
Returns the client serial number of the message. This can’t be set.
536 537 538 539 540 |
# File 'ext/ruby-dbus-message.c', line 536 static VALUE cDBusMessage_get_serial(VALUE self) { return INT2NUM((MSG_GET(self))); } |
#get_signature ⇒ Object
Gets the type signature.
A type signature is the type of the message argument values in the message payload. The signature is a string consisting of TYPE_xxx type codes:
399 400 401 402 403 |
# File 'ext/ruby-dbus-message.c', line 399 static VALUE cDBusMessage_get_signature(VALUE self) { MESSAGE_STR_GETTER_BODY(signature); } |
#get_type ⇒ Object
Returns an integer representing the message type. Its value will be one of the MESSAGE_TYPE constants.
211 212 213 214 215 |
# File 'ext/ruby-dbus-message.c', line 211 static VALUE cDBusMessage_get_type(VALUE self) { return INT2FIX((MSG_GET(self))); } |
#has_destination(service) ⇒ Object
Returns true if the message has a destination service with the given service name.
493 494 495 496 497 498 499 |
# File 'ext/ruby-dbus-message.c', line 493 static VALUE cDBusMessage_has_destination(VALUE self, VALUE service) { if (!(MSG_GET(self), StringValuePtr(service))) return Qfalse; return Qtrue; } |
#has_sender(service) ⇒ Object
Returns true if the message has the given service name as its sender.
507 508 509 510 511 512 513 |
# File 'ext/ruby-dbus-message.c', line 507 static VALUE cDBusMessage_has_sender(VALUE self, VALUE service) { if (!(MSG_GET(self), StringValuePtr(service))) return Qfalse; return Qtrue; } |
#has_signature(signature) ⇒ Object
Returns true if the message has the given type signature. See DBusMessage#get_signature for more details on type signatures.
522 523 524 525 526 527 528 |
# File 'ext/ruby-dbus-message.c', line 522 static VALUE cDBusMessage_has_signature(VALUE self, VALUE signature) { if (!(MSG_GET(self), StringValuePtr(signature))) return Qfalse; return Qtrue; } |
#is_error(error_name) ⇒ Object
Returns true if the message is an error message with the given error name field.
478 479 480 481 482 483 484 |
# File 'ext/ruby-dbus-message.c', line 478 static VALUE cDBusMessage_is_error(VALUE self, VALUE error) { if (!(MSG_GET(self), StringValuePtr(error))) return Qfalse; return Qtrue; } |
#is_method_call(interface, method_name) ⇒ Object
Returns true if the message is a method call message with the given method name and interface fields.
446 447 448 449 450 451 452 453 |
# File 'ext/ruby-dbus-message.c', line 446 static VALUE cDBusMessage_is_method_call(VALUE self, VALUE interface, VALUE method) { if (!(MSG_GET(self), StringValuePtr(interface), StringValuePtr(method))) return Qfalse; return Qtrue; } |
#is_signal(interface, signal_name) ⇒ Object
Returns true if the message is a signal message with the given interface and signal name fields.
462 463 464 465 466 467 468 469 |
# File 'ext/ruby-dbus-message.c', line 462 static VALUE cDBusMessage_is_signal(VALUE self, VALUE interface, VALUE signal_name) { if (!(MSG_GET(self), StringValuePtr(interface), StringValuePtr(signal_name))) return Qfalse; return Qtrue; } |
#set_auto_activation(true|false) ⇒ nil
Indicates that the addressed service will be auto-activated before the message is delivered. If the service fails to activate, an activation error reply message will be received.
578 579 580 581 582 583 584 585 586 587 588 589 |
# File 'ext/ruby-dbus-message.c', line 578 static VALUE cDBusMessage_set_auto_activation(VALUE self, VALUE value) { dbus_bool_t val; if (TYPE(value) == T_FALSE || TYPE(value) == T_NIL) val = FALSE; else val = TRUE; (MSG_GET(self), val); return Qnil; } |
#set_destination(service) ⇒ Object
Sets the message’s destination service.
Returns false if not enough memory.
290 291 292 293 294 |
# File 'ext/ruby-dbus-message.c', line 290 static VALUE cDBusMessage_set_destination(VALUE self, VALUE value) { MESSAGE_STR_SETTER_BODY(destination); } |
#set_error_name(name) ⇒ Object
Sets the name of the error (for an error message).
Returns false if not enough memory.
276 277 278 279 280 |
# File 'ext/ruby-dbus-message.c', line 276 static VALUE cDBusMessage_set_error_name(VALUE self, VALUE value) { MESSAGE_STR_SETTER_BODY(error_name); } |
#set_interface(interface) ⇒ Object
Sets the interface this message is being sent to (for a method call), or the interface a signal is being emitted from (for a signal).
Returns false if not enough memory.
247 248 249 250 251 |
# File 'ext/ruby-dbus-message.c', line 247 static VALUE cDBusMessage_set_interface(VALUE self, VALUE value) { MESSAGE_STR_SETTER_BODY(interface); } |
#set_member(member) ⇒ Object
Sets the interface member being invoked (for a method call), or emitted (for a signal).
Returns false if not enough memory.
262 263 264 265 266 |
# File 'ext/ruby-dbus-message.c', line 262 static VALUE cDBusMessage_set_member(VALUE self, VALUE value) { MESSAGE_STR_SETTER_BODY(member); } |
#set_no_reply(true|false) ⇒ nil
Indicates whether or not the message wants a reply. If set, there is no way to know whether a message arrived successfully at the destination.
412 413 414 415 416 417 418 419 420 421 422 423 |
# File 'ext/ruby-dbus-message.c', line 412 static VALUE cDBusMessage_set_no_reply(VALUE self, VALUE value) { dbus_bool_t val; if (TYPE(value) == T_FALSE || TYPE(value) == T_NIL) val = FALSE; else val = TRUE; (MSG_GET(self), val); return Qnil; } |
#set_path(object_path) ⇒ Object
Sets the object path this message is being sent to (for a method call), or the path a signal is being emitted from (for a signal).
Returns false if not enough memory.
232 233 234 235 236 |
# File 'ext/ruby-dbus-message.c', line 232 static VALUE cDBusMessage_set_path(VALUE self, VALUE value) { MESSAGE_STR_SETTER_BODY(path); } |
#set_reply_serial(serial) ⇒ true
Sets the serial number (see DbusMessage#get_serial) of the message that this message is a reply to.
562 563 564 565 566 567 568 |
# File 'ext/ruby-dbus-message.c', line 562 static VALUE cDBusMessage_set_reply_serial(VALUE self, VALUE serial) { if (!(MSG_GET(self), NUM2UINT(serial))) return Qfalse; return Qtrue; } |
#set_sender(service) ⇒ Object
Sets the service sending this message.
Returns false if not enough memory.
304 305 306 307 308 |
# File 'ext/ruby-dbus-message.c', line 304 static VALUE cDBusMessage_set_sender(VALUE self, VALUE value) { MESSAGE_STR_SETTER_BODY(sender); } |
#to_s ⇒ Object
87 88 89 |
# File 'lib/dbus/binding.rb', line 87 def to_s "#<#{self.class.to_s} path=\"#{get_path}\" interface=\"#{get_interface}\" member=\"#{get_member}\" sender=\"#{get_sender}\">" end |