diff --git a/interfaces/innerkits/c_api/include/ipc_cparcel.h b/interfaces/innerkits/c_api/include/ipc_cparcel.h
index 10a3123a..3e89733c 100644
--- a/interfaces/innerkits/c_api/include/ipc_cparcel.h
+++ b/interfaces/innerkits/c_api/include/ipc_cparcel.h
@@ -20,7 +20,7 @@
* @addtogroup OHIPCParcel
* @{
*
- * @brief 提供IPC序列化/反序列化C接口.
+ * @brief Defines C interfaces for IPC serialization and deserialization.
*
* @syscap SystemCapability.Communication.IPC.Core
* @since 12
@@ -29,9 +29,10 @@
/**
* @file ipc_cparcel.h
*
- * @brief 提供IPC序列化/反序列化C接口.
+ * @brief Defines C interfaces for IPC serialization and deserialization.
*
* @library libipc_capi.so
+ * @syscap SystemCapability.Communication.IPC.Core
* @since 12
*/
@@ -41,426 +42,482 @@
extern "C" {
#endif
+/**
+* @brief Defines an IPC serialized object.
+*
+* @syscap SystemCapability.Communication.IPC.Core
+* @since 12
+*/
struct OHIPCParcel;
+
+/**
+* @brief Typedef an IPC serialized object.
+*
+* @syscap SystemCapability.Communication.IPC.Core
+* @since 12
+*/
+typedef struct OHIPCParcel OHIPCParcel;
+
+/**
+* @brief Defines an IPC remote proxy object.
+*
+* @syscap SystemCapability.Communication.IPC.Core
+* @since 12
+*/
struct OHIPCRemoteProxy;
+
+/**
+* @brief Typedef an IPC remote proxy object.
+*
+* @syscap SystemCapability.Communication.IPC.Core
+* @since 12
+*/
+typedef struct OHIPCRemoteProxy OHIPCRemoteProxy;
+
+/**
+* @brief Defines an IPC remote service object.
+*
+* @syscap SystemCapability.Communication.IPC.Core
+* @since 12
+*/
struct OHIPCRemoteStub;
/**
- * @brief 内存分配函数类型.
+* @brief Typedef an IPC remote service object.
+*
+* @syscap SystemCapability.Communication.IPC.Core
+* @since 12
+*/
+typedef struct OHIPCRemoteStub OHIPCRemoteStub;
+
+/**
+ * @brief Allocates memory.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param len 分配内存长度.
- * @return 成功返回分配的内存地址;失败返回NULL.
+ * @param len Length of the memory to allocate.
+ * @return Returns the address of the memory allocated if the operation is successful; returns NULL otherwise.
* @since 12
*/
typedef void* (*OH_IPC_MemAllocator)(int32_t len);
/**
- * @brief 创建OHIPCParcel对象,对象可序列化大小不能超过204800字节.
+ * @brief Creates an OHIPCParcel object, which cannot exceed 204,800 bytes.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @return 成功返回OHIPCParcel对象指针;失败返回NULL.
+ * @return Returns the pointer to the OHIPCParcel object created if the operation is successful;
+ * returns NULL otherwise.
* @since 12
*/
OHIPCParcel* OH_IPCParcel_Create(void);
/**
- * @brief 销毁OHIPCParcel对象.
+ * @brief Destroys an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel 需要销毁OHIPCParcel对象的指针.
+ * @param parcel Pointer to the OHIPCParcel object to destroy.
* @since 12
*/
void OH_IPCParcel_Destroy(OHIPCParcel *parcel);
/**
- * @brief 获取OHIPCParcel对象包含的数据的大小.
+ * @brief Obtains the size of the data contained in an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @return 返回数据大小,参数不合法时返回-1.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @return Returns the data size obtained if the operation is successful.\n
+ * Returns -1 if invalid parameters are found.
* @since 12
*/
int OH_IPCParcel_GetDataSize(const OHIPCParcel *parcel);
/**
- * @brief 获取OHIPCParcel对象可以写入的字节数.
+ * @brief Obtains the number of bytes that can be written to an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @return 返回可写字节数大小,参数不合法时返回-1.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @return Returns the number of bytes that can be written to the OHIPCParcel object. \n
+ * Returns -1 if invalid parameters are found.
* @since 12
*/
int OH_IPCParcel_GetWritableBytes(const OHIPCParcel *parcel);
/**
- * @brief 获取OHIPCParcel对象还可以读取的字节数.
+ * @brief Obtains the number of bytes that can be read from an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @return 返回可读字节数大小,参数不合法时返回-1.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @return Returns the number of bytes that can be read from the OHIPCParcel object. \n
+ * Returns -1 if invalid parameters are found.
* @since 12
*/
int OH_IPCParcel_GetReadableBytes(const OHIPCParcel *parcel);
/**
- * @brief 获取OHIPCParcel对象当前读取位置.
+ * @brief Obtains the position where data is read in an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @return 返回当前读位置,参数不合法时返回-1
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @return Returns the position obtained if the operation is successful. \n
+ * Returns -1 if invalid parameters are found.
* @since 12
*/
int OH_IPCParcel_GetReadPosition(const OHIPCParcel *parcel);
/**
- * @brief 获取OHIPCParcel对象当前写入位置.
+ * @brief Obtains the position where data is written in an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @return 返回当前写入位置,参数不合法时返回-1.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @return Returns the position obtained if the operation is successful. \n
+ * Returns -1 if invalid parameters are found.
* @since 12
*/
int OH_IPCParcel_GetWritePosition(const OHIPCParcel *parcel);
/**
- * @brief 重置OHIPCParcel对象读取位置.
+ * @brief Resets the position to read data in an IPC parcel.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @param newReadPos 新的读取位置,范围:[0, 当前数据大小].
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数不合法时返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @param newReadPos New position to read data. The value ranges from 0 to the current data size.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found.
* @since 12
*/
int OH_IPCParcel_RewindReadPosition(OHIPCParcel *parcel, uint32_t newReadPos);
/**
- * @brief 重置OHIPCParcel对象写入位置.
+ * @brief Resets the position to write data in an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @param newWritePos 新的写入位置,范围:[0, 当前数据大小].
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数不合法时返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @param newWritePos New position to write data. The value ranges from 0 to the current data size.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found.
* @since 12
*/
int OH_IPCParcel_RewindWritePosition(OHIPCParcel *parcel, uint32_t newWritePos);
/**
- * @brief 向OHIPCParcel对象写入int8_t值.
+ * @brief Writes an int8_t value to an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @param value 要写入的值.
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数不合法时返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 写入失败返回{@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR}.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @param value Value to write.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails.
* @since 12
*/
int OH_IPCParcel_WriteInt8(OHIPCParcel *parcel, int8_t value);
/**
- * @brief 从OHIPCParcel对象读取int8_t值.
+ * @brief Reads an int8_t value from an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @param value 存储读取数据的指针,不能为空.
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数不合法时返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 读取失败返回{@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR}.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @param value Pointer to the data to read. It cannot be NULL.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR} if the read operation fails.
* @since 12
*/
int OH_IPCParcel_ReadInt8(const OHIPCParcel *parcel, int8_t *value);
/**
- * @brief 向OHIPCParcel对象写入int16_t值.
+ * @brief Writes an int16_t value to an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @param value 要写入的值.
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数不合法时返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 写入失败返回{@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR}.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @param value Value to write.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails.
* @since 12
*/
int OH_IPCParcel_WriteInt16(OHIPCParcel *parcel, int16_t value);
/**
- * @brief 从OHIPCParcel对象读取int16_t值.
+ * @brief Reads an int16_t value from an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @param value 存储读取数据的指针,不能为空.
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数不合法时返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 读取失败返回{@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR}.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @param value Pointer to the data to read. It cannot be NULL.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR} if the read operation fails.
* @since 12
*/
int OH_IPCParcel_ReadInt16(const OHIPCParcel *parcel, int16_t *value);
/**
- * @brief 向OHIPCParcel对象写入int32_t值.
+ * @brief Writes an int32_t value to an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @param value 要写入的值.
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数不合法时返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 写入失败返回{@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR}.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @param value Value to write.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails.
* @since 12
*/
int OH_IPCParcel_WriteInt32(OHIPCParcel *parcel, int32_t value);
/**
- * @brief 从OHIPCParcel对象读取int32_t值.
+ * @brief Reads an int32_t value from an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @param value 存储读取数据的指针,不能为空.
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数不合法时返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 读取失败返回{@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR}.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @param value Pointer to the data to read. It cannot be NULL.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR} if the read operation fails.
* @since 12
*/
int OH_IPCParcel_ReadInt32(const OHIPCParcel *parcel, int32_t *value);
/**
- * @brief 向OHIPCParcel对象写入int64_t值.
+ * @brief Writes an int64_t value to an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @param value 要写入的值.
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数不合法时返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 写入失败返回{@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR}.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @param value Value to write.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails.
* @since 12
*/
int OH_IPCParcel_WriteInt64(OHIPCParcel *parcel, int64_t value);
/**
- * @brief 从OHIPCParcel对象读取int64_t值.
+ * @brief Reads an int64_t value from an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @param value 存储读取数据的指针,不能为空.
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数不合法时返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 读取失败返回{@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR}.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @param value Pointer to the data to read. It cannot be NULL.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR} if the read operation fails.
* @since 12
*/
int OH_IPCParcel_ReadInt64(const OHIPCParcel *parcel, int64_t *value);
/**
- * @brief 向OHIPCParcel对象写入float值.
+ * @brief Writes a float value to an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @param value 要写入的值.
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数不合法时返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 写入失败返回{@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR}.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @param value Value to write.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails.
* @since 12
*/
int OH_IPCParcel_WriteFloat(OHIPCParcel *parcel, float value);
/**
- * @brief 从OHIPCParcel对象读取float值.
+ * @brief Reads a float value from an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @param value 存储读取数据的指针,不能为空.
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数不合法时返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 读取失败返回{@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR}.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @param value Pointer to the data to read. It cannot be NULL.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR} if the read operation fails.
* @since 12
*/
int OH_IPCParcel_ReadFloat(const OHIPCParcel *parcel, float *value);
/**
- * @brief 向OHIPCParcel对象写入double值.
+ * @brief Writes a double value to an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @param value 要写入的值.
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数不合法时返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 写入失败返回{@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR}.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @param value Value to write.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails.
* @since 12
*/
int OH_IPCParcel_WriteDouble(OHIPCParcel *parcel, double value);
/**
- * @brief 从OHIPCParcel对象读取double值.
+ * @brief Reads a double value from an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @param value 存储读取数据的指针,不能为空.
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数不合法时返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 读取失败返回{@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR}.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @param value Pointer to the data to read. It cannot be NULL.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR} if the read operation fails.
* @since 12
*/
int OH_IPCParcel_ReadDouble(const OHIPCParcel *parcel, double *value);
/**
- * @brief 向OHIPCParcel对象写入字符串,包含字符串结束符.
+ * @brief Writes a string including a string terminator to an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @param str 写入字符串,不能为空.
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数不合法时返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 写入失败返回{@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR}.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @param str String to write, which cannot be NULL.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails.
* @since 12
*/
int OH_IPCParcel_WriteString(OHIPCParcel *parcel, const char *str);
/**
- * @brief 从OHIPCParcel对象读取字符串,用户可通过strlen获取字符串长度。
+ * @brief Reads a string from an OHIPCParcel object. You can obtain the length of the string from strlen.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空。
- * @return 成功返回读取字符串地址;参数不合法或读取失败时返回NULL。
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @return Returns the address of the string read if the operation is successful;
+ * returns NULL if the operation fails or invalid parameters are found.
* @since 12
*/
const char* OH_IPCParcel_ReadString(const OHIPCParcel *parcel);
/**
- * @brief 向OHIPCParcel对象写入指定长度的内存信息.
+ * @brief Writes data of the specified length from the memory to an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @param buffer 写入内存信息地址.
- * @param len 写入信息长度.
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数不合法时返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 写入失败返回{@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR}.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @param buffer Pointer to the address of the memory information to write.
+ * @param len Length of the data to write.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails.
* @since 12
*/
int OH_IPCParcel_WriteBuffer(OHIPCParcel *parcel, const uint8_t *buffer, int32_t len);
/**
- * @brief 从OHIPCParcel对象读取指定长度内存信息。
+ * @brief Reads memory information of the specified length from an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空。
- * @param len 读取内存的长度。
- * @return 成功返回读取到的内存地址;参数不合法或len超过parcel可读长度时返回NULL。
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @param len Length of the memory to be read.
+ * @return Returns the memory address read if the operation is successful;
+ * returns NULL if invalid parameters are found or len exceeds the readable length of parcel.
* @since 12
*/
const uint8_t* OH_IPCParcel_ReadBuffer(const OHIPCParcel *parcel, int32_t len);
/**
- * @brief 向OHIPCParcel对象写入OHIPCRemoteStub对象.
+ * @brief Writes an OHIPCRemoteStub object to an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @param stub 需要写入的OHIPCRemoteStub对象指针,不能为空.
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数不合法时返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 写入失败返回{@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR}.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @param stub Pointer to the OHIPCRemoteStub object to write. It cannot be NULL.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails.
* @since 12
*/
int OH_IPCParcel_WriteRemoteStub(OHIPCParcel *parcel, const OHIPCRemoteStub *stub);
/**
- * @brief 从OHIPCParcel对象读取OHIPCRemoteStub对象.
+ * @brief Reads the OHIPCRemoteStub object from an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @return 成功返回OHIPCRemoteStub对象指针;失败返回NULL.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @return Returns the pointer to the OHIPCRemoteStub object read if the operation is successful;
+ * returns NULL otherwise.
* @since 12
*/
OHIPCRemoteStub* OH_IPCParcel_ReadRemoteStub(const OHIPCParcel *parcel);
/**
- * @brief 向OHIPCParcel对象写入OHIPCRemoteProxy对象.
+ * @brief Writes an OHIPCRemoteProxy object to an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @param proxy 需要写入的OHIPCRemoteProxy对象指针,不能为空.
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数不合法时返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 写入失败返回{@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR}.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @param proxy Pointer to the OHIPCRemoteProxy object to write. It cannot be NULL.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails.
* @since 12
*/
int OH_IPCParcel_WriteRemoteProxy(OHIPCParcel *parcel, const OHIPCRemoteProxy *proxy);
/**
- * @brief 从OHIPCParcel对象读取OHIPCRemoteProxy对象.
+ * @brief Reads the OHIPCRemoteProxy object from an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @return 成功返回OHIPCRemoteProxy对象指针;失败返回NULL.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @return Returns the pointer to the OHIPCRemoteProxy object read if the operation is successful;
+ * returns NULL otherwise.
* @since 12
*/
OHIPCRemoteProxy* OH_IPCParcel_ReadRemoteProxy(const OHIPCParcel *parcel);
/**
- * @brief 向OHIPCParcel对象写入文件描述符
+ * @brief Writes a file descriptor to an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @param fd 要写入的文件描述符.
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数不合法时返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 写入失败返回{@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR}.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @param fd File descriptor to write.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails.
* @since 12
*/
int OH_IPCParcel_WriteFileDescriptor(OHIPCParcel *parcel, int32_t fd);
/**
- * @brief 从OHIPCParcel对象读取文件描述符.
+ * @brief Reads a file descriptor from an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @param fd 存储读取文件描述符的指针,不能为空.
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数不合法时返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 读取失败返回{@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR}.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @param fd Pointer to the file descriptor to read. It cannot be NULL.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR} if the read operation fails.
* @since 12
*/
int OH_IPCParcel_ReadFileDescriptor(const OHIPCParcel *parcel, int32_t *fd);
/**
- * @brief OHIPCParcel对象数据拼接.
+ * @brief Appends data to an OHIPCParcel object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel 拼接目标OHIPCParcel对象的指针,不能为空.
- * @param data 源OHIPCParcel对象的指针,不能为空.
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数不合法时返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 拼接失败返回{@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR}.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @param data Pointer to the data to append. It cannot be NULL.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the operation fails.
* @since 12
*/
int OH_IPCParcel_Append(OHIPCParcel *parcel, const OHIPCParcel *data);
/**
- * @brief 向OHIPCParcel对象写入接口描述符,用于接口身份校验.
+ * @brief Writes an interface token to an OHIPCParcel object for interface identity verification.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @param token 需要写入的接口描述符信息,不能为空.
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数不合法时返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 写入失败返回{@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR}.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @param token Pointer to the interface token to write. It cannot be NULL.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails.
* @since 12
*/
int OH_IPCParcel_WriteInterfaceToken(OHIPCParcel *parcel, const char *token);
/**
- * @brief 从OHIPCParcel对象读取接口描述符信息,用于接口身份校验.
+ * @brief Reads an interface token from an OHIPCParcel object for interface identity verification.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param parcel OHIPCParcel对象的指针,不能为空.
- * @param token 用于存储接口描述符信息的内存地址,该内存由用户提供的分配器进行内存分配,用户使用完后需要主动释放,不能为空. \n
- * 接口返回失败时,用户依然需要判断该内存是否为空,并主动释放,否则会造成内存泄漏.
- * @param len 存储读取接口描述符的长度,包含结束符,不能为空.
- * @param allocator 用户指定的用来分配token的内存分配器,不能为空.
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数不合法时返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 读取失败返回{@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR}.
+ * @param parcel Pointer to the target OHIPCParcel object. It cannot be NULL.
+ * @param token Pointer to the address of the memory for storing the interface token.
+ * The memory is allocated by the allocator provided by the user and needs to be released. This pointer cannot be NULL.
+ * If an error code is returned, you still need to check whether the memory is empty and release the memory.
+ * Otherwise, memory leaks may occur.
+ * @param len Pointer to the length of the interface token read, including the terminator. It cannot be NULL.
+ * @param allocator Memory allocator specified by the user for allocating memory for token. It cannot be NULL.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR} if the read operation fails.
* @since 12
*/
int OH_IPCParcel_ReadInterfaceToken(const OHIPCParcel *parcel, char **token, int32_t *len,
@@ -470,4 +527,5 @@ int OH_IPCParcel_ReadInterfaceToken(const OHIPCParcel *parcel, char **token, int
}
#endif
+/** @} */
#endif
diff --git a/interfaces/innerkits/c_api/include/ipc_cremote_object.h b/interfaces/innerkits/c_api/include/ipc_cremote_object.h
index 1f56c1ea..8155b725 100644
--- a/interfaces/innerkits/c_api/include/ipc_cremote_object.h
+++ b/interfaces/innerkits/c_api/include/ipc_cremote_object.h
@@ -20,7 +20,8 @@
* @addtogroup OHIPCRemoteObject
* @{
*
- * @brief 提供远端对象创建、销毁、数据发送、远端对象死亡状态监听等功能C接口.
+ * @brief Provides C interfaces for creating and destroying a remote object, transferring data,
+ * and observing the dead status of a remote object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @since 12
@@ -29,9 +30,11 @@
/**
* @file ipc_cremote_object.h
*
- * @brief 提供远端对象创建、销毁、数据发送、远端对象死亡状态监听等功能C接口.
+ * @brief Defines C interfaces for creating and destroying a remote object, transferring data,
+ * and observing the dead status of a remote object.
*
* @library libipc_capi.so
+ * @syscap SystemCapability.Communication.IPC.Core
* @since 12
*/
@@ -43,214 +46,234 @@
extern "C" {
#endif
+/**
+* @brief Defines an OHIPCDeathRecipient object, which is used to receive a notification
+* when the OHIPCRemoteStub object dies unexpectedly.
+*
+* @syscap SystemCapability.Communication.IPC.Core
+* @since 12
+*/
struct OHIPCDeathRecipient;
/**
- * @brief Stub端用于处理远端数据请求的回调函数.
+* @brief Typedef an OHIPCDeathRecipient object.
+*
+* @syscap SystemCapability.Communication.IPC.Core
+* @since 12
+*/
+typedef struct OHIPCDeathRecipient OHIPCDeathRecipient;
+
+/**
+ * @brief Called to process the remote data request at the stub.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param code 用户自定义通讯命令字,范围:[0x01, 0x00ffffff].
- * @param data 请求数据对象指针,不会为空,函数内不允许释放.
- * @param reply 回应数据对象指针,不会为空,函数内不允许释放. \n
- * 如果函数返回错误,该值不允许写入数据.
- * @param userData 用户私有数据,可以为空.
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 否则返回用户自定义错误码或系统错误码,自定义错误码范围:[1909001, 1909999]. \n
- * 如果用户自定义错误码超出范围,将返回{@link OH_IPC_ErrorCode#OH_IPC_INVALID_USER_ERROR_CODE}.
+ * @param code Custom command word for communication, in the range [0x01, 0x00ffffff].
+ * @param data Pointer to the request data object. It cannot be NULL or released in the function.
+ * @param reply Pointer to the response data object. It cannot be NULL or released in the function.
+ * If this function returns an error, data cannot be written to this parameter.
+ * @param userData Pointer to the user data. It can be NULL.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns a custom error code in the range [1909001, 1909999] or a system error code otherwise. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_INVALID_USER_ERROR_CODE} if the custom error code is out of the value range.
* @since 12
*/
typedef int (*OH_OnRemoteRequestCallback)(uint32_t code, const OHIPCParcel *data,
OHIPCParcel *reply, void *userData);
/**
- * @brief Stub端用于监听对象销毁的回调函数.
+ * @brief Called when an observed object is destroyed.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param userData 用户私有数据,可以为空.
+ * @param userData Pointer to the user data. It can be NULL.
* @since 12
*/
typedef void (*OH_OnRemoteDestroyCallback)(void *userData);
/**
- * @brief 创建OHIPCRemoteStub对象.
+ * @brief Creates an OHIPCRemoteStub object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param descriptor OHIPCRemoteStub对象描述符,不能为空.
- * @param requestCallback 数据请求处理函数,不能为空.
- * @param destroyCallback 对象销毁回调函数,可以为空.
- * @param userData 用户私有数据,可以为空.
- * @return 成功返回OHIPCRemoteStub对象指针,否则返回NULL.
+ * @param descriptor Pointer to the descriptor of the OHIPCRemoteStub object to create. It cannot be NULL.
+ * @param requestCallback Callback used to process the data request. It cannot be NULL.
+ * @param destroyCallback Callback to be invoked when the object is destroyed. It can be NULL.
+ * @param userData Pointer to the user data. It can be NULL.
+ * @return Returns the pointer to the OHIPCRemoteStub object created if the operation is successful;
+ * returns NULL otherwise.
* @since 12
*/
OHIPCRemoteStub* OH_IPCRemoteStub_Create(const char *descriptor, OH_OnRemoteRequestCallback requestCallback,
OH_OnRemoteDestroyCallback destroyCallback, void *userData);
/**
- * @brief 销毁OHIPCRemoteStub对象.
+ * @brief Destroys an OHIPCRemoteStub object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param stub 要销毁的OHIPCRemoteStub对象指针.
+ * @param stub Pointer to the OHIPCRemoteStub object to destroy.
* @since 12
*/
void OH_IPCRemoteStub_Destroy(OHIPCRemoteStub *stub);
/**
- * @brief 销毁OHIPCRemoteProxy对象.
+ * @brief Destroys an OHIPCRemoteProxy object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param proxy 要销毁的OHIPCRemoteProxy对象指针.
+ * @param proxy Pointer to the OHIPCRemoteProxy object to destroy.
* @since 12
*/
void OH_IPCRemoteProxy_Destroy(OHIPCRemoteProxy *proxy);
/**
- * @brief IPC请求模式定义
+ * @brief Enumerates the IPC request modes.
*
* @since 12
*/
-enum OH_IPC_RequestMode {
- /**
- * 同步请求模式
- */
+typedef enum {
+ /** Synchronous request. */
OH_IPC_REQUEST_MODE_SYNC = 0,
- /**
- * 异步请求模式
- */
+ /** Asynchronous request. */
OH_IPC_REQUEST_MODE_ASYNC = 1,
-};
+} OH_IPC_RequestMode;
/**
- * @brief IPC消息选项定义.
+ * @brief Defines the IPC message options.
*
* @since 12
*/
#pragma pack(4)
-struct OH_IPC_MessageOption {
- /**
- * 消息请求模式
- */
+typedef struct {
+ /** Message request mode. */
OH_IPC_RequestMode mode;
- /**
- * RPC预留参数,该参数对IPC无效
- */
+ /** Parameter reserved for RPC, which is invalid for IPC. */
uint32_t timeout;
- /**
- * 保留参数,必须为空
- */
+ /** Reserved parameter, which must be NULL. */
void* reserved;
-};
+} OH_IPC_MessageOption;
#pragma pack()
/**
- * @brief IPC消息发送函数.
+ * @brief Sends an IPC message.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param proxy OHIPCRemoteProxy对象指针,不能为空.
- * @param code 用户定义的IPC命令字,范围:[0x01,0x00ffffff].
- * @param data 请求数据对象指针,不能为空.
- * @param reply 回应数据对象指针,同步请求时,不能为空;异步请求时,可以为空.
- * @param option 消息选项指针,可以为空,为空时按同步处理.
- * @return 发送成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数不合法时返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 远端OHIPCRemoteStub对象死亡返回{@link OH_IPC_ErrorCode#OH_IPC_DEAD_REMOTE_OBJECT}. \n
- * code超出范围返回{@link OH_IPC_ErrorCode#OH_IPC_CODE_OUT_OF_RANGE}. \n
- * 其它返回{@link OH_IPC_ErrorCode#OH_IPC_INNER_ERROR}或用户自定义错误码.
+ * @param proxy Pointer to the OHIPCRemoteProxy object. It cannot be NULL.
+ * @param code Custom IPC command word, in the range [0x01, 0x00ffffff].
+ * @param data Pointer to the request data object. It cannot be NULL.
+ * @param reply Pointer to the response data object. It cannot be NULL in the case of a synchronous request,
+ * and can be NULL in the case of an asynchronous request.
+ * @param option Pointer to the message options. It can be NULL, which indicates a synchronous request.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_DEAD_REMOTE_OBJECT} if the OHIPCRemoteStub object is dead. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CODE_OUT_OF_RANGE} if the error code is out of the value range. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_INNER_ERROR} or a custom error code in other cases.
* @since 12
*/
int OH_IPCRemoteProxy_SendRequest(const OHIPCRemoteProxy *proxy, uint32_t code, const OHIPCParcel *data,
OHIPCParcel *reply, const OH_IPC_MessageOption *option);
/**
- * @brief 从Stub端获取接口描述符.
+ * @brief Obtains the interface descriptor from the stub.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param proxy OHIPCRemoteProxy对象指针,不能为空.
- * @param descriptor 用于存储描述符的内存地址,该内存由用户提供的分配器进行内存分配,用户使用完后需要主动释放,不能为空. \n
- * 接口返回失败时,用户依然需要判断该内存是否为空,并主动释放,否则会造成内存泄漏.
- * @param len 写入descriptor的数据长度,包含结束符,不能为空.
- * @param allocator 用户指定的用来分配descriptor的内存分配器,不能为空.
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数错误返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 远端OHIPCRemoteStub对象死亡返回{@link OH_IPC_ErrorCode#OH_IPC_DEAD_REMOTE_OBJECT}. \n
- * 内存分配失败返回{@link OH_IPC_ErrorCode#OH_IPC_MEM_ALLOCATOR_ERROR}. \n
- * 序列化读失败返回{@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR}.
+ * @param proxy Pointer to the OHIPCRemoteProxy object. It cannot be NULL.
+ * @param descriptor Double pointer to the address of the memory for holding the interface descriptor.
+ * The memory is allocated by the allocator provided by the user and needs to be released. This pointer cannot be NULL.
+ * If an error code is returned, you still need to check whether the memory is empty and release the memory.
+ * Otherwise, memory leaks may occur.
+ * @param len Pointer to the length of the data to be written to the descriptor, including the terminator.
+ * This parameter cannot be NULL.
+ * @param allocator Memory allocator specified by the user for allocating memory for descriptor.
+ * It cannot be NULL.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if incorrect parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_DEAD_REMOTE_OBJECT} if the OHIPCRemoteStub object is dead. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_MEM_ALLOCATOR_ERROR} if memory allocation fails. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR} if the data in the serialized object failed to be read.
* @since 12
*/
int OH_IPCRemoteProxy_GetInterfaceDescriptor(OHIPCRemoteProxy *proxy, char **descriptor, int32_t *len,
OH_IPC_MemAllocator allocator);
/**
- * @brief 远端OHIPCRemoteStub对象死亡通知的回调函数类型.
+ * @brief Called when the OHIPCRemoteStub object dies unexpectedly.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param userData 用户私有数据指针,可以为空.
+ * @param userData Pointer to the user data. It can be NULL.
* @since 12
*/
typedef void (*OH_OnDeathRecipientCallback)(void *userData);
/**
- * @brief OHIPCDeathRecipient对象销毁回调函数类型.
+ * @brief Called when the OHIPCDeathRecipient object is destroyed.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param userData 用户私有数据指针,可以为空.
+ * @param userData Pointer to the user data. It can be NULL.
* @since 12
*/
typedef void (*OH_OnDeathRecipientDestroyCallback)(void *userData);
/**
- * @brief 创建远端OHIPCRemoteStub对象死亡通知对象OHIPCDeathRecipient.
+ * @brief Creates an OHIPCDeathRecipient object, which allows a notification to be received
+ * when the OHIPCRemoteStub object dies unexpectedly.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param deathRecipientCallback 远端OHIPCRemoteStub对象死亡通知的回调处理函数,不能为空.
- * @param destroyCallback 对象销毁回调处理函数,可以为空.
- * @param userData 用户私有数据指针,可以为空.
- * @return 成功返回OHIPCDeathRecipient对象指针;否则返回NULL.
+ * @param deathRecipientCallback Callback to be invoked when the OHIPCRemoteStub object is dead.
+ * It cannot be NULL.
+ * @param destroyCallback Callback to be invoked when the object is destroyed. It can be NULL.
+ * @param userData Pointer to the user data. It can be NULL.
+ * @return Returns the pointer to the OHIPCDeathRecipient object created if the operation is successful;
+ * returns NULL otherwise.
* @since 12
*/
OHIPCDeathRecipient* OH_IPCDeathRecipient_Create(OH_OnDeathRecipientCallback deathRecipientCallback,
OH_OnDeathRecipientDestroyCallback destroyCallback, void *userData);
/**
- * @brief 销毁OHIPCDeathRecipient对象.
+ * @brief Destroys an OHIPCDeathRecipient object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param recipient 要销毁的OHIPCDeathRecipient对象指针.
+ * @param recipient Pointer to the OHIPCDeathRecipient object to destroy.
* @since 12
*/
void OH_IPCDeathRecipient_Destroy(OHIPCDeathRecipient *recipient);
/**
- * @brief 向OHIPCRemoteProxy对象添加死亡监听,用于接收远端OHIPCRemoteStub对象死亡的回调通知.
+ * @brief Subscribes to the death of an OHIPCRemoteStub object for an OHIPCRemoteProxy object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param proxy 需要添加死亡通知的OHIPCRemoteProxy对象指针,不能为空.
- * @param recipient 用于接收远程对象死亡通知的死亡对象指针,不能为空.
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数错误返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 其它{@link OH_IPC_ErrorCode#OH_IPC_INNER_ERROR}.
+ * @param proxy Pointer to the OHIPCRemoteProxy object that subscribes to the death notification.
+ * It cannot be NULL.
+ * @param recipient Pointer to the object that receives the death notification of the OHIPCRemoteStub object.
+ * It cannot be NULL.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if incorrect parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_INNER_ERROR} in other cases.
* @since 12
*/
int OH_IPCRemoteProxy_AddDeathRecipient(OHIPCRemoteProxy *proxy, OHIPCDeathRecipient *recipient);
/**
- * @brief 移除向OHIPCRemoteProxy对象已经添加的死亡监听.
+ * @brief Unsubscribes from the death of the OHIPCRemoteStub object for an OHIPCRemoteProxy object.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param proxy 需要移除死亡通知的OHIPCRemoteProxy对象指针,不能为空.
- * @param recipient 用于接收远程对象死亡通知的死亡对象指针,不能为空.
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数错误返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 其它{@link OH_IPC_ErrorCode#OH_IPC_INNER_ERROR}.
+ * @param proxy Pointer to the OHIPCRemoteProxy object that unsubscribes from the death notification.
+ * It cannot be NULL.
+ * @param recipient Pointer to the object that receives the death notification of the OHIPCRemoteStub object.
+ * It cannot be NULL.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if incorrect parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_INNER_ERROR} in other cases.
* @since 12
*/
int OH_IPCRemoteProxy_RemoveDeathRecipient(OHIPCRemoteProxy *proxy, OHIPCDeathRecipient *recipient);
/**
- * @brief 判断OHIPCRemoteProxy对象对应的远端OHIPCRemoteStub对象是否死亡.
+ * @brief Checks whether the OHIPCRemoteStub object corresponding to the OHIPCRemoteProxy object is dead.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param proxy 需要判断远端是否死亡的OHIPCRemoteProxy对象指针,不能为空.
- * @return 远端OHIPCRemoteStub对象死亡返回1; 否则,返回0. 参数非法时,说明其远端OHIPCRemoteStub对象不存在,返回1.
+ * @param proxy Pointer to the OHIPCRemoteProxy object to check. It cannot be NULL.
+ * @return Returns 1 if the OHIPCRemoteStub object is dead; returns 0 otherwise.
+ * If an invalid parameter is found, the OHIPCRemoteStub object does not exist.
+ * In this case, 1 is returned.
* @since 12
*/
int OH_IPCRemoteProxy_IsRemoteDead(const OHIPCRemoteProxy *proxy);
diff --git a/interfaces/innerkits/c_api/include/ipc_cskeleton.h b/interfaces/innerkits/c_api/include/ipc_cskeleton.h
index f79f64a4..bc70d2bb 100644
--- a/interfaces/innerkits/c_api/include/ipc_cskeleton.h
+++ b/interfaces/innerkits/c_api/include/ipc_cskeleton.h
@@ -20,7 +20,8 @@
* @addtogroup OHIPCSkeleton
* @{
*
- * @brief 提供IPC框架tokenId、凭据、PID/UID、线程池配置等功能C接口.
+ * @brief Provides C interfaces for managing the token IDs, credentials, process IDs (PIDs),
+ * user IDs (UIDs), and thread pool in the IPC framework.
*
* @syscap SystemCapability.Communication.IPC.Core
* @since 12
@@ -29,9 +30,11 @@
/**
* @file ipc_cskeleton.h
*
- * @brief 提供IPC框架tokenId、凭据、PID/UID、线程池配置等功能C接口.
+ * @brief Defines C interfaces for managing the token IDs, credentials, PIDs, UIDs, and thread
+ * pool in the IPC framework.
*
* @library libipc_capi.so
+ * @syscap SystemCapability.Communication.IPC.Core
* @since 12
*/
@@ -44,7 +47,7 @@ extern "C" {
#endif
/**
- * @brief 当前线程加入IPC工作线程池.
+ * @brief Joints this thread to the IPC worker thread pool.
*
* @syscap SystemCapability.Communication.IPC.Core
* @since 12
@@ -52,7 +55,7 @@ extern "C" {
void OH_IPCSkeleton_JoinWorkThread(void);
/**
- * @brief 当前线程退出IPC工作线程池.
+ * @brief Stops this thread.
*
* @syscap SystemCapability.Communication.IPC.Core
* @since 12
@@ -60,104 +63,111 @@ void OH_IPCSkeleton_JoinWorkThread(void);
void OH_IPCSkeleton_StopWorkThread(void);
/**
- * @brief 获取调用方TokenId.该接口需要在IPC上下文中调用,否则返回自身TokenId.
+ * @brief Obtains the token ID of the caller. This function must be called in the IPC context.
+ * Otherwise, the local token ID is returned.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @return 返回调用方TokenId.
+ * @return Returns the token ID of the caller.
* @since 12
*/
uint64_t OH_IPCSkeleton_GetCallingTokenId(void);
/**
- * @brief 获取首调者TokenId.
+ * @brief Obtains the token ID of the first caller.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @return 返回首调者TokenId.
+ * @return Returns the token ID obtained.
* @since 12
*/
uint64_t OH_IPCSkeleton_GetFirstTokenId(void);
/**
- * @brief 获取自身TokenId.
+ * @brief Obtains the local token ID.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @return 返回自身TokenId.
+ * @return Returns the token ID obtained.
* @since 12
*/
uint64_t OH_IPCSkeleton_GetSelfTokenId(void);
/**
- * @brief 获取调用方进程ID.该接口需要在IPC上下文中调用,否则返当前进程ID.
+ * @brief Obtains the process ID of the caller. This function must be called in the IPC context.
+ * Otherwise, the current process ID is returned.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @return 返回调用方进程ID.
+ * @return Returns the process ID of the caller.
* @since 12
*/
uint64_t OH_IPCSkeleton_GetCallingPid(void);
/**
- * @brief 获取调用方用户ID.该接口需要在IPC上下文中调用,否则返当前用户ID.
+ * @brief Obtains the UID of the caller. This function must be called in the IPC context.
+ * Otherwise, the current UID is returned.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @return 返回调用方用户ID.
+ * @return Returns the UID of the caller.
* @since 12
*/
uint64_t OH_IPCSkeleton_GetCallingUid(void);
/**
- * @brief 判断是否正在进行本地调用.
+ * @brief Checks whether a local calling is being made.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @return 正在进行本地调用,返回1;否则,返回0.
+ * @return Returns 1 if a local calling is in progress; returns 0 otherwise.
* @since 12
*/
int OH_IPCSkeleton_IsLocalCalling(void);
/**
- * @brief 设置最大工作线程数.
+ * @brief Sets the maximum number of worker threads.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param maxThreadNum 最大工作线程数,默认16,范围[1, 32].
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数错误返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 其它情况返回{@link OH_IPC_ErrorCode#OH_IPC_INNER_ERROR}.
+ * @param maxThreadNum Maximum number of worker threads to set. The default value is 16.
+ * The value range is [1, 32].
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if incorrect parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_INNER_ERROR} in other cases.
* @since 12
*/
int OH_IPCSkeleton_SetMaxWorkThreadNum(const int maxThreadNum);
/**
- * @brief 重置调用方身份凭证为自身进程的身份凭证(包括tokenid、UID和PID信息),并返回调用方的凭证信息.
- * 该信息主要用于OH_IPCSkeleton_SetCallingIdentity接口调用.
+ * @brief Resets the caller identity credential (including the token ID, UID, and PID) to that of this process and
+ * returns the caller credential information.
+ * The identity information is used in OH_IPCSkeleton_SetCallingIdentity.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param identity 用于存储调凭证的内存地址,该内存由用户提供的分配器进行内存分配,用户使用完后需要主动释放,不能为空.
- * @param len 写入identity的数据长度,不能为空.
- * @param allocator 用户指定的用来分配identity的内存分配器,不能为空.
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数错误返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 内存分配失败返回{@link OH_IPC_ErrorCode#OH_IPC_MEM_ALLOCATOR_ERROR}. \n
- * 其它情况返回{@link OH_IPC_ErrorCode#OH_IPC_INNER_ERROR}.
+ * @param identity Pointer to the address of the memory for holding the caller identity information.
+ * The memory is allocated by the allocator provided by the user and needs to be released. This pointer cannot be NULL.
+ * @param len Pointer to the length of the identity information. It cannot be NULL.
+ * @param allocator Memory allocator specified by the user for allocating memory for identity. It cannot be NULL.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if incorrect parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_MEM_ALLOCATOR_ERROR} if memory allocation fails. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_INNER_ERROR} in other cases.
* @since 12
*/
int OH_IPCSkeleton_ResetCallingIdentity(char **identity, int32_t *len, OH_IPC_MemAllocator allocator);
/**
- * @brief 恢复调用方凭证信息至IPC上下文中.
+ * @brief Sets the caller credential information to the IPC context.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @param identity 调用方凭证,不能为空.来源于OH_IPCSkeleton_ResetCallingIdentity的返回值.
- * @return 成功返回{@link OH_IPC_ErrorCode#OH_IPC_SUCCESS}. \n
- * 参数错误返回{@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR}. \n
- * 其它情况返回{@link OH_IPC_ErrorCode#OH_IPC_INNER_ERROR}.
+ * @param identity Pointer to the caller identity, which cannot be NULL.
+ * The value is returned by OH_IPCSkeleton_ResetCallingIdentity.
+ * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if incorrect parameters are found. \n
+ * Returns {@link OH_IPC_ErrorCode#OH_IPC_INNER_ERROR} in other cases.
* @since 12
*/
int OH_IPCSkeleton_SetCallingIdentity(const char *identity);
/**
- * @brief 是否正在处理IPC请求.
+ * @brief Checks whether an IPC request is being handled.
*
* @syscap SystemCapability.Communication.IPC.Core
- * @return 正在处理IPC请求,返回1;否则,返回0.
+ * @return Returns 1 if an IPC request is being handled; returns 0 otherwise.
* @since 12
*/
int OH_IPCSkeleton_IsHandlingTransaction(void);
diff --git a/interfaces/innerkits/c_api/include/ipc_error_code.h b/interfaces/innerkits/c_api/include/ipc_error_code.h
index 213c4d09..723693e2 100644
--- a/interfaces/innerkits/c_api/include/ipc_error_code.h
+++ b/interfaces/innerkits/c_api/include/ipc_error_code.h
@@ -20,7 +20,7 @@
* @addtogroup OHIPCErrorCode
* @{
*
- * @brief Provides IPC error code define.
+ * @brief Provides IPC error codes.
*
* @syscap SystemCapability.Communication.IPC.Core
* @since 12
@@ -29,71 +29,46 @@
/**
* @file ipc_error_code.h
*
- * @brief Provides IPC error code define.
+ * @brief Defines IPC error codes.
*
* @library libipc_capi.so
+ * @syscap SystemCapability.Communication.IPC.Core
* @since 12
*/
/**
- * @brief IPC错误码定义. \n
- *
- * @since 12
- */
-enum OH_IPC_ErrorCode {
- /**
- * 执行成功
- */
+* @brief Enumerates IPC error codes.
+*
+* @since 12
+*/
+typedef enum {
+ /** @error Execution successful. */
OH_IPC_SUCCESS = 0,
- /**
- * 错误码区间起始值
- */
+ /** @error Start error code. */
OH_IPC_ERROR_CODE_BASE = 1901000,
- /**
- * 参数错误
- */
+ /** @error Invalid parameters. */
OH_IPC_CHECK_PARAM_ERROR = OH_IPC_ERROR_CODE_BASE,
- /**
- * 序列化对象写入数据失败
- */
+ /** @error Failed to write data to the serialized object. */
OH_IPC_PARCEL_WRITE_ERROR = OH_IPC_ERROR_CODE_BASE + 1,
- /**
- * 序列化对象读取数据失败
- */
+ /** @error Failed to read data from the serialized object. */
OH_IPC_PARCEL_READ_ERROR = OH_IPC_ERROR_CODE_BASE + 2,
- /**
- * 内存分配失败
- */
+ /** @error Failed to allocate memory. */
OH_IPC_MEM_ALLOCATOR_ERROR = OH_IPC_ERROR_CODE_BASE + 3,
- /**
- * 命令字超出定义范围[0x01,0x00ffffff]
- */
+ /** @error The command word is out of the value range [0x01,0x00ffffff]. */
OH_IPC_CODE_OUT_OF_RANGE = OH_IPC_ERROR_CODE_BASE + 4,
- /**
- * 远端对象死亡
- */
+ /** @error The remote object is dead. */
OH_IPC_DEAD_REMOTE_OBJECT = OH_IPC_ERROR_CODE_BASE + 5,
- /**
- * 用户自定义错误码超出范围[1900001, 1999999]
- */
+ /** @error The custom error code is out of range [1900001, 1999999]. */
OH_IPC_INVALID_USER_ERROR_CODE = OH_IPC_ERROR_CODE_BASE + 6,
- /**
- * IPC内部错误
- */
+ /** @error IPC internal error. */
OH_IPC_INNER_ERROR = OH_IPC_ERROR_CODE_BASE + 7,
- /**
- * 错误码区间最大值
- */
+ /** @error Maximum error code. */
OH_IPC_ERROR_CODE_MAX = OH_IPC_ERROR_CODE_BASE + 1000,
- /**
- * 用户自定义错误码最小值
- */
+ /** @error Minimum value for a custom error code. */
OH_IPC_USER_ERROR_CODE_MIN = 1909000,
- /**
- * 用户自定义错误码最大值
- */
+ /** @error Maximum value for a custom error code. */
OH_IPC_USER_ERROR_CODE_MAX = 1909999,
-};
+} OH_IPC_ErrorCode;
/** @} */
#endif
\ No newline at end of file
diff --git a/interfaces/innerkits/c_api/include/ipc_kit.h b/interfaces/innerkits/c_api/include/ipc_kit.h
index 0befe523..8a01e2bd 100644
--- a/interfaces/innerkits/c_api/include/ipc_kit.h
+++ b/interfaces/innerkits/c_api/include/ipc_kit.h
@@ -16,9 +16,30 @@
#ifndef CAPI_INCLUDE_IPC_KIT_H
#define CAPI_INCLUDE_IPC_KIT_H
+/**
+ * @addtogroup IPCKit
+ * @{
+ *
+ * @brief Provides an entry to the IPC header files for you to reference.
+ *
+ * @syscap SystemCapability.Communication.IPC.Core
+ * @since 12
+ */
+
+/**
+ * @file ipc_cparcel.h
+ *
+ * @brief Provides an entry to the IPC header files for you to reference.
+ *
+ * @library libipc_capi.so
+ * @syscap SystemCapability.Communication.IPC.Core
+ * @since 12
+ */
+
#include "ipc_error_code.h"
#include "ipc_cparcel.h"
#include "ipc_cremote_object.h"
#include "ipc_cskeleton.h"
+/** @} */
#endif
\ No newline at end of file
diff --git a/ipc/native/src/mock/include/binder_invoker.h b/ipc/native/src/mock/include/binder_invoker.h
index f17819ec..4b399162 100644
--- a/ipc/native/src/mock/include/binder_invoker.h
+++ b/ipc/native/src/mock/include/binder_invoker.h
@@ -164,7 +164,11 @@ private:
void OnReleaseObject(uint32_t cmd);
- void OnTransaction(const uint8_t *);
+ void Transaction(const uint8_t *buffer);
+
+ void OnTransaction(int32_t &error);
+
+ void OnSpawnThread();
int HandleCommands(uint32_t cmd);
@@ -217,6 +221,21 @@ private:
int lastErrCnt_ = 0;
const std::unordered_set readHandleFromCommandsSet = {BC_ACQUIRE, BC_RELEASE,
BC_REQUEST_DEATH_NOTIFICATION, BC_REPLY, BC_CLEAR_DEATH_NOTIFICATION, BC_FREE_BUFFER, BC_TRANSACTION};
+ const std::map> commandMap_ = {
+ { BR_ERROR, [&](int32_t cmd, int32_t &error) { error = input_.ReadInt32(); } },
+ { BR_ACQUIRE, [&](int32_t cmd, int32_t &error) { OnAcquireObject(cmd); } },
+ { BR_INCREFS, [&](int32_t cmd, int32_t &error) { OnAcquireObject(cmd); } },
+ { BR_RELEASE, [&](int32_t cmd, int32_t &error) { OnReleaseObject(cmd); } },
+ { BR_DECREFS, [&](int32_t cmd, int32_t &error) { OnReleaseObject(cmd); } },
+ { BR_ATTEMPT_ACQUIRE, [&](int32_t cmd, int32_t &error) { OnAttemptAcquire(); } },
+ { BR_TRANSACTION, [&](int32_t cmd, int32_t &error) { OnTransaction(error); } },
+ { BR_SPAWN_LOOPER, [&](int32_t cmd, int32_t &error) { OnSpawnThread(); } },
+ { BR_FINISHED, [&](int32_t cmd, int32_t &error) { error = -ERR_TIMED_OUT; } },
+ { BR_DEAD_BINDER, [&](int32_t cmd, int32_t &error) { OnBinderDied(); } },
+ { BR_OK, [&](int32_t cmd, int32_t &error) { } },
+ { BR_NOOP, [&](int32_t cmd, int32_t &error) { } },
+ { BR_CLEAR_DEATH_NOTIFICATION_DONE, [&](int32_t cmd, int32_t &error) { OnRemoveRecipientDone(); } },
+ };
#ifdef CONFIG_ACTV_BINDER
bool useActvBinder_ = false;
ActvHandlerInfo *actvHandlerInfo_ = nullptr;
diff --git a/ipc/native/src/mock/source/binder_invoker.cpp b/ipc/native/src/mock/source/binder_invoker.cpp
index 1f2bb642..eec5ebec 100644
--- a/ipc/native/src/mock/source/binder_invoker.cpp
+++ b/ipc/native/src/mock/source/binder_invoker.cpp
@@ -558,7 +558,7 @@ void BinderInvoker::GetSenderInfo(uint64_t &callerTokenID, uint64_t &firstTokenI
realPid = static_cast(sender.sender_pid_nr);
}
-void BinderInvoker::OnTransaction(const uint8_t *buffer)
+void BinderInvoker::Transaction(const uint8_t *buffer)
{
const binder_transaction_data *tr = reinterpret_cast(buffer);
auto binderAllocator = new (std::nothrow) BinderAllocator();
@@ -695,6 +695,24 @@ void BinderInvoker::OnRemoveRecipientDone()
}
}
+void BinderInvoker::OnSpawnThread()
+{
+ IPCProcessSkeleton *current = IPCProcessSkeleton::GetCurrent();
+ if (current != nullptr) {
+ current->SpawnThread();
+ }
+}
+
+void BinderInvoker::OnTransaction(int32_t &error)
+{
+ const uint8_t *buffer = input_.ReadBuffer(sizeof(binder_transaction_data));
+ if (buffer == nullptr) {
+ error = IPC_INVOKER_INVALID_DATA_ERR;
+ return;
+ }
+ Transaction(buffer);
+}
+
int BinderInvoker::HandleReply(MessageParcel *reply)
{
const size_t readSize = sizeof(binder_transaction_data);
@@ -742,52 +760,12 @@ int BinderInvoker::HandleReply(MessageParcel *reply)
int BinderInvoker::HandleCommandsInner(uint32_t cmd)
{
int error = ERR_NONE;
- switch (cmd) {
- case BR_ERROR:
- error = input_.ReadInt32();
- break;
- case BR_ACQUIRE:
- case BR_INCREFS:
- OnAcquireObject(cmd);
- break;
- case BR_RELEASE:
- case BR_DECREFS:
- OnReleaseObject(cmd);
- break;
- case BR_ATTEMPT_ACQUIRE:
- OnAttemptAcquire();
- break;
- case BR_TRANSACTION: {
- const uint8_t *buffer = input_.ReadBuffer(sizeof(binder_transaction_data));
- if (buffer == nullptr) {
- error = IPC_INVOKER_INVALID_DATA_ERR;
- break;
- }
- OnTransaction(buffer);
- break;
- }
- case BR_SPAWN_LOOPER: {
- IPCProcessSkeleton *current = IPCProcessSkeleton::GetCurrent();
- if (current != nullptr) {
- current->SpawnThread();
- }
- break;
- }
- case BR_FINISHED:
- error = -ERR_TIMED_OUT;
- break;
- case BR_DEAD_BINDER:
- OnBinderDied();
- break;
- case BR_CLEAR_DEATH_NOTIFICATION_DONE:
- OnRemoveRecipientDone();
- break;
- case BR_OK:
- case BR_NOOP:
- break;
- default:
- error = IPC_INVOKER_ON_TRANSACT_ERR;
- break;
+
+ auto it = commandMap_.find(cmd);
+ if (it != commandMap_.end()) {
+ it->second(cmd, error);
+ } else {
+ error = IPC_INVOKER_ON_TRANSACT_ERR;
}
return error;
diff --git a/ipc/native/test/fuzztest/mock/binderinvoker_fuzzer/binderinvoker_fuzzer.cpp b/ipc/native/test/fuzztest/mock/binderinvoker_fuzzer/binderinvoker_fuzzer.cpp
index aeb28d19..dfb3975a 100644
--- a/ipc/native/test/fuzztest/mock/binderinvoker_fuzzer/binderinvoker_fuzzer.cpp
+++ b/ipc/native/test/fuzztest/mock/binderinvoker_fuzzer/binderinvoker_fuzzer.cpp
@@ -26,7 +26,7 @@
namespace OHOS {
- void OnTransactionTest(const uint8_t* data, size_t size)
+ void TransactionTest(const uint8_t* data, size_t size)
{
if (data == nullptr || size < sizeof(binder_transaction_data)) {
return;
@@ -38,7 +38,7 @@ namespace OHOS {
trData.target.ptr = 0;
trData.offsets_size = 0;
trData.flags = 0;
- invoker->OnTransaction(reinterpret_cast(&trData));
+ invoker->Transaction(reinterpret_cast(&trData));
delete invoker;
}
}
@@ -47,6 +47,6 @@ namespace OHOS {
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
- OHOS::OnTransactionTest(data, size);
+ OHOS::TransactionTest(data, size);
return 0;
}
\ No newline at end of file
diff --git a/ipc/native/test/unittest/common/ipc_capi_parcel_unittest.cpp b/ipc/native/test/unittest/common/ipc_capi_parcel_unittest.cpp
index 130f8816..b8efef9e 100644
--- a/ipc/native/test/unittest/common/ipc_capi_parcel_unittest.cpp
+++ b/ipc/native/test/unittest/common/ipc_capi_parcel_unittest.cpp
@@ -48,6 +48,7 @@ static constexpr int MAX_MEMORY_SIZE = 204800;
static constexpr int MAX_INTERFACE_TOKEN_LEN = 100;
static constexpr int TEST_PARCEL_SIZE = MAX_MEMORY_SIZE - 10;
static constexpr int TEST_PERFORMANCE_OPERATOR_COUNT = 2000;
+static constexpr int TEST_PERFORMANCE_OPERATOR_GROUP = 50;
struct PerformanceResult {
uint32_t min{ 100 };
@@ -65,12 +66,20 @@ public:
void TearDown();
uint32_t CalcSpendTime(TimePoint &start, TimePoint &end);
- void ReadWriteStringPerformance(PerformanceResult &writeResult, PerformanceResult &readResult);
- void ReadWriteStringCppPerformance(PerformanceResult &writeResult, PerformanceResult &readResult);
- void ReadWriteBufferPerformance(PerformanceResult &writeResult, PerformanceResult &readResult);
- void ReadWriteBufferCppPerformance(PerformanceResult &writeResult, PerformanceResult &readResult);
- void ReadWriteInterfaceTokenPerformance(PerformanceResult &writeResult, PerformanceResult &readResult);
- void ReadWriteInterfaceTokenCppPerformance(PerformanceResult &writeResult, PerformanceResult &readResult);
+ void ReadWriteString(const char *str, uint32_t &writeDuration, uint32_t &readDuration);
+ void ReadWriteStringCpp(const char *str, uint32_t &writeDuration, uint32_t &readDuration);
+ void ReadWriteStringPerformance(PerformanceResult &writeResult, PerformanceResult &readResult,
+ PerformanceResult &writeCppResult, PerformanceResult &readCppResult);
+ void ReadWriteBuffer(const uint8_t *buf, int32_t bufLength, uint32_t &writeDuration, uint32_t &readDuration);
+ void ReadWriteBufferCpp(const uint8_t *buf, int32_t bufLength, uint32_t &writeDuration, uint32_t &readDuration);
+ void ReadWriteBufferPerformance(PerformanceResult &writeResult, PerformanceResult &readResult,
+ PerformanceResult &writeCppResult, PerformanceResult &readCppResult);
+ void ReadWriteInterfaceToken(const char *token, uint32_t &writeDuration, uint32_t &readDuration);
+ void ReadWriteInterfaceTokenCpp(const char *token, uint32_t &writeDuration, uint32_t &readDuration);
+ void ReadWriteInterfaceTokenPerformance(PerformanceResult &writeResult, PerformanceResult &readResult,
+ PerformanceResult &writeCppResult, PerformanceResult &readCppResult);
+
+ void PerformanceStatistic(uint32_t writeAvg, uint32_t readAvg, uint32_t writeCppAvg, uint32_t readCppAvg);
static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_ID_TEST, "IpcCApiUnitTest" };
};
@@ -119,206 +128,234 @@ uint32_t IpcCApiParcelUnitTest::CalcSpendTime(TimePoint& start, TimePoint& end)
return static_cast(std::chrono::duration_cast(duration).count());
}
-void IpcCApiParcelUnitTest::ReadWriteStringPerformance(PerformanceResult &writeResult,
- PerformanceResult &readResult)
+void IpcCApiParcelUnitTest::PerformanceStatistic(uint32_t writeAvg, uint32_t readAvg,
+ uint32_t writeCppAvg, uint32_t readCppAvg)
{
- char buf[TEST_PARCEL_SIZE] = {0};
- EXPECT_EQ(memset_s(buf, sizeof(buf) - 1, '1', sizeof(buf) - 1), EOK);
- for (int i = 0; i < TEST_PERFORMANCE_OPERATOR_COUNT; ++i) {
- auto dataCParcel = OH_IPCParcel_Create();
- int ret = OH_IPC_SUCCESS;
- auto startPoint = std::chrono::steady_clock::now();
- ret = OH_IPCParcel_WriteString(dataCParcel, buf);
- auto endPoint = std::chrono::steady_clock::now();
- ASSERT_EQ(ret, OH_IPC_SUCCESS);
-
- uint32_t duration = CalcSpendTime(startPoint, endPoint);
- writeResult.min = (duration > writeResult.min) ? writeResult.min : duration;
- writeResult.max = (duration < writeResult.max) ? writeResult.max : duration;
- writeResult.average += duration;
-
- startPoint = std::chrono::steady_clock::now();
- const char *readStr = OH_IPCParcel_ReadString(dataCParcel);
- endPoint = std::chrono::steady_clock::now();
- ASSERT_NE(readStr, nullptr);
- EXPECT_EQ(strlen(readStr), sizeof(buf) - 1);
-
- duration = CalcSpendTime(startPoint, endPoint);
- readResult.min = (duration > readResult.min) ? readResult.min : duration;
- readResult.max = (duration < readResult.max) ? readResult.max : duration;
- readResult.average += duration;
-
- OH_IPCParcel_Destroy(dataCParcel);
+ static constexpr uint32_t PERCENT = 100;
+ static constexpr uint32_t PERCENT_RANGE = 105;
+ static constexpr uint32_t ERROR_VALUE = 5;
+ std::cout << "OHIPCParcel writeAvg:" << writeAvg << "us, readAvg:" << readAvg << "us" << std::endl;
+ std::cout << "MessageParcel writeAvg:" << writeCppAvg << "us, readAvg:" << readCppAvg << "us" << std::endl;
+ if (writeCppAvg >= ERROR_VALUE) {
+ ASSERT_LE(writeAvg * PERCENT, writeCppAvg * PERCENT_RANGE);
+ } else {
+ ASSERT_LE(writeAvg, writeCppAvg + ERROR_VALUE);
+ }
+ if (readCppAvg >= ERROR_VALUE) {
+ ASSERT_LE(readAvg * PERCENT, readCppAvg * PERCENT_RANGE);
+ } else {
+ ASSERT_LE(readAvg, readCppAvg + ERROR_VALUE);
}
- writeResult.average /= TEST_PERFORMANCE_OPERATOR_COUNT;
- readResult.average /= TEST_PERFORMANCE_OPERATOR_COUNT;
}
-void IpcCApiParcelUnitTest::ReadWriteStringCppPerformance(PerformanceResult &writeResult,
- PerformanceResult &readResult)
+void IpcCApiParcelUnitTest::ReadWriteString(const char *str, uint32_t &writeDuration, uint32_t &readDuration)
{
- char buf[TEST_PARCEL_SIZE] = {0};
- EXPECT_EQ(memset_s(buf, sizeof(buf) - 1, '1', sizeof(buf) - 1), EOK);
+ auto dataCParcel = OH_IPCParcel_Create();
+ int ret = OH_IPC_SUCCESS;
+ auto startPoint = std::chrono::steady_clock::now();
+ ret = OH_IPCParcel_WriteString(dataCParcel, str);
+ auto endPoint = std::chrono::steady_clock::now();
+ ASSERT_EQ(ret, OH_IPC_SUCCESS);
+ writeDuration = CalcSpendTime(startPoint, endPoint);
+
+ startPoint = std::chrono::steady_clock::now();
+ const char *readStr = OH_IPCParcel_ReadString(dataCParcel);
+ endPoint = std::chrono::steady_clock::now();
+ ASSERT_NE(readStr, nullptr);
+ EXPECT_EQ(strlen(readStr), strlen(str));
+ OH_IPCParcel_Destroy(dataCParcel);
+ readDuration = CalcSpendTime(startPoint, endPoint);
+}
+
+void IpcCApiParcelUnitTest::ReadWriteStringCpp(const char *str, uint32_t &writeDuration, uint32_t &readDuration)
+{
+ MessageParcel dataCpp;
+ auto startPoint = std::chrono::steady_clock::now();
+ dataCpp.WriteCString(str);
+ auto endPoint = std::chrono::steady_clock::now();
+ writeDuration = CalcSpendTime(startPoint, endPoint);
+
+ startPoint = std::chrono::steady_clock::now();
+ const char *readStr = dataCpp.ReadCString();
+ endPoint = std::chrono::steady_clock::now();
+ ASSERT_NE(readStr, nullptr);
+ EXPECT_EQ(strlen(readStr), strlen(str));
+ readDuration = CalcSpendTime(startPoint, endPoint);
+}
+
+void IpcCApiParcelUnitTest::ReadWriteStringPerformance(PerformanceResult &writeResult,
+ PerformanceResult &readResult, PerformanceResult &writeCppResult, PerformanceResult &readCppResult)
+{
+ char str[TEST_PARCEL_SIZE] = {0};
+ ASSERT_EQ(memset_s(str, sizeof(str) - 1, '1', sizeof(str) - 1), EOK);
for (int i = 0; i < TEST_PERFORMANCE_OPERATOR_COUNT; ++i) {
- MessageParcel dataCpp;
- auto startPoint = std::chrono::steady_clock::now();
- dataCpp.WriteCString(buf);
- auto endPoint = std::chrono::steady_clock::now();
+ uint32_t writeDuration = 0;
+ uint32_t readDuration = 0;
+ ReadWriteString(str, writeDuration, readDuration);
+ writeResult.min = (writeDuration > writeResult.min) ? writeResult.min : writeDuration;
+ writeResult.max = (writeDuration < writeResult.max) ? writeResult.max : writeDuration;
+ writeResult.average += writeDuration;
+ readResult.min = (readDuration > readResult.min) ? readResult.min : readDuration;
+ readResult.max = (readDuration < readResult.max) ? readResult.max : readDuration;
+ readResult.average += readDuration;
- uint32_t duration = CalcSpendTime(startPoint, endPoint);
- writeResult.min = (duration > writeResult.min) ? writeResult.min : duration;
- writeResult.max = (duration < writeResult.max) ? writeResult.max : duration;
- writeResult.average += duration;
-
- startPoint = std::chrono::steady_clock::now();
- const char* readCString = dataCpp.ReadCString();
- endPoint = std::chrono::steady_clock::now();
- ASSERT_NE(readCString, nullptr);
- EXPECT_EQ(strlen(readCString), sizeof(buf) - 1);
-
- duration = CalcSpendTime(startPoint, endPoint);
- readResult.min = (duration > readResult.min) ? readResult.min : duration;
- readResult.max = (duration < readResult.max) ? readResult.max : duration;
- readResult.average += duration;
+ uint32_t writeCppDuration = 0;
+ uint32_t readCppDuration = 0;
+ ReadWriteStringCpp(str, writeCppDuration, readCppDuration);
+ writeCppResult.min = (writeCppDuration > writeCppResult.min) ? writeCppResult.min : writeCppDuration;
+ writeCppResult.max = (writeCppDuration < writeCppResult.max) ? writeCppResult.max : writeCppDuration;
+ writeCppResult.average += writeCppDuration;
+ readCppResult.min = (readCppDuration > readCppResult.min) ? readCppResult.min : readCppDuration;
+ readCppResult.max = (readCppDuration < readCppResult.max) ? readCppResult.max : readCppDuration;
+ readCppResult.average += readCppDuration;
}
writeResult.average /= TEST_PERFORMANCE_OPERATOR_COUNT;
readResult.average /= TEST_PERFORMANCE_OPERATOR_COUNT;
+ writeCppResult.average /= TEST_PERFORMANCE_OPERATOR_COUNT;
+ readCppResult.average /= TEST_PERFORMANCE_OPERATOR_COUNT;
+}
+
+void IpcCApiParcelUnitTest::ReadWriteBuffer(const uint8_t *buf, int32_t bufLength,
+ uint32_t &writeDuration, uint32_t &readDuration)
+{
+ auto dataCParcel = OH_IPCParcel_Create();
+ int ret = OH_IPC_SUCCESS;
+ auto startPoint = std::chrono::steady_clock::now();
+ ret = OH_IPCParcel_WriteBuffer(dataCParcel, buf, bufLength);
+ auto endPoint = std::chrono::steady_clock::now();
+ ASSERT_EQ(ret, OH_IPC_SUCCESS);
+ writeDuration = CalcSpendTime(startPoint, endPoint);
+
+ startPoint = std::chrono::steady_clock::now();
+ const uint8_t *readBuffer = OH_IPCParcel_ReadBuffer(dataCParcel, bufLength);
+ endPoint = std::chrono::steady_clock::now();
+ ASSERT_NE(readBuffer, nullptr);
+ EXPECT_EQ(memcmp(readBuffer, buf, bufLength), 0);
+ OH_IPCParcel_Destroy(dataCParcel);
+ readDuration = CalcSpendTime(startPoint, endPoint);
+}
+
+void IpcCApiParcelUnitTest::ReadWriteBufferCpp(const uint8_t *buf, int32_t bufLength,
+ uint32_t &writeDuration, uint32_t &readDuration)
+{
+ MessageParcel dataCpp;
+ auto startPoint = std::chrono::steady_clock::now();
+ dataCpp.WriteBuffer(buf, TEST_PARCEL_SIZE);
+ auto endPoint = std::chrono::steady_clock::now();
+ writeDuration = CalcSpendTime(startPoint, endPoint);
+
+ startPoint = std::chrono::steady_clock::now();
+ const uint8_t *readBuf = dataCpp.ReadBuffer(TEST_PARCEL_SIZE);
+ endPoint = std::chrono::steady_clock::now();
+ ASSERT_NE(readBuf, nullptr);
+ EXPECT_EQ(memcmp(readBuf, buf, bufLength), 0);
+ readDuration = CalcSpendTime(startPoint, endPoint);
}
void IpcCApiParcelUnitTest::ReadWriteBufferPerformance(PerformanceResult &writeResult,
- PerformanceResult &readResult)
+ PerformanceResult &readResult, PerformanceResult &writeCppResult, PerformanceResult &readCppResult)
{
uint8_t buf[TEST_PARCEL_SIZE] = {0};
- EXPECT_EQ(memset_s(buf, sizeof(buf), '2', sizeof(buf)), EOK);
+ ASSERT_EQ(memset_s(buf, sizeof(buf), '2', sizeof(buf)), EOK);
for (int i = 0; i < TEST_PERFORMANCE_OPERATOR_COUNT; ++i) {
- auto dataCParcel = OH_IPCParcel_Create();
- int ret = OH_IPC_SUCCESS;
- auto startPoint = std::chrono::steady_clock::now();
- ret = OH_IPCParcel_WriteBuffer(dataCParcel, buf, TEST_PARCEL_SIZE);
- auto endPoint = std::chrono::steady_clock::now();
- ASSERT_EQ(ret, OH_IPC_SUCCESS);
+ uint32_t writeDuration = 0;
+ uint32_t readDuration = 0;
+ ReadWriteBuffer(buf, TEST_PARCEL_SIZE, writeDuration, readDuration);
+ writeResult.min = (writeDuration > writeResult.min) ? writeResult.min : writeDuration;
+ writeResult.max = (writeDuration < writeResult.max) ? writeResult.max : writeDuration;
+ writeResult.average += writeDuration;
+ readResult.min = (readDuration > readResult.min) ? readResult.min : readDuration;
+ readResult.max = (readDuration < readResult.max) ? readResult.max : readDuration;
+ readResult.average += readDuration;
- uint32_t duration = CalcSpendTime(startPoint, endPoint);
- writeResult.min = (duration > writeResult.min) ? writeResult.min : duration;
- writeResult.max = (duration < writeResult.max) ? writeResult.max : duration;
- writeResult.average += duration;
-
- startPoint = std::chrono::steady_clock::now();
- const uint8_t *readBuffer = OH_IPCParcel_ReadBuffer(dataCParcel, TEST_PARCEL_SIZE);
- endPoint = std::chrono::steady_clock::now();
- ASSERT_NE(readBuffer, nullptr);
- EXPECT_EQ(memcmp(readBuffer, buf, TEST_PARCEL_SIZE), 0);
-
- duration = CalcSpendTime(startPoint, endPoint);
- readResult.min = (duration > readResult.min) ? readResult.min : duration;
- readResult.max = (duration < readResult.max) ? readResult.max : duration;
- readResult.average += duration;
-
- OH_IPCParcel_Destroy(dataCParcel);
+ uint32_t writeCppDuration = 0;
+ uint32_t readCppDuration = 0;
+ ReadWriteBufferCpp(buf, TEST_PARCEL_SIZE, writeCppDuration, readCppDuration);
+ writeCppResult.min = (writeCppDuration > writeCppResult.min) ? writeCppResult.min : writeCppDuration;
+ writeCppResult.max = (writeCppDuration < writeCppResult.max) ? writeCppResult.max : writeCppDuration;
+ writeCppResult.average += writeCppDuration;
+ readCppResult.min = (readCppDuration > readCppResult.min) ? readCppResult.min : readCppDuration;
+ readCppResult.max = (readCppDuration < readCppResult.max) ? readCppResult.max : readCppDuration;
+ readCppResult.average += readCppDuration;
}
writeResult.average /= TEST_PERFORMANCE_OPERATOR_COUNT;
readResult.average /= TEST_PERFORMANCE_OPERATOR_COUNT;
+ writeCppResult.average /= TEST_PERFORMANCE_OPERATOR_COUNT;
+ readCppResult.average /= TEST_PERFORMANCE_OPERATOR_COUNT;
}
-void IpcCApiParcelUnitTest::ReadWriteBufferCppPerformance(PerformanceResult &writeResult,
- PerformanceResult &readResult)
+void IpcCApiParcelUnitTest::ReadWriteInterfaceToken(const char *token,
+ uint32_t &writeDuration, uint32_t &readDuration)
{
- uint8_t buf[TEST_PARCEL_SIZE] = {0};
- EXPECT_EQ(memset_s(buf, sizeof(buf), '2', sizeof(buf)), EOK);
- for (int i = 0; i < TEST_PERFORMANCE_OPERATOR_COUNT; ++i) {
- MessageParcel dataCpp;
- auto startPoint = std::chrono::steady_clock::now();
- dataCpp.WriteBuffer(buf, TEST_PARCEL_SIZE);
- auto endPoint = std::chrono::steady_clock::now();
+ auto dataCParcel = OH_IPCParcel_Create();
+ int ret = OH_IPC_SUCCESS;
+ auto startPoint = std::chrono::steady_clock::now();
+ ret = OH_IPCParcel_WriteInterfaceToken(dataCParcel, token);
+ auto endPoint = std::chrono::steady_clock::now();
+ ASSERT_EQ(ret, OH_IPC_SUCCESS);
+ writeDuration = CalcSpendTime(startPoint, endPoint);
- uint32_t duration = CalcSpendTime(startPoint, endPoint);
- writeResult.min = (duration > writeResult.min) ? writeResult.min : duration;
- writeResult.max = (duration < writeResult.max) ? writeResult.max : duration;
- writeResult.average += duration;
+ int readLen = 0;
+ char *readInterfaceToken = nullptr;
+ startPoint = std::chrono::steady_clock::now();
+ ret = OH_IPCParcel_ReadInterfaceToken(dataCParcel, &readInterfaceToken, &readLen, LocalMemAllocator);
+ endPoint = std::chrono::steady_clock::now();
+ EXPECT_EQ(strcmp(token, readInterfaceToken), 0);
+ EXPECT_EQ(readLen, strlen(token) + 1);
+ free(readInterfaceToken);
+ OH_IPCParcel_Destroy(dataCParcel);
+ readDuration = CalcSpendTime(startPoint, endPoint);
+}
- startPoint = std::chrono::steady_clock::now();
- const uint8_t* readBuf = dataCpp.ReadBuffer(TEST_PARCEL_SIZE);
- endPoint = std::chrono::steady_clock::now();
- ASSERT_NE(readBuf, nullptr);
- EXPECT_EQ(memcmp(readBuf, buf, TEST_PARCEL_SIZE), 0);
+void IpcCApiParcelUnitTest::ReadWriteInterfaceTokenCpp(const char *token,
+ uint32_t &writeDuration, uint32_t &readDuration)
+{
+ MessageParcel dataCpp;
+ auto startPoint = std::chrono::steady_clock::now();
+ auto u16Token = OHOS::Str8ToStr16(token);
+ dataCpp.WriteInterfaceToken(u16Token.c_str());
+ auto endPoint = std::chrono::steady_clock::now();
+ writeDuration = CalcSpendTime(startPoint, endPoint);
- duration = CalcSpendTime(startPoint, endPoint);
- readResult.min = (duration > readResult.min) ? readResult.min : duration;
- readResult.max = (duration < readResult.max) ? readResult.max : duration;
- readResult.average += duration;
- }
- writeResult.average /= TEST_PERFORMANCE_OPERATOR_COUNT;
- readResult.average /= TEST_PERFORMANCE_OPERATOR_COUNT;
+ startPoint = std::chrono::steady_clock::now();
+ auto u16TokenRead = dataCpp.ReadInterfaceToken();
+ std::string strTokenRead = OHOS::Str16ToStr8(u16TokenRead);
+ endPoint = std::chrono::steady_clock::now();
+ EXPECT_EQ(strTokenRead.length(), strlen(token));
+ EXPECT_EQ(strTokenRead.compare(token), 0);
+ readDuration = CalcSpendTime(startPoint, endPoint);
}
void IpcCApiParcelUnitTest::ReadWriteInterfaceTokenPerformance(PerformanceResult &writeResult,
- PerformanceResult &readResult)
+ PerformanceResult &readResult, PerformanceResult &writeCppResult, PerformanceResult &readCppResult)
{
char token[MAX_INTERFACE_TOKEN_LEN] = {0};
- EXPECT_EQ(memset_s(token, sizeof(token) - 1, '1', sizeof(token) - 1), EOK);
+ ASSERT_EQ(memset_s(token, sizeof(token) - 1, '1', sizeof(token) - 1), EOK);
for (int i = 0; i < TEST_PERFORMANCE_OPERATOR_COUNT; ++i) {
- auto dataCParcel = OH_IPCParcel_Create();
- int ret = OH_IPC_SUCCESS;
- auto startPoint = std::chrono::steady_clock::now();
- ret = OH_IPCParcel_WriteInterfaceToken(dataCParcel, token);
- auto endPoint = std::chrono::steady_clock::now();
- ASSERT_EQ(ret, OH_IPC_SUCCESS);
+ uint32_t writeDuration = 0;
+ uint32_t readDuration = 0;
+ ReadWriteInterfaceToken(token, writeDuration, readDuration);
+ writeResult.min = (writeDuration > writeResult.min) ? writeResult.min : writeDuration;
+ writeResult.max = (writeDuration < writeResult.max) ? writeResult.max : writeDuration;
+ writeResult.average += writeDuration;
+ readResult.min = (readDuration > readResult.min) ? readResult.min : readDuration;
+ readResult.max = (readDuration < readResult.max) ? readResult.max : readDuration;
+ readResult.average += readDuration;
- uint32_t duration = CalcSpendTime(startPoint, endPoint);
- writeResult.min = (duration > writeResult.min) ? writeResult.min : duration;
- writeResult.max = (duration < writeResult.max) ? writeResult.max : duration;
- writeResult.average += duration;
-
- int readLen = 0;
- char *readInterfaceToken = nullptr;
- startPoint = std::chrono::steady_clock::now();
- ret = OH_IPCParcel_ReadInterfaceToken(dataCParcel, &readInterfaceToken, &readLen, LocalMemAllocator);
- endPoint = std::chrono::steady_clock::now();
- EXPECT_EQ(strcmp(token, readInterfaceToken), 0);
- EXPECT_EQ(readLen, MAX_INTERFACE_TOKEN_LEN);
-
- duration = CalcSpendTime(startPoint, endPoint);
- readResult.min = (duration > readResult.min) ? readResult.min : duration;
- readResult.max = (duration < readResult.max) ? readResult.max : duration;
- readResult.average += duration;
-
- OH_IPCParcel_Destroy(dataCParcel);
- }
- writeResult.average /= TEST_PERFORMANCE_OPERATOR_COUNT;
- readResult.average /= TEST_PERFORMANCE_OPERATOR_COUNT;
-}
-
-void IpcCApiParcelUnitTest::ReadWriteInterfaceTokenCppPerformance(PerformanceResult &writeResult,
- PerformanceResult &readResult)
-{
- char token[MAX_INTERFACE_TOKEN_LEN] = {0};
- EXPECT_EQ(memset_s(token, sizeof(token) - 1, '1', sizeof(token) - 1), EOK);
- for (int i = 0; i < TEST_PERFORMANCE_OPERATOR_COUNT; ++i) {
- MessageParcel dataCpp;
- auto startPoint = std::chrono::steady_clock::now();
- auto u16Token = OHOS::Str8ToStr16(token);
- dataCpp.WriteInterfaceToken(u16Token.c_str());
- auto endPoint = std::chrono::steady_clock::now();
-
- uint32_t duration = CalcSpendTime(startPoint, endPoint);
- writeResult.min = (duration > writeResult.min) ? writeResult.min : duration;
- writeResult.max = (duration < writeResult.max) ? writeResult.max : duration;
- writeResult.average += duration;
-
- startPoint = std::chrono::steady_clock::now();
- auto u16TokenRead = dataCpp.ReadInterfaceToken();
- std::string strTokenRead = OHOS::Str16ToStr8(u16TokenRead);
- endPoint = std::chrono::steady_clock::now();
- EXPECT_EQ(strTokenRead.length(), MAX_INTERFACE_TOKEN_LEN - 1);
- EXPECT_EQ(strTokenRead.compare(token), 0);
-
- duration = CalcSpendTime(startPoint, endPoint);
- readResult.min = (duration > readResult.min) ? readResult.min : duration;
- readResult.max = (duration < readResult.max) ? readResult.max : duration;
- readResult.average += duration;
+ uint32_t writeCppDuration = 0;
+ uint32_t readCppDuration = 0;
+ ReadWriteInterfaceTokenCpp(token, writeCppDuration, readCppDuration);
+ writeCppResult.min = (writeCppDuration > writeCppResult.min) ? writeCppResult.min : writeCppDuration;
+ writeCppResult.max = (writeCppDuration < writeCppResult.max) ? writeCppResult.max : writeCppDuration;
+ writeCppResult.average += writeCppDuration;
+ readCppResult.min = (readCppDuration > readCppResult.min) ? readCppResult.min : readCppDuration;
+ readCppResult.max = (readCppDuration < readCppResult.max) ? readCppResult.max : readCppDuration;
+ readCppResult.average += readCppDuration;
}
writeResult.average /= TEST_PERFORMANCE_OPERATOR_COUNT;
readResult.average /= TEST_PERFORMANCE_OPERATOR_COUNT;
+ writeCppResult.average /= TEST_PERFORMANCE_OPERATOR_COUNT;
+ readCppResult.average /= TEST_PERFORMANCE_OPERATOR_COUNT;
}
HWTEST_F(IpcCApiParcelUnitTest, OH_IPCParcel_Create_001, TestSize.Level1)
@@ -764,64 +801,108 @@ HWTEST_F(IpcCApiParcelUnitTest, OH_IPCParcel_TestReadWriteInterfaceToken_001, Te
HWTEST_F(IpcCApiParcelUnitTest, OH_IPCParcel_TestReadWriteStringPerformance_001, TestSize.Level1)
{
- PerformanceResult writeResult;
- PerformanceResult readResult;
- ReadWriteStringPerformance(writeResult, readResult);
+ uint32_t writeAvg = 0;
+ uint32_t readAvg = 0;
+ uint32_t writeCppAvg = 0;
+ uint32_t readCppAvg = 0;
+ for (int i = 0; i < TEST_PERFORMANCE_OPERATOR_GROUP; ++i) {
+ PerformanceResult writeResult;
+ PerformanceResult readResult;
+ PerformanceResult writeCppResult;
+ PerformanceResult readCppResult;
+ ReadWriteStringPerformance(writeResult, readResult, writeCppResult, readCppResult);
- PerformanceResult writeCppResult;
- PerformanceResult readCppResult;
- ReadWriteStringCppPerformance(writeCppResult, readCppResult);
+ writeAvg += writeResult.average;
+ readAvg += readResult.average;
+ writeCppAvg += writeCppResult.average;
+ readCppAvg += readCppResult.average;
- std::cout << "Test String len:" << TEST_PARCEL_SIZE << ", count:" << TEST_PERFORMANCE_OPERATOR_COUNT << std::endl;
- std::cout << "OHIPCParcel WriteCString spend:[min:" << writeResult.min << ", max:" << writeResult.max
- << ", avg:" << writeResult.average << "]us" << std::endl;
- std::cout << "MessageParcel WriteCString spend:[min:" << writeCppResult.min << ", max:" << writeCppResult.max
- << ", avg:" << writeCppResult.average << "]us" << std::endl;
- std::cout << "OHIPCParcel ReadCString spend:[min:" << readResult.min << ", max:" << readResult.max
- << ", avg:" << readResult.average << "]us" << std::endl;
- std::cout << "MessageParcel ReadCString spend:[min:" << readCppResult.min << ", max:" << readCppResult.max
- << ", avg:" << readCppResult.average << "]us" << std::endl;
+ std::cout << "Test String len:" << TEST_PARCEL_SIZE << ", count:"
+ << TEST_PERFORMANCE_OPERATOR_COUNT << std::endl;
+ std::cout << "OHIPCParcel WriteCString spend:[min:" << writeResult.min << ", max:" << writeResult.max
+ << ", avg:" << writeResult.average << "]us" << std::endl;
+ std::cout << "MessageParcel WriteCString spend:[min:" << writeCppResult.min << ", max:" << writeCppResult.max
+ << ", avg:" << writeCppResult.average << "]us" << std::endl;
+ std::cout << "OHIPCParcel ReadCString spend:[min:" << readResult.min << ", max:" << readResult.max
+ << ", avg:" << readResult.average << "]us" << std::endl;
+ std::cout << "MessageParcel ReadCString spend:[min:" << readCppResult.min << ", max:" << readCppResult.max
+ << ", avg:" << readCppResult.average << "]us" << std::endl;
+ }
+ writeAvg /= TEST_PERFORMANCE_OPERATOR_GROUP;
+ readAvg /= TEST_PERFORMANCE_OPERATOR_GROUP;
+ writeCppAvg /= TEST_PERFORMANCE_OPERATOR_GROUP;
+ readCppAvg /= TEST_PERFORMANCE_OPERATOR_GROUP;
+ PerformanceStatistic(writeAvg, readAvg, writeCppAvg, readCppAvg);
}
HWTEST_F(IpcCApiParcelUnitTest, OH_IPCParcel_TestReadWriteBufferPerformance_001, TestSize.Level1)
{
- PerformanceResult writeResult;
- PerformanceResult readResult;
- ReadWriteBufferPerformance(writeResult, readResult);
+ uint32_t writeAvg = 0;
+ uint32_t readAvg = 0;
+ uint32_t writeCppAvg = 0;
+ uint32_t readCppAvg = 0;
+ for (int i = 0; i < TEST_PERFORMANCE_OPERATOR_GROUP; ++i) {
+ PerformanceResult writeResult;
+ PerformanceResult readResult;
+ PerformanceResult writeCppResult;
+ PerformanceResult readCppResult;
+ ReadWriteBufferPerformance(writeResult, readResult, writeCppResult, readCppResult);
- PerformanceResult writeCppResult;
- PerformanceResult readCppResult;
- ReadWriteBufferCppPerformance(writeCppResult, readCppResult);
+ writeAvg += writeResult.average;
+ readAvg += readResult.average;
+ writeCppAvg += writeCppResult.average;
+ readCppAvg += readCppResult.average;
- std::cout << "Test Buffer len:" << TEST_PARCEL_SIZE << ", count:" << TEST_PERFORMANCE_OPERATOR_COUNT << std::endl;
- std::cout << "OHIPCParcel WriteBuffer spend:[min:" << writeResult.min << ", max:" << writeResult.max
- << ", avg:" << writeResult.average << "]us" << std::endl;
- std::cout << "MessageParcel WriteBuffer spend:[min:" << writeCppResult.min << ", max:" << writeCppResult.max
- << ", avg:" << writeCppResult.average << "]us" << std::endl;
- std::cout << "OHIPCParcel ReadBuffer spend:[min:" << readResult.min << ", max:" << readResult.max
- << ", avg:" << readResult.average << "]us" << std::endl;
- std::cout << "MessageParcel ReadBuffer spend:[min:" << readCppResult.min << ", max:" << readCppResult.max
- << ", avg:" << readCppResult.average << "]us" << std::endl;
+ std::cout << "Test Buffer len:" << TEST_PARCEL_SIZE << ", count:"
+ << TEST_PERFORMANCE_OPERATOR_COUNT << std::endl;
+ std::cout << "OHIPCParcel WriteBuffer spend:[min:" << writeResult.min << ", max:" << writeResult.max
+ << ", avg:" << writeResult.average << "]us" << std::endl;
+ std::cout << "MessageParcel WriteBuffer spend:[min:" << writeCppResult.min << ", max:" << writeCppResult.max
+ << ", avg:" << writeCppResult.average << "]us" << std::endl;
+ std::cout << "OHIPCParcel ReadBuffer spend:[min:" << readResult.min << ", max:" << readResult.max
+ << ", avg:" << readResult.average << "]us" << std::endl;
+ std::cout << "MessageParcel ReadBuffer spend:[min:" << readCppResult.min << ", max:" << readCppResult.max
+ << ", avg:" << readCppResult.average << "]us" << std::endl;
+ }
+ writeAvg /= TEST_PERFORMANCE_OPERATOR_GROUP;
+ readAvg /= TEST_PERFORMANCE_OPERATOR_GROUP;
+ writeCppAvg /= TEST_PERFORMANCE_OPERATOR_GROUP;
+ readCppAvg /= TEST_PERFORMANCE_OPERATOR_GROUP;
+ PerformanceStatistic(writeAvg, readAvg, writeCppAvg, readCppAvg);
}
HWTEST_F(IpcCApiParcelUnitTest, OH_IPCParcel_TestReadWriteInterfaceTokenPerformance_001, TestSize.Level1)
{
- PerformanceResult writeResult;
- PerformanceResult readResult;
- ReadWriteInterfaceTokenPerformance(writeResult, readResult);
+ uint32_t writeAvg = 0;
+ uint32_t readAvg = 0;
+ uint32_t writeCppAvg = 0;
+ uint32_t readCppAvg = 0;
+ for (int i = 0; i < TEST_PERFORMANCE_OPERATOR_GROUP; ++i) {
+ PerformanceResult writeResult;
+ PerformanceResult readResult;
+ PerformanceResult writeCppResult;
+ PerformanceResult readCppResult;
+ ReadWriteInterfaceTokenPerformance(writeResult, readResult, writeCppResult, readCppResult);
- PerformanceResult writeCppResult;
- PerformanceResult readCppResult;
- ReadWriteInterfaceTokenCppPerformance(writeCppResult, readCppResult);
+ writeAvg += writeResult.average;
+ readAvg += readResult.average;
+ writeCppAvg += writeCppResult.average;
+ readCppAvg += readCppResult.average;
- std::cout << "Test token len:" << MAX_INTERFACE_TOKEN_LEN << ", count:"
- << TEST_PERFORMANCE_OPERATOR_COUNT << std::endl;
- std::cout << "OHIPCParcel WriteInterfaceToken spend:[min:" << writeResult.min << ", max:"
- << writeResult.max << ", avg:" << writeResult.average << "]us" << std::endl;
- std::cout << "MessageParcel WriteInterfaceToken spend:[min:" << writeCppResult.min
- << ", max:" << writeCppResult.max << ", avg:" << writeCppResult.average << "]us" << std::endl;
- std::cout << "OHIPCParcel ReadInterfaceToken spend:[min:" << readResult.min << ", max:"
- << readResult.max << ", avg:" << readResult.average << "]us" << std::endl;
- std::cout << "MessageParcel ReadInterfaceToken spend:[min:" << readCppResult.min << ", max:"
- << readCppResult.max << ", avg:" << readCppResult.average << "]us" << std::endl;
+ std::cout << "Test token len:" << MAX_INTERFACE_TOKEN_LEN << ", count:"
+ << TEST_PERFORMANCE_OPERATOR_COUNT << std::endl;
+ std::cout << "OHIPCParcel WriteInterfaceToken spend:[min:" << writeResult.min << ", max:"
+ << writeResult.max << ", avg:" << writeResult.average << "]us" << std::endl;
+ std::cout << "MessageParcel WriteInterfaceToken spend:[min:" << writeCppResult.min
+ << ", max:" << writeCppResult.max << ", avg:" << writeCppResult.average << "]us" << std::endl;
+ std::cout << "OHIPCParcel ReadInterfaceToken spend:[min:" << readResult.min << ", max:"
+ << readResult.max << ", avg:" << readResult.average << "]us" << std::endl;
+ std::cout << "MessageParcel ReadInterfaceToken spend:[min:" << readCppResult.min << ", max:"
+ << readCppResult.max << ", avg:" << readCppResult.average << "]us" << std::endl;
+ }
+ writeAvg /= TEST_PERFORMANCE_OPERATOR_GROUP;
+ readAvg /= TEST_PERFORMANCE_OPERATOR_GROUP;
+ writeCppAvg /= TEST_PERFORMANCE_OPERATOR_GROUP;
+ readCppAvg /= TEST_PERFORMANCE_OPERATOR_GROUP;
+ PerformanceStatistic(writeAvg, readAvg, writeCppAvg, readCppAvg);
}
diff --git a/ipc/test/auxiliary/native/include/test_capi_skeleton.h b/ipc/test/auxiliary/native/include/test_capi_skeleton.h
index 0eb81542..540ea5a1 100644
--- a/ipc/test/auxiliary/native/include/test_capi_skeleton.h
+++ b/ipc/test/auxiliary/native/include/test_capi_skeleton.h
@@ -88,8 +88,8 @@ private:
std::random_device randomDevice_;
std::uniform_int_distribution<> randomDistribution_{ 1, 10000 };
- OHIPCRemoteProxy* proxy_{ nullptr };
- OHIPCRemoteStub* stubCallBack_{ nullptr };
+ OHIPCRemoteProxy *proxy_{ nullptr };
+ OHIPCRemoteStub *stubCallBack_{ nullptr };
};
class NativeRemoteStubTest : public NativeRemoteBase {
diff --git a/ipc/test/auxiliary/native/src/main_client.cpp b/ipc/test/auxiliary/native/src/main_client.cpp
index 658cd6e1..c7353802 100644
--- a/ipc/test/auxiliary/native/src/main_client.cpp
+++ b/ipc/test/auxiliary/native/src/main_client.cpp
@@ -143,6 +143,6 @@ void SignalHandler(int signum)
}
if (signum == SIGINT) {
ZLOGD(LABEL, "SIGINT");
- exit(1);
+ IPCSkeleton::StopWorkThread();
}
}