From aebab0140fb1ebff63512eed171c8a2c4d6b9e2c Mon Sep 17 00:00:00 2001 From: wangsen1994 Date: Thu, 21 Nov 2024 19:16:49 +0800 Subject: [PATCH] =?UTF-8?q?5.1=E7=89=88=E6=9C=ACces=E6=96=B0=E5=A2=9Enapi?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangsen1994 --- .../commonevent/libcommonevent.ndk.json | 116 ++++++ BasicServicesKit/commonevent/oh_commonevent.h | 353 ++++++++++++++++++ 2 files changed, 469 insertions(+) diff --git a/BasicServicesKit/commonevent/libcommonevent.ndk.json b/BasicServicesKit/commonevent/libcommonevent.ndk.json index 40ddccdfe..23769c084 100644 --- a/BasicServicesKit/commonevent/libcommonevent.ndk.json +++ b/BasicServicesKit/commonevent/libcommonevent.ndk.json @@ -94,5 +94,121 @@ { "first_introduced": "12", "name":"OH_CommonEvent_GetDoubleArrayFromParameters" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_Publish" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_GetCodeFromSubscriber" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_SetCodeForSubscriber" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_GetDataFromSubscriber" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_SetDataForSubscriber" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_IsOrderedCommonEvent" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_AbortCommonEvent" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_ClearAbortCommonEvent" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_GetAbortCommonEvent" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_FinishCommonEvent" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_CreatePublishInfo" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_DestoryPublishInfo" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_SetPublishInfoBundleName" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_SetPublishInfoPermissions" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_SetPublishInfoCode" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_SetPublishInfoData" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_SetPublishInfoParameters" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_CreateParameters" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_DestoryParameters" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_SetParametersForInt" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_SetParametersForIntArray" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_SetParametersForLong" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_SetParametersForLongArray" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_SetParametersForDouble" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_SetParametersForDoubleArray" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_SetParametersForBool" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_SetParametersForBoolArray" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_SetParametersForChar" + }, + { + "first_introduced": "16", + "name":"OH_CommonEvent_SetParametersForCharArray" } ] diff --git a/BasicServicesKit/commonevent/oh_commonevent.h b/BasicServicesKit/commonevent/oh_commonevent.h index 44c679926..d6fbbab1c 100644 --- a/BasicServicesKit/commonevent/oh_commonevent.h +++ b/BasicServicesKit/commonevent/oh_commonevent.h @@ -58,12 +58,18 @@ typedef enum CommonEvent_ErrCode { /** @error invalid input parameter. */ COMMONEVENT_ERR_INVALID_PARAMETER = 401, + /** @error the application cannot send system common events. */ + COMMONEVENT_ERR_NOT_SYSTEM_SERVICE = 1500004, + /** @error IPC request failed to send. */ COMMONEVENT_ERR_SENDING_REQUEST_FAILED = 1500007, /** @error Common event service not init. */ COMMONEVENT_ERR_INIT_UNDONE = 1500008, + /** @error Failed to obtain system parameters. */ + COMMONEVENT_ERR_OBTAIN_SYSTEM_PARAMS = 1500009, + /** @error The subscriber number exceed system specification */ COMMONEVENT_ERR_SUBSCRIBER_NUM_EXCEEDED = 1500010, @@ -107,6 +113,13 @@ typedef void CommonEvent_Parameters; */ typedef void (*CommonEvent_ReceiveCallback)(const CommonEvent_RcvData *data); +/** + * @brief Publish the properties of a public event. + * + * @since 16 + */ +typedef struct CommonEvent_PublishInfo CommonEvent_PublishInfo; + /** * @brief Create subscribe information. * @@ -363,6 +376,346 @@ double OH_CommonEvent_GetDoubleFromParameters(const CommonEvent_Parameters* para int32_t OH_CommonEvent_GetDoubleArrayFromParameters(const CommonEvent_Parameters* para, const char* key, double** array); +/** + * @brief Publishes an ordered or standard common event. + * + * @param event Name of the common event. + * @param info Properties of the common event. + * @return Returns the error code. + * Returns {@link COMMONEVENT_ERR_INVALID_PARAMETER} if invalid input parameter. + * Returns {@link COMMONEVENT_ERR_NOT_SYSTEM_SERVICE } if the application cannot send system common events. + * Returns {@link COMMONEVENT_ERR_SENDING_REQUEST_FAILED } if IPC request failed to send. + * Returns {@link COMMONEVENT_ERR_INIT_UNDONE } if ces not init done. + * Returns {@link COMMONEVENT_ERR_OBTAIN_SYSTEM_PARAMS } if Failed to obtain system parameters. + * @since 16 + */ +CommonEvent_ErrCode OH_CommonEvent_Publish(const char* event, const CommonEvent_PublishInfo* info); + +/** + * @brief Get ordered common event code from subscriber. + * + * @param subscriber Indicates the created subscriber. + * @return Returns the event of result code, default is 0. + * @since 16 + */ +int32_t OH_CommonEvent_GetCodeFromSubscriber(const CommonEvent_Subscriber* subscriber); + +/** + * @brief Set ordered common event's code. + * + * @param subscriber Indicates the created subscriber. + * @param code Indicates the code of common event. + * @return Returns the result code, true indicates operate successful. + * @since 16 + */ +bool OH_CommonEvent_SetCodeForSubscriber(CommonEvent_Subscriber* subscriber, int32_t code); + +/** + * @brief Get ordered common event data from subscriber. + * + * @param subscriber Indicates the created subscriber. + * @return Returns the event of result data, default is null. + * @since 16 + */ +const char* OH_CommonEvent_GetDataFromSubscriber(const CommonEvent_Subscriber* subscriber); + +/** + * @brief Set ordered common event's data. + * + * @param subscriber Indicates the created subscriber. + * @param data Indicates the data of common event. + * @param length Indicates the length of data. + * @return Returns the result code, true indicates operate successful. + * @since 16 + */ +bool OH_CommonEvent_SetDataForSubscriber(CommonEvent_Subscriber* subscriber, const char* data, size_t length); + +/** + * @brief Check whether the common event is ordered. + * + * @param subscriber Indicates the created subscriber. + * @return Returns the check result. + * @since 16 + */ +bool OH_CommonEvent_IsOrderedCommonEvent(const CommonEvent_Subscriber* subscriber); + +/** + * @brief Abort the current ordered common event. + * + * @param subscriber Indicates the created subscriber. + * @return Returns the result code, true indicates operate successful. + * @since 16 + */ +bool OH_CommonEvent_AbortCommonEvent(CommonEvent_Subscriber* subscriber); + +/** + * @brief Clear the suspension status of the current ordered common event. + * + * @param subscriber Indicates the created subscriber. + * @return Returns the result code, true indicates operate successful. + * @since 16 + */ +bool OH_CommonEvent_ClearAbortCommonEvent(CommonEvent_Subscriber* subscriber); + +/** + * @brief Chceck whether the ordered common event is in aborted state. + * + * @param subscriber Indicates the created subscriber. + * @return Returns the check result. + * @since 16 + */ +bool OH_CommonEvent_GetAbortCommonEvent(CommonEvent_Subscriber* subscriber); + +/** + * @brief Finish processing of current ordered public events. + * + * @param subscriber Indicates the created subscriber. + * @return Returns the result code, true indicates operate successful. + * @since 16 + */ +bool OH_CommonEvent_FinishCommonEvent(CommonEvent_Subscriber* subscriber); + +/** + * @brief Create a publish info. + * + * @param ordered Indicates whether it is an ordered event. + * @return Returns the CommonEvent_PublishInfo, if allocate memory failed, returns null. + * @since 16 + */ +CommonEvent_PublishInfo* OH_CommonEvent_CreatePublishInfo(bool ordered); + +/** + * @brief Destory a publish info. + * + * @param info Indicates the created CommonEvent_PublishInfo. + * @since 16 + */ +void OH_CommonEvent_DestoryPublishInfo(CommonEvent_PublishInfo* info); + +/** + * @brief Set the publishInfo of bundleName. + * + * @param info Indicates the created CommonEvent_PublishInfo. + * @param bundleName Indicates the subscriber of bundleName. + * @return Returns the error code. + * Returns {@link COMMONEVENT_ERR_OK} if the operation is successful. + * Returns {@link COMMONEVENT_ERR_INVALID_PARAMETER} if a parameter error occurs. + * @since 16 + */ +CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoBundleName(CommonEvent_PublishInfo* info, const char* bundleName); + +/** + * @brief Set the publishInfo of permissions. + * + * @param info Indicates the created CommonEvent_PublishInfo. + * @param permissions Indicates the subscriber of Permissions. + * @param num Indicates the number of Permissions. + * @return Returns the error code. + * Returns {@link COMMONEVENT_ERR_OK} if the operation is successful. + * Returns {@link COMMONEVENT_ERR_INVALID_PARAMETER} if a parameter error occurs. + * @since 16 + */ +CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoPermissions(CommonEvent_PublishInfo* info, const char* permissions[], + int32_t num); + +/** + * @brief Set the publishInfo of code. + * + * @param info Indicates the created CommonEvent_PublishInfo. + * @param code Indicates the publish information of code. + * @return Returns the error code. + * Returns {@link COMMONEVENT_ERR_OK} if the operation is successful. + * Returns {@link COMMONEVENT_ERR_INVALID_PARAMETER} if a parameter error occurs. + * @since 16 + */ +CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoCode(CommonEvent_PublishInfo* info, const int32_t code); + +/** + * @brief Set the publishInfo of custom result data. + * + * @param info Indicates the created CommonEvent_PublishInfo. + * @param data Indicates the custom result data. + * @param length Indicates the length of data. + * @return Returns the error code. + * Returns {@link COMMONEVENT_ERR_OK} if the operation is successful. + * Returns {@link COMMONEVENT_ERR_INVALID_PARAMETER} if a parameter error occurs. + * @since 16 + */ +CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoData(CommonEvent_PublishInfo* info, const char* data, size_t length); + +/** + * @brief Set the publishInfo of parameters. + * + * @param info Indicates the created CommonEvent_PublishInfo. + * @param para Indicates the parameters. + * @return Returns the error code. + * Returns {@link COMMONEVENT_ERR_OK} if the operation is successful. + * Returns {@link COMMONEVENT_ERR_INVALID_PARAMETER} if a parameter error occurs. + * @since 16 + */ +CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoParameters(CommonEvent_PublishInfo* info, + const CommonEvent_Parameters* para); + +/** + * @brief Create a publish parameters. + * + * @return Returns the CommonEvent_Parameters, if allocate memory failed, returns null. + * @since 16 + */ +CommonEvent_Parameters* OH_CommonEvent_CreateParameters(); + +/** + * @brief Destory the created parameters. + * + * @param param Indicates the created CommonEvent_Parameters. + * @since 16 + */ +void OH_CommonEvent_DestoryParameters(CommonEvent_Parameters* param); + +/** + * @brief Set an int data for parameters. + * + * @param param Indicates the created CommonEvent_Parameters. + * @param key Indicates the value of key. + * @param value Indicates the int value. + * @return Returns the error code. + * Returns {@link COMMONEVENT_ERR_OK} if the operation is successful. + * Returns {@link COMMONEVENT_ERR_INVALID_PARAMETER} if a parameter error occurs. + * @since 16 + */ +CommonEvent_ErrCode OH_CommonEvent_SetParametersForInt(CommonEvent_Parameters* param, const char* key, const int value); + +/** + * @brief Set an int array data for parameters. + * + * @param param Indicates the created CommonEvent_Parameters. + * @param key Indicates the value of key. + * @param value Indicates the int array. + * @param num Indicates the number of array. + * @return Returns the error code. + * Returns {@link COMMONEVENT_ERR_OK} if the operation is successful. + * Returns {@link COMMONEVENT_ERR_INVALID_PARAMETER} if a parameter error occurs. + * @since 16 + */ +CommonEvent_ErrCode OH_CommonEvent_SetParametersForIntArray(CommonEvent_Parameters* param, const char* key, + const int* value, size_t num); + +/** + * @brief Set a long data for parameters. + * + * @param param Indicates the created CommonEvent_Parameters. + * @param key Indicates the value of key. + * @param value Indicates the long value. + * @return Returns the error code. + * Returns {@link COMMONEVENT_ERR_OK} if the operation is successful. + * Returns {@link COMMONEVENT_ERR_INVALID_PARAMETER} if a parameter error occurs. + * @since 16 + */ +CommonEvent_ErrCode OH_CommonEvent_SetParametersForLong(CommonEvent_Parameters* param, const char* key, + const long value); + +/** + * @brief Set a long array data for parameters. + * + * @param param Indicates the created CommonEvent_Parameters. + * @param key Indicates the value of key. + * @param value Indicates the long array. + * @param num Indicates the number of array. + * @return Returns the error code. + * Returns {@link COMMONEVENT_ERR_OK} if the operation is successful. + * Returns {@link COMMONEVENT_ERR_INVALID_PARAMETER} if a parameter error occurs. + * @since 16 + */ +CommonEvent_ErrCode OH_CommonEvent_SetParametersForLongArray(CommonEvent_Parameters* param, const char* key, + const long* value, size_t num); + +/** + * @brief Set a double data for parameters. + * + * @param param Indicates the created CommonEvent_Parameters. + * @param key Indicates the value of key. + * @param value Indicates the double value. + * @return Returns the error code. + * Returns {@link COMMONEVENT_ERR_OK} if the operation is successful. + * Returns {@link COMMONEVENT_ERR_INVALID_PARAMETER} if a parameter error occurs. + * @since 16 + */ +CommonEvent_ErrCode OH_CommonEvent_SetParametersForDouble(CommonEvent_Parameters* param, const char* key, + const double value); + +/** + * @brief Set a double array data for parameters. + * + * @param param Indicates the created CommonEvent_Parameters. + * @param key Indicates the value of key. + * @param value Indicates the double array. + * @param num Indicates the number of array. + * @return Returns the error code. + * Returns {@link COMMONEVENT_ERR_OK} if the operation is successful. + * Returns {@link COMMONEVENT_ERR_INVALID_PARAMETER} if a parameter error occurs. + * @since 16 + */ +CommonEvent_ErrCode OH_CommonEvent_SetParametersForDoubleArray(CommonEvent_Parameters* param, const char* key, + const double* value, size_t num); + +/** + * @brief Set a bool data for parameters. + * + * @param param Indicates the created CommonEvent_Parameters. + * @param key Indicates the value of key. + * @param value Indicates the bool value. + * @return Returns the error code. + * Returns {@link COMMONEVENT_ERR_OK} if the operation is successful. + * Returns {@link COMMONEVENT_ERR_INVALID_PARAMETER} if a parameter error occurs. + * @since 16 + */ +CommonEvent_ErrCode OH_CommonEvent_SetParametersForBool(CommonEvent_Parameters* param, const char* key, + const bool value); + +/** + * @brief Set a bool array data for parameters. + * + * @param param Indicates the created CommonEvent_Parameters. + * @param key Indicates the value of key. + * @param value Indicates the bool array. + * @param num Indicates the number of array. + * @return Returns the error code. + * Returns {@link COMMONEVENT_ERR_OK} if the operation is successful. + * Returns {@link COMMONEVENT_ERR_INVALID_PARAMETER} if a parameter error occurs. + * @since 16 + */ +CommonEvent_ErrCode OH_CommonEvent_SetParametersForBoolArray(CommonEvent_Parameters* param, const char* key, + const bool* value, size_t num); + +/** + * @brief Set a char data for parameters. + * + * @param param Indicates the created CommonEvent_Parameters. + * @param key Indicates the value of key. + * @param value Indicates the char value. + * @return Returns the error code. + * Returns {@link COMMONEVENT_ERR_OK} if the operation is successful. + * Returns {@link COMMONEVENT_ERR_INVALID_PARAMETER} if a parameter error occurs. + * @since 16 + */ +CommonEvent_ErrCode OH_CommonEvent_SetParametersForChar(CommonEvent_Parameters* param, const char* key, + const char value); + +/** + * @brief Set a char array data for parameters. + * + * @param param Indicates the created CommonEvent_Parameters. + * @param key Indicates the value of key. + * @param value Indicates the char array. + * @param num Indicates the number of array. + * @return Returns the error code. + * Returns {@link COMMONEVENT_ERR_OK} if the operation is successful. + * Returns {@link COMMONEVENT_ERR_INVALID_PARAMETER} if a parameter error occurs. + * @since 16 + */ +CommonEvent_ErrCode OH_CommonEvent_SetParametersForCharArray(CommonEvent_Parameters* param, const char* key, + const char* value, size_t num); + #ifdef __cplusplus } #endif -- Gitee