oh_commonevent.h

Overview

Defines the APIs for subscribing to and unsubscribing from common events.

Library: libohcommonevent.so

System capability: SystemCapability.Notification.CommonEvent

Since: 12

Related module: CommonEvent

Summary

Types

Name Description
typedef struct CommonEvent_SubscribeInfo CommonEvent_SubscribeInfo Defines the subscriber information.
typedef void CommonEvent_Subscriber Defines a subscriber.
typedef struct CommonEvent_RcvData CommonEvent_RcvData Defines the common event data.
typedef void CommonEvent_Parameters Defines the additional information about a common event.
typedef void (*CommonEvent_ReceiveCallback)(const CommonEvent_RcvData *data) Defines the callback function of a common event.

Enums

Name Description
typedef enum CommonEvent_ErrCode {
COMMONEVENT_ERR_OK = 0,
COMMONEVENT_ERR_PERMISSION_ERROR = 201,
COMMONEVENT_ERR_INVALID_PARAMETER = 401,
COMMONEVENT_ERR_SENDING_REQUEST_FAILED = 1500007,
COMMONEVENT_ERR_INIT_UNDONE = 1500008,
COMMONEVENT_ERR_SUBSCRIBER_NUM_EXCEEDED = 1500010,
COMMONEVENT_ERR_ALLOC_MEMORY_FAILED = 1500011
}
Enumerates the error codes.

Functions

Name Description
CommonEvent_SubscribeInfo* OH_CommonEvent_CreateSubscribeInfo(const char* events[], int32_t eventsNum) Creates the subscriber information.
CommonEvent_ErrCode OH_CommonEvent_SetPublisherPermission(CommonEvent_SubscribeInfo* info, const char* permission) Sets the subscriber permission.
CommonEvent_ErrCode OH_CommonEvent_SetPublisherBundleName(CommonEvent_SubscribeInfo* info, const char* bundleName); Sets a bundle name of the subscriber.
void OH_CommonEvent_DestroySubscribeInfo(CommonEvent_SubscribeInfo* info) Destroys the subscriber information.
CommonEvent_Subscriber* OH_CommonEvent_CreateSubscriber(const CommonEvent_SubscribeInfo* info, CommonEvent_ReceiveCallback callback) Creates a subscriber.
void OH_CommonEvent_DestroySubscriber(CommonEvent_Subscriber* subscriber); Destroys a subscriber.
CommonEvent_ErrCode OH_CommonEvent_Subscribe(const CommonEvent_Subscriber* subscriber); Subscribes to a common event.
CommonEvent_ErrCode OH_CommonEvent_UnSubscribe(const CommonEvent_Subscriber* subscriber); Unsubscribes from a common event.
const char* OH_CommonEvent_GetEventFromRcvData(const CommonEvent_RcvData* rcvData); Obtains the name of a common event.
int32_t OH_CommonEvent_GetCodeFromRcvData(const CommonEvent_RcvData* rcvData); Obtains the result code of a common event.
const char* OH_CommonEvent_GetDataStrFromRcvData(const CommonEvent_RcvData* rcvData); Obtains the custom result data of a common event.
const char* OH_CommonEvent_GetBundleNameFromRcvData(const CommonEvent_RcvData* rcvData); Obtains the bundle name of a common event.
const CommonEvent_Parameters* OH_CommonEvent_GetParametersFromRcvData(const CommonEvent_RcvData* rcvData); Obtains the additional information about a common event.
bool OH_CommonEvent_HasKeyInParameters(const CommonEvent_Parameters* para, const char* key); Checks whether the additional information of a common event contains a key-value pair.
int 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.
int32_t 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.
long 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.
int32_t 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.
bool 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.
int32_t OH_CommonEvent_GetBoolArrayFromParameters(const CommonEvent_Parameters* para, const char* key, bool** array); Obtains the bool array information from the additional information of a common event.
char 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.
int32_t 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.
double 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.
int32_t 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.