Merge branch 'master' of gitee.com:openharmony/communication_ipc into master

Signed-off-by: yanghang <yanghang86@huawei.com>
This commit is contained in:
yanghang 2024-05-16 06:35:39 +00:00 committed by Gitee
commit 3f17d50615
11 changed files with 788 additions and 623 deletions

View File

@ -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 <b>OHIPCParcel</b> object, which cannot exceed 204,800 bytes.
*
* @syscap SystemCapability.Communication.IPC.Core
* @return OHIPCParcel对象指针NULL.
* @return Returns the pointer to the <b>OHIPCParcel</b> object created if the operation is successful;
* returns NULL otherwise.
* @since 12
*/
OHIPCParcel* OH_IPCParcel_Create(void);
/**
* @brief OHIPCParcel对象.
* @brief Destroys an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @param parcel OHIPCParcel对象的指针.
* @param parcel Pointer to the <b>OHIPCParcel</b> object to destroy.
* @since 12
*/
void OH_IPCParcel_Destroy(OHIPCParcel *parcel);
/**
* @brief OHIPCParcel对象包含的数据的大小.
* @brief Obtains the size of the data contained in an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @param parcel OHIPCParcel对象的指针.
* @return -1.
* @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
* @return Returns the data size obtained if the operation is successful.\n
* Returns <b>-1</b> 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 <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @param parcel OHIPCParcel对象的指针.
* @return -1.
* @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
* @return Returns the number of bytes that can be written to the <b>OHIPCParcel</b> object. \n
* Returns <b>-1</b> 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 <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @param parcel OHIPCParcel对象的指针.
* @return -1.
* @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
* @return Returns the number of bytes that can be read from the <b>OHIPCParcel</b> object. \n
* Returns <b>-1</b> 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 <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @param parcel OHIPCParcel对象的指针.
* @return -1
* @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
* @return Returns the position obtained if the operation is successful. \n
* Returns <b>-1</b> 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 <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @param parcel OHIPCParcel对象的指针.
* @return -1.
* @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
* @return Returns the position obtained if the operation is successful. \n
* Returns <b>-1</b> 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 <b>OHIPCParcel</b> object. It cannot be NULL.
* @param newReadPos New position to read data. The value ranges from <b>0</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> object. It cannot be NULL.
* @param newWritePos New position to write data. The value ranges from <b>0</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> object. You can obtain the length of the string from <b>strlen</b>.
*
* @syscap SystemCapability.Communication.IPC.Core
* @param parcel OHIPCParcel对象的指针
* @return NULL
* @param parcel Pointer to the target <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @param parcel OHIPCParcel对象的指针
* @param len
* @return len超过parcel可读长度时返回NULL
* @param parcel Pointer to the target <b>OHIPCParcel</b> 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 <b>len</b> exceeds the readable length of <b>parcel</b>.
* @since 12
*/
const uint8_t* OH_IPCParcel_ReadBuffer(const OHIPCParcel *parcel, int32_t len);
/**
* @brief OHIPCParcel对象写入OHIPCRemoteStub对象.
* @brief Writes an <b>OHIPCRemoteStub</b> object to an <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> object. It cannot be NULL.
* @param stub Pointer to the <b>OHIPCRemoteStub</b> 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 <b>OHIPCRemoteStub</b> object from an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @param parcel OHIPCParcel对象的指针.
* @return OHIPCRemoteStub对象指针NULL.
* @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
* @return Returns the pointer to the <b>OHIPCRemoteStub</b> 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 <b>OHIPCRemoteProxy</b> object to an <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> object. It cannot be NULL.
* @param proxy Pointer to the <b>OHIPCRemoteProxy</b> 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 <b>OHIPCRemoteProxy</b> object from an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @param parcel OHIPCParcel对象的指针.
* @return OHIPCRemoteProxy对象指针NULL.
* @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
* @return Returns the pointer to the <b>OHIPCRemoteProxy</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>OHIPCParcel</b> 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 <b>token</b>. 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

View File

@ -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 <b>OHIPCDeathRecipient</b> object, which is used to receive a notification
* when the <b>OHIPCRemoteStub</b> object dies unexpectedly.
*
* @syscap SystemCapability.Communication.IPC.Core
* @since 12
*/
struct OHIPCDeathRecipient;
/**
* @brief Stub端用于处理远端数据请求的回调函数.
* @brief Typedef an <b>OHIPCDeathRecipient</b> 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 <b>OHIPCRemoteStub</b> 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 <b>OHIPCRemoteStub</b> 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 <b>OHIPCRemoteStub</b> 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 <b>OHIPCRemoteStub</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @param stub OHIPCRemoteStub对象指针.
* @param stub Pointer to the <b>OHIPCRemoteStub</b> object to destroy.
* @since 12
*/
void OH_IPCRemoteStub_Destroy(OHIPCRemoteStub *stub);
/**
* @brief OHIPCRemoteProxy对象.
* @brief Destroys an <b>OHIPCRemoteProxy</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @param proxy OHIPCRemoteProxy对象指针.
* @param proxy Pointer to the <b>OHIPCRemoteProxy</b> 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 <b>OHIPCRemoteProxy</b> 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 <b>OHIPCRemoteStub</b> 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 <b>OHIPCRemoteProxy</b> 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 <b>descriptor</b>.
* 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 <b>OHIPCRemoteStub</b> 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 <b>OHIPCRemoteStub</b> 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 <b>OHIPCDeathRecipient</b> 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 <b>OHIPCDeathRecipient</b> object, which allows a notification to be received
* when the <b>OHIPCRemoteStub</b> 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 <b>OHIPCRemoteStub</b> 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 <b>OHIPCDeathRecipient</b> 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 <b>OHIPCDeathRecipient</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @param recipient OHIPCDeathRecipient对象指针.
* @param recipient Pointer to the <b>OHIPCDeathRecipient</b> object to destroy.
* @since 12
*/
void OH_IPCDeathRecipient_Destroy(OHIPCDeathRecipient *recipient);
/**
* @brief OHIPCRemoteProxy对象添加死亡监听OHIPCRemoteStub对象死亡的回调通知.
* @brief Subscribes to the death of an <b>OHIPCRemoteStub</b> object for an <b>OHIPCRemoteProxy</b> 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 <b>OHIPCRemoteProxy</b> object that subscribes to the death notification.
* It cannot be NULL.
* @param recipient Pointer to the object that receives the death notification of the <b>OHIPCRemoteStub</b> 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 <b>OHIPCRemoteStub</b> object for an <b>OHIPCRemoteProxy</b> 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 <b>OHIPCRemoteProxy</b> object that unsubscribes from the death notification.
* It cannot be NULL.
* @param recipient Pointer to the object that receives the death notification of the <b>OHIPCRemoteStub</b> 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 <b>OHIPCRemoteStub</b> object corresponding to the <b>OHIPCRemoteProxy</b> object is dead.
*
* @syscap SystemCapability.Communication.IPC.Core
* @param proxy OHIPCRemoteProxy对象指针.
* @return OHIPCRemoteStub对象死亡返回1; 0. OHIPCRemoteStub对象不存在1.
* @param proxy Pointer to the <b>OHIPCRemoteProxy</b> object to check. It cannot be NULL.
* @return Returns <b>1</b> if the <b>OHIPCRemoteStub</b> object is dead; returns <b>0</b> otherwise.
* If an invalid parameter is found, the <b>OHIPCRemoteStub</b> object does not exist.
* In this case, <b>1</b> is returned.
* @since 12
*/
int OH_IPCRemoteProxy_IsRemoteDead(const OHIPCRemoteProxy *proxy);

