add ipc capi interface

Signed-off-by: hubin <hubin29@huawei.com>
This commit is contained in:
hubin 2024-05-08 11:27:32 +08:00
parent ce83e4aff6
commit 0c9c5f03e2
7 changed files with 1382 additions and 0 deletions

40
IPCKit/BUILD.gn Normal file
View File

@ -0,0 +1,40 @@
# Copyright (C) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos.gni")
import("//build/ohos/ndk/ndk.gni")
ohos_ndk_headers("ipc_capi_header") {
dest_dir = "$ndk_headers_out_dir/IPCKit"
sources = [
"./ipc_cparcel.h",
"./ipc_cremote_object.h",
"./ipc_cskeleton.h",
"./ipc_error_code.h",
"./ipc_kit.h",
]
}
ohos_ndk_library("libipc_capi") {
output_name = "ipc_capi"
output_extension = "so"
ndk_description_file = "./libipc_capi.json"
system_capability = "SystemCapability.Communication.IPC.Core"
system_capability_headers = [
"IPCKit/ipc_cparcel.h",
"IPCKit/ipc_cremote_object.h",
"IPCKit/ipc_cskeleton.h",
"IPCKit/ipc_error_code.h",
"IPCKit/ipc_kit.h",
]
}

531
IPCKit/ipc_cparcel.h Normal file
View File

@ -0,0 +1,531 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef CAPI_INCLUDE_IPC_CPARCEL_H
#define CAPI_INCLUDE_IPC_CPARCEL_H
/**
* @addtogroup OHIPCParcel
* @{
*
* @brief Defines C interfaces for IPC serialization and deserialization.
*
* @syscap SystemCapability.Communication.IPC.Core
* @since 12
*/
/**
* @file ipc_cparcel.h
*
* @brief Defines C interfaces for IPC serialization and deserialization.
*
* @library libipc_capi.so
* @syscap SystemCapability.Communication.IPC.Core
* @since 12
*/
#include <stdint.h>
#ifdef __cplusplus
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 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 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 Creates an <b>OHIPCParcel</b> object, which cannot exceed 204,800 bytes.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Destroys an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @param parcel Pointer to the <b>OHIPCParcel</b> object to destroy.
* @since 12
*/
void OH_IPCParcel_Destroy(OHIPCParcel *parcel);
/**
* @brief Obtains the size of the data contained in an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Obtains the number of bytes that can be written to an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Obtains the number of bytes that can be read from an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Obtains the position where data is read in an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Obtains the position where data is written in an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Resets the position to read data in an IPC parcel.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Resets the position to write data in an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Writes an int8_t value to an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Reads an int8_t value from an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Writes an int16_t value to an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Reads an int16_t value from an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Writes an int32_t value to an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Reads an int32_t value from an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Writes an int64_t value to an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Reads an int64_t value from an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Writes a float value to an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Reads a float value from an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Writes a double value to an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Reads a double value from an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Writes a string including a string terminator to an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 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 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 Writes data of the specified length from the memory to an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Reads memory information of the specified length from an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Writes an <b>OHIPCRemoteStub</b> object to an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Reads the <b>OHIPCRemoteStub</b> object from an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Writes an <b>OHIPCRemoteProxy</b> object to an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Reads the <b>OHIPCRemoteProxy</b> object from an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Writes a file descriptor to an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Reads a file descriptor from an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Appends data to an <b>OHIPCParcel</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Writes an interface token to an <b>OHIPCParcel</b> object for interface identity verification.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Reads an interface token from an <b>OHIPCParcel</b> object for interface identity verification.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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,
OH_IPC_MemAllocator allocator);
#ifdef __cplusplus
}
#endif
/** @} */
#endif

286
IPCKit/ipc_cremote_object.h Normal file
View File

