harmony 鸿蒙oh_commonevent.h

  • 2025-06-12
  • 浏览 (3)

oh_commonevent.h

概述

声明公共事件相关的API,包含订阅公共事件与退订公共事件。

库: libohcommonevent.so

系统能力: SystemCapability.Notification.CommonEvent

起始版本: 12

相关模块:CommonEvent

汇总

类型定义

名称 描述
typedef struct CommonEvent_SubscribeInfo CommonEvent_SubscribeInfo 订阅者信息。
typedef void CommonEvent_Subscriber 订阅者。
typedef struct CommonEvent_RcvData CommonEvent_RcvData 公共事件的数据。
typedef void CommonEvent_Parameters 公共事件的附加信息。
typedef void (*CommonEvent_ReceiveCallback)(const CommonEvent_RcvData *data) 公共事件的回调函数。
typedef struct CommonEvent_PublishInfo CommonEvent_PublishInfo 发布自定义公共事件时使用的公共事件属性对象。

枚举

名称 描述
typedef enum CommonEvent_ErrCode {
COMMONEVENT_ERR_OK = 0,
COMMONEVENT_ERR_PERMISSION_ERROR = 201,
COMMONEVENT_ERR_INVALID_PARAMETER = 401,
COMMONEVENT_ERR_NOT_SYSTEM_SERVICE = 1500004,
COMMONEVENT_ERR_SENDING_REQUEST_FAILED = 1500007,
COMMONEVENT_ERR_INIT_UNDONE = 1500008,
COMMONEVENT_ERR_SUBSCRIBER_NUM_EXCEEDED = 1500010,
COMMONEVENT_ERR_ALLOC_MEMORY_FAILED = 1500011
}
枚举错误码。

函数