View File

@ -20,7 +20,8 @@
* @addtogroup OHIPCSkeleton
* @{
*
* @brief IPC框架tokenIdPID/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框架tokenIdPID/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 10.
* @return Returns <b>1</b> if a local calling is in progress; returns <b>0</b> 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 <b>16</b>.
* 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 tokenidUID和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 <b>OH_IPCSkeleton_SetCallingIdentity</b>.
*
* @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 <b>identity</b>. 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 <b>OH_IPCSkeleton_ResetCallingIdentity</b>.
* @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请求10.
* @return Returns <b>1</b> if an IPC request is being handled; returns <b>0</b> otherwise.
* @since 12
*/
int OH_IPCSkeleton_IsHandlingTransaction(void);

View File

@ -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

View File

@ -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

View File

@ -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<int32_t> readHandleFromCommandsSet = {BC_ACQUIRE, BC_RELEASE,
BC_REQUEST_DEATH_NOTIFICATION, BC_REPLY, BC_CLEAR_DEATH_NOTIFICATION, BC_FREE_BUFFER, BC_TRANSACTION};
const std::map<int32_t, std::function<void(int32_t cmd, int32_t &error)>> 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;

View File

@ -558,7 +558,7 @@ void BinderInvoker::GetSenderInfo(uint64_t &callerTokenID, uint64_t &firstTokenI
realPid = static_cast<pid_t>(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<const binder_transaction_data *>(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;

View File

@ -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<const uint8_t*>(&trData));
invoker->Transaction(reinterpret_cast<const uint8_t*>(&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;
}

View File

@ -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<uint32_t>(std::chrono::duration_cast<std::chrono::microseconds>(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);
}

View File

@ -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 {

View File

@ -143,6 +143,6 @@ void SignalHandler(int signum)
}
if (signum == SIGINT) {
ZLOGD(LABEL, "SIGINT");
exit(1);
IPCSkeleton::StopWorkThread();
}
}