1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef CAPI_INCLUDE_IPC_CPARCEL_H 17 #define CAPI_INCLUDE_IPC_CPARCEL_H 18 19 /** 20 * @addtogroup OHIPCParcel 21 * @{ 22 * 23 * @brief Defines C interfaces for IPC serialization and deserialization. 24 * 25 * @syscap SystemCapability.Communication.IPC.Core 26 * @since 12 27 */ 28 29 /** 30 * @file ipc_cparcel.h 31 * 32 * @brief Defines C interfaces for IPC serialization and deserialization. 33 * 34 * @library libipc_capi.so 35 * @syscap SystemCapability.Communication.IPC.Core 36 * @since 12 37 */ 38 39 #include <stdint.h> 40 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 45 /** 46 * @brief Defines an IPC serialized object. 47 * 48 * @syscap SystemCapability.Communication.IPC.Core 49 * @since 12 50 */ 51 struct OHIPCParcel; 52 53 /** 54 * @brief Typedef an IPC serialized object. 55 * 56 * @syscap SystemCapability.Communication.IPC.Core 57 * @since 12 58 */ 59 typedef struct OHIPCParcel OHIPCParcel; 60 61 /** 62 * @brief Defines an IPC remote proxy object. 63 * 64 * @syscap SystemCapability.Communication.IPC.Core 65 * @since 12 66 */ 67 struct OHIPCRemoteProxy; 68 69 /** 70 * @brief Typedef an IPC remote proxy object. 71 * 72 * @syscap SystemCapability.Communication.IPC.Core 73 * @since 12 74 */ 75 typedef struct OHIPCRemoteProxy OHIPCRemoteProxy; 76 77 /** 78 * @brief Defines an IPC remote service object. 79 * 80 * @syscap SystemCapability.Communication.IPC.Core 81 * @since 12 82 */ 83 struct OHIPCRemoteStub; 84 85 /** 86 * @brief Typedef an IPC remote service object. 87 * 88 * @syscap SystemCapability.Communication.IPC.Core 89 * @since 12 90 */ 91 typedef struct OHIPCRemoteStub OHIPCRemoteStub; 92 93 /** 94 * @brief Allocates memory. 95 * 96 * @syscap SystemCapability.Communication.IPC.Core 97 * @param len Length of the memory to allocate. 98 * @return Returns the address of the memory allocated if the operation is successful; returns NULL otherwise. 99 * @since 12 100 */ 101 typedef void* (*OH_IPC_MemAllocator)(int32_t len); 102 103 /** 104 * @brief Creates an <b>OHIPCParcel</b> object, which cannot exceed 204,800 bytes. 105 * 106 * @syscap SystemCapability.Communication.IPC.Core 107 * @return Returns the pointer to the <b>OHIPCParcel</b> object created if the operation is successful; 108 * returns NULL otherwise. 109 * @since 12 110 */ 111 OHIPCParcel* OH_IPCParcel_Create(void); 112 113 /** 114 * @brief Destroys an <b>OHIPCParcel</b> object. 115 * 116 * @syscap SystemCapability.Communication.IPC.Core 117 * @param parcel Pointer to the <b>OHIPCParcel</b> object to destroy. 118 * @since 12 119 */ 120 void OH_IPCParcel_Destroy(OHIPCParcel *parcel); 121 122 /** 123 * @brief Obtains the size of the data contained in an <b>OHIPCParcel</b> object. 124 * 125 * @syscap SystemCapability.Communication.IPC.Core 126 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 127 * @return Returns the data size obtained if the operation is successful.\n 128 * Returns <b>-1</b> if invalid parameters are found. 129 * @since 12 130 */ 131 int OH_IPCParcel_GetDataSize(const OHIPCParcel *parcel); 132 133 /** 134 * @brief Obtains the number of bytes that can be written to an <b>OHIPCParcel</b> object. 135 * 136 * @syscap SystemCapability.Communication.IPC.Core 137 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 138 * @return Returns the number of bytes that can be written to the <b>OHIPCParcel</b> object. \n 139 * Returns <b>-1</b> if invalid parameters are found. 140 * @since 12 141 */ 142 int OH_IPCParcel_GetWritableBytes(const OHIPCParcel *parcel); 143 144 /** 145 * @brief Obtains the number of bytes that can be read from an <b>OHIPCParcel</b> object. 146 * 147 * @syscap SystemCapability.Communication.IPC.Core 148 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 149 * @return Returns the number of bytes that can be read from the <b>OHIPCParcel</b> object. \n 150 * Returns <b>-1</b> if invalid parameters are found. 151 * @since 12 152 */ 153 int OH_IPCParcel_GetReadableBytes(const OHIPCParcel *parcel); 154 155 /** 156 * @brief Obtains the position where data is read in an <b>OHIPCParcel</b> object. 157 * 158 * @syscap SystemCapability.Communication.IPC.Core 159 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 160 * @return Returns the position obtained if the operation is successful. \n 161 * Returns <b>-1</b> if invalid parameters are found. 162 * @since 12 163 */ 164 int OH_IPCParcel_GetReadPosition(const OHIPCParcel *parcel); 165 166 /** 167 * @brief Obtains the position where data is written in an <b>OHIPCParcel</b> object. 168 * 169 * @syscap SystemCapability.Communication.IPC.Core 170 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 171 * @return Returns the position obtained if the operation is successful. \n 172 * Returns <b>-1</b> if invalid parameters are found. 173 * @since 12 174 */ 175 int OH_IPCParcel_GetWritePosition(const OHIPCParcel *parcel); 176 177 /** 178 * @brief Resets the position to read data in an IPC parcel. 179 * 180 * @syscap SystemCapability.Communication.IPC.Core 181 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 182 * @param newReadPos New position to read data. The value ranges from <b>0</b> to the current data size. 183 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n 184 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. 185 * @since 12 186 */ 187 int OH_IPCParcel_RewindReadPosition(OHIPCParcel *parcel, uint32_t newReadPos); 188 189 /** 190 * @brief Resets the position to write data in an <b>OHIPCParcel</b> object. 191 * 192 * @syscap SystemCapability.Communication.IPC.Core 193 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 194 * @param newWritePos New position to write data. The value ranges from <b>0</b> to the current data size. 195 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n 196 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. 197 * @since 12 198 */ 199 int OH_IPCParcel_RewindWritePosition(OHIPCParcel *parcel, uint32_t newWritePos); 200 201 /** 202 * @brief Writes an int8_t value to an <b>OHIPCParcel</b> object. 203 * 204 * @syscap SystemCapability.Communication.IPC.Core 205 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 206 * @param value Value to write. 207 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n 208 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n 209 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails. 210 * @since 12 211 */ 212 int OH_IPCParcel_WriteInt8(OHIPCParcel *parcel, int8_t value); 213 214 /** 215 * @brief Reads an int8_t value from an <b>OHIPCParcel</b> object. 216 * 217 * @syscap SystemCapability.Communication.IPC.Core 218 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 219 * @param value Pointer to the data to read. It cannot be NULL. 220 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n 221 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n 222 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR} if the read operation fails. 223 * @since 12 224 */ 225 int OH_IPCParcel_ReadInt8(const OHIPCParcel *parcel, int8_t *value); 226 227 /** 228 * @brief Writes an int16_t value to an <b>OHIPCParcel</b> object. 229 * 230 * @syscap SystemCapability.Communication.IPC.Core 231 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 232 * @param value Value to write. 233 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n 234 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n 235 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails. 236 * @since 12 237 */ 238 int OH_IPCParcel_WriteInt16(OHIPCParcel *parcel, int16_t value); 239 240 /** 241 * @brief Reads an int16_t value from an <b>OHIPCParcel</b> object. 242 * 243 * @syscap SystemCapability.Communication.IPC.Core 244 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 245 * @param value Pointer to the data to read. It cannot be NULL. 246 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n 247 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n 248 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR} if the read operation fails. 249 * @since 12 250 */ 251 int OH_IPCParcel_ReadInt16(const OHIPCParcel *parcel, int16_t *value); 252 253 /** 254 * @brief Writes an int32_t value to an <b>OHIPCParcel</b> object. 255 * 256 * @syscap SystemCapability.Communication.IPC.Core 257 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 258 * @param value Value to write. 259 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n 260 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n 261 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails. 262 * @since 12 263 */ 264 int OH_IPCParcel_WriteInt32(OHIPCParcel *parcel, int32_t value); 265 266 /** 267 * @brief Reads an int32_t value from an <b>OHIPCParcel</b> object. 268 * 269 * @syscap SystemCapability.Communication.IPC.Core 270 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 271 * @param value Pointer to the data to read. It cannot be NULL. 272 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n 273 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n 274 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR} if the read operation fails. 275 * @since 12 276 */ 277 int OH_IPCParcel_ReadInt32(const OHIPCParcel *parcel, int32_t *value); 278 279 /** 280 * @brief Writes an int64_t value to an <b>OHIPCParcel</b> object. 281 * 282 * @syscap SystemCapability.Communication.IPC.Core 283 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 284 * @param value Value to write. 285 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n 286 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n 287 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails. 288 * @since 12 289 */ 290 int OH_IPCParcel_WriteInt64(OHIPCParcel *parcel, int64_t value); 291 292 /** 293 * @brief Reads an int64_t value from an <b>OHIPCParcel</b> object. 294 * 295 * @syscap SystemCapability.Communication.IPC.Core 296 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 297 * @param value Pointer to the data to read. It cannot be NULL. 298 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n 299 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n 300 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR} if the read operation fails. 301 * @since 12 302 */ 303 int OH_IPCParcel_ReadInt64(const OHIPCParcel *parcel, int64_t *value); 304 305 /** 306 * @brief Writes a float value to an <b>OHIPCParcel</b> object. 307 * 308 * @syscap SystemCapability.Communication.IPC.Core 309 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 310 * @param value Value to write. 311 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n 312 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n 313 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails. 314 * @since 12 315 */ 316 int OH_IPCParcel_WriteFloat(OHIPCParcel *parcel, float value); 317 318 /** 319 * @brief Reads a float value from an <b>OHIPCParcel</b> object. 320 * 321 * @syscap SystemCapability.Communication.IPC.Core 322 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 323 * @param value Pointer to the data to read. It cannot be NULL. 324 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n 325 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n 326 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR} if the read operation fails. 327 * @since 12 328 */ 329 int OH_IPCParcel_ReadFloat(const OHIPCParcel *parcel, float *value); 330 331 /** 332 * @brief Writes a double value to an <b>OHIPCParcel</b> object. 333 * 334 * @syscap SystemCapability.Communication.IPC.Core 335 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 336 * @param value Value to write. 337 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n 338 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n 339 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails. 340 * @since 12 341 */ 342 int OH_IPCParcel_WriteDouble(OHIPCParcel *parcel, double value); 343 344 /** 345 * @brief Reads a double value from an <b>OHIPCParcel</b> object. 346 * 347 * @syscap SystemCapability.Communication.IPC.Core 348 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 349 * @param value Pointer to the data to read. It cannot be NULL. 350 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n 351 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n 352 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR} if the read operation fails. 353 * @since 12 354 */ 355 int OH_IPCParcel_ReadDouble(const OHIPCParcel *parcel, double *value); 356 357 /** 358 * @brief Writes a string including a string terminator to an <b>OHIPCParcel</b> object. 359 * 360 * @syscap SystemCapability.Communication.IPC.Core 361 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 362 * @param str String to write, which cannot be NULL. 363 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n 364 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n 365 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails. 366 * @since 12 367 */ 368 int OH_IPCParcel_WriteString(OHIPCParcel *parcel, const char *str); 369 370 /** 371 * @brief Reads a string from an <b>OHIPCParcel</b> object. You can obtain the length of the string from <b>strlen</b>. 372 * 373 * @syscap SystemCapability.Communication.IPC.Core 374 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 375 * @return Returns the address of the string read if the operation is successful; 376 * returns NULL if the operation fails or invalid parameters are found. 377 * @since 12 378 */ 379 const char* OH_IPCParcel_ReadString(const OHIPCParcel *parcel); 380 381 /** 382 * @brief Writes data of the specified length from the memory to an <b>OHIPCParcel</b> object. 383 * 384 * @syscap SystemCapability.Communication.IPC.Core 385 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 386 * @param buffer Pointer to the address of the memory information to write. 387 * @param len Length of the data to write. 388 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n 389 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n 390 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails. 391 * @since 12 392 */ 393 int OH_IPCParcel_WriteBuffer(OHIPCParcel *parcel, const uint8_t *buffer, int32_t len); 394 395 /** 396 * @brief Reads memory information of the specified length from an <b>OHIPCParcel</b> object. 397 * 398 * @syscap SystemCapability.Communication.IPC.Core 399 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 400 * @param len Length of the memory to be read. 401 * @return Returns the memory address read if the operation is successful; 402 * returns NULL if invalid parameters are found or <b>len</b> exceeds the readable length of <b>parcel</b>. 403 * @since 12 404 */ 405 const uint8_t* OH_IPCParcel_ReadBuffer(const OHIPCParcel *parcel, int32_t len); 406 407 /** 408 * @brief Writes an <b>OHIPCRemoteStub</b> object to an <b>OHIPCParcel</b> object. 409 * 410 * @syscap SystemCapability.Communication.IPC.Core 411 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 412 * @param stub Pointer to the <b>OHIPCRemoteStub</b> object to write. It cannot be NULL. 413 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n 414 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n 415 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails. 416 * @since 12 417 */ 418 int OH_IPCParcel_WriteRemoteStub(OHIPCParcel *parcel, const OHIPCRemoteStub *stub); 419 420 /** 421 * @brief Reads the <b>OHIPCRemoteStub</b> object from an <b>OHIPCParcel</b> object. 422 * 423 * @syscap SystemCapability.Communication.IPC.Core 424 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 425 * @return Returns the pointer to the <b>OHIPCRemoteStub</b> object read if the operation is successful; 426 * returns NULL otherwise. 427 * @since 12 428 */ 429 OHIPCRemoteStub* OH_IPCParcel_ReadRemoteStub(const OHIPCParcel *parcel); 430 431 /** 432 * @brief Writes an <b>OHIPCRemoteProxy</b> object to an <b>OHIPCParcel</b> object. 433 * 434 * @syscap SystemCapability.Communication.IPC.Core 435 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 436 * @param proxy Pointer to the <b>OHIPCRemoteProxy</b> object to write. It cannot be NULL. 437 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n 438 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n 439 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails. 440 * @since 12 441 */ 442 int OH_IPCParcel_WriteRemoteProxy(OHIPCParcel *parcel, const OHIPCRemoteProxy *proxy); 443 444 /** 445 * @brief Reads the <b>OHIPCRemoteProxy</b> object from an <b>OHIPCParcel</b> object. 446 * 447 * @syscap SystemCapability.Communication.IPC.Core 448 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 449 * @return Returns the pointer to the <b>OHIPCRemoteProxy</b> object read if the operation is successful; 450 * returns NULL otherwise. 451 * @since 12 452 */ 453 OHIPCRemoteProxy* OH_IPCParcel_ReadRemoteProxy(const OHIPCParcel *parcel); 454 455 /** 456 * @brief Writes a file descriptor to an <b>OHIPCParcel</b> object. 457 * 458 * @syscap SystemCapability.Communication.IPC.Core 459 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 460 * @param fd File descriptor to write. 461 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n 462 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n 463 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails. 464 * @since 12 465 */ 466 int OH_IPCParcel_WriteFileDescriptor(OHIPCParcel *parcel, int32_t fd); 467 468 /** 469 * @brief Reads a file descriptor from an <b>OHIPCParcel</b> object. 470 * 471 * @syscap SystemCapability.Communication.IPC.Core 472 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 473 * @param fd Pointer to the file descriptor to read. It cannot be NULL. 474 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n 475 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n 476 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR} if the read operation fails. 477 * @since 12 478 */ 479 int OH_IPCParcel_ReadFileDescriptor(const OHIPCParcel *parcel, int32_t *fd); 480 481 /** 482 * @brief Appends data to an <b>OHIPCParcel</b> object. 483 * 484 * @syscap SystemCapability.Communication.IPC.Core 485 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 486 * @param data Pointer to the data to append. It cannot be NULL. 487 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n 488 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n 489 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the operation fails. 490 * @since 12 491 */ 492 int OH_IPCParcel_Append(OHIPCParcel *parcel, const OHIPCParcel *data); 493 494 /** 495 * @brief Writes an interface token to an <b>OHIPCParcel</b> object for interface identity verification. 496 * 497 * @syscap SystemCapability.Communication.IPC.Core 498 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 499 * @param token Pointer to the interface token to write. It cannot be NULL. 500 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n 501 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n 502 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails. 503 * @since 12 504 */ 505 int OH_IPCParcel_WriteInterfaceToken(OHIPCParcel *parcel, const char *token); 506 507 /** 508 * @brief Reads an interface token from an <b>OHIPCParcel</b> object for interface identity verification. 509 * 510 * @syscap SystemCapability.Communication.IPC.Core 511 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL. 512 * @param token Pointer to the address of the memory for storing the interface token. 513 * The memory is allocated by the allocator provided by the user and needs to be released. This pointer cannot be NULL. 514 * If an error code is returned, you still need to check whether the memory is empty and release the memory. 515 * Otherwise, memory leaks may occur. 516 * @param len Pointer to the length of the interface token read, including the terminator. It cannot be NULL. 517 * @param allocator Memory allocator specified by the user for allocating memory for <b>token</b>. It cannot be NULL. 518 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n 519 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n 520 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR} if the read operation fails. 521 * @since 12 522 */ 523 int OH_IPCParcel_ReadInterfaceToken(const OHIPCParcel *parcel, char **token, int32_t *len, 524 OH_IPC_MemAllocator allocator); 525 526 #ifdef __cplusplus 527 } 528 #endif 529 530 /** @} */ 531 #endif 532