名称 描述
CommonEvent_SubscribeInfo* OH_CommonEvent_CreateSubscribeInfo(const char* events[], int32_t eventsNum); 创建订阅者信息。
CommonEvent_ErrCode OH_CommonEvent_SetPublisherPermission(CommonEvent_SubscribeInfo* info, const char* permission); 设置订阅者权限。
CommonEvent_ErrCode OH_CommonEvent_SetPublisherBundleName(CommonEvent_SubscribeInfo* info, const char* bundleName); 设置订阅者包名称。
void OH_CommonEvent_DestroySubscribeInfo(CommonEvent_SubscribeInfo* info); 销毁订阅者信息。
CommonEvent_Subscriber* OH_CommonEvent_CreateSubscriber(const CommonEvent_SubscribeInfo* info, CommonEvent_ReceiveCallback callback); 创建订阅者。
void OH_CommonEvent_DestroySubscriber(CommonEvent_Subscriber* subscriber); 销毁订阅者。
CommonEvent_ErrCode OH_CommonEvent_Subscribe(const CommonEvent_Subscriber* subscriber); 订阅事件。
CommonEvent_ErrCode OH_CommonEvent_UnSubscribe(const CommonEvent_Subscriber* subscriber); 退订事件。
const char* OH_CommonEvent_GetEventFromRcvData(const CommonEvent_RcvData* rcvData); 获取公共事件名称。
int32_t OH_CommonEvent_GetCodeFromRcvData(const CommonEvent_RcvData* rcvData); 获取公共事件结果代码。
const char* OH_CommonEvent_GetDataStrFromRcvData(const CommonEvent_RcvData* rcvData); 获取公共事件自定义结果数据。
const char* OH_CommonEvent_GetBundleNameFromRcvData(const CommonEvent_RcvData* rcvData); 获取公共事件包名称。
const CommonEvent_Parameters* OH_CommonEvent_GetParametersFromRcvData(const CommonEvent_RcvData* rcvData); 获取公共事件附加信息。
bool OH_CommonEvent_HasKeyInParameters(const CommonEvent_Parameters* para, const char* key); 检查公共事件附加信息中是否包含某个键值对信息。
int OH_CommonEvent_GetIntFromParameters(const CommonEvent_Parameters* para, const char* key, const int defaultValue); 获取公共事件附加信息中int数据信息。
int32_t OH_CommonEvent_GetIntArrayFromParameters(const CommonEvent_Parameters* para, const char* key, int** array); 获取公共事件附加信息中int数组信息。
long OH_CommonEvent_GetLongFromParameters(const CommonEvent_Parameters* para, const char* key, const long defaultValue); 获取公共事件附加信息中long数据信息。
int32_t OH_CommonEvent_GetLongArrayFromParameters(const CommonEvent_Parameters* para, const char* key, long** array); 获取公共事件附加信息中long数组信息。
bool OH_CommonEvent_GetBoolFromParameters(const CommonEvent_Parameters* para, const char* key, const bool defaultValue); 获取公共事件附加信息中布尔数据信息。
int32_t OH_CommonEvent_GetBoolArrayFromParameters(const CommonEvent_Parameters* para, const char* key, bool** array); 获取公共事件附加信息中布尔数组信息。
char OH_CommonEvent_GetCharFromParameters(const CommonEvent_Parameters* para, const char* key, const char defaultValue); 获取公共事件附加信息中字符数据信息。
int32_t OH_CommonEvent_GetCharArrayFromParameters(const CommonEvent_Parameters* para, const char* key, char** array); 获取公共事件附加信息中字符数组信息。
double OH_CommonEvent_GetDoubleFromParameters(const CommonEvent_Parameters* para, const char* key, const double defaultValue); 获取公共事件附加信息中double数据信息。
int32_t OH_CommonEvent_GetDoubleArrayFromParameters(const CommonEvent_Parameters* para, const char* key, double** array); 获取公共事件附加信息中double数组信息。
CommonEvent_Parameters* OH_CommonEvent_CreateParameters(); 创建公共事件附加信息对象。
void OH_CommonEvent_DestroyParameters(CommonEvent_Parameters* param); 销毁公共事件附加信息对象。
CommonEvent_ErrCode OH_CommonEvent_SetIntToParameters(CommonEvent_Parameters* param, const char* key, const int value); 设置公共事件附加信息的int类型内容。
CommonEvent_ErrCode OH_CommonEvent_SetIntArrayToParameters(CommonEvent_Parameters* param, const char* key, const int* value, const size_t num); 设置公共事件附加信息的int数组内容。
CommonEvent_ErrCode OH_CommonEvent_SetLongToParameters(CommonEvent_Parameters* param, const char* key, const long value); 设置公共事件附加信息的long类型内容。
CommonEvent_ErrCode OH_CommonEvent_SetLongArrayToParameters(CommonEvent_Parameters* param, const char* key, const long* value, const size_t num); 设置公共事件附加信息的long数组内容。
CommonEvent_ErrCode OH_CommonEvent_SetDoubleToParameters(CommonEvent_Parameters* param, const char* key, const double value); 设置公共事件附加信息的double类型内容。
CommonEvent_ErrCode OH_CommonEvent_SetDoubleArrayToParameters(CommonEvent_Parameters* param, const char* key, const double* value, const size_t num); 设置公共事件附加信息的double数组内容。
CommonEvent_ErrCode OH_CommonEvent_SetBoolToParameters(CommonEvent_Parameters* param, const char* key, const bool value); 设置公共事件附加信息的布尔类型内容。
CommonEvent_ErrCode OH_CommonEvent_SetBoolArrayToParameters(CommonEvent_Parameters* param, const char* key, const bool* value, const size_t num); 设置公共事件附加信息的布尔数组内容。
CommonEvent_ErrCode OH_CommonEvent_SetCharToParameters(CommonEvent_Parameters* param, const char* key, const char value); 设置公共事件附加信息的字符类型内容。
CommonEvent_ErrCode OH_CommonEvent_SetCharArrayToParameters(CommonEvent_Parameters* param, const char* key, const char* value, const size_t num); 设置公共事件附加信息的字符数组内容。
CommonEvent_PublishInfo* OH_CommonEvent_CreatePublishInfo(const bool ordered); 创建公共事件属性对象。
void OH_CommonEvent_DestroyPublishInfo(CommonEvent_PublishInfo* info); 销毁公共事件属性对象。
CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoBundleName(CommonEvent_PublishInfo* info, const char* bundleName); 设置公共事件包名称。
CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoPermissions(CommonEvent_PublishInfo* info,const char* permissions[], const int32_t num); 设置公共事件权限。
CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoCode(CommonEvent_PublishInfo* info, const int32_t code); 设置公共事件结果码。
CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoData(CommonEvent_PublishInfo* info, const char* data, const size_t length); 设置公共事件结果数据。
CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoParameters(CommonEvent_PublishInfo* info, CommonEvent_Parameters* param); 设置公共事件附加信息。
CommonEvent_ErrCode OH_CommonEvent_Publish(const char* event); 发布自定义公共事件。
CommonEvent_ErrCode OH_CommonEvent_PublishWithInfo(const char* event, const CommonEvent_PublishInfo* info); 发布带有指定属性的自定义公共事件。
bool OH_CommonEvent_IsOrderedCommonEvent(const CommonEvent_Subscriber* subscriber); 查询当前公共事件是否为有序公共事件。
bool OH_CommonEvent_FinishCommonEvent(CommonEvent_Subscriber* subscriber); 用于订阅者结束对当前有序公共事件的处理。
bool OH_CommonEvent_GetAbortCommonEvent(const CommonEvent_Subscriber* subscriber); 获取当前有序公共事件是否处于中止状态。
bool OH_CommonEvent_AbortCommonEvent(CommonEvent_Subscriber* subscriber); 中止当前的有序公共事件。
bool OH_CommonEvent_ClearAbortCommonEvent(CommonEvent_Subscriber* subscriber); 取消当前有序公共事件的中止状态。
int32_t OH_CommonEvent_GetCodeFromSubscriber(const CommonEvent_Subscriber* subscriber); 获取有序公共事件代码。
int32_t OH_CommonEvent_GetDataFromSubscriber(const CommonEvent_Subscriber* subscriber); 获取有序公共事件的数据。
int32_t OH_CommonEvent_SetCodeToSubscriber(CommonEvent_Subscriber* subscriber, const int32_t code); 设置有序公共事件的代码。
int32_t OH_CommonEvent_SetDataToSubscriber(CommonEvent_Subscriber* subscriber, const char* data, const size_t length); 设置有序公共事件的数据。

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Basic Services Kit(基础服务)

harmony 鸿蒙DeviceInfo

harmony 鸿蒙OH_Print

harmony 鸿蒙Print_Margin

harmony 鸿蒙Print_PageSize

harmony 鸿蒙Print_PrintAttributes

harmony 鸿蒙Print_PrintDocCallback

harmony 鸿蒙Print_Range

harmony 鸿蒙TimeService

harmony 鸿蒙ohscan.h

0  赞