2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
26 * @addtogroup CORE_LIB_PARCEL_MODULE
35 * @brief The parcel handle.
38 typedef void *parcel_h;
41 * @brief The interface for converting data to/from a parcel.
45 void (*to)(parcel_h parcel, void *data);
46 void (*from)(parcel_h parcel, void *data);
50 * @brief Enumeration for error codes for a parcel.
54 PARCEL_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
55 PARCEL_ERROR_ILLEGAL_BYTE_SEQ = TIZEN_ERROR_ILLEGAL_BYTE_SEQ, /**< Illegal byte sequence */
56 PARCEL_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
57 PARCEL_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA, /**< No data available */
58 PARCEL_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
62 * @brief Creates a parcel handle.
64 * @remarks You MUST release @a parcel using parcel_destroy().
65 * @param[out] parcel The parcel handle that is newly created
66 * @return @c 0 on success,
67 * otherwise a negative error value
68 * @retval #PARCEL_ERROR_NONE Successful
69 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
70 * @retval #PARCEL_ERROR_OUT_OF_MEMORY Out of memory
71 * @see parcel_destroy()
73 int parcel_create(parcel_h *parcel);
76 * @brief Destroys a parcel handle.
78 * @param[in] parcel The parcel handle
79 * @return @c 0 on success,
80 * otherwise a negative error value
81 * @retval #PARCEL_ERROR_NONE Successful
82 * @retval #PARCEL_ERROR_INVALID_PARAMETER
83 * @see parcel_create()
85 int parcel_destroy(parcel_h parcel);
88 * @brief Creates and returns a copy of the given parcel handle.
90 * @remarks A newly created parcel should be destroyed by calling the parcel_destroy() if it is no longer needed.
91 * @param[in] parcel The parcel handle
92 * @param[out] If successful, a newly created parcel handle will be returned
93 * @return @c 0 on success,
94 * otherwise a negative error value
95 * @retval #PARCEL_ERROR_NONE Successful
96 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
97 * @see parcel_destroy()
99 int parcel_clone(parcel_h parcel, parcel_h *clone);
102 * @brief Writes bytes to the parcel handle.
104 * @param[in] parcel The parcel handle
105 * @param[in] buf The array buffer to write
106 * @param[in] size The size of bytes to write
107 * @return @c 0 on success,
108 * otherwise a negative error value
109 * @retval #PARCEL_ERROR_NONE Successful
110 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
111 * @see parcel_burst_read()
113 int parcel_burst_write(parcel_h parcel, const void *buf, uint32_t size);
116 * @brief Reads bytes from the parcel handle.
118 * @param[in] parcel The parcel handle
119 * @param[out] buf The array buffer to read
120 * @param[in] size The size of bytes to read
121 * @return @c 0 on success,
122 * otherwise a negative error value
123 * @retval #PARCEL_ERROR_NONE Successful
124 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
125 * @retval #PARCEL_ERROR_NO_DATA No data available
126 * @retval #PARCEL_ERROR_ILLEGAL_BYTE_SEQ Illegal byte sequence
127 * @see parcel_burst_write()
129 int parcel_burst_read(parcel_h parcel, void *buf, uint32_t size);
132 * @brief Writes a boolean value into the parcel handle.
134 * @param[in] parcel The parcel handle
135 * @param[in] val The boolean value
136 * @return @c 0 on success,
137 * otherwise a negative error value
138 * @retval #PARCEL_ERROR_NONE Successful
139 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
140 * @see parcel_read_bool()
142 int parcel_write_bool(parcel_h parcel, bool val);
145 * @brief Writes a byte value into the parcel handle.
147 * @param[in] parcel The parcel handle
148 * @param[in] val The byte value
149 * @return @c 0 on success,
150 * otherwise a negative error value
151 * @retval #PARCEL_ERROR_NONE Successful
152 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
153 * @see parcel_read_uint8()
155 int parcel_write_byte(parcel_h parcel, char val);
158 * @brief Writes an unsigned short value into the parcel handle.
160 * @param[in] parcel The parcel handle
161 * @param[in] val The unsigned short value
162 * @return @c 0 on success,
163 * otherwise a negative error value
164 * @retval #PARCEL_ERROR_NONE Successful
165 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
166 * @see parcel_read_uint16()
168 int parcel_write_uint16(parcel_h parcel, uint16_t val);
171 * @brief Writes an unsigned integer value into the parcel handle.
173 * @param[in] parcel The parcel handle
174 * @param[in] val The unsigned integer value
175 * @return @c 0 on success,
176 * otherwise a negative error value
177 * @retval #PARCEL_ERROR_NONE Successful
178 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
179 * @see parcel_read_uint32()
181 int parcel_write_uint32(parcel_h parcel, uint32_t val);
184 * @brief Writes an unsigned long long integer value into the parcel handle.
186 * @param[in] parcel The parcel handle
187 * @param[in] val The unsigned long long interger value
188 * @return @c 0 on success,
189 * otherwise a negative error value
190 * @retval #PARCEL_ERROR_NONE Successful
191 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
192 * @see parcel_read_uint64()
194 int parcel_write_uint64(parcel_h parcel, uint64_t val);
197 * @brief Writes a signed short value into the parcel handle.
199 * @param[in] parcel The parcel handle
200 * @param[in] val The signed short value
201 * @return @c 0 on success,
202 * otherwise a negative error value
203 * @retval #PARCEL_ERROR_NONE Successful
204 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
205 * @see parcel_read_int16()
207 int parcel_write_int16(parcel_h parcel, int16_t val);
210 * @brief Writes a signed integer value into the parcel handle.
212 * @param[in] parcel The parcel handle
213 * @param[in] val The signed integer value
214 * @return @c 0 on success,
215 * otherwise a negative error value
216 * @retval #PARCEL_ERROR_NONE Successful
217 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
218 * @see parcel_read_int32()
220 int parcel_write_int32(parcel_h parcel, int32_t val);
223 * @brief Writes a signed long long integer value into the parcel handle.
225 * @param[in] parcel The parcel handle
226 * @param[in] val The signedi long long integer value
227 * @return @c 0 on success,
228 * otherwise a negative error value
229 * @retval #PARCEL_ERROR_NONE Successful
230 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
231 * @see parcel_read_int64()
233 int parcel_write_int64(parcel_h parcel, int64_t val);
236 * @brief Writes a floating point value into the parcel handle.
238 * @param[in] parcel The parcel handle
239 * @param[in] val The floating point value
240 * @return @c 0 on success,
241 * otherwise a negative error value
242 * @retval #PARCEL_ERROR_NONE Successful
243 * @retval #PARCLE_ERROR_INVALID_PARAMETER Invalid parameter
244 * @see parcel_read_float()
246 int parcel_write_float(parcel_h parcel, float val);
249 * @brief Writes a double precision floating point value into the parcel handle.
251 * @param[in] parcel The parcel handle
252 * @param[in] val The double precision floating point value
253 * @return @c 0 on success,
254 * otherwise a negative error value
255 * @retval #PARCEL_ERROR_NONE Successful
256 * @retval #PARCLE_ERROR_INVALID_PARAMETER Invalid parameter
257 * @see parcel_read_double()
259 int parcel_write_double(parcel_h parcel, double val);
262 * @brief Writes a string data into the parcel handle.
264 * @param[in] parcel The parcel handle
265 * @param[in] str The string data
266 * @return @c 0 on success,
267 * otherwise a negative error value
268 * @retval #PARCEL_ERROR_NONE Successful
269 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
270 * @see parcel_read_string()
272 int parcel_write_string(parcel_h parcel, const char *str);
275 * @brief Writes a bundle data into the parcel handle.
277 * @param[in] parcel The parcel handle
278 * @param[in] b The bundle data
279 * @return @c 0 on success,
280 * otherwise a negative error value
281 * @retval #PARCEL_ERROR_NONE Successful
282 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
283 * @see parcel_read_bundle()
285 int parcel_write_bundle(parcel_h parcel, bundle* b);
288 * @brief Reads a boolean value from the parcel handle.
290 * @param[in] parcel The parcel handle
291 * @param[out] val The boolean value
292 * @return @c 0 on success,
293 * otherwise a negative error value
294 * @retval #PARCEL_ERROR_NONE Successful
295 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
296 * @retval #PARCEL_ERROR_NO_DATA No data available
297 * @retval #PARCEL_ERROR_ILLEGAL_BYTE_SEQ Illegal byte sequence
298 * @see parcel_write_bool()
300 int parcel_read_bool(parcel_h parcel, bool *val);
303 * @brief Reads a byte value from the parcel handle.
305 * @param[in] parcel The parcel handle
306 * @param[out] val The byte value
307 * @return @c 0 on success,
308 * otherwise a negative error value
309 * @retval #PARCEL_ERROR_NONE Successful
310 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
311 * @retval #PARCEL_ERROR_NO_DATA No data available
312 * @retval #PARCEL_ERROR_ILLEGAL_BYTE_SEQ Illegal byte sequence
313 * @see parcel_write_uint8()
315 int parcel_read_byte(parcel_h parcel, char *val);
318 * @brief Reads an unsigned short value from the parcel handle.
320 * @param[in] parcel The parcel handle
321 * @param[out] val The unsigned short value
322 * @return @c 0 on success,
323 * otherwise a negative error value
324 * @retval #PARCEL_ERROR_NONE Successful
325 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
326 * @retval #PARCEL_ERROR_NO_DATA No data available
327 * @retval #PARCEL_ERROR_ILLEGAL_BYTE_SEQ Illegal byte sequence
328 * @see parcel_write_uint16()
330 int parcel_read_uint16(parcel_h parcel, uint16_t *val);
333 * @brief Reads an unsigned integer value from the parcel handle.
335 * @param[in] parcel The parcel handle
336 * @param[out] val The unsigned integer value
337 * @return @c 0 on success,
338 * otherwise a negative error value
339 * @retval #PARCEL_ERROR_NONE Successful
340 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
341 * @retval #PARCEL_ERROR_NO_DATA No data available
342 * @retval #PARCEL_ERROR_ILLEGAL_BYTE_SEQ Illegal byte sequence
343 * @see parcel_write_uint32()
345 int parcel_read_uint32(parcel_h parcel, uint32_t *val);
348 * @brief Reads an unsigned long long integer value from the parcel handle.
350 * @param[in] parcel The parcel handle
351 * @param[out] val The unsigned long long integer value
352 * @return @c 0 on success,
353 * otherwise a negative error value
354 * @retval #PARCEL_ERROR_NONE Successful
355 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
356 * @retval #PARCEL_ERROR_NO_DATA No data available
357 * @retval #PARCEL_ERROR_ILLEGAL_BYTE_SEQ Illegal byte sequence
358 * @see parcel_write_uint64()
360 int parcel_read_uint64(parcel_h parcel, uint64_t *val);
363 * @brief Reads a signed short value from the parcel handle.
365 * @param[in] parcel The parcel handle
366 * @param[out] val The signed short value
367 * @return @c 0 on success,
368 * otherwise a negative error value
369 * @retval #PARCEL_ERROR_NONE Successful
370 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
371 * @retval #PARCEL_ERROR_NO_DATA No data available
372 * @retval #PARCEL_ERROR_ILLEGAL_BYTE_SEQ Illegal byte sequence
373 * @see parcel_write_int16()
375 int parcel_read_int16(parcel_h parcel, int16_t *val);
378 * @brief Reads a signed integer value from the parcel handle.
380 * @param[in] parcel The parcel handle
381 * @param[out] val The signed integer value
382 * @return @c 0 on success,
383 * otherwise a negative error value
384 * @retval #PARCEL_ERROR_NONE Successful
385 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
386 * @retval #PARCEL_ERROR_NO_DATA No data available
387 * @retval #PARCEL_ERROR_ILLEGAL_BYTE_SEQ Illegal byte sequence
388 * @see parcel_write_int32()
390 int parcel_read_int32(parcel_h parcel, int32_t *val);
393 * @brief Reads a signed long long integer value from the parcel handle.
395 * @param[in] parcel The parcel handle
396 * @param[out] val The signed long long integer value
397 * @return @c 0 on success,
398 * otherwise a negative error value
399 * @retval #PARCEL_ERROR_NONE Successful
400 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
401 * @retval #PARCEL_ERROR_NO_DATA No data available
402 * @retval #PARCEL_ERROR_ILLEGAL_BYTE_SEQ Illegal byte sequence
403 * @see parcel_write_int64()
405 int parcel_read_int64(parcel_h parcel, int64_t *val);
408 * @brief Reads a floating point value from the parcel handle.
410 * @param[in] parcel The parcel handle
411 * @param[out] val The floating point value
412 * @return @c 0 on success,
413 * otherwise a negative error value
414 * @retval #PARCEL_ERROR_NONE Successful
415 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
416 * @retval #PARCEL_ERROR_NO_DATA No data available
417 * @retval #PARCEL_ERROR_ILLEGAL_BYTE_SEQ Illegal byte sequence
418 * @see parcel_write_uint8()
420 int parcel_read_float(parcel_h parcel, float *val);
423 * @brief Reads a double precision floating point value from the parcel handle.
425 * @param[in] parcel The parcel handle
426 * @param[out] val The double precision floating point value
427 * @return @c 0 on success,
428 * otherwise a negative error value
429 * @retval #PARCEL_ERROR_NONE Successful
430 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
431 * @retval #PARCEL_ERROR_NO_DATA No data available
432 * @retval #PARCEL_ERROR_ILLEGAL_BYTE_SEQ Illegal byte sequence
433 * @see parcel_write_uint8()
435 int parcel_read_double(parcel_h parcel, double *val);
438 * @brief Reads a string data from the parcel handle.
440 * @param[in] parcel The parcel handle
441 * @param[out] str The string data
442 * @return @c 0 on success,
443 * otherwise a negative error value
444 * @retval #PARCEL_ERROR_NONE Successful
445 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
446 * @retval #PARCEL_ERROR_NO_DATA No data available
447 * @retval #PARCEL_ERROR_ILLEGAL_BYTE_SEQ Illegal byte sequence
448 * @retval #PARCEL_ERROR_OUT_OF_MEMORY Out of memory
449 * @see parcel_write_uint8()
451 int parcel_read_string(parcel_h parcel, char **str);
454 * @brief Reads a bundle data from the parcel handle.
456 * @param[in] parcel The parcel handle
457 * @param[out] val The bundle data
458 * @return @c 0 on success,
459 * otherwise a negative error value
460 * @retval #PARCEL_ERROR_NONE Successful
461 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
462 * @retval #PARCEL_ERROR_NO_DATA No data available
463 * @retval #PARCEL_ERROR_ILLEGAL_BYTE_SEQ Illegal byte sequence
464 * @retval #PARCEL_ERROR_OUT_OF_MEMORY Out of memory
465 * @see parcel_write_uint8()
467 int parcel_read_bundle(parcel_h parcel, bundle **b);
470 * @brief Resets the reader pointer of the parcel handle to the start.
472 * @param[in] parcel The parcel handle
473 * @return @c 0 on success,
474 * otherwise a negative error value
475 * @retval #PARCEL_ERROR_NONE Successful
476 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
478 int parcel_reset_reader(parcel_h parcel);
481 * @brief Clears the data of the parcel handle.
483 * @param[in] parcel The parcel handle
484 * @return @c 0 on success,
485 * otherwise a negative error value
486 * @retval #PARCEL_ERROR_NONE Successful
487 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
489 int parcel_clear(parcel_h parcel);
492 * @brief Resets the data of the parcel handle.
494 * @param[in] parcel The parcel handle
495 * @param[in] buf The array buffer to write
496 * @param[in] size The size of bytes to write
497 * @return @c 0 on success,
498 * otherwise a negative error value
499 * @retval #PARCEL_ERROR_NONE Successful
500 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
502 int parcel_reset(parcel_h parcel, const void *buf, uint32_t size);
505 * @brief Writes the data using @a parcelable to the parcel handle.
507 * @param[in] parcel The parcel handle
508 * @param[in] parcelable The interface to write the data into the parcel handle
509 * @param[in] data The user data which writes into the parcel handle
510 * @return @c 0 on success,
511 * otherwise a negative error value
512 * @retval #PARCEL_ERROR_NONE Successful
513 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
516 int parcel_write(parcel_h parcel, parcelable_t *parcelable, void *data);
519 * @brief Reads the data using @a parcelable from the parcel handle.
521 * @param[in] parcel The parcel handle
522 * @param[in] parcelable The interface to read the data from the parcel handle
523 * @param[in] data The user data which reads from the parcel handle
524 * @return @c 0 on success,
525 * otherwise a negative error value
526 * @retval #PARCEL_ERROR_NONE Successful
527 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
528 * @see parcel_write()
530 int parcel_read(parcel_h parcel, parcelable_t *parcelable, void *data);
533 * @brief Gets the raw data of the parcel handle.
535 * @remarks You MUST NOT release @a raw using free(). It's managed by platform.
536 * @param[in] parcel The parcel handle
537 * @param[out] raw The raw data
538 * @param[out] size The size of the raw data
539 * @return @c 0 on success,
540 * otherwise a negative error value
541 * @retval #PARCEL_ERROR_NONE Successful
542 * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
544 int parcel_get_raw(parcel_h parcel, void **raw, uint32_t *size);
554 #endif /* __PARCEL_H__ */