diff options
author | Anders Carlsson <andersca@codefactory.se> | 2003-01-24 23:34:01 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@codefactory.se> | 2003-01-24 23:34:01 +0000 |
commit | dc6a61a15b2d9cdc6504753fa9eb0a718f99d6d8 (patch) | |
tree | 49c51aef2648d20651c44b63071ccfa441ae4f48 /dbus | |
parent | c514c719ec52bba3ad359580c989d0944d2f6ffe (diff) |
2003-01-25 Anders Carlsson <andersca@codefactory.se>
* dbus/dbus-connection.c: (dbus_connection_send_message):
Unlock the message in case it was sent earlier.
(dbus_connection_send_message_with_reply_and_block):
Remove the reply message from the list.
* dbus/dbus-marshal.c: (_dbus_demarshal_string_array):
Set array_len and new_pos correctly.
(_dbus_marshal_test):
Remove debug output.
* dbus/dbus-message-internal.h:
* dbus/dbus-message.c: (_dbus_message_get_reply_serial):
New function that returns the reply serial.
(_dbus_message_unlock):
New function that unlocks a message and resets its header.
(dbus_message_append_string_array),
(dbus_message_get_fields_valist),
(dbus_message_iter_get_field_type),
(dbus_message_iter_get_string_array),
(dbus_message_get_fields),
(dbus_message_append_fields_valist):
Handle string arrays.
(dbus_message_set_sender):
Make this function public since the bus daemon needs it.
(decode_header_data):
Set the reply serial to -1 initially.
* dbus/dbus-message.h:
Add dbus_message_set_sender.
Diffstat (limited to 'dbus')
-rw-r--r-- | dbus/dbus-connection.c | 7 | ||||
-rw-r--r-- | dbus/dbus-marshal.c | 11 | ||||
-rw-r--r-- | dbus/dbus-message-internal.h | 3 | ||||
-rw-r--r-- | dbus/dbus-message.c | 141 | ||||
-rw-r--r-- | dbus/dbus-message.h | 45 |
5 files changed, 158 insertions, 49 deletions
diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c index e8ff5b6a..9fcabb9c 100644 --- a/dbus/dbus-connection.c +++ b/dbus/dbus-connection.c @@ -644,6 +644,9 @@ dbus_connection_send_message (DBusConnection *connection, _dbus_verbose ("Message %p added to outgoing queue, %d pending to send\n", message, connection->n_outgoing); + /* Unlock the message, resetting its header. */ + _dbus_message_unlock (message); + serial = _dbus_connection_get_next_client_serial (connection); _dbus_message_set_client_serial (message, serial); @@ -728,9 +731,6 @@ dbus_connection_send_message_with_reply (DBusConnection *connection, * time. I think there probably has to be a loop: "while (!timeout_elapsed) * { check_for_reply_in_queue(); iterate_with_remaining_timeout(); }" * - * @todo need to remove the reply from the message queue, or someone - * else might process it again later. - * * @param connection the connection * @param message the message to send * @param timeout_milliseconds timeout in milliseconds or -1 for default @@ -771,6 +771,7 @@ dbus_connection_send_message_with_reply_and_block (DBusConnection *connectio if (_dbus_message_get_reply_serial (reply) == client_serial) { + _dbus_list_remove (&connection->incoming_messages, link); dbus_message_ref (message); if (result) diff --git a/dbus/dbus-marshal.c b/dbus/dbus-marshal.c index 148ce08e..9b9e9e62 100644 --- a/dbus/dbus-marshal.c +++ b/dbus/dbus-marshal.c @@ -718,9 +718,9 @@ _dbus_demarshal_string_array (DBusString *str, { int len, i, j; char **retval; - + len = _dbus_demarshal_uint32 (str, byte_order, pos, &pos); - + retval = dbus_new (char *, len); if (!retval) @@ -734,6 +734,12 @@ _dbus_demarshal_string_array (DBusString *str, goto error; } + if (new_pos) + *new_pos = pos; + + if (array_len) + *array_len = len; + return retval; error: @@ -1033,7 +1039,6 @@ _dbus_marshal_test (void) /* Marshal signed integer arrays */ if (!_dbus_marshal_int32_array (&str, DBUS_BIG_ENDIAN, array1, 3)) _dbus_assert_not_reached ("could not marshal integer array"); - _dbus_verbose_bytes_of_string (&str, 0, _dbus_string_get_length (&str)); array2 = _dbus_demarshal_int32_array (&str, DBUS_BIG_ENDIAN, pos, &pos, &len); printf ("length is: %d\n", len); if (len != 3) diff --git a/dbus/dbus-message-internal.h b/dbus/dbus-message-internal.h index 9507a0a4..8059ecdc 100644 --- a/dbus/dbus-message-internal.h +++ b/dbus/dbus-message-internal.h @@ -35,10 +35,9 @@ void _dbus_message_get_network_data (DBusMessage *message, const DBusString **body); void _dbus_message_lock (DBusMessage *message); +void _dbus_message_unlock (DBusMessage *message); void _dbus_message_set_client_serial (DBusMessage *message, dbus_int32_t client_serial); -void _dbus_message_set_sender (DBusMessage *message, - const char *sender); dbus_int32_t _dbus_message_get_reply_serial (DBusMessage *message); void _dbus_message_add_size_counter (DBusMessage *message, DBusCounter *counter); diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c index e491a7db..d5b1fb86 100644 --- a/dbus/dbus-message.c +++ b/dbus/dbus-message.c @@ -134,23 +134,7 @@ _dbus_message_set_client_serial (DBusMessage *message, dbus_int32_t _dbus_message_get_reply_serial (DBusMessage *message) { - return message->client_serial; -} - -/** - * Sets the message sender. This can only - * be done once on a message. - * - * @param message the message - * @param sender the sender - */ -void -_dbus_message_set_sender (DBusMessage *message, - const char *sender) -{ - _dbus_assert (message->sender == NULL); - - message->sender = _dbus_strdup (sender); + return message->reply_serial; } /** @@ -255,6 +239,25 @@ dbus_message_write_header (DBusMessage *message) } /** + * Unlocks a message so that it can be re-sent to another client. + * + * @see _dbus_message_lock + * @param message the message to unlock. + */ +void +_dbus_message_unlock (DBusMessage *message) +{ + if (!message->locked) + return; + + /* Restore header */ + _dbus_string_set_length (&message->header, 0); + + message->client_serial = -1; + message->locked = FALSE; +} + +/** * Locks a message. Allows checking that applications don't keep a * reference to a message in the outgoing queue and change it * underneath us. Messages are locked when they enter the outgoing @@ -522,6 +525,19 @@ dbus_message_append_fields_valist (DBusMessage *message, goto enomem; } break; + case DBUS_TYPE_STRING_ARRAY: + { + int len; + const char **data; + + data = va_arg (var_args, const char **); + len = va_arg (var_args, int); + + if (!dbus_message_append_string_array (message, data, len)) + goto enomem; + } + break; + default: _dbus_warn ("Unknown field type %d\n", type); } @@ -654,6 +670,31 @@ dbus_message_append_byte_array (DBusMessage *message, } /** + * Appends a string array to the message. + * + * @param message the message + * @param value the array + * @param len the length of the array + * @returns #TRUE on success + */ +dbus_bool_t +dbus_message_append_string_array (DBusMessage *message, + const char **value, + int len) +{ + _dbus_assert (!message->locked); + + if (!_dbus_string_append_byte (&message->body, DBUS_TYPE_STRING_ARRAY)) + { + _dbus_string_shorten (&message->body, 1); + return FALSE; + } + + return _dbus_marshal_string_array (&message->body, + DBUS_COMPILER_BYTE_ORDER, value, len); +} + +/** * Gets fields from a message given a variable argument list. * The variable argument list should contain the type of the * field followed by a pointer to where the value should be @@ -672,6 +713,8 @@ dbus_message_get_fields (DBusMessage *message, DBusResultCode retval; va_list var_args; + _dbus_verbose_bytes_of_string (&message->header, 0, + _dbus_string_get_length (&message->header)); va_start (var_args, first_field_type); retval = dbus_message_get_fields_valist (message, first_field_type, var_args); va_end (var_args); @@ -708,7 +751,7 @@ dbus_message_get_fields_valist (DBusMessage *message, iter = dbus_message_get_fields_iter (message); if (iter == NULL) - return FALSE; + return DBUS_RESULT_NO_MEMORY; spec_type = first_field_type; i = 0; @@ -775,10 +818,10 @@ dbus_message_get_fields_valist (DBusMessage *message, case DBUS_TYPE_BYTE_ARRAY: { - char **ptr; + unsigned char **ptr; int *len; - ptr = va_arg (var_args, char **); + ptr = va_arg (var_args, unsigned char **); len = va_arg (var_args, int *); *ptr = dbus_message_iter_get_byte_array (iter, len); @@ -788,6 +831,21 @@ dbus_message_get_fields_valist (DBusMessage *message, break; } + case DBUS_TYPE_STRING_ARRAY: + { + char ***ptr; + int *len; + + ptr = va_arg (var_args, char ***); + len = va_arg (var_args, int *); + + *ptr = dbus_message_iter_get_string_array (iter, len); + + if (!*ptr) + return DBUS_RESULT_NO_MEMORY; + + break; + } default: _dbus_warn ("Unknown field type %d\n", spec_type); } @@ -933,7 +991,7 @@ dbus_message_iter_get_field_type (DBusMessageIter *iter) _dbus_string_get_const_data_len (&iter->message->body, &data, iter->pos, 1); - if (*data > DBUS_TYPE_INVALID && *data <= DBUS_TYPE_STRING) + if (*data > DBUS_TYPE_INVALID && *data <= DBUS_TYPE_STRING_ARRAY) return *data; return DBUS_TYPE_INVALID; @@ -1027,6 +1085,43 @@ dbus_message_iter_get_byte_array (DBusMessageIter *iter, iter->pos + 1, NULL, len); } +/** + * Returns the string array that the iterator may point to. + * Note that you need to check that the iterator points + * to a byte array prior to using this function. + * + * @todo this function should probably take "char **" as + * an out param argument, and return boolean or result code. + * + * @param iter the iterator + * @param len return location for length of byte array + * @returns the byte array + */ +char ** +dbus_message_iter_get_string_array (DBusMessageIter *iter, + int *len) +{ + _dbus_assert (dbus_message_iter_get_field_type (iter) == DBUS_TYPE_STRING_ARRAY); + + return _dbus_demarshal_string_array (&iter->message->body, iter->message->byte_order, + iter->pos + 1, NULL, len); +} + +/** + * Sets the message sender. + * + * @param message the message + * @param sender the sender + */ +void +dbus_message_set_sender (DBusMessage *message, + const char *sender) +{ + _dbus_assert (!message->locked); + + message->sender = _dbus_strdup (sender); +} + /** @} */ /** @@ -1224,6 +1319,7 @@ decode_header_data (DBusString *data, /* First demarshal the client serial */ *client_serial = _dbus_demarshal_int32 (data, byte_order, 12, &pos); + *reply_serial = -1; *service = NULL; *name = NULL; *sender = NULL; @@ -1376,11 +1472,10 @@ _dbus_message_loader_return_buffer (DBusMessageLoader *loader, return; } - message = dbus_message_new (service, name); message->reply_serial = reply_serial; message->client_serial = client_serial; - _dbus_message_set_sender (message, sender); + dbus_message_set_sender (message, sender); dbus_free (service); dbus_free (name); diff --git a/dbus/dbus-message.h b/dbus/dbus-message.h index 7d5ea21b..f5ef9159 100644 --- a/dbus/dbus-message.h +++ b/dbus/dbus-message.h @@ -44,26 +44,33 @@ DBusMessage* dbus_message_new_reply (const char *name, void dbus_message_ref (DBusMessage *message); void dbus_message_unref (DBusMessage *message); -const char* dbus_message_get_name (DBusMessage *message); -const char* dbus_message_get_service (DBusMessage *message); +const char* dbus_message_get_name (DBusMessage *message); +const char* dbus_message_get_service (DBusMessage *message); +void dbus_message_set_sender (DBusMessage *message, + const char *sender); -dbus_bool_t dbus_message_append_fields (DBusMessage *message, - int first_field_type, + +dbus_bool_t dbus_message_append_fields (DBusMessage *message, + int first_field_type, ...); -dbus_bool_t dbus_message_append_fields_valist (DBusMessage *message, - int first_field_type, - va_list var_args); -dbus_bool_t dbus_message_append_int32 (DBusMessage *message, - dbus_int32_t value); -dbus_bool_t dbus_message_append_uint32 (DBusMessage *message, - dbus_uint32_t value); -dbus_bool_t dbus_message_append_double (DBusMessage *message, - double value); -dbus_bool_t dbus_message_append_string (DBusMessage *message, - const char *value); -dbus_bool_t dbus_message_append_byte_array (DBusMessage *message, - unsigned const char *value, - int len); +dbus_bool_t dbus_message_append_fields_valist (DBusMessage *message, + int first_field_type, + va_list var_args); +dbus_bool_t dbus_message_append_int32 (DBusMessage *message, + dbus_int32_t value); +dbus_bool_t dbus_message_append_uint32 (DBusMessage *message, + dbus_uint32_t value); +dbus_bool_t dbus_message_append_double (DBusMessage *message, + double value); +dbus_bool_t dbus_message_append_string (DBusMessage *message, + const char *value); +dbus_bool_t dbus_message_append_byte_array (DBusMessage *message, + unsigned const char *value, + int len); +dbus_bool_t dbus_message_append_string_array (DBusMessage *message, + const char **value, + int len); + DBusMessageIter *dbus_message_get_fields_iter (DBusMessage *message); @@ -86,6 +93,8 @@ double dbus_message_iter_get_double (DBusMessageIter *iter); char * dbus_message_iter_get_string (DBusMessageIter *iter); unsigned char * dbus_message_iter_get_byte_array (DBusMessageIter *iter, int *len); +char ** dbus_message_iter_get_string_array (DBusMessageIter *iter, + int *len) |