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.
17 #ifndef PARCEL_PARCEL_HH_
18 #define PARCEL_PARCEL_HH_
21 * @addtogroup CORE_LIB_PARCEL_MODULE
25 #include <bundle_cpp.h>
32 #include "parcel/common.hh"
33 #include "parcel/parcelable.hh"
35 namespace tizen_base {
38 * @brief The class for Parcel API.
41 class EXPORT Parcel final {
44 * @brief Enumeration for parcel error.
48 None = TIZEN_ERROR_NONE, /**< Successful */
49 IllegalByteSeq = TIZEN_ERROR_ILLEGAL_BYTE_SEQ, /**< Illegal byte sequence */
50 InvalidParameter = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
51 NoData = TIZEN_ERROR_NO_DATA, /**< No data available */
52 OutOfMemory = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
64 * @param[in] buf The bytes to write
65 * @param[in] size the size of bytes to write
67 Parcel(const void* buf, uint32_t size);
76 * @brief Copy-constructor.
78 * @param[in] p The object to copy
80 Parcel(const Parcel& p);
85 * @param[in] b The object to copy
87 Parcel& operator = (const Parcel& p);
90 * @brief Move-constructor.
92 * @param[in] p The object to move
94 Parcel(Parcel&& p) noexcept;
99 * @param[in] p The object to move
101 Parcel& operator = (Parcel&& p) noexcept;
104 * @brief Checks the parcel is empty or not.
106 * @return true if the parcel is empty
108 bool IsEmpty() const noexcept;
111 * @brief Writes bytes into the parcel.
113 * @param[in] buf The bytes to write
114 * @param[in] size The size of bytes to write
116 void Write(const void* buf, uint32_t size);
119 * @brief Reads bytes from the parcel.
121 * @param[out] buf The bytes to read
122 * @param[in] size The size of bytes to read
123 * @return @c 0 on success,
124 * otherwise a negative error value
126 int Read(void* buf, uint32_t size);
129 * @brief Writes a boolean value into the parcel.
131 * @param[in] val The boolean value
133 void WriteBool(bool val);
136 * @brief Writes a byte value into the parcel.
138 * @param[in] val The unsigned byte value
140 void WriteByte(char byte);
143 * @brief Writes an unsigned short value into the parcel.
145 * @param[in] val The unsigned short value
147 void WriteUInt16(uint16_t val);
150 * @brief Writes an unsigned integer value into the parcel.
152 * @param[in] val The unsigned integer value
154 void WriteUInt32(uint32_t val);
157 * @brief Writes an unsigned long long integer into the parcel.
159 * @param[in] val The unsigned long long integer value
161 void WriteUInt64(uint64_t val);
164 * @brief Writes a signed short value into the parcel.
166 * @param[in] val The signed short value
168 void WriteInt16(int16_t val);
171 * @brief Writes a signed integer value into the parcel.
173 * @param[in] val The signed integer value
175 void WriteInt32(int32_t val);
178 * @brief Writes a signed long long integer value into the parcel.
180 * @param[in] val The signed long long integer value
182 void WriteInt64(int64_t val);
185 * @brief Writes a floating point value into the parcel.
187 * @param[in] val The floating point value
189 void WriteFloat(float val);
192 * @brief Writes a double precision floating point value into the parcel.
194 * @param[in] val The double precision floating point value
196 void WriteDouble(double val);
199 * @brief Writes a string data into the parcel.
201 * @param[in] str The string data
203 void WriteString(const std::string& str);
206 * @brief Writes a string data into the parcel.
208 * @param[in] str The string data
210 void WriteCString(const char* str);
213 * @brief Writes a bundle data into the parcel.
215 * @param[in] b The bundle data
217 void WriteCBundle(bundle* b);
220 * @brief Writes a bundle data into the parcel.
222 * @param[in] b The bundle data
224 void WriteBundle(const Bundle& b);
227 * @brief Reads a boolean value from the parcel.
229 * @param[out] val The boolean value
230 * @return @c 0 on success,
231 * otherwise a negative error value
233 int ReadBool(bool* val);
236 * @brief Reads a byte value from the parcel.
238 * @param[out] val The unsigned byte value
239 * @return @c 0 on success,
240 * otherwise a negative error value
242 int ReadByte(char* val);
245 * @breif Reads an unsigned short value from the parcel.
247 * @param[out] val The unsigned short value
248 * @return @c 0 on success,
249 * otherwise a negative error value
251 int ReadUInt16(uint16_t* val);
254 * @brief Reads an unsigned integer value from the parcel.
256 * @param[out] val The unsigned integer value
257 * @return @c 0 on success,
258 * otherwise a negative error value
260 int ReadUInt32(uint32_t* val);
263 * @brief Reads an unsigned long long integer value from the parcel.
265 * @param[out] val The unsigned long long integer value
266 * @return @c 0 on success,
267 * otherwise a negative error value
269 int ReadUInt64(uint64_t* val);
272 * @brief Reads a signed byte value from the parcel.
274 * @param[out] val The signed byte value
275 * @return @c 0 on success,
276 * otherwise a negative error value
278 int ReadInt8(int8_t* val);
281 * @brief Reads a signed short value from the parcel.
283 * @param[out] val The signed short value
284 * @return @c 0 on success,
285 * otherwise a negative error value
287 int ReadInt16(int16_t* val);
290 * @brief Reads a signed integer value from the parcel.
292 * @param[out] val The signed integer value
293 * @return @c 0 on success,
294 * otherwise a negative error value
296 int ReadInt32(int32_t* val);
299 * @brief Reads a signed long long integer value from the parcel.
301 * @param[out] val The signed long long integer value
302 * @return @c 0 on success,
303 * otherwise a negative error value
305 int ReadInt64(int64_t* val);
308 * @brief Reads a floating point value from the parcel.
310 * @param[out] val The floating point value
311 * @return @c 0 on success,
312 * otherwise a negative error value
314 int ReadFloat(float* val);
317 * @brief Reads a double precision floating point value from the parcel.
319 * @param[out] val The double precision floating point value
320 * @return @c 0 on success,
321 * otherwise a negative error value
323 int ReadDouble(double* val);
326 * @brief Reads a string data from the parcel.
328 * @return The string data
329 * @remarks Before using the returned value, you should check the result using get_last_result().
330 * @see get_last_result()
332 std::string ReadString();
335 * @brief Reads a string data from the parcel.
337 * @remarks You should release @a str using free().
338 * @param[out] str The string data
339 * @return @c 0 on success,
340 * otherwise a negative error value
342 int ReadCString(char** str);
345 * @brief Reads a bundle data from the parcel.
347 * @remarks You should release @a b using bundle_free().
348 * @param[out] b The bundle data
349 * @return @c 0 on success,
350 * otherwise a negative error value
352 int ReadCBundle(bundle** b);
355 * @brief Reads a bundle data from the parcel.
357 * @return The bundle data
358 * @remarks Before using the returned value, you should check the result using get_last_result().
359 * @see get_last_result();
364 * @brief Gets the raw data of the parcel.
366 * @return The raw data
368 const std::vector<uint8_t>& GetRaw();
371 * @brief Resets the reader pointer of the parcel to the start.
377 * @brief Clears the data of the parcel.
383 * @brief Resets the parcel.
385 * @param[in] buf The bytes to write
386 * @param[in] size The size of bytes to write
388 void Reset(const void* buf, uint32_t size);
391 * @brief Writes the data using @a parcelable into the parcel.
393 * @param[in] parcelable The interface to write the data into the parcel
395 void WriteParcelable(const Parcelable& parcelable);
398 * @brief Reads the data using @a parcelable from the parcel.
400 * @param[out] parcelable The interface to get data from the parcel
401 * @return @c 0 on success,
402 * otherwise a negative error value
404 int ReadParcelable(Parcelable* parcelable);
408 std::unique_ptr<Impl> impl_;
411 } // naemspace tizen_base
417 #endif // PARCEL_PARCEL_HH_