1# oh_commonevent.h 2 3<!--Kit: Basic Services Kit--> 4<!--Subsystem: Notification--> 5<!--Owner: @michael_woo888--> 6<!--Designer: @dongqingran; @wulong158--> 7<!--Tester: @wanghong1997--> 8<!--Adviser: @huipeizi--> 9 10## Overview 11 12Defines the APIs for subscribing to and unsubscribing from common events and enumerates the error codes. 13 14**Library**: libohcommonevent.so 15 16**System capability**: SystemCapability.Notification.CommonEvent 17 18**Since**: 12 19 20**Related module**: [OH_CommonEvent](capi-oh-commonevent.md) 21 22## Summary 23 24### Structs 25 26| Name| typedef Keyword| Description| 27| -- | -- | -- | 28| [CommonEvent_SubscribeInfo](capi-oh-commonevent-commonevent-subscribeinfo.md) | CommonEvent_SubscribeInfo | Defines a struct for the subscriber information.| 29| [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md) | CommonEvent_PublishInfo | Defines the property object used for publishing a common event.| 30| [CommonEvent_RcvData](capi-oh-commonevent-commonevent-rcvdata.md) | CommonEvent_RcvData | Defines a struct for the common event data.| 31 32### Variables 33 34| Name| typedef Keyword| Description| 35|----|------------|----| 36| void | CommonEvent_Subscriber | Defines a struct for the subscriber. | 37| void | CommonEvent_Parameters | Defines a struct for the additional information of a common event. | 38 39### Enums 40 41| Name| typedef Keyword| Description| 42| -- | -- | -- | 43| [CommonEvent_ErrCode](#commonevent_errcode) | CommonEvent_ErrCode | Enumerates the error codes.| 44 45### Functions 46 47| Name| typedef Keyword| Description| 48| -- | -- | -- | 49| [typedef void (\*CommonEvent_ReceiveCallback)(const CommonEvent_RcvData *data)](#commonevent_receivecallback) | CommonEvent_ReceiveCallback | Defines the callback function of a common event.| 50| [CommonEvent_SubscribeInfo* OH_CommonEvent_CreateSubscribeInfo(const char* events[], int32_t eventsNum)](#oh_commonevent_createsubscribeinfo) | - | Creates the subscriber information.| 51| [CommonEvent_ErrCode OH_CommonEvent_SetPublisherPermission(CommonEvent_SubscribeInfo* info, const char* permission)](#oh_commonevent_setpublisherpermission) | - | Sets the subscriber permission.| 52| [CommonEvent_ErrCode OH_CommonEvent_SetPublisherBundleName(CommonEvent_SubscribeInfo* info, const char* bundleName)](#oh_commonevent_setpublisherbundlename) | - | Sets a bundle name of the publisher.| 53| [void OH_CommonEvent_DestroySubscribeInfo(CommonEvent_SubscribeInfo* info)](#oh_commonevent_destroysubscribeinfo) | - | Destroys the subscriber information.| 54| [CommonEvent_Subscriber* OH_CommonEvent_CreateSubscriber(const CommonEvent_SubscribeInfo* info,CommonEvent_ReceiveCallback callback)](#oh_commonevent_createsubscriber) | - | Creates a subscriber.| 55| [void OH_CommonEvent_DestroySubscriber(CommonEvent_Subscriber* subscriber)](#oh_commonevent_destroysubscriber) | - | Destroys a subscriber.| 56| [CommonEvent_ErrCode OH_CommonEvent_Subscribe(const CommonEvent_Subscriber* subscriber)](#oh_commonevent_subscribe) | - | Subscribes to a common event.| 57| [CommonEvent_ErrCode OH_CommonEvent_UnSubscribe(const CommonEvent_Subscriber* subscriber)](#oh_commonevent_unsubscribe) | - | Unsubscribes from the common event.| 58| [const char* OH_CommonEvent_GetEventFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_geteventfromrcvdata) | - | Obtains the name of a common event.| 59| [int32_t OH_CommonEvent_GetCodeFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_getcodefromrcvdata) | - | Obtains the result code (number type) of a common event.| 60| [const char* OH_CommonEvent_GetDataStrFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_getdatastrfromrcvdata) | - | Obtains the result data (string type) of a common event.| 61| [const char* OH_CommonEvent_GetBundleNameFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_getbundlenamefromrcvdata) | - | Obtains the bundle name of a common event.| 62| [const CommonEvent_Parameters* OH_CommonEvent_GetParametersFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_getparametersfromrcvdata) | - | Obtains the additional information of a common event.| 63| [CommonEvent_PublishInfo* OH_CommonEvent_CreatePublishInfo(bool ordered)](#oh_commonevent_createpublishinfo) | - | Creates a property object of a common event.| 64| [void OH_CommonEvent_DestroyPublishInfo(CommonEvent_PublishInfo* info)](#oh_commonevent_destroypublishinfo) | - | Destroys a property object of a common event.| 65| [CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoBundleName(CommonEvent_PublishInfo* info, const char* bundleName)](#oh_commonevent_setpublishinfobundlename) | - | Sets the bundle name of a common event.| 66| [CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoPermissions(CommonEvent_PublishInfo* info,const char* permissions[], int32_t num)](#oh_commonevent_setpublishinfopermissions) | - | Sets permissions for a common event.| 67| [CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoCode(CommonEvent_PublishInfo* info, int32_t code)](#oh_commonevent_setpublishinfocode) | - | Sets the result code (number type) of a common event.| 68| [CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoData(CommonEvent_PublishInfo* info,const char* data, size_t length)](#oh_commonevent_setpublishinfodata) | - | Sets the result data (string type) of a common event.| 69| [CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoParameters(CommonEvent_PublishInfo* info,CommonEvent_Parameters* param)](#oh_commonevent_setpublishinfoparameters) | - | Sets the additional information of a common event.| 70| [CommonEvent_Parameters* OH_CommonEvent_CreateParameters()](#oh_commonevent_createparameters) | - | Creates an additional information object of a common event.| 71| [void OH_CommonEvent_DestroyParameters(CommonEvent_Parameters* param)](#oh_commonevent_destroyparameters) | - | Destroys the additional information object of a common event.| 72| [bool OH_CommonEvent_HasKeyInParameters(const CommonEvent_Parameters* para, const char* key)](#oh_commonevent_haskeyinparameters) | - | Checks whether the additional information of a common event contains a KV pair.| 73| [int OH_CommonEvent_GetIntFromParameters(const CommonEvent_Parameters* para, const char* key, const int defaultValue)](#oh_commonevent_getintfromparameters) | - | Obtains the int data with a specific key from the additional information of a common event. | 74| [CommonEvent_ErrCode OH_CommonEvent_SetIntToParameters(CommonEvent_Parameters* param, const char* key, int value)](#oh_commonevent_setinttoparameters) | - | Sets the int data with a specific key for the additional information of a common event.| 75| [int32_t OH_CommonEvent_GetIntArrayFromParameters(const CommonEvent_Parameters* para, const char* key, int** array)](#oh_commonevent_getintarrayfromparameters) | - | Obtains the int array with a specific key from the additional information of a common event.| 76| [CommonEvent_ErrCode OH_CommonEvent_SetIntArrayToParameters(CommonEvent_Parameters* param, const char* key,const int* value, size_t num)](#oh_commonevent_setintarraytoparameters) | - | Sets the int array with a specific key for the additional information of a common event.| 77| [long OH_CommonEvent_GetLongFromParameters(const CommonEvent_Parameters* para, const char* key, const long defaultValue)](#oh_commonevent_getlongfromparameters) | - | Obtains the long data with a specific key from the additional information of a common event.| 78| [CommonEvent_ErrCode OH_CommonEvent_SetLongToParameters(CommonEvent_Parameters* param, const char* key, long value)](#oh_commonevent_setlongtoparameters) | - | Sets the long data with a specific key for the additional information of a common event.| 79| [int32_t OH_CommonEvent_GetLongArrayFromParameters(const CommonEvent_Parameters* para, const char* key, long** array)](#oh_commonevent_getlongarrayfromparameters) | - | Obtains the long array with a specific key from the additional information of a common event.| 80| [CommonEvent_ErrCode OH_CommonEvent_SetLongArrayToParameters(CommonEvent_Parameters* param, const char* key,const long* value, size_t num)](#oh_commonevent_setlongarraytoparameters) | - | Sets the long array for the additional information of a common event.| 81| [bool OH_CommonEvent_GetBoolFromParameters(const CommonEvent_Parameters* para, const char* key, const bool defaultValue)](#oh_commonevent_getboolfromparameters) | - | Obtains the Boolean data with a specific key from the additional information of a common event.| 82| [CommonEvent_ErrCode OH_CommonEvent_SetBoolToParameters(CommonEvent_Parameters* param, const char* key, bool value)](#oh_commonevent_setbooltoparameters) | - | Sets the Boolean data with a specific key for the additional information of a common event.| 83| [int32_t OH_CommonEvent_GetBoolArrayFromParameters(const CommonEvent_Parameters* para, const char* key, bool** array)](#oh_commonevent_getboolarrayfromparameters) | - | Obtains the Boolean array with a specific key from the additional information of a common event.| 84| [CommonEvent_ErrCode OH_CommonEvent_SetBoolArrayToParameters(CommonEvent_Parameters* param, const char* key,const bool* value, size_t num)](#oh_commonevent_setboolarraytoparameters) | - | Sets the Boolean array with a specific key for the additional information of a common event.| 85| [char OH_CommonEvent_GetCharFromParameters(const CommonEvent_Parameters* para, const char* key, const char defaultValue)](#oh_commonevent_getcharfromparameters) | - | Obtains the character data with a specific key from the additional information of a common event.| 86| [CommonEvent_ErrCode OH_CommonEvent_SetCharToParameters(CommonEvent_Parameters* param, const char* key, char value)](#oh_commonevent_setchartoparameters) | - | Sets the character data with a specific key for the additional information of a common event.| 87| [int32_t OH_CommonEvent_GetCharArrayFromParameters(const CommonEvent_Parameters* para, const char* key, char** array)](#oh_commonevent_getchararrayfromparameters) | - | Obtains the character array with a specific key from the additional information of a common event.| 88| [CommonEvent_ErrCode OH_CommonEvent_SetCharArrayToParameters(CommonEvent_Parameters* param, const char* key,const char* value, size_t num)](#oh_commonevent_setchararraytoparameters) | - | Sets the character array with a specific key for the additional information of a common event.| 89| [double OH_CommonEvent_GetDoubleFromParameters(const CommonEvent_Parameters* para, const char* key,const double defaultValue)](#oh_commonevent_getdoublefromparameters) | - | Obtains the double data with a specific key from the additional information of a common event.| 90| [CommonEvent_ErrCode OH_CommonEvent_SetDoubleToParameters(CommonEvent_Parameters* param, const char* key,double value)](#oh_commonevent_setdoubletoparameters) | - | Sets the double data with a specific key for the additional information of a common event.| 91| [int32_t OH_CommonEvent_GetDoubleArrayFromParameters(const CommonEvent_Parameters* para, const char* key,double** array)](#oh_commonevent_getdoublearrayfromparameters) | - | Obtains the double array data with a specific key from the additional information of a common event.| 92| [CommonEvent_ErrCode OH_CommonEvent_SetDoubleArrayToParameters(CommonEvent_Parameters* param, const char* key,const double* value, size_t num)](#oh_commonevent_setdoublearraytoparameters) | - | Sets the double array with a specific key for the additional information of a common event.| 93| [CommonEvent_ErrCode OH_CommonEvent_Publish(const char* event)](#oh_commonevent_publish) | - | Publishes a common event.| 94| [CommonEvent_ErrCode OH_CommonEvent_PublishWithInfo(const char* event, const CommonEvent_PublishInfo* info)](#oh_commonevent_publishwithinfo) | - | Publishes a common event with specified properties.| 95| [bool OH_CommonEvent_IsOrderedCommonEvent(const CommonEvent_Subscriber* subscriber)](#oh_commonevent_isorderedcommonevent) | - | Checks whether a common event is an ordered one.| 96| [bool OH_CommonEvent_FinishCommonEvent(CommonEvent_Subscriber* subscriber)](#oh_commonevent_finishcommonevent) | - | Finishes an ordered common event.| 97| [bool OH_CommonEvent_GetAbortCommonEvent(const CommonEvent_Subscriber* subscriber)](#oh_commonevent_getabortcommonevent) | - | Checks whether an ordered common event is aborted.| 98| [bool OH_CommonEvent_AbortCommonEvent(CommonEvent_Subscriber* subscriber)](#oh_commonevent_abortcommonevent) | - | Aborts an ordered common event when used with [OH_CommonEvent_FinishCommonEvent](#oh_commonevent_finishcommonevent). After the abort, the common event is not sent to the next subscriber.| 99| [bool OH_CommonEvent_ClearAbortCommonEvent(CommonEvent_Subscriber* subscriber)](#oh_commonevent_clearabortcommonevent) | - | Clears the aborted state of an ordered common event when used with [OH_CommonEvent_FinishCommonEvent](#oh_commonevent_finishcommonevent). After the clearance, the common event is sent to the next subscriber.| 100| [int32_t OH_CommonEvent_GetCodeFromSubscriber(const CommonEvent_Subscriber* subscriber)](#oh_commonevent_getcodefromsubscriber) | - | Obtains the result code (number type) of an ordered common event.| 101| [bool OH_CommonEvent_SetCodeToSubscriber(CommonEvent_Subscriber* subscriber, int32_t code)](#oh_commonevent_setcodetosubscriber) | - | Sets the result code (number type) of an ordered common event.| 102| [const char* OH_CommonEvent_GetDataFromSubscriber(const CommonEvent_Subscriber* subscriber)](#oh_commonevent_getdatafromsubscriber) | - | Obtains the result data (string type) of an ordered common event.| 103| [bool OH_CommonEvent_SetDataToSubscriber(CommonEvent_Subscriber* subscriber, const char* data, size_t length)](#oh_commonevent_setdatatosubscriber) | - | Sets the result data (string type) of an ordered common event.| 104 105## Enum Description 106 107### CommonEvent_ErrCode 108 109``` 110enum CommonEvent_ErrCode 111``` 112 113**Description** 114 115Enumerates the error codes. 116 117**Since**: 12 118 119| Value| Description| 120| -- | -- | 121| COMMONEVENT_ERR_OK = 0 | Operation successful.| 122| COMMONEVENT_ERR_PERMISSION_ERROR = 201 | Permission denied.| 123| COMMONEVENT_ERR_INVALID_PARAMETER = 401 | Invalid parameter.| 124| COMMONEVENT_ERR_SENDING_LIMIT_EXCEEDED = 1500003| Event sending frequency is too high.<br>**Since**: 20| 125| COMMONEVENT_ERR_NOT_SYSTEM_SERVICE = 1500004 | The third-party application fails to send system common events.| 126| COMMONEVENT_ERR_SENDING_REQUEST_FAILED = 1500007 | Failed to send IPC requests.| 127| COMMONEVENT_ERR_INIT_UNDONE = 1500008 | Services not initialized.| 128| COMMONEVENT_ERR_OBTAIN_SYSTEM_PARAMS = 1500009 | System error.| 129| COMMONEVENT_ERR_SUBSCRIBER_NUM_EXCEEDED = 1500010 | The number of subscribers exceeds the upper limit.| 130| COMMONEVENT_ERR_ALLOC_MEMORY_FAILED = 1500011 | Failed to allocate memory.| 131 132 133## Function Description 134 135### CommonEvent_ReceiveCallback() 136 137``` 138typedef void (*CommonEvent_ReceiveCallback)(const CommonEvent_RcvData *data) 139``` 140 141**Description** 142 143Defines the callback function of a common event. 144 145**Since**: 12 146 147 148**Parameters** 149 150| Name | Description| 151|-------------------------------------| -- | 152| const [CommonEvent_RcvData](capi-oh-commonevent-commonevent-rcvdata.md) *data | Pointer to the callback data of a common event.| 153 154### OH_CommonEvent_CreateSubscribeInfo() 155 156``` 157CommonEvent_SubscribeInfo* OH_CommonEvent_CreateSubscribeInfo(const char* events[], int32_t eventsNum) 158``` 159 160**Description** 161 162Creates the subscriber information. 163 164**Since**: 12 165 166 167**Parameters** 168 169| Name| Description| 170| -- | -- | 171| const char* events[] | Pointer to the common events.| 172| int32_t eventsNum | Number of common events to subscribe.| 173 174**Returns** 175 176| Type | Description| 177|--------------------------------| -- | 178| [CommonEvent_SubscribeInfo](capi-oh-commonevent-commonevent-subscribeinfo.md)* | Returns the subscriber information created if the operation is successful; returns **NULL** otherwise.| 179 180### OH_CommonEvent_SetPublisherPermission() 181 182``` 183CommonEvent_ErrCode OH_CommonEvent_SetPublisherPermission(CommonEvent_SubscribeInfo* info, const char* permission) 184``` 185 186**Description** 187 188Sets the subscriber permission. 189 190**Since**: 12 191 192 193**Parameters** 194 195| Name| Description| 196| -- | -- | 197| [CommonEvent_SubscribeInfo](capi-oh-commonevent-commonevent-subscribeinfo.md)* info | Pointer to the subscriber information.| 198| const char* permission | Pointer to the permission name.| 199 200**Returns** 201 202| Type| Description| 203| -- | -- | 204| [CommonEvent_ErrCode](#commonevent_errcode) | Returns an execution result.<br> [COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode): operation successful.<br> [COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode): invalid parameter.| 205 206### OH_CommonEvent_SetPublisherBundleName() 207 208``` 209CommonEvent_ErrCode OH_CommonEvent_SetPublisherBundleName(CommonEvent_SubscribeInfo* info, const char* bundleName) 210``` 211 212**Description** 213 214Sets a bundle name of the publisher. 215 216**Since**: 12 217 218 219**Parameters** 220 221| Name| Description| 222| -- | -- | 223| [CommonEvent_SubscribeInfo](capi-oh-commonevent-commonevent-subscribeinfo.md)* info | Pointer to the subscriber information.| 224| const char* bundleName | Pointer to the bundle name.| 225 226**Returns** 227 228| Type| Description| 229| -- | -- | 230| [CommonEvent_ErrCode](#commonevent_errcode) | Returns an execution result.<br> [COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode): operation successful.<br> [COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode): invalid parameter.| 231 232### OH_CommonEvent_DestroySubscribeInfo() 233 234``` 235void OH_CommonEvent_DestroySubscribeInfo(CommonEvent_SubscribeInfo* info) 236``` 237 238**Description** 239 240Destroys the subscriber information. 241 242**Since**: 12 243 244 245**Parameters** 246 247| Name| Description| 248| -- | -- | 249| [CommonEvent_SubscribeInfo](capi-oh-commonevent-commonevent-subscribeinfo.md)* info | Pointer to the subscriber information.| 250 251### OH_CommonEvent_CreateSubscriber() 252 253``` 254CommonEvent_Subscriber* OH_CommonEvent_CreateSubscriber(const CommonEvent_SubscribeInfo* info,CommonEvent_ReceiveCallback callback) 255``` 256 257**Description** 258 259Creates a subscriber. 260 261**Since**: 12 262 263 264**Parameters** 265 266| Name | Description| 267|----------------------------------------------------------------------| -- | 268| const [CommonEvent_SubscribeInfo](capi-oh-commonevent-commonevent-subscribeinfo.md)* info | Pointer to the subscriber information.| 269| [CommonEvent_ReceiveCallback](#commonevent_receivecallback) callback | Callback to be invoked when a common event is triggered.| 270 271**Returns** 272 273| Type| Description| 274| -- | -- | 275| [CommonEvent_Subscriber](#variables)*| Returns the subscriber created if the operation is successful; returns **NULL** otherwise.| 276 277### OH_CommonEvent_DestroySubscriber() 278 279``` 280void OH_CommonEvent_DestroySubscriber(CommonEvent_Subscriber* subscriber) 281``` 282 283**Description** 284 285Destroys a subscriber. 286 287**Since**: 12 288 289 290**Parameters** 291 292| Name| Description| 293| -- | -- | 294| [CommonEvent_Subscriber](#variables)* subscriber| Pointer to the common event subscriber.| 295 296### OH_CommonEvent_Subscribe() 297 298``` 299CommonEvent_ErrCode OH_CommonEvent_Subscribe(const CommonEvent_Subscriber* subscriber) 300``` 301 302**Description** 303 304Subscribes to a common event. 305 306**Since**: 12 307 308 309**Parameters** 310 311| Name| Description| 312| -- | -- | 313| const [CommonEvent_Subscriber](#variables)* subscriber| Pointer to the common event subscriber.| 314 315**Returns** 316 317| Type| Description| 318| -- | -- | 319| [CommonEvent_ErrCode](#commonevent_errcode) | Returns an execution result.<br> [COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode): operation successful.<br> [COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode): invalid parameter.<br> [COMMONEVENT_ERR_SENDING_REQUEST_FAILED](capi-oh-commonevent-h.md#commonevent_errcode): Failed to send IPC requests.<br> [COMMONEVENT_ERR_INIT_UNDONE](capi-oh-commonevent-h.md#commonevent_errcode): common event services not initialized.<br> [COMMONEVENT_ERR_SUBSCRIBER_NUM_EXCEEDED](capi-oh-commonevent-h.md#commonevent_errcode): The number of subscribers exceeds 200.<br> [COMMONEVENT_ERR_ALLOC_MEMORY_FAILED](capi-oh-commonevent-h.md#commonevent_errcode): Failed to allocate memory.| 320 321### OH_CommonEvent_UnSubscribe() 322 323``` 324CommonEvent_ErrCode OH_CommonEvent_UnSubscribe(const CommonEvent_Subscriber* subscriber) 325``` 326 327**Description** 328 329Unsubscribes from the common events. 330 331**Since**: 12 332 333 334**Parameters** 335 336| Name| Description| 337| -- | -- | 338| const [CommonEvent_Subscriber](#variables)* subscriber| Pointer to the common event subscriber.| 339 340**Returns** 341 342| Type| Description| 343| -- | -- | 344| [CommonEvent_ErrCode](#commonevent_errcode) | Returns an execution result.<br> [COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode): operation successful.<br> [COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode): invalid parameter.<br> [COMMONEVENT_ERR_SENDING_REQUEST_FAILED](capi-oh-commonevent-h.md#commonevent_errcode): Failed to send IPC requests.<br> [COMMONEVENT_ERR_INIT_UNDONE](capi-oh-commonevent-h.md#commonevent_errcode): common event services not initialized.| 345 346### OH_CommonEvent_GetEventFromRcvData() 347 348``` 349const char* OH_CommonEvent_GetEventFromRcvData(const CommonEvent_RcvData* rcvData) 350``` 351 352**Description** 353 354Obtains the name of a common event. 355 356**Since**: 12 357 358 359**Parameters** 360 361| Name | Description| 362|----------------------------------------| -- | 363| const [CommonEvent_RcvData](capi-oh-commonevent-commonevent-rcvdata.md)* rcvData | Pointer to the callback data of a common event.| 364 365**Returns** 366 367| Type| Description| 368| -- | -- | 369| const char* | Event name obtained.| 370 371### OH_CommonEvent_GetCodeFromRcvData() 372 373``` 374int32_t OH_CommonEvent_GetCodeFromRcvData(const CommonEvent_RcvData* rcvData) 375``` 376 377**Description** 378 379Obtains the result code (number type) of a common event. 380 381**Since**: 12 382 383 384**Parameters** 385 386| Name| Description| 387| -- | -- | 388| const [CommonEvent_RcvData](capi-oh-commonevent-commonevent-rcvdata.md)* rcvData | Pointer to the callback data of a common event.| 389 390**Returns** 391 392| Type| Description| 393| -- | -- | 394| int32_t | Result code obtained.| 395 396### OH_CommonEvent_GetDataStrFromRcvData() 397 398``` 399const char* OH_CommonEvent_GetDataStrFromRcvData(const CommonEvent_RcvData* rcvData) 400``` 401 402**Description** 403 404Obtains the result data (string type) of a common event. 405 406**Since**: 12 407 408 409**Parameters** 410 411| Name| Description| 412| -- | -- | 413| const [CommonEvent_RcvData](capi-oh-commonevent-commonevent-rcvdata.md)* rcvData | Pointer to the callback data of a common event.| 414 415**Returns** 416 417| Type| Description| 418| -- | -- | 419| const char* | Result data obtained.| 420 421### OH_CommonEvent_GetBundleNameFromRcvData() 422 423``` 424const char* OH_CommonEvent_GetBundleNameFromRcvData(const CommonEvent_RcvData* rcvData) 425``` 426 427**Description** 428 429Obtains the bundle name of a common event. 430 431**Since**: 12 432 433 434**Parameters** 435 436| Name| Description| 437| -- | -- | 438| const [CommonEvent_RcvData](capi-oh-commonevent-commonevent-rcvdata.md)* rcvData | Pointer to the callback data of a common event.| 439 440**Returns** 441 442| Type| Description| 443| -- | -- | 444| const char* | Bundle name obtained.| 445 446### OH_CommonEvent_GetParametersFromRcvData() 447 448``` 449const CommonEvent_Parameters* OH_CommonEvent_GetParametersFromRcvData(const CommonEvent_RcvData* rcvData) 450``` 451 452**Description** 453 454Obtains the additional information of a common event. 455 456**Since**: 12 457 458 459**Parameters** 460 461| Name| Description| 462| -- | -- | 463| const [CommonEvent_RcvData](capi-oh-commonevent-commonevent-rcvdata.md)* rcvData | Pointer to the callback data of a common event.| 464 465**Returns** 466 467| Type| Description| 468| -- | -- | 469| const [CommonEvent_Parameters](#variables) *| Additional information obtained.| 470 471### OH_CommonEvent_CreatePublishInfo() 472 473``` 474CommonEvent_PublishInfo* OH_CommonEvent_CreatePublishInfo(bool ordered) 475``` 476 477**Description** 478 479Creates a property object of a common event. 480 481**Since**: 18 482 483 484**Parameters** 485 486| Name| Description| 487| -- | -- | 488| bool ordered | Whether the common event is an ordered one.<br> - **true**: ordered common event.<br> - **false**: unordered common event.| 489 490**Returns** 491 492| Type | Description| 493|------------------------------| -- | 494| [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* | Returns the property object if the operation is successful; returns **null** otherwise.| 495 496### OH_CommonEvent_DestroyPublishInfo() 497 498``` 499void OH_CommonEvent_DestroyPublishInfo(CommonEvent_PublishInfo* info) 500``` 501 502**Description** 503 504Destroys a property object of a common event. 505 506**Since**: 18 507 508 509**Parameters** 510 511| Name| Description| 512| -- | -- | 513| [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* info | Pointer to the property object of the common event to destroy.| 514 515### OH_CommonEvent_SetPublishInfoBundleName() 516 517``` 518CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoBundleName(CommonEvent_PublishInfo* info, const char* bundleName) 519``` 520 521**Description** 522 523Sets the bundle name of a common event. 524 525**Since**: 18 526 527 528**Parameters** 529 530| Name| Description| 531| -- | -- | 532| [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* info | Pointer to the property object of a common event.| 533| const char* bundleName | Pointer to the bundle name to set.| 534 535**Returns** 536 537| Type| Description| 538| -- | -- | 539| [CommonEvent_ErrCode](#commonevent_errcode) | Returns an execution result.<br> [COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode): operation successful.<br> [COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode): invalid parameter.| 540 541### OH_CommonEvent_SetPublishInfoPermissions() 542 543``` 544CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoPermissions(CommonEvent_PublishInfo* info,const char* permissions[], int32_t num) 545``` 546 547**Description** 548 549Sets permissions for a common event. 550 551**Since**: 18 552 553 554**Parameters** 555 556| Name| Description| 557| -- | -- | 558| [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* info | Pointer to the property object of a common event.| 559| const char* permissions[] | Pointer to the array of permission names.| 560| int32_t num | Number of permissions.| 561 562**Returns** 563 564| Type| Description| 565| -- | -- | 566| [CommonEvent_ErrCode](#commonevent_errcode) | Returns an execution result.<br> [COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode): operation successful.<br> [COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode): invalid parameter.| 567 568### OH_CommonEvent_SetPublishInfoCode() 569 570``` 571CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoCode(CommonEvent_PublishInfo* info, int32_t code) 572``` 573 574**Description** 575 576Sets the result code (number type) of a common event. 577 578**Since**: 18 579 580 581**Parameters** 582 583| Name| Description| 584| -- | -- | 585| [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* info | Pointer to the property object of a common event.| 586| int32_t code | Result code to set.| 587 588**Returns** 589 590| Type| Description| 591| -- | -- | 592| [CommonEvent_ErrCode](#commonevent_errcode) | Returns an execution result.<br> [COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode): operation successful.<br> [COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode): invalid parameter.| 593 594### OH_CommonEvent_SetPublishInfoData() 595 596``` 597CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoData(CommonEvent_PublishInfo* info,const char* data, size_t length) 598``` 599 600**Description** 601 602Sets the result data (string type) of a common event. 603 604**Since**: 18 605 606 607**Parameters** 608 609| Name| Description| 610| -- | -- | 611| [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* info | Pointer to the property object of a common event.| 612| const char* data | Pointer to the result data to set.| 613| size_t length | Length of the result data.| 614 615**Returns** 616 617| Type| Description| 618| -- | -- | 619| [CommonEvent_ErrCode](#commonevent_errcode) | Returns an execution result.<br> [COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode): operation successful.<br> [COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode): invalid parameter.| 620 621### OH_CommonEvent_SetPublishInfoParameters() 622 623``` 624CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoParameters(CommonEvent_PublishInfo* info,CommonEvent_Parameters* param) 625``` 626 627**Description** 628 629Sets the additional information of a common event. 630 631**Since**: 18 632 633 634**Parameters** 635 636| Name| Description| 637| -- | -- | 638| [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* info | Pointer to the property object of a common event.| 639| CommonEvent_Parameters* param | Pointer to the additional information to set.| 640 641**Returns** 642 643| Type| Description| 644| -- | -- | 645| [CommonEvent_ErrCode](#commonevent_errcode) | Returns an execution result.<br> [COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode): operation successful.<br> [COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode): invalid parameter.| 646 647### OH_CommonEvent_CreateParameters() 648 649``` 650CommonEvent_Parameters* OH_CommonEvent_CreateParameters() 651``` 652 653**Description** 654 655Creates an additional information object of a common event. 656 657**Since**: 18 658 659**Returns** 660 661| Type| Description| 662| -- | -- | 663| [CommonEvent_Parameters](#variables)*| Returns additional information of the common event if operation is successful; returns **null** otherwise.| 664 665### OH_CommonEvent_DestroyParameters() 666 667``` 668void OH_CommonEvent_DestroyParameters(CommonEvent_Parameters* param) 669``` 670 671**Description** 672 673Destroys the additional information object of a common event. 674 675**Since**: 18 676 677 678**Parameters** 679 680| Name| Description| 681| -- | -- | 682| [CommonEvent_Parameters](#variables)* param| Pointer to the additional information to destroy.| 683 684### OH_CommonEvent_HasKeyInParameters() 685 686``` 687bool OH_CommonEvent_HasKeyInParameters(const CommonEvent_Parameters* para, const char* key) 688``` 689 690**Description** 691 692Checks whether the additional information of a common event contains a KV pair. 693 694**Since**: 12 695 696 697**Parameters** 698 699| Name| Description| 700| -- | -- | 701| const [CommonEvent_Parameters](#variables)* para| Pointer to the additional information to check.| 702| const char* key | Pointer to the key.| 703 704**Returns** 705 706| Type| Description| 707| -- | -- | 708| bool | Returns the check result.<br> - **true**: The key exists.<br> - **false**: The key does not exist.| 709 710### OH_CommonEvent_GetIntFromParameters() 711 712``` 713int OH_CommonEvent_GetIntFromParameters(const CommonEvent_Parameters* para, const char* key, const int defaultValue) 714``` 715 716**Description** 717 718Obtains the int data with a specific key from the additional information of a common event. 719 720**Since**: 12 721 722 723**Parameters** 724 725| Name| Description| 726| -- | -- | 727| const [CommonEvent_Parameters](#variables) * para| Pointer to the additional information of a common event.| 728| const char* key | Pointer to the key.| 729| const int defaultValue | Default value.| 730 731**Returns** 732 733| Type| Description| 734| -- | -- | 735| int | The int data obtained.| 736 737### OH_CommonEvent_SetIntToParameters() 738 739``` 740CommonEvent_ErrCode OH_CommonEvent_SetIntToParameters(CommonEvent_Parameters* param, const char* key, int value) 741``` 742 743**Description** 744 745Sets the int data with a specific key for the additional information of a common event. 746 747**Since**: 18 748 749 750**Parameters** 751 752| Name| Description| 753| -- | -- | 754| [CommonEvent_Parameters](#variables)* param| Pointer to the additional information of a common event.| 755| const char* key | Pointer to the key.| 756| int value | The int data to set.| 757 758**Returns** 759 760| Type| Description| 761| -- | -- | 762| [CommonEvent_ErrCode](#commonevent_errcode) | Returns an execution result.<br> [COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode): operation successful.<br> [COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode): invalid parameter.| 763 764### OH_CommonEvent_GetIntArrayFromParameters() 765 766``` 767int32_t OH_CommonEvent_GetIntArrayFromParameters(const CommonEvent_Parameters* para, const char* key, int** array) 768``` 769 770**Description** 771 772Obtains the int array with a specific key from the additional information of a common event. 773 774**Since**: 12 775 776 777**Parameters** 778 779| Name| Description| 780| -- | -- | 781| const [CommonEvent_Parameters](#variables) * para| Pointer to the additional information of a common event.| 782| const char* key | Pointer to the key.| 783| int** array | The int array to obtain.| 784 785**Returns** 786 787| Type| Description| 788| -- | -- | 789| int32_t | Length of the array obtained. The default value is **0**.| 790 791### OH_CommonEvent_SetIntArrayToParameters() 792 793``` 794CommonEvent_ErrCode OH_CommonEvent_SetIntArrayToParameters(CommonEvent_Parameters* param, const char* key,const int* value, size_t num) 795``` 796 797**Description** 798 799Sets the int array with a specific key for the additional information of a common event. 800 801**Since**: 18 802 803 804**Parameters** 805 806| Name| Description| 807| -- | -- | 808| [CommonEvent_Parameters](#variables)* param| Pointer to the additional information of a common event.| 809| const char* key | Pointer to the key.| 810| const int* value | The int array to set.| 811| size_t num | Number of elements in the int array.| 812 813**Returns** 814 815| Type| Description| 816| -- | -- | 817| [CommonEvent_ErrCode](#commonevent_errcode) | Returns an execution result.<br> [COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode): operation successful.<br> [COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode): invalid parameter.<br> [COMMONEVENT_ERR_ALLOC_MEMORY_FAILED](capi-oh-commonevent-h.md#commonevent_errcode): Failed to allocate memory.| 818 819### OH_CommonEvent_GetLongFromParameters() 820 821``` 822long OH_CommonEvent_GetLongFromParameters(const CommonEvent_Parameters* para, const char* key, const long defaultValue) 823``` 824 825**Description** 826 827Obtains the long data with a specific key from the additional information of a common event. 828 829**Since**: 12 830 831 832**Parameters** 833 834| Name| Description| 835| -- | -- | 836| const [CommonEvent_Parameters](#variables) * para| Pointer to the additional information of a common event.| 837| const char* key | Pointer to the key.| 838| const long defaultValue | Default value.| 839 840**Returns** 841 842| Type| Description| 843| -- | -- | 844| long | The long data obtained.| 845 846### OH_CommonEvent_SetLongToParameters() 847 848``` 849CommonEvent_ErrCode OH_CommonEvent_SetLongToParameters(CommonEvent_Parameters* param, const char* key, long value) 850``` 851 852**Description** 853 854Sets the long data with a specific key for the additional information of a common event. 855 856**Since**: 18 857 858 859**Parameters** 860 861| Name| Description| 862| -- | -- | 863| [CommonEvent_Parameters](#variables)* param| Pointer to the additional information of a common event.| 864| const char* key | Pointer to the key.| 865| long value | The long data to set.| 866 867**Returns** 868 869| Type| Description| 870| -- | -- | 871| [CommonEvent_ErrCode](#commonevent_errcode) | Returns an execution result.<br> [COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode): operation successful.<br> [COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode): invalid parameter.| 872 873### OH_CommonEvent_GetLongArrayFromParameters() 874 875``` 876int32_t OH_CommonEvent_GetLongArrayFromParameters(const CommonEvent_Parameters* para, const char* key, long** array) 877``` 878 879**Description** 880 881Obtains the long array with a specific key from the additional information of a common event. 882 883**Since**: 12 884 885 886**Parameters** 887 888| Name| Description| 889| -- | -- | 890| const [CommonEvent_Parameters](#variables) * para| Pointer to the additional information of a common event.| 891| const char* key | Pointer to the key.| 892| long** array | Double pointer to the long array to obtain.| 893 894**Returns** 895 896| Type| Description| 897| -- | -- | 898| int32_t | Length of the array obtained. The default value is **0**.| 899 900### OH_CommonEvent_SetLongArrayToParameters() 901 902``` 903CommonEvent_ErrCode OH_CommonEvent_SetLongArrayToParameters(CommonEvent_Parameters* param, const char* key,const long* value, size_t num) 904``` 905 906**Description** 907 908Sets the long array for the additional information of a common event. 909 910**Since**: 18 911 912 913**Parameters** 914 915| Name| Description| 916| -- | -- | 917| [CommonEvent_Parameters](#variables)* param| Pointer to the additional information of a common event.| 918| const char* key | Pointer to the key.| 919| const long* value | Pointer to the long array to set.| 920| size_t num | Number of elements in the long array.| 921 922**Returns** 923 924| Type| Description| 925| -- | -- | 926| [CommonEvent_ErrCode](#commonevent_errcode) | Returns an execution result.<br> [COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode): operation successful.<br> [COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode): invalid parameter.<br> [COMMONEVENT_ERR_ALLOC_MEMORY_FAILED](capi-oh-commonevent-h.md#commonevent_errcode): Failed to allocate memory.| 927 928### OH_CommonEvent_GetBoolFromParameters() 929 930``` 931bool OH_CommonEvent_GetBoolFromParameters(const CommonEvent_Parameters* para, const char* key, const bool defaultValue) 932``` 933 934**Description** 935 936Obtains the Boolean data with a specific key from the additional information of a common event. 937 938**Since**: 12 939 940 941**Parameters** 942 943| Name| Description| 944| -- | -- | 945| const [CommonEvent_Parameters](#variables) * para| Pointer to the additional information of a common event.| 946| const char* key | Pointer to the key.| 947| const bool defaultValue | Default value.| 948 949**Returns** 950 951| Type| Description| 952| -- | -- | 953| bool | The Boolean data obtained.| 954 955### OH_CommonEvent_SetBoolToParameters() 956 957``` 958CommonEvent_ErrCode OH_CommonEvent_SetBoolToParameters(CommonEvent_Parameters* param, const char* key, bool value) 959``` 960 961**Description** 962 963Sets the Boolean data with a specific key for the additional information of a common event. 964 965**Since**: 18 966 967 968**Parameters** 969 970| Name| Description| 971| -- | -- | 972| [CommonEvent_Parameters](#variables)* param| Pointer to the additional information of a common event.| 973| const char* key | Pointer to the key.| 974| bool value | The Boolean data to set.| 975 976**Returns** 977 978| Type| Description| 979| -- | -- | 980| [CommonEvent_ErrCode](#commonevent_errcode) | Returns an execution result.<br> [COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode): operation successful.<br> [COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode): invalid parameter.| 981 982### OH_CommonEvent_GetBoolArrayFromParameters() 983 984``` 985int32_t OH_CommonEvent_GetBoolArrayFromParameters(const CommonEvent_Parameters* para, const char* key, bool** array) 986``` 987 988**Description** 989 990Obtains the Boolean array with a specific key from the additional information of a common event. 991 992**Since**: 12 993 994 995**Parameters** 996 997| Name| Description| 998| -- | -- | 999| const [CommonEvent_Parameters](#variables) * para| Pointer to the additional information of a common event.| 1000| const char* key | Pointer to the key.| 1001| bool** array | Double pointer to the Boolean array to obtain.| 1002 1003**Returns** 1004 1005| Type| Description| 1006| -- | -- | 1007| int32_t | Length of the array obtained. The default value is **0**.| 1008 1009### OH_CommonEvent_SetBoolArrayToParameters() 1010 1011``` 1012CommonEvent_ErrCode OH_CommonEvent_SetBoolArrayToParameters(CommonEvent_Parameters* param, const char* key,const bool* value, size_t num) 1013``` 1014 1015**Description** 1016 1017Sets the Boolean array with a specific key for the additional information of a common event. 1018 1019**Since**: 18 1020 1021 1022**Parameters** 1023 1024| Name| Description| 1025| -- | -- | 1026| [CommonEvent_Parameters](#variables)* param| Pointer to the additional information of a common event.| 1027| const char* key | Pointer to the key.| 1028| const bool* value | Pointer to the Boolean array to set.| 1029| size_t num | Number of elements in the Boolean array.| 1030 1031**Returns** 1032 1033| Type| Description| 1034| -- | -- | 1035| [CommonEvent_ErrCode](#commonevent_errcode) | Returns an execution result.<br> [COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode): operation successful.<br> [COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode): invalid parameter.<br> [COMMONEVENT_ERR_ALLOC_MEMORY_FAILED](capi-oh-commonevent-h.md#commonevent_errcode): Failed to allocate memory.| 1036 1037### OH_CommonEvent_GetCharFromParameters() 1038 1039``` 1040char OH_CommonEvent_GetCharFromParameters(const CommonEvent_Parameters* para, const char* key, const char defaultValue) 1041``` 1042 1043**Description** 1044 1045Obtains the character data with a specific key from the additional information of a common event. 1046 1047**Since**: 12 1048 1049 1050**Parameters** 1051 1052| Name| Description| 1053| -- | -- | 1054| const [CommonEvent_Parameters](#variables) * para| Pointer to the additional information of a common event.| 1055| const char* key | Pointer to the key.| 1056| const char defaultValue | Default value.| 1057 1058**Returns** 1059 1060| Type| Description| 1061| -- | -- | 1062| char | The character data obtained.| 1063 1064### OH_CommonEvent_SetCharToParameters() 1065 1066``` 1067CommonEvent_ErrCode OH_CommonEvent_SetCharToParameters(CommonEvent_Parameters* param, const char* key, char value) 1068``` 1069 1070**Description** 1071 1072Sets the character data with a specific key for the additional information of a common event. 1073 1074**Since**: 18 1075 1076 1077**Parameters** 1078 1079| Name| Description| 1080| -- | -- | 1081| [CommonEvent_Parameters](#variables)* param| Pointer to the additional information of a common event.| 1082| const char* key | Pointer to the key.| 1083| char value | The character data to set.| 1084 1085**Returns** 1086 1087| Type| Description| 1088| -- | -- | 1089| [CommonEvent_ErrCode](#commonevent_errcode) | Returns an execution result.<br> [COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode): operation successful.<br> [COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode): invalid parameter.| 1090 1091### OH_CommonEvent_GetCharArrayFromParameters() 1092 1093``` 1094int32_t OH_CommonEvent_GetCharArrayFromParameters(const CommonEvent_Parameters* para, const char* key, char** array) 1095``` 1096 1097**Description** 1098 1099Obtains the character array with a specific key from the additional information of a common event. 1100 1101**Since**: 12 1102 1103 1104**Parameters** 1105 1106| Name| Description| 1107| -- | -- | 1108| const [CommonEvent_Parameters](#variables) * para| Pointer to the additional information of a common event.| 1109| const char* key | Pointer to the key.| 1110| char** array | Double pointer to the character array to obtain.| 1111 1112**Returns** 1113 1114| Type| Description| 1115| -- | -- | 1116| int32_t | Length of the array obtained. The default value is **0**.| 1117 1118### OH_CommonEvent_SetCharArrayToParameters() 1119 1120``` 1121CommonEvent_ErrCode OH_CommonEvent_SetCharArrayToParameters(CommonEvent_Parameters* param, const char* key,const char* value, size_t num) 1122``` 1123 1124**Description** 1125 1126Sets the character array with a specific key for the additional information of a common event. 1127 1128**Since**: 18 1129 1130 1131**Parameters** 1132 1133| Name| Description| 1134| -- | -- | 1135| [CommonEvent_Parameters](#variables)* param| Pointer to the additional information of a common event.| 1136| const char* key | Pointer to the key.| 1137| const char* value | Pointer to the character array to set.| 1138| size_t num | Number of elements in the character array.| 1139 1140**Returns** 1141 1142| Type| Description| 1143| -- | -- | 1144| [CommonEvent_ErrCode](#commonevent_errcode) | Returns an execution result.<br> [COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode): operation successful.<br> [COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode): invalid parameter.| 1145 1146### OH_CommonEvent_GetDoubleFromParameters() 1147 1148``` 1149double OH_CommonEvent_GetDoubleFromParameters(const CommonEvent_Parameters* para, const char* key,const double defaultValue) 1150``` 1151 1152**Description** 1153 1154Obtains the double data with a specific key from the additional information of a common event. 1155 1156**Since**: 12 1157 1158 1159**Parameters** 1160 1161| Name| Description| 1162| -- | -- | 1163| const [CommonEvent_Parameters](#variables) * para| Pointer to the additional information of a common event.| 1164| const char* key | Pointer to the key.| 1165| const double defaultValue | Default value.| 1166 1167**Returns** 1168 1169| Type| Description| 1170| -- | -- | 1171| double | The double data obtained.| 1172 1173### OH_CommonEvent_SetDoubleToParameters() 1174 1175``` 1176CommonEvent_ErrCode OH_CommonEvent_SetDoubleToParameters(CommonEvent_Parameters* param, const char* key,double value) 1177``` 1178 1179**Description** 1180 1181Sets the double data with a specific key for the additional information of a common event. 1182 1183**Since**: 18 1184 1185 1186**Parameters** 1187 1188| Name| Description| 1189| -- | -- | 1190| [CommonEvent_Parameters](#variables)* param| Pointer to the additional information of a common event.| 1191| const char* key | Pointer to the key.| 1192| double value | The double data to set.| 1193 1194**Returns** 1195 1196| Type| Description| 1197| -- | -- | 1198| [CommonEvent_ErrCode](#commonevent_errcode) | Returns an execution result.<br> [COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode): operation successful.<br> [COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode): invalid parameter.| 1199 1200### OH_CommonEvent_GetDoubleArrayFromParameters() 1201 1202``` 1203int32_t OH_CommonEvent_GetDoubleArrayFromParameters(const CommonEvent_Parameters* para, const char* key,double** array) 1204``` 1205 1206**Description** 1207 1208Obtains the double array with a specific key from the additional information of a common event. 1209 1210**Since**: 12 1211 1212 1213**Parameters** 1214 1215| Name| Description| 1216| -- | -- | 1217| const [CommonEvent_Parameters](#variables) * para| Pointer to the additional information of a common event.| 1218| const char* key | Pointer to the key.| 1219| double** array | Double pointer to the array to obtain.| 1220 1221**Returns** 1222 1223| Type| Description| 1224| -- | -- | 1225| int32_t | Length of the array obtained. The default value is **0**.| 1226 1227### OH_CommonEvent_SetDoubleArrayToParameters() 1228 1229``` 1230CommonEvent_ErrCode OH_CommonEvent_SetDoubleArrayToParameters(CommonEvent_Parameters* param, const char* key,const double* value, size_t num) 1231``` 1232 1233**Description** 1234 1235Sets the double array with a specific key for the additional information of a common event. 1236 1237**Since**: 18 1238 1239 1240**Parameters** 1241 1242| Name| Description| 1243| -- | -- | 1244| [CommonEvent_Parameters](#variables)* param| Pointer to the additional information of a common event.| 1245| const char* key | Pointer to the key.| 1246| const double* value | Pointer to the double array to set.| 1247| size_t num | Number of elements in the double array.| 1248 1249**Returns** 1250 1251| Type| Description| 1252| -- | -- | 1253| [CommonEvent_ErrCode](#commonevent_errcode) | Returns an execution result.<br> [COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode): operation successful.<br> [COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode): invalid parameter.<br> [COMMONEVENT_ERR_ALLOC_MEMORY_FAILED](capi-oh-commonevent-h.md#commonevent_errcode): Failed to allocate memory.| 1254 1255### OH_CommonEvent_Publish() 1256 1257``` 1258CommonEvent_ErrCode OH_CommonEvent_Publish(const char* event) 1259``` 1260 1261**Description** 1262 1263Publishes a common event. 1264 1265**Since**: 18 1266 1267 1268**Parameters** 1269 1270| Name| Description| 1271| -- | -- | 1272| const char* event | Pointer to the name of the common event.| 1273 1274**Returns** 1275 1276| Type| Description| 1277| -- | -- | 1278| [CommonEvent_ErrCode](#commonevent_errcode) | Returns an execution result.<br> [COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode): operation successful.<br> [COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode): invalid parameter.<br> [COMMONEVENT_ERR_SENDING_LIMIT_EXCEEDED](capi-oh-commonevent-h.md#commonevent_errcode): Event sending frequency is too high.<br> [COMMONEVENT_ERR_SENDING_REQUEST_FAILED](capi-oh-commonevent-h.md#commonevent_errcode): Failed to send IPC requests.<br> [COMMONEVENT_ERR_INIT_UNDONE](capi-oh-commonevent-h.md#commonevent_errcode): common event services not initialized.| 1279 1280### OH_CommonEvent_PublishWithInfo() 1281 1282``` 1283CommonEvent_ErrCode OH_CommonEvent_PublishWithInfo(const char* event, const CommonEvent_PublishInfo* info) 1284``` 1285 1286**Description** 1287 1288Publishes a common event with specified properties. 1289 1290**Since**: 18 1291 1292 1293**Parameters** 1294 1295| Name| Description| 1296| -- | -- | 1297| const char* event | Pointer to the name of the common event.| 1298| const [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* info | Pointer to the property object of the common event.| 1299 1300**Returns** 1301 1302| Type| Description| 1303| -- | -- | 1304| [CommonEvent_ErrCode](#commonevent_errcode) | Returns an execution result.<br> [COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode): operation successful.<br> [COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode): invalid parameter.<br> [COMMONEVENT_ERR_SENDING_LIMIT_EXCEEDED](capi-oh-commonevent-h.md#commonevent_errcode): Event sending frequency is too high.<br> [COMMONEVENT_ERR_SENDING_REQUEST_FAILED](capi-oh-commonevent-h.md#commonevent_errcode): Failed to send IPC requests.<br> [COMMONEVENT_ERR_INIT_UNDONE](capi-oh-commonevent-h.md#commonevent_errcode): common event services not initialized.| 1305 1306### OH_CommonEvent_IsOrderedCommonEvent() 1307 1308``` 1309bool OH_CommonEvent_IsOrderedCommonEvent(const CommonEvent_Subscriber* subscriber) 1310``` 1311 1312**Description** 1313 1314Checks whether a common event is an ordered one. 1315 1316**Since**: 18 1317 1318 1319**Parameters** 1320 1321| Name| Description| 1322| -- | -- | 1323| const [CommonEvent_Subscriber](#variables)* subscriber| Pointer to the common event subscriber.| 1324 1325**Returns** 1326 1327| Type| Description| 1328| -- | -- | 1329| bool | Returns **true** if the common event is an ordered one; returns **false** if the common event is an unordered one.| 1330 1331### OH_CommonEvent_FinishCommonEvent() 1332 1333``` 1334bool OH_CommonEvent_FinishCommonEvent(CommonEvent_Subscriber* subscriber) 1335``` 1336 1337**Description** 1338 1339Finishes an ordered common event. 1340 1341**Since**: 18 1342 1343 1344**Parameters** 1345 1346| Name| Description| 1347| -- | -- | 1348| [CommonEvent_Subscriber](#variables)* subscriber| Pointer to the common event subscriber.| 1349 1350**Returns** 1351 1352| Type| Description| 1353| -- | -- | 1354| bool | Returns **true** if the operation is successful; returns **false** otherwise.| 1355 1356### OH_CommonEvent_GetAbortCommonEvent() 1357 1358``` 1359bool OH_CommonEvent_GetAbortCommonEvent(const CommonEvent_Subscriber* subscriber) 1360``` 1361 1362**Description** 1363 1364Checks whether an ordered common event is aborted. 1365 1366**Since**: 18 1367 1368 1369**Parameters** 1370 1371| Name| Description| 1372| -- | -- | 1373| const [CommonEvent_Subscriber](#variables)* subscriber| Pointer to the common event subscriber.| 1374 1375**Returns** 1376 1377| Type| Description| 1378| -- | -- | 1379| bool | Returns **true** if the ordered common event is in the aborted state; returns **false** otherwise.| 1380 1381### OH_CommonEvent_AbortCommonEvent() 1382 1383``` 1384bool OH_CommonEvent_AbortCommonEvent(CommonEvent_Subscriber* subscriber) 1385``` 1386 1387**Description** 1388 1389Aborts an ordered common event when used with [OH_CommonEvent_FinishCommonEvent](#oh_commonevent_finishcommonevent). After the abort, the common event is not sent to the next subscriber. 1390 1391**Since**: 18 1392 1393 1394**Parameters** 1395 1396| Name| Description| 1397| -- | -- | 1398| [CommonEvent_Subscriber](#variables)* subscriber| Pointer to the common event subscriber.| 1399 1400**Returns** 1401 1402| Type| Description| 1403| -- | -- | 1404| bool | Returns **true** if the operation is successful; returns **false** otherwise.| 1405 1406### OH_CommonEvent_ClearAbortCommonEvent() 1407 1408``` 1409bool OH_CommonEvent_ClearAbortCommonEvent(CommonEvent_Subscriber* subscriber) 1410``` 1411 1412**Description** 1413 1414Clears the aborted state of an ordered common event when used with [OH_CommonEvent_FinishCommonEvent](#oh_commonevent_finishcommonevent). After the clearance, the common event is sent to the next subscriber. 1415 1416**Since**: 18 1417 1418 1419**Parameters** 1420 1421| Name| Description| 1422| -- | -- | 1423| [CommonEvent_Subscriber](#variables)* subscriber| Pointer to the common event subscriber.| 1424 1425**Returns** 1426 1427| Type| Description| 1428| -- | -- | 1429| bool | Returns **true** if the operation is successful; returns **false** otherwise.| 1430 1431### OH_CommonEvent_GetCodeFromSubscriber() 1432 1433``` 1434int32_t OH_CommonEvent_GetCodeFromSubscriber(const CommonEvent_Subscriber* subscriber) 1435``` 1436 1437**Description** 1438 1439Obtains the result code (number type) of an ordered common event. 1440 1441**Since**: 18 1442 1443 1444**Parameters** 1445 1446| Name| Description| 1447| -- | -- | 1448| const [CommonEvent_Subscriber](#variables)* subscriber| Pointer to the common event subscriber.| 1449 1450**Returns** 1451 1452| Type| Description| 1453| -- | -- | 1454| int32_t | Returns the result code obtained if the operation is successful; returns **0** otherwise.| 1455 1456### OH_CommonEvent_SetCodeToSubscriber() 1457 1458``` 1459bool OH_CommonEvent_SetCodeToSubscriber(CommonEvent_Subscriber* subscriber, int32_t code) 1460``` 1461 1462**Description** 1463 1464Sets the result code (number type) of an ordered common event. 1465 1466**Since**: 18 1467 1468 1469**Parameters** 1470 1471| Name| Description| 1472| -- | -- | 1473| [CommonEvent_Subscriber](#variables)* subscriber| Pointer to the common event subscriber.| 1474| int32_t code | Result code to set.| 1475 1476**Returns** 1477 1478| Type| Description| 1479| -- | -- | 1480| bool | Returns **true** if the operation is successful; returns **false** otherwise.| 1481 1482### OH_CommonEvent_GetDataFromSubscriber() 1483 1484``` 1485const char* OH_CommonEvent_GetDataFromSubscriber(const CommonEvent_Subscriber* subscriber) 1486``` 1487 1488**Description** 1489 1490Obtains the result data (string type) of an ordered common event. 1491 1492**Since**: 18 1493 1494 1495**Parameters** 1496 1497| Name| Description| 1498| -- | -- | 1499| const [CommonEvent_Subscriber](#variables)* subscriber| Pointer to the common event subscriber.| 1500 1501**Returns** 1502 1503| Type| Description| 1504| -- | -- | 1505| const char* | Returns the result data obtained if the operation is successful; returns **null** otherwise.| 1506 1507### OH_CommonEvent_SetDataToSubscriber() 1508 1509``` 1510bool OH_CommonEvent_SetDataToSubscriber(CommonEvent_Subscriber* subscriber, const char* data, size_t length) 1511``` 1512 1513**Description** 1514 1515Sets the result data (string type) of an ordered common event. 1516 1517**Since**: 18 1518 1519 1520**Parameters** 1521 1522| Name| Description| 1523| -- | -- | 1524| [CommonEvent_Subscriber](#variables)* subscriber| Pointer to the common event subscriber.| 1525| const char* data | Pointer to the result data to set.| 1526| size_t length | Data length.| 1527 1528**Returns** 1529 1530| Type| Description| 1531| -- | -- | 1532| bool | Returns **true** if the operation is successful; returns **false** otherwise.| 1533