1e41f4b71Sopenharmony_ci# hiappevent.h
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ci## Overview
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ciDefines the application event logging functions of the HiAppEvent module.
7e41f4b71Sopenharmony_ci
8e41f4b71Sopenharmony_ciBefore performing application event logging, you must construct a parameter list object to store the input event parameters and specify the event domain, event name, and event type.
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ciEvent domain: domain associated with the application event.
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ciEvent name: name of the application event.
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ciEvent type: fault, statistics, security, or behavior.
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ciParameter list: a linked list used to store event parameters. Each parameter consists of a parameter name and a parameter value.
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ciExample:
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci1. Import the header file.
21e41f4b71Sopenharmony_ci   ```
22e41f4b71Sopenharmony_ci   #include "hiappevent/hiappevent.h"
23e41f4b71Sopenharmony_ci   ```
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci2. Create a parameter list pointer.
26e41f4b71Sopenharmony_ci   ```
27e41f4b71Sopenharmony_ci   ParamList list = OH_HiAppEvent_CreateParamList();
28e41f4b71Sopenharmony_ci   ```
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci3. Add parameters to the parameter list.
31e41f4b71Sopenharmony_ci   ```
32e41f4b71Sopenharmony_ci   bool boolean = true;
33e41f4b71Sopenharmony_ci   OH_HiAppEvent_AddBoolParam(list, "bool_key", boolean);
34e41f4b71Sopenharmony_ci   int32_t nums[] = {1, 2, 3};
35e41f4b71Sopenharmony_ci   OH_HiAppEvent_AddInt32ArrayParam(list, "int32_arr_key", nums, sizeof(nums) / sizeof(nums[0]));
36e41f4b71Sopenharmony_ci   ```
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci4. Perform event logging.
39e41f4b71Sopenharmony_ci   ```
40e41f4b71Sopenharmony_ci   int res = OH_HiAppEvent_Write("test_domain", "test_event", BEHAVIOR, list);
41e41f4b71Sopenharmony_ci   ```
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci5. Destroy the parameter list pointer and release its allocated memory.
44e41f4b71Sopenharmony_ci   ```
45e41f4b71Sopenharmony_ci   OH_HiAppEvent_DestroyParamList(list);
46e41f4b71Sopenharmony_ci   ```
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ci**Since**: 8
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ci**Related module**: [HiAppEvent](_hi_app_event.md)
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci## Summary
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ci### Structs
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci| Name| Description| 
59e41f4b71Sopenharmony_ci| -------- | -------- |
60e41f4b71Sopenharmony_ci| struct  [HiAppEvent_AppEventInfo](_hi_app_event___app_event_info.md) | Defines information about a single event, including the event domain, event name, event type, and custom parameter list in JSON string format. | 
61e41f4b71Sopenharmony_ci| struct  [HiAppEvent_AppEventGroup](_hi_app_event___app_event_group.md) | Event array with the same event name. | 
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci### Types
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci| Name| Description| 
67e41f4b71Sopenharmony_ci| -------- | -------- |
68e41f4b71Sopenharmony_ci| typedef struct [HiAppEvent_AppEventInfo](_hi_app_event___app_event_info.md) [HiAppEvent_AppEventInfo](_hi_app_event.md#hiappevent_appeventinfo) | Defines information about a single event, including the event domain, event name, event type, and custom parameter list in JSON string format. | 
69e41f4b71Sopenharmony_ci| typedef struct [HiAppEvent_AppEventGroup](_hi_app_event___app_event_group.md) [HiAppEvent_AppEventGroup](_hi_app_event.md#hiappevent_appeventgroup) | Event array with the same event name. | 
70e41f4b71Sopenharmony_ci| typedef struct ParamListNode \* [ParamList](_hi_app_event.md#paramlist) | Event parameter list node. | 
71e41f4b71Sopenharmony_ci| typedef struct [HiAppEvent_Watcher](_hi_app_event.md#hiappevent_watcher) [HiAppEvent_Watcher](_hi_app_event.md#hiappevent_watcher) | Defines the watcher for application events. | 
72e41f4b71Sopenharmony_ci| typedef void(\* [OH_HiAppEvent_OnReceive](_hi_app_event.md#oh_hiappevent_onreceive)) (const char \*domain, const struct [HiAppEvent_AppEventGroup](_hi_app_event___app_event_group.md) \*appEventGroups, uint32_t groupLen) | Callback invoked to pass event content to the caller. | 
73e41f4b71Sopenharmony_ci| typedef void(\* [OH_HiAppEvent_OnTrigger](_hi_app_event.md#oh_hiappevent_ontrigger)) (int row, int size) | Callback invoked if the event received by the watcher meets the conditions specified by OH_HiAppEvent_SetTriggerCondition. Specifically, if the OH_HiAppEvent_OnReceive callback is not set in the watcher, the event received by the watcher will be saved. If the saved event meets the conditions specified by OH_HiAppEvent_SetTriggerCondition, the callback is invoked. After the callback is complete, if a newly saved event meets the specified condition, the callback is invoked again. | 
74e41f4b71Sopenharmony_ci| typedef void(\* [OH_HiAppEvent_OnTake](_hi_app_event.md#oh_hiappevent_ontake)) (const char \*const \*events, uint32_t eventLen) | Callback invoked to pass the events received by the watcher to the caller when OH_HiAppEvent_TakeWatcherData is used to obtain the events. | 
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci### Enums
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci| Name| Description| 
80e41f4b71Sopenharmony_ci| -------- | -------- |
81e41f4b71Sopenharmony_ci| [EventType](_hi_app_event.md#eventtype) { FAULT = 1, STATISTIC = 2, SECURITY = 3, BEHAVIOR = 4 } | Event type.| 
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci### Callback
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci| Name| Description| 
87e41f4b71Sopenharmony_ci| -------- | -------- |
88e41f4b71Sopenharmony_ci| [ParamList](_hi_app_event.md#paramlist) [OH_HiAppEvent_CreateParamList](_hi_app_event.md#oh_hiappevent_createparamlist) (void) | Creates a pointer to a parameter list object. | 
89e41f4b71Sopenharmony_ci| void [OH_HiAppEvent_DestroyParamList](_hi_app_event.md#oh_hiappevent_destroyparamlist) ([ParamList](_hi_app_event.md#paramlist) list) | Destroys a pointer to a parameter list object and releases its allocated memory. | 
90e41f4b71Sopenharmony_ci| [ParamList](_hi_app_event.md#paramlist) [OH_HiAppEvent_AddBoolParam](_hi_app_event.md#oh_hiappevent_addboolparam) ([ParamList](_hi_app_event.md#paramlist) list, const char \*name, bool boolean) | Adds an event parameter of the Boolean type to the parameter list. | 
91e41f4b71Sopenharmony_ci| [ParamList](_hi_app_event.md#paramlist) [OH_HiAppEvent_AddBoolArrayParam](_hi_app_event.md#oh_hiappevent_addboolarrayparam) ([ParamList](_hi_app_event.md#paramlist) list, const char \*name, const bool \*booleans, int arrSize) | Adds an event parameter of the Boolean array type to the parameter list. | 
92e41f4b71Sopenharmony_ci| [ParamList](_hi_app_event.md#paramlist) [OH_HiAppEvent_AddInt8Param](_hi_app_event.md#oh_hiappevent_addint8param) ([ParamList](_hi_app_event.md#paramlist) list, const char \*name, int8_t num) | Adds an event parameter of the int8_t type to the parameter list. | 
93e41f4b71Sopenharmony_ci| [ParamList](_hi_app_event.md#paramlist) [OH_HiAppEvent_AddInt8ArrayParam](_hi_app_event.md#oh_hiappevent_addint8arrayparam) ([ParamList](_hi_app_event.md#paramlist) list, const char \*name, const int8_t \*nums, int arrSize) | Adds an event parameter of the int8_t array type to the parameter list. | 
94e41f4b71Sopenharmony_ci| [ParamList](_hi_app_event.md#paramlist) [OH_HiAppEvent_AddInt16Param](_hi_app_event.md#oh_hiappevent_addint16param) ([ParamList](_hi_app_event.md#paramlist) list, const char \*name, int16_t num) | Adds an event parameter of the int16_t type to the parameter list. | 
95e41f4b71Sopenharmony_ci| [ParamList](_hi_app_event.md#paramlist) [OH_HiAppEvent_AddInt16ArrayParam](_hi_app_event.md#oh_hiappevent_addint16arrayparam) ([ParamList](_hi_app_event.md#paramlist) list, const char \*name, const int16_t \*nums, int arrSize) | Adds an event parameter of the int16_t array type to the parameter list. | 
96e41f4b71Sopenharmony_ci| [ParamList](_hi_app_event.md#paramlist) [OH_HiAppEvent_AddInt32Param](_hi_app_event.md#oh_hiappevent_addint32param) ([ParamList](_hi_app_event.md#paramlist) list, const char \*name, int32_t num) | Adds an event parameter of the int32_t type to the parameter list. | 
97e41f4b71Sopenharmony_ci| [ParamList](_hi_app_event.md#paramlist) [OH_HiAppEvent_AddInt32ArrayParam](_hi_app_event.md#oh_hiappevent_addint32arrayparam) ([ParamList](_hi_app_event.md#paramlist) list, const char \*name, const int32_t \*nums, int arrSize) | Adds an event parameter of the int32_t array type to the parameter list. | 
98e41f4b71Sopenharmony_ci| [ParamList](_hi_app_event.md#paramlist) [OH_HiAppEvent_AddInt64Param](_hi_app_event.md#oh_hiappevent_addint64param) ([ParamList](_hi_app_event.md#paramlist) list, const char \*name, int64_t num) | Adds an event parameter of the int64_t type to the parameter list. | 
99e41f4b71Sopenharmony_ci| [ParamList](_hi_app_event.md#paramlist) [OH_HiAppEvent_AddInt64ArrayParam](_hi_app_event.md#oh_hiappevent_addint64arrayparam) ([ParamList](_hi_app_event.md#paramlist) list, const char \*name, const int64_t \*nums, int arrSize) | Adds an event parameter of the int64_t array type to the parameter list. | 
100e41f4b71Sopenharmony_ci| [ParamList](_hi_app_event.md#paramlist) [OH_HiAppEvent_AddFloatParam](_hi_app_event.md#oh_hiappevent_addfloatparam) ([ParamList](_hi_app_event.md#paramlist) list, const char \*name, float num) | Adds an event parameter of the float type to the parameter list. | 
101e41f4b71Sopenharmony_ci| [ParamList](_hi_app_event.md#paramlist) [OH_HiAppEvent_AddFloatArrayParam](_hi_app_event.md#oh_hiappevent_addfloatarrayparam) ([ParamList](_hi_app_event.md#paramlist) list, const char \*name, const float \*nums, int arrSize) | Adds an event parameter of the float array type to the parameter list. | 
102e41f4b71Sopenharmony_ci| [ParamList](_hi_app_event.md#paramlist) [OH_HiAppEvent_AddDoubleParam](_hi_app_event.md#oh_hiappevent_adddoubleparam) ([ParamList](_hi_app_event.md#paramlist) list, const char \*name, double num) | Adds an event parameter of the Double type to the parameter list. | 
103e41f4b71Sopenharmony_ci| [ParamList](_hi_app_event.md#paramlist) [OH_HiAppEvent_AddDoubleArrayParam](_hi_app_event.md#oh_hiappevent_adddoublearrayparam) ([ParamList](_hi_app_event.md#paramlist) list, const char \*name, const double \*nums, int arrSize) | Adds an event parameter of the double array type to the parameter list. | 
104e41f4b71Sopenharmony_ci| [ParamList](_hi_app_event.md#paramlist) [OH_HiAppEvent_AddStringParam](_hi_app_event.md#oh_hiappevent_addstringparam) ([ParamList](_hi_app_event.md#paramlist) list, const char \*name, const char \*str) | Adds a parameter of the string type to the parameter list. | 
105e41f4b71Sopenharmony_ci| [ParamList](_hi_app_event.md#paramlist) [OH_HiAppEvent_AddStringArrayParam](_hi_app_event.md#oh_hiappevent_addstringarrayparam) ([ParamList](_hi_app_event.md#paramlist) list, const char \*name, const char \*const \*strs, int arrSize) | Adds a parameter of the string array type to the parameter list. | 
106e41f4b71Sopenharmony_ci| int [OH_HiAppEvent_Write](_hi_app_event.md#oh_hiappevent_write) (const char \*domain, const char \*name, enum [EventType](_hi_app_event.md#eventtype) type, const [ParamList](_hi_app_event.md#paramlist) list) | Logs application events whose parameters are of the list type. | 
107e41f4b71Sopenharmony_ci| bool [OH_HiAppEvent_Configure](_hi_app_event.md#oh_hiappevent_configure) (const char \*name, const char \*value) | Configures the application event logging function. | 
108e41f4b71Sopenharmony_ci| [HiAppEvent_Watcher](_hi_app_event.md#hiappevent_watcher) \* [OH_HiAppEvent_CreateWatcher](_hi_app_event.md#oh_hiappevent_createwatcher) (const char \*name) | Creates a watcher for application events. | 
109e41f4b71Sopenharmony_ci| void [OH_HiAppEvent_DestroyWatcher](_hi_app_event.md#oh_hiappevent_destroywatcher) ([HiAppEvent_Watcher](_hi_app_event.md#hiappevent_watcher) \*watcher) | Destroys a created watcher. | 
110e41f4b71Sopenharmony_ci| int [OH_HiAppEvent_SetTriggerCondition](_hi_app_event.md#oh_hiappevent_settriggercondition) ([HiAppEvent_Watcher](_hi_app_event.md#hiappevent_watcher) \*watcher, int row, int size, int timeOut) | Sets the conditions for triggering the **OH_HiAppEvent_OnTrigger** callback, including the number and size of newly received events and the timeout interval for triggering **onTrigger**. Ensure that at least one of the trigger conditions is set on the caller side. | 
111e41f4b71Sopenharmony_ci| int [OH_HiAppEvent_SetAppEventFilter](_hi_app_event.md#oh_hiappevent_setappeventfilter) ([HiAppEvent_Watcher](_hi_app_event.md#hiappevent_watcher) \*watcher, const char \*domain, uint8_t eventTypes, const char \*const \*names, int namesLen) | Sets the type of events to listen for. | 
112e41f4b71Sopenharmony_ci| int [OH_HiAppEvent_SetWatcherOnTrigger](_hi_app_event.md#oh_hiappevent_setwatcherontrigger) ([HiAppEvent_Watcher](_hi_app_event.md#hiappevent_watcher) \*watcher, [OH_HiAppEvent_OnTrigger](_hi_app_event.md#oh_hiappevent_ontrigger) onTrigger) | Sets the **onTrigger** callback. | 
113e41f4b71Sopenharmony_ci| int [OH_HiAppEvent_SetWatcherOnReceive](_hi_app_event.md#oh_hiappevent_setwatcheronreceive) ([HiAppEvent_Watcher](_hi_app_event.md#hiappevent_watcher) \*watcher, [OH_HiAppEvent_OnReceive](_hi_app_event.md#oh_hiappevent_onreceive) onReceive) | Sets the **onReceive** callback. When the listener detects the corresponding event, the onReceive callback is called. | 
114e41f4b71Sopenharmony_ci| int [OH_HiAppEvent_TakeWatcherData](_hi_app_event.md#oh_hiappevent_takewatcherdata) ([HiAppEvent_Watcher](_hi_app_event.md#hiappevent_watcher) \*watcher, uint32_t eventNum, [OH_HiAppEvent_OnTake](_hi_app_event.md#oh_hiappevent_ontake) onTake) | Obtains the event saved by the watcher. | 
115e41f4b71Sopenharmony_ci| int [OH_HiAppEvent_AddWatcher](_hi_app_event.md#oh_hiappevent_addwatcher) ([HiAppEvent_Watcher](_hi_app_event.md#hiappevent_watcher) \*watcher) | Adds a watcher. Once a watcher is added, it starts to listen for system messages. | 
116e41f4b71Sopenharmony_ci| int [OH_HiAppEvent_RemoveWatcher](_hi_app_event.md#oh_hiappevent_removewatcher) ([HiAppEvent_Watcher](_hi_app_event.md#hiappevent_watcher) \*watcher) | Removes a watcher. Once a watcher is removed, it stops listening for system messages. | 
117e41f4b71Sopenharmony_ci| void [OH_HiAppEvent_ClearData](_hi_app_event.md#oh_hiappevent_cleardata) (void) | Clears the events saved by all watchers. | 
118