@ -0,0 +1,286 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef CAPI_INCLUDE_IPC_CREMOTE_OBJECT_H
#define CAPI_INCLUDE_IPC_CREMOTE_OBJECT_H
/**
* @addtogroup OHIPCRemoteObject
* @{
*
* @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
*/
/**
* @file ipc_cremote_object.h
*
* @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
*/
#include <stdint.h>
#include "ipc_cparcel.h"
#ifdef __cplusplus
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 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 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 Called when an observed object is destroyed.
*
* @syscap SystemCapability.Communication.IPC.Core
* @param userData Pointer to the user data. It can be NULL.
* @since 12
*/
typedef void (*OH_OnRemoteDestroyCallback)(void *userData);
/**
* @brief Creates an <b>OHIPCRemoteStub</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Destroys an <b>OHIPCRemoteStub</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @param stub Pointer to the <b>OHIPCRemoteStub</b> object to destroy.
* @since 12
*/
void OH_IPCRemoteStub_Destroy(OHIPCRemoteStub *stub);
/**
* @brief Destroys an <b>OHIPCRemoteProxy</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @param proxy Pointer to the <b>OHIPCRemoteProxy</b> object to destroy.
* @since 12
*/
void OH_IPCRemoteProxy_Destroy(OHIPCRemoteProxy *proxy);
/**
* @brief Enumerates the IPC request modes.
*
* @since 12
*/
typedef enum {
/** Synchronous request. */
OH_IPC_REQUEST_MODE_SYNC = 0,
/** Asynchronous request. */
OH_IPC_REQUEST_MODE_ASYNC = 1,
} OH_IPC_RequestMode;
/**
* @brief Defines the IPC message options.
*
* @since 12
*/
#pragma pack(4)
typedef struct {
/** Message request mode. */
OH_IPC_RequestMode mode;
/** 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 Sends an IPC message.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Obtains the interface descriptor from the stub.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Called when the <b>OHIPCRemoteStub</b> object dies unexpectedly.
*
* @syscap SystemCapability.Communication.IPC.Core
* @param userData Pointer to the user data. It can be NULL.
* @since 12
*/
typedef void (*OH_OnDeathRecipientCallback)(void *userData);
/**
* @brief Called when the <b>OHIPCDeathRecipient</b> object is destroyed.
*
* @syscap SystemCapability.Communication.IPC.Core
* @param userData Pointer to the user data. It can be NULL.
* @since 12
*/
typedef void (*OH_OnDeathRecipientDestroyCallback)(void *userData);
/**
* @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 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 Destroys an <b>OHIPCDeathRecipient</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @param recipient Pointer to the <b>OHIPCDeathRecipient</b> object to destroy.
* @since 12
*/
void OH_IPCDeathRecipient_Destroy(OHIPCDeathRecipient *recipient);
/**
* @brief Subscribes to the death of an <b>OHIPCRemoteStub</b> object for an <b>OHIPCRemoteProxy</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Unsubscribes from the death of the <b>OHIPCRemoteStub</b> object for an <b>OHIPCRemoteProxy</b> object.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Checks whether the <b>OHIPCRemoteStub</b> object corresponding to the <b>OHIPCRemoteProxy</b> object is dead.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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);
#ifdef __cplusplus
}
#endif
/** @} */
#endif

180
IPCKit/ipc_cskeleton.h Normal file
View File

@ -0,0 +1,180 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef CAPI_INCLUDE_IPC_CSKELETON_H
#define CAPI_INCLUDE_IPC_CSKELETON_H
/**
* @addtogroup OHIPCSkeleton
* @{
*
* @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
*/
/**
* @file ipc_cskeleton.h
*
* @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
*/
#include <stdint.h>
#include "ipc_cparcel.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Joints this thread to the IPC worker thread pool.
*
* @syscap SystemCapability.Communication.IPC.Core
* @since 12
*/
void OH_IPCSkeleton_JoinWorkThread(void);
/**
* @brief Stops this thread.
*
* @syscap SystemCapability.Communication.IPC.Core
* @since 12
*/
void OH_IPCSkeleton_StopWorkThread(void);
/**
* @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 Returns the token ID of the caller.
* @since 12
*/
uint64_t OH_IPCSkeleton_GetCallingTokenId(void);
/**
* @brief Obtains the token ID of the first caller.
*
* @syscap SystemCapability.Communication.IPC.Core
* @return Returns the token ID obtained.
* @since 12
*/
uint64_t OH_IPCSkeleton_GetFirstTokenId(void);
/**
* @brief Obtains the local token ID.
*
* @syscap SystemCapability.Communication.IPC.Core
* @return Returns the token ID obtained.
* @since 12
*/
uint64_t OH_IPCSkeleton_GetSelfTokenId(void);
/**
* @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 Returns the process ID of the caller.
* @since 12
*/
uint64_t OH_IPCSkeleton_GetCallingPid(void);
/**
* @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 Returns the UID of the caller.
* @since 12
*/
uint64_t OH_IPCSkeleton_GetCallingUid(void);
/**
* @brief Checks whether a local calling is being made.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Sets the maximum number of worker threads.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 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 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 Sets the caller credential information to the IPC context.
*
* @syscap SystemCapability.Communication.IPC.Core
* @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 Checks whether an IPC request is being handled.
*
* @syscap SystemCapability.Communication.IPC.Core
* @return Returns <b>1</b> if an IPC request is being handled; returns <b>0</b> otherwise.
* @since 12
*/
int OH_IPCSkeleton_IsHandlingTransaction(void);
#ifdef __cplusplus
}
#endif
/** @} */
#endif

