1e41f4b71Sopenharmony_ci# oh_commonevent.h
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ci## Overview
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ciDefines the APIs for subscribing to and unsubscribing from common events.
7e41f4b71Sopenharmony_ci
8e41f4b71Sopenharmony_ci**Library**: libohcommonevent.so
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Notification.CommonEvent
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci**Since**: 12
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci**Related module**: [CommonEvent](capi-common-event.md)
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci## Summary
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci### Types
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci| Name| Description|
22e41f4b71Sopenharmony_ci| -------- | -------- |
23e41f4b71Sopenharmony_ci|typedef struct [CommonEvent_SubscribeInfo](./capi-common-event.md#commonevent_subscribeinfo) [CommonEvent_SubscribeInfo](./capi-common-event.md#commonevent_subscribeinfo) | Defines the subscriber information.|
24e41f4b71Sopenharmony_ci|typedef void [CommonEvent_Subscriber](./capi-common-event.md#commonevent_subscriber) | Defines a subscriber.|
25e41f4b71Sopenharmony_ci|typedef struct [CommonEvent_RcvData](./capi-common-event.md#commonevent_rcvdata) [CommonEvent_RcvData](./capi-common-event.md#commonevent_rcvdata) | Defines the common event data.|
26e41f4b71Sopenharmony_ci|typedef void [CommonEvent_Parameters](./capi-common-event.md#commonevent_parameters) | Defines the additional information about a common event.|
27e41f4b71Sopenharmony_ci|typedef void (*[CommonEvent_ReceiveCallback](./capi-common-event.md#commonevent_receivecallback))(const [CommonEvent_RcvData](./capi-common-event.md#commonevent_rcvdata) *data) | Defines the callback function of a common event.|
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci### Enums
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci| Name| Description|
32e41f4b71Sopenharmony_ci| -------- | -------- |
33e41f4b71Sopenharmony_ci| typedef enum [CommonEvent_ErrCode](./capi-common-event.md#commonevent_errcode)  {<br>COMMONEVENT_ERR_OK = 0,<br>COMMONEVENT_ERR_PERMISSION_ERROR = 201,<br>COMMONEVENT_ERR_INVALID_PARAMETER = 401,<br>COMMONEVENT_ERR_SENDING_REQUEST_FAILED = 1500007,<br>COMMONEVENT_ERR_INIT_UNDONE = 1500008,<br>COMMONEVENT_ERR_SUBSCRIBER_NUM_EXCEEDED = 1500010,<br>COMMONEVENT_ERR_ALLOC_MEMORY_FAILED = 1500011<br>} | Enumerates the error codes.|
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci### Functions
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci| Name| Description|
39e41f4b71Sopenharmony_ci| -------- | -------- |
40e41f4b71Sopenharmony_ci| CommonEvent_SubscribeInfo* [OH_CommonEvent_CreateSubscribeInfo](./capi-common-event.md#oh_commonevent_createsubscribeinfo)(const char* events[], int32_t eventsNum) | Creates the subscriber information.|
41e41f4b71Sopenharmony_ci| CommonEvent_ErrCode [OH_CommonEvent_SetPublisherPermission](./capi-common-event.md#oh_commonevent_setpublisherpermission)(CommonEvent_SubscribeInfo* info, const char* permission) | Sets the subscriber permission.|
42e41f4b71Sopenharmony_ci| CommonEvent_ErrCode [OH_CommonEvent_SetPublisherBundleName](./capi-common-event.md#oh_commonevent_setpublisherbundlename)(CommonEvent_SubscribeInfo* info, const char* bundleName); | Sets a bundle name of the subscriber.|
43e41f4b71Sopenharmony_ci| void [OH_CommonEvent_DestroySubscribeInfo](./capi-common-event.md#oh_commonevent_destroysubscribeinfo)(CommonEvent_SubscribeInfo* info) | Destroys the subscriber information.|
44e41f4b71Sopenharmony_ci| CommonEvent_Subscriber* [OH_CommonEvent_CreateSubscriber](./capi-common-event.md#oh_commonevent_createsubscriber)(const CommonEvent_SubscribeInfo* info, CommonEvent_ReceiveCallback callback) | Creates a subscriber.|
45e41f4b71Sopenharmony_ci| void [OH_CommonEvent_DestroySubscriber](./capi-common-event.md#oh_commonevent_destroysubscriber)(CommonEvent_Subscriber* subscriber); | Destroys a subscriber.|
46e41f4b71Sopenharmony_ci| CommonEvent_ErrCode [OH_CommonEvent_Subscribe](./capi-common-event.md#oh_commonevent_subscribe)(const CommonEvent_Subscriber* subscriber); | Subscribes to a common event.|
47e41f4b71Sopenharmony_ci| CommonEvent_ErrCode [OH_CommonEvent_UnSubscribe](./capi-common-event.md#oh_commonevent_unsubscribe)(const CommonEvent_Subscriber* subscriber); | Unsubscribes from a common event.|
48e41f4b71Sopenharmony_ci| const char* [OH_CommonEvent_GetEventFromRcvData](./capi-common-event.md#oh_commonevent_geteventfromrcvdata)(const CommonEvent_RcvData* rcvData); | Obtains the name of a common event.|
49e41f4b71Sopenharmony_ci| int32_t [OH_CommonEvent_GetCodeFromRcvData](./capi-common-event.md#oh_commonevent_getcodefromrcvdata)(const CommonEvent_RcvData* rcvData); | Obtains the result code of a common event.|
50e41f4b71Sopenharmony_ci| const char* [OH_CommonEvent_GetDataStrFromRcvData](./capi-common-event.md#oh_commonevent_getdatastrfromrcvdata)(const CommonEvent_RcvData* rcvData); | Obtains the custom result data of a common event.|
51e41f4b71Sopenharmony_ci| const char* [OH_CommonEvent_GetBundleNameFromRcvData](./capi-common-event.md#oh_commonevent_getbundlenamefromrcvdata)(const CommonEvent_RcvData* rcvData); | Obtains the bundle name of a common event.|
52e41f4b71Sopenharmony_ci| const CommonEvent_Parameters* [OH_CommonEvent_GetParametersFromRcvData](./capi-common-event.md#oh_commonevent_getparametersfromrcvdata)(const CommonEvent_RcvData* rcvData); | Obtains the additional information about a common event.|
53e41f4b71Sopenharmony_ci| bool [OH_CommonEvent_HasKeyInParameters](./capi-common-event.md#oh_commonevent_haskeyinparameters)(const CommonEvent_Parameters* para, const char* key); | Checks whether the additional information of a common event contains a key-value pair.|
54e41f4b71Sopenharmony_ci| int [OH_CommonEvent_GetIntFromParameters](./capi-common-event.md#oh_commonevent_getintfromparameters)(const CommonEvent_Parameters* para, const char* key, const int defaultValue); | Obtains the **int** data information from the additional information of a common event.|
55e41f4b71Sopenharmony_ci| int32_t [OH_CommonEvent_GetIntArrayFromParameters](./capi-common-event.md#oh_commonevent_getintarrayfromparameters)(const CommonEvent_Parameters* para, const char* key, int** array); | Obtains the **int** array information from the additional information of a common event.|
56e41f4b71Sopenharmony_ci| long [OH_CommonEvent_GetLongFromParameters](./capi-common-event.md#oh_commonevent_getlongfromparameters)(const CommonEvent_Parameters* para, const char* key, const long defaultValue);| Obtains the **long** data information from the additional information of a common event.|
57e41f4b71Sopenharmony_ci| int32_t [OH_CommonEvent_GetLongArrayFromParameters](./capi-common-event.md#oh_commonevent_getlongarrayfromparameters)(const CommonEvent_Parameters* para, const char* key, long** array);| Obtains the **long** array information from the additional information of a common event.|
58e41f4b71Sopenharmony_ci| bool [OH_CommonEvent_GetBoolFromParameters](./capi-common-event.md#oh_commonevent_getboolfromparameters)(const CommonEvent_Parameters* para, const char* key, const bool defaultValue);| Obtains the **bool** data information from the additional information of a common event.|
59e41f4b71Sopenharmony_ci| int32_t [OH_CommonEvent_GetBoolArrayFromParameters](./capi-common-event.md#oh_commonevent_getlongarrayfromparameters)(const CommonEvent_Parameters* para, const char* key, bool** array);| Obtains the **bool** array information from the additional information of a common event.|
60e41f4b71Sopenharmony_ci| char [OH_CommonEvent_GetCharFromParameters](./capi-common-event.md#oh_commonevent_getcharfromparameters)(const CommonEvent_Parameters* para, const char* key, const char defaultValue);| Obtains the **char** data from the additional information of a common event.|
61e41f4b71Sopenharmony_ci| int32_t [OH_CommonEvent_GetCharArrayFromParameters](./capi-common-event.md#oh_commonevent_getchararrayfromparameters)(const CommonEvent_Parameters* para, const char* key, char** array);| Obtains the **char** array information from the additional information of a common event.|
62e41f4b71Sopenharmony_ci| double [OH_CommonEvent_GetDoubleFromParameters](./capi-common-event.md#oh_commonevent_getdoublefromparameters)(const CommonEvent_Parameters* para, const char* key, const double defaultValue);| Obtains the **double** data information from the additional information of a common event.|
63e41f4b71Sopenharmony_ci| int32_t [OH_CommonEvent_GetDoubleArrayFromParameters](./capi-common-event.md#oh_commonevent_getdoublearrayfromparameters)(const CommonEvent_Parameters* para, const char* key, double** array);| Obtains the **double** array information from the additional information of a common event.|
64