+2003-01-07 Anders Carlsson <andersca@codefactory.se>
+
+ * dbus/dbus-marshal.c: (_dbus_marshal_string),
+ (_dbus_demarshal_string), (_dbus_marshal_test):
+ * dbus/dbus-marshal.h:
+ * dbus/dbus-message.c: (dbus_message_get_name),
+ Document these functions.
+
+ (dbus_message_append_int32), (dbus_message_append_uint32),
+ (dbus_message_append_double), (dbus_message_append_string),
+ (dbus_message_append_byte_array):
+ * dbus/dbus-message.h:
+ Add functions for adding message fields of different types.
+
+ * dbus/dbus-protocol.h:
+ Add the different types.
+
2003-01-05 Havoc Pennington <hp@pobox.com>
* bus/connection.c: implement routines for handling connections,
* @{
*/
+/**
+ * Marshals a double value.
+ *
+ * @param str the string to append the marshalled value to
+ * @param byte_order the byte order to use
+ * @param value the value
+ * @returns #TRUE on success
+ */
dbus_bool_t
_dbus_marshal_double (DBusString *str,
int byte_order,
return _dbus_string_append_len (str, (const char *)&value, sizeof (double));
}
+/**
+ * Marshals a 32 bit signed integer value.
+ *
+ * @param str the string to append the marshalled value to
+ * @param byte_order the byte order to use
+ * @param value the value
+ * @returns #TRUE on success
+ */
dbus_bool_t
_dbus_marshal_int32 (DBusString *str,
int byte_order,
return _dbus_string_append_len (str, (const char *)&value, sizeof (dbus_int32_t));
}
+/**
+ * Marshals a 32 bit unsigned integer value.
+ *
+ * @param str the string to append the marshalled value to
+ * @param byte_order the byte order to use
+ * @param value the value
+ * @returns #TRUE on success
+ */
dbus_bool_t
_dbus_marshal_uint32 (DBusString *str,
int byte_order,
return _dbus_string_append_len (str, (const char *)&value, sizeof (dbus_uint32_t));
}
+/**
+ * Marshals a UTF-8 string
+ *
+ * @param str the string to append the marshalled value to
+ * @param byte_order the byte order to use
+ * @param value the string
+ * @returns #TRUE on success
+ */
dbus_bool_t
-_dbus_marshal_utf8_string (DBusString *str,
- int byte_order,
- const char *value)
+_dbus_marshal_string (DBusString *str,
+ int byte_order,
+ const char *value)
{
int len;
return _dbus_string_append_len (str, value, len + 1);
}
+/**
+ * Marshals a byte array
+ *
+ * @param str the string to append the marshalled value to
+ * @param byte_order the byte order to use
+ * @param value the byte array
+ * @param len the length of the byte array
+ * @returns #TRUE on success
+ */
dbus_bool_t
_dbus_marshal_byte_array (DBusString *str,
int byte_order,
return _dbus_string_append_len (str, value, len);
}
+/**
+ * Demarshals a double.
+ *
+ * @param str the string containing the data
+ * @param byte_order the byte order
+ * @param pos the position in the string
+ * @param new_pos the new position of the string
+ * @returns the demarshaled double.
+ */
double
_dbus_demarshal_double (DBusString *str,
int byte_order,
return retval;
}
+/**
+ * Demarshals a 32 bit signed integer.
+ *
+ * @param str the string containing the data
+ * @param byte_order the byte order
+ * @param pos the position in the string
+ * @param new_pos the new position of the string
+ * @returns the demarshaled integer.
+ */
dbus_int32_t
_dbus_demarshal_int32 (DBusString *str,
int byte_order,
return unpack_int32 (byte_order, buffer);
}
+/**
+ * Demarshals a 32 bit unsigned integer.
+ *
+ * @param str the string containing the data
+ * @param byte_order the byte order
+ * @param pos the position in the string
+ * @param new_pos the new position of the string
+ * @returns the demarshaled integer.
+ */
dbus_uint32_t
_dbus_demarshal_uint32 (DBusString *str,
int byte_order,
return unpack_uint32 (byte_order, buffer);
}
+/**
+ * Demarshals an UTF-8 string.
+ *
+ * @todo Should we check the string to make sure
+ * that it's valid UTF-8, and maybe "fix" the string
+ * if it's broken?
+ *
+ * @param str the string containing the data
+ * @param byte_order the byte order
+ * @param pos the position in the string
+ * @param new_pos the new position of the string
+ * @returns the demarshaled string.
+ */
char *
-_dbus_demarshal_utf8_string (DBusString *str,
- int byte_order,
- int pos,
- int *new_pos)
+_dbus_demarshal_string (DBusString *str,
+ int byte_order,
+ int pos,
+ int *new_pos)
{
int len;
char *retval;
/* Marshal strings */
tmp1 = "This is the dbus test string";
- if (!_dbus_marshal_utf8_string (&str, DBUS_BIG_ENDIAN, tmp1))
+ if (!_dbus_marshal_string (&str, DBUS_BIG_ENDIAN, tmp1))
_dbus_assert_not_reached ("could not marshal string");
- tmp2 = _dbus_demarshal_utf8_string (&str, DBUS_BIG_ENDIAN, pos, &pos);
+ tmp2 = _dbus_demarshal_string (&str, DBUS_BIG_ENDIAN, pos, &pos);
_dbus_assert (strcmp (tmp1, tmp2) == 0);
dbus_free (tmp2);
tmp1 = "This is the dbus test string";
- if (!_dbus_marshal_utf8_string (&str, DBUS_LITTLE_ENDIAN, tmp1))
+ if (!_dbus_marshal_string (&str, DBUS_LITTLE_ENDIAN, tmp1))
_dbus_assert_not_reached ("could not marshal string");
- tmp2 = _dbus_demarshal_utf8_string (&str, DBUS_LITTLE_ENDIAN, pos, &pos);
+ tmp2 = _dbus_demarshal_string (&str, DBUS_LITTLE_ENDIAN, pos, &pos);
_dbus_assert (strcmp (tmp1, tmp2) == 0);
dbus_free (tmp2);
#define DBUS_COMPILER_BYTE_ORDER DBUS_LITTLE_ENDIAN
#endif
-dbus_bool_t _dbus_marshal_double (DBusString *str,
- int byte_order,
- double value);
-dbus_bool_t _dbus_marshal_int32 (DBusString *str,
- int byte_order,
- dbus_int32_t value);
-dbus_bool_t _dbus_marshal_uint32 (DBusString *str,
- int byte_order,
- dbus_uint32_t value);
-dbus_bool_t _dbus_marshal_utf8_string (DBusString *str,
- int byte_order,
- const char *value);
-dbus_bool_t _dbus_marshal_byte_array (DBusString *str,
- int byte_order,
- const unsigned char *value,
- int len);
+dbus_bool_t _dbus_marshal_double (DBusString *str,
+ int byte_order,
+ double value);
+dbus_bool_t _dbus_marshal_int32 (DBusString *str,
+ int byte_order,
+ dbus_int32_t value);
+dbus_bool_t _dbus_marshal_uint32 (DBusString *str,
+ int byte_order,
+ dbus_uint32_t value);
+dbus_bool_t _dbus_marshal_string (DBusString *str,
+ int byte_order,
+ const char *value);
+dbus_bool_t _dbus_marshal_byte_array (DBusString *str,
+ int byte_order,
+ const unsigned char *value,
+ int len);
+double _dbus_demarshal_double (DBusString *str,
+ int byte_order,
+ int pos,
+ int *new_pos);
+dbus_int32_t _dbus_demarshal_int32 (DBusString *str,
+ int byte_order,
+ int pos,
+ int *new_pos);
+dbus_uint32_t _dbus_demarshal_uint32 (DBusString *str,
+ int byte_order,
+ int pos,
+ int *new_pos);
+char * _dbus_demarshal_string (DBusString *str,
+ int byte_order,
+ int pos,
+ int *new_pos);
-double _dbus_demarshal_double (DBusString *str,
- int byte_order,
- int pos,
- int *new_pos);
-dbus_int32_t _dbus_demarshal_int32 (DBusString *str,
- int byte_order,
- int pos,
- int *new_pos);
-dbus_uint32_t _dbus_demarshal_uint32 (DBusString *str,
- int byte_order,
- int pos,
- int *new_pos);
-char * _dbus_demarshal_utf8_string (DBusString *str,
- int byte_order,
- int pos,
- int *new_pos);
*/
#include "dbus-internals.h"
+#include "dbus-marshal.h"
#include "dbus-message.h"
#include "dbus-message-internal.h"
#include "dbus-memory.h"
/**
* Gets the name of a message.
+ *
* @param message the message
* @returns the message name (should not be freed)
*/
return NULL;
}
+/**
+ * Appends a 32 bit signed integer to the message.
+ *
+ * @param message the message
+ * @param value the integer value
+ * @returns #TRUE on success
+ */
+dbus_bool_t
+dbus_message_append_int32 (DBusMessage *message,
+ dbus_int32_t value)
+{
+ _dbus_assert (message != NULL);
+ _dbus_assert (!message->locked);
+
+ if (!_dbus_string_append_byte (&message->body, DBUS_TYPE_INT32))
+ return FALSE;
+
+ return _dbus_marshal_int32 (&message->body,
+ DBUS_COMPILER_BYTE_ORDER, value);
+}
+
+/**
+ * Appends a 32 bit unsigned integer to the message.
+ *
+ * @param message the message
+ * @param value the integer value
+ * @returns #TRUE on success
+ */
+dbus_bool_t
+dbus_message_append_uint32 (DBusMessage *message,
+ dbus_uint32_t value)
+{
+ _dbus_assert (message != NULL);
+ _dbus_assert (!message->locked);
+
+ if (!_dbus_string_append_byte (&message->body, DBUS_TYPE_UINT32))
+ return FALSE;
+
+ return _dbus_marshal_uint32 (&message->body,
+ DBUS_COMPILER_BYTE_ORDER, value);
+}
+
+/**
+ * Appends a double value to the message.
+ *
+ * @param message the message
+ * @param value the double value
+ * @returns #TRUE on success
+ */
+dbus_bool_t
+dbus_message_append_double (DBusMessage *message,
+ double value)
+{
+ _dbus_assert (message != NULL);
+ _dbus_assert (!message->locked);
+
+ if (!_dbus_string_append_byte (&message->body, DBUS_TYPE_INT32))
+ return FALSE;
+
+ return _dbus_marshal_double (&message->body,
+ DBUS_COMPILER_BYTE_ORDER, value);
+}
+
+/**
+ * Appends a UTF-8 string to the message.
+ *
+ * @param message the message
+ * @param value the string
+ * @returns #TRUE on success
+ */
+dbus_bool_t
+dbus_message_append_string (DBusMessage *message,
+ const char *value)
+{
+ _dbus_assert (message != NULL);
+ _dbus_assert (!message->locked);
+ _dbus_assert (value != NULL);
+
+ if (!_dbus_string_append_byte (&message->body, DBUS_TYPE_UTF8_STRING))
+ return FALSE;
+
+ return _dbus_marshal_string (&message->body,
+ DBUS_COMPILER_BYTE_ORDER, value);
+}
+
+/**
+ * Appends a byte 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_byte_array (DBusMessage *message,
+ unsigned const char *value,
+ int len)
+{
+ _dbus_assert (message != NULL);
+ _dbus_assert (!message->locked);
+ _dbus_assert (value != NULL);
+
+ if (!_dbus_string_append_byte (&message->body, DBUS_TYPE_BYTE_ARRAY))
+ return FALSE;
+
+ return _dbus_marshal_byte_array (&message->body,
+ DBUS_COMPILER_BYTE_ORDER, value, len);
+}
+
/** @} */
/**
const char* dbus_message_get_name (DBusMessage *message);
+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_END_DECLS;
#endif /* DBUS_MESSAGE_H */
#define DBUS_LITTLE_ENDIAN ('l') /* LSB first */
#define DBUS_BIG_ENDIAN ('B') /* MSB first */
+/* Data types */
+#define DBUS_TYPE_INVALID 0
+#define DBUS_TYPE_INT32 1
+#define DBUS_TYPE_UINT32 2
+#define DBUS_TYPE_DOUBLE 3
+#define DBUS_TYPE_INT32_ARRAY 4
+#define DBUS_TYPE_UINT32_ARRAY 5
+#define DBUS_TYPE_DOUBLE_ARRAY 6
+#define DBUS_TYPE_BYTE_ARRAY 7
+#define DBUS_TYPE_UTF8_STRING 8
+
#ifdef __cplusplus
}
#endif