74
IPCKit/ipc_error_code.h Normal file
View File

@ -0,0 +1,74 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef CAPI_INCLUDE_IPC_ERROR_CODE_H
#define CAPI_INCLUDE_IPC_ERROR_CODE_H
/**
* @addtogroup OHIPCErrorCode
* @{
*
* @brief Provides IPC error codes.
*
* @syscap SystemCapability.Communication.IPC.Core
* @since 12
*/
/**
* @file ipc_error_code.h
*
* @brief Defines IPC error codes.
*
* @library libipc_capi.so
* @syscap SystemCapability.Communication.IPC.Core
* @since 12
*/
/**
* @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,
/** @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,
/** @error The custom error code is out of range [1900001, 1999999]. */
OH_IPC_INVALID_USER_ERROR_CODE = OH_IPC_ERROR_CODE_BASE + 6,
/** @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

45
IPCKit/ipc_kit.h Normal file
View File

@ -0,0 +1,45 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#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

226
IPCKit/libipc_capi.json Normal file
View File

@ -0,0 +1,226 @@
[
{
"first_introduced": "12",
"name": "OH_IPCSkeleton_JoinWorkThread"
},
{
"first_introduced": "12",
"name": "OH_IPCSkeleton_StopWorkThread"
},
{
"first_introduced": "12",
"name": "OH_IPCSkeleton_GetCallingTokenId"
},
{
"first_introduced": "12",
"name": "OH_IPCSkeleton_GetFirstTokenId"
},
{
"first_introduced": "12",
"name": "OH_IPCSkeleton_GetSelfTokenId"
},
{
"first_introduced": "12",
"name": "OH_IPCSkeleton_GetCallingPid"
},
{
"first_introduced": "12",
"name": "OH_IPCSkeleton_GetCallingUid"
},
{
"first_introduced": "12",
"name": "OH_IPCSkeleton_IsLocalCalling"
},
{
"first_introduced": "12",
"name": "OH_IPCSkeleton_SetMaxWorkThreadNum"
},
{
"first_introduced": "12",
"name": "OH_IPCSkeleton_ResetCallingIdentity"
},
{
"first_introduced": "12",
"name": "OH_IPCSkeleton_SetCallingIdentity"
},
{
"first_introduced": "12",
"name": "OH_IPCSkeleton_IsHandlingTransaction"
},
{
"first_introduced": "12",
"name": "OH_IPCRemoteStub_Create"
},
{
"first_introduced": "12",
"name": "OH_IPCRemoteStub_Destroy"
},
{
"first_introduced": "12",
"name": "OH_IPCRemoteProxy_Destroy"
},
{
"first_introduced": "12",
"name": "OH_IPCRemoteProxy_SendRequest"
},
{
"first_introduced": "12",
"name": "OH_IPCRemoteProxy_GetInterfaceDescriptor"
},
{
"first_introduced": "12",
"name": "OH_IPCDeathRecipient_Create"
},
{
"first_introduced": "12",
"name": "OH_IPCDeathRecipient_Destroy"
},
{
"first_introduced": "12",
"name": "OH_IPCRemoteProxy_AddDeathRecipient"
},
{
"first_introduced": "12",
"name": "OH_IPCRemoteProxy_RemoveDeathRecipient"
},
{
"first_introduced": "12",
"name": "OH_IPCRemoteProxy_IsRemoteDead"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_Create"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_Destroy"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_GetDataSize"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_GetWritableBytes"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_GetReadableBytes"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_GetReadPosition"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_GetWritePosition"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_RewindReadPosition"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_RewindWritePosition"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_WriteInt8"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_ReadInt8"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_WriteInt16"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_ReadInt16"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_WriteInt32"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_ReadInt32"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_WriteInt64"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_ReadInt64"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_WriteFloat"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_ReadFloat"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_WriteDouble"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_ReadDouble"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_WriteString"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_ReadString"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_WriteBuffer"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_ReadBuffer"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_WriteRemoteStub"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_ReadRemoteStub"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_WriteRemoteProxy"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_ReadRemoteProxy"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_WriteFileDescriptor"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_ReadFileDescriptor"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_Append"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_WriteInterfaceToken"
},
{
"first_introduced": "12",
"name": "OH_IPCParcel_ReadInterfaceToken"
}
]