Finalized tests
[profile/ivi/common-api-dbus-runtime.git] / dbus-DBusMessage-add-support-for-custom-marshaling.patch
1 From 467a2e307462b02865b35397c572b6048c2934e2 Mon Sep 17 00:00:00 2001
2 From: Aleksandar Kanchev <kanchev@itestra.com>
3 Date: Mon, 9 Jul 2012 18:09:04 +0200
4 Subject: [PATCH] DBusMessage: add support for custom marshaling
5
6 Add functions to support querying and manipulating the message body and
7 signature. This is useful for code generators, which can generate custom
8 marshaling functions based on a given IDL. Those functions tend to be
9 optimized and faster than the generic iterator based marshaling.
10 ---
11  dbus/dbus-message.c |  143 +++++++++++++++++++++++++++++++++++----------------
12  dbus/dbus-message.h |   13 +++++
13  dbus/dbus-string.c  |   16 ++++++
14  dbus/dbus-string.h  |    4 ++
15  4 files changed, 132 insertions(+), 44 deletions(-)
16
17 diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c
18 index 24ef5ac..fbacfba 100644
19 --- a/dbus/dbus-message.c
20 +++ b/dbus/dbus-message.c
21 @@ -356,50 +356,6 @@ set_or_delete_string_field (DBusMessage *message,
22                                           &value);
23  }
24  
25 -#if 0
26 -/* Probably we don't need to use this */
27 -/**
28 - * Sets the signature of the message, i.e. the arguments in the
29 - * message payload. The signature includes only "in" arguments for
30 - * #DBUS_MESSAGE_TYPE_METHOD_CALL and only "out" arguments for
31 - * #DBUS_MESSAGE_TYPE_METHOD_RETURN, so is slightly different from
32 - * what you might expect (it does not include the signature of the
33 - * entire C++-style method).
34 - *
35 - * The signature is a string made up of type codes such as
36 - * #DBUS_TYPE_INT32. The string is terminated with nul (nul is also
37 - * the value of #DBUS_TYPE_INVALID). The macros such as
38 - * #DBUS_TYPE_INT32 evaluate to integers; to assemble a signature you
39 - * may find it useful to use the string forms, such as
40 - * #DBUS_TYPE_INT32_AS_STRING.
41 - *
42 - * An "unset" or #NULL signature is considered the same as an empty
43 - * signature. In fact dbus_message_get_signature() will never return
44 - * #NULL.
45 - *
46 - * @param message the message
47 - * @param signature the type signature or #NULL to unset
48 - * @returns #FALSE if no memory
49 - */
50 -static dbus_bool_t
51 -_dbus_message_set_signature (DBusMessage *message,
52 -                             const char  *signature)
53 -{
54 -  _dbus_return_val_if_fail (message != NULL, FALSE);
55 -  _dbus_return_val_if_fail (!message->locked, FALSE);
56 -  _dbus_return_val_if_fail (signature == NULL ||
57 -                            _dbus_check_is_valid_signature (signature));
58 -  /* can't delete the signature if you have a message body */
59 -  _dbus_return_val_if_fail (_dbus_string_get_length (&message->body) == 0 ||
60 -                            signature != NULL);
61 -
62 -  return set_or_delete_string_field (message,
63 -                                     DBUS_HEADER_FIELD_SIGNATURE,
64 -                                     DBUS_TYPE_SIGNATURE,
65 -                                     signature);
66 -}
67 -#endif
68 -
69  /* Message Cache
70   *
71   * We cache some DBusMessage to reduce the overhead of allocating
72 @@ -3370,6 +3326,47 @@ dbus_message_get_sender (DBusMessage *message)
73  }
74  
75  /**
76 + * Sets the signature of the message, i.e. the arguments in the
77 + * message payload. The signature includes only "in" arguments for
78 + * #DBUS_MESSAGE_TYPE_METHOD_CALL and only "out" arguments for
79 + * #DBUS_MESSAGE_TYPE_METHOD_RETURN, so is slightly different from
80 + * what you might expect (it does not include the signature of the
81 + * entire C++-style method).
82 + *
83 + * The signature is a string made up of type codes such as
84 + * #DBUS_TYPE_INT32. The string is terminated with nul (nul is also
85 + * the value of #DBUS_TYPE_INVALID). The macros such as
86 + * #DBUS_TYPE_INT32 evaluate to integers; to assemble a signature you
87 + * may find it useful to use the string forms, such as
88 + * #DBUS_TYPE_INT32_AS_STRING.
89 + *
90 + * An "unset" or #NULL signature is considered the same as an empty
91 + * signature. In fact dbus_message_get_signature() will never return
92 + * #NULL.
93 + *
94 + * @param message the message
95 + * @param signature the type signature or #NULL to unset
96 + * @returns #FALSE if no memory
97 + */
98 +dbus_bool_t
99 +dbus_message_set_signature (DBusMessage *message,
100 +                            const char  *signature)
101 +{
102 +  _dbus_return_val_if_fail (message != NULL, FALSE);
103 +  _dbus_return_val_if_fail (!message->locked, FALSE);
104 +  _dbus_return_val_if_fail (signature == NULL ||
105 +                            _dbus_check_is_valid_signature (signature), FALSE);
106 +  /* can't delete the signature if you have a message body */
107 +  _dbus_return_val_if_fail (_dbus_string_get_length (&message->body) == 0 ||
108 +                            signature != NULL, FALSE);
109 +
110 +  return set_or_delete_string_field (message,
111 +                                     DBUS_HEADER_FIELD_SIGNATURE,
112 +                                     DBUS_TYPE_SIGNATURE,
113 +                                     signature);
114 +}
115 +
116 +/**
117   * Gets the type signature of the message, i.e. the arguments in the
118   * message payload. The signature includes only "in" arguments for
119   * #DBUS_MESSAGE_TYPE_METHOD_CALL and only "out" arguments for
120 @@ -4519,6 +4516,64 @@ dbus_message_type_to_string (int type)
121  }
122  
123  /**
124 + * Returns pointer to the buffer used to store the message body.
125 + *
126 + * @param message the message
127 + * @return pointer to the message body memory
128 + */
129 +char*
130 +dbus_message_get_body (DBusMessage *message) {
131 +  _dbus_return_val_if_fail (message != NULL, NULL);
132 +
133 +  return _dbus_string_get_data(&(message->body));
134 +}
135 +
136 +/**
137 + * Adjust the length of the message body buffer. The memory will be reallocated
138 + * if the new length is bigger than the already allocated size.
139 + *
140 + * @see dbus_message_get_body_allocated
141 + * @param message the message
142 + * @param length the new length of the body
143 + * @return #TRUE if successful
144 + */
145 +dbus_bool_t
146 +dbus_message_set_body_length (DBusMessage *message,
147 +                              int length) {
148 +  _dbus_return_val_if_fail (message != NULL, FALSE);
149 +  _dbus_return_val_if_fail (length >= 0, FALSE);
150 +
151 +  return _dbus_string_set_length(&(message->body), length);
152 +}
153 +
154 +/**
155 + * Gets the length of the message body buffer.
156 + *
157 + * @param message the message
158 + * @param length the new length of the body
159 + * @return the length of the body buffer
160 + */
161 +int
162 +dbus_message_get_body_length (DBusMessage *message) {
163 +  _dbus_return_val_if_fail (message != NULL, 0);
164 +
165 +  return _dbus_string_get_length(&(message->body));
166 +}
167 +
168 +/**
169 + * Gets the allocated memory size used to hold the message body.
170 + *
171 + * @param message the message
172 + * @return size of the allocated message body memory
173 + */
174 +int
175 +dbus_message_get_body_allocated (DBusMessage *message) {
176 +  _dbus_return_val_if_fail (message != NULL, 0);
177 +
178 +  return _dbus_string_get_allocated(&(message->body));
179 +}
180 +
181 +/**
182   * Turn a DBusMessage into the marshalled form as described in the D-Bus
183   * specification.
184   *
185 diff --git a/dbus/dbus-message.h b/dbus/dbus-message.h
186 index 5500492..55388ac 100644
187 --- a/dbus/dbus-message.h
188 +++ b/dbus/dbus-message.h
189 @@ -138,6 +138,9 @@ dbus_bool_t   dbus_message_set_sender       (DBusMessage   *message,
190  DBUS_EXPORT
191  const char*   dbus_message_get_sender       (DBusMessage   *message);
192  DBUS_EXPORT
193 +dbus_bool_t   dbus_message_set_signature    (DBusMessage   *message,
194 +                                             const char    *signature);
195 +DBUS_EXPORT
196  const char*   dbus_message_get_signature    (DBusMessage   *message);
197  DBUS_EXPORT
198  void          dbus_message_set_no_reply     (DBusMessage   *message,
199 @@ -264,6 +267,16 @@ void        dbus_message_iter_abandon_container  (DBusMessageIter *iter,
200                                                    DBusMessageIter *sub);
201  
202  DBUS_EXPORT
203 +char*       dbus_message_get_body           (DBusMessage   *message);
204 +DBUS_EXPORT
205 +dbus_bool_t dbus_message_set_body_length    (DBusMessage   *message,
206 +                                             int length);
207 +DBUS_EXPORT
208 +int         dbus_message_get_body_length    (DBusMessage   *message);
209 +DBUS_EXPORT
210 +int         dbus_message_get_body_allocated (DBusMessage   *message);
211 +
212 +DBUS_EXPORT
213  void dbus_message_lock    (DBusMessage  *message);
214  
215  DBUS_EXPORT
216 diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c
217 index e2eb93b..d8628ba 100644
218 --- a/dbus/dbus-string.c
219 +++ b/dbus/dbus-string.c
220 @@ -848,6 +848,22 @@ _dbus_string_get_length (const DBusString  *str)
221  }
222  #endif /* !_dbus_string_get_length */
223  
224 +/* Only have the function if we don't have the macro */
225 +#ifndef _dbus_string_get_allocated
226 +/**
227 + * Gets the allocated length of a string (not including nul termination).
228 + *
229 + * @returns the allocated length.
230 + */
231 +int
232 +_dbus_string_get_allocated(const DBusString  *str)
233 +{
234 +  DBUS_CONST_STRING_PREAMBLE (str);
235 +
236 +  return real->allocated;
237 +}
238 +#endif /* !_dbus_string_get_allocated */
239 +
240  /**
241   * Makes a string longer by the given number of bytes.  Checks whether
242   * adding additional_length to the current length would overflow an
243 diff --git a/dbus/dbus-string.h b/dbus/dbus-string.h
244 index 2f1ed31..490aea6 100644
245 --- a/dbus/dbus-string.h
246 +++ b/dbus/dbus-string.h
247 @@ -62,6 +62,7 @@ struct DBusString
248   */
249  #define _dbus_string_get_data(s) ((char*)(((DBusString*)(s))->dummy1))
250  #define _dbus_string_get_length(s) (((DBusString*)(s))->dummy2)
251 +#define _dbus_string_get_allocated(s) (((DBusString*)(s))->dummy3 - _DBUS_STRING_ALLOCATION_PADDING)
252  #define _dbus_string_set_byte(s, i, b) ((((unsigned char*)(((DBusString*)(s))->dummy1))[(i)]) = (unsigned char) (b))
253  #define _dbus_string_get_byte(s, i) (((const unsigned char*)(((DBusString*)(s))->dummy1))[(i)])
254  #define _dbus_string_get_const_data(s) ((const char*)(((DBusString*)(s))->dummy1))
255 @@ -131,6 +132,9 @@ void          _dbus_string_copy_to_buffer_with_nul (const DBusString  *str,
256  #ifndef _dbus_string_get_length
257  int           _dbus_string_get_length            (const DBusString  *str);
258  #endif /* !_dbus_string_get_length */
259 +#ifndef _dbus_string_get_allocated
260 +int           _dbus_string_get_allocated         (const DBusString  *str);
261 +#endif /* !_dbus_string_get_allocated */
262  
263  dbus_bool_t   _dbus_string_lengthen              (DBusString        *str,
264                                                    int                additional_length);
265 -- 
266 1.7.10.2
267