1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef HISYSEVENT_INTERFACES_NATIVE_INNERKITS_HISYSEVENT_MANAGER_INCLUDE_HISYSEVENT_MANAGER_C_H 17 #define HISYSEVENT_INTERFACES_NATIVE_INNERKITS_HISYSEVENT_MANAGER_INCLUDE_HISYSEVENT_MANAGER_C_H 18 19 #include "hisysevent_record_c.h" 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 #define MAX_NUMBER_OF_EVENT_LIST 10 26 #define MAX_NUMBER_OF_WATCH_EVENT_LIST 20 27 28 /** 29 * @brief Define the argument of the query. 30 */ 31 struct HiSysEventQueryArg { 32 int64_t beginTime; 33 int64_t endTime; 34 int32_t maxEvents; 35 }; 36 typedef struct HiSysEventQueryArg HiSysEventQueryArg; 37 38 /** 39 * @brief Define the rule of the query. 40 */ 41 struct HiSysEventQueryRule { 42 char domain[MAX_LENGTH_OF_EVENT_DOMAIN]; 43 char eventList[MAX_NUMBER_OF_EVENT_LIST][MAX_LENGTH_OF_EVENT_NAME]; 44 size_t eventListSize; 45 char* condition; 46 }; 47 typedef struct HiSysEventQueryRule HiSysEventQueryRule; 48 49 /** 50 * @brief Define the callback of the query. 51 */ 52 struct HiSysEventQueryCallback { 53 void (*OnQuery)(HiSysEventRecordC records[], size_t size); 54 void (*OnComplete)(int32_t reason, int32_t total); 55 }; 56 typedef struct HiSysEventQueryCallback HiSysEventQueryCallback; 57 58 /** 59 * @brief Query event. 60 * @param arg arg of query. 61 * @param rules rules of query. 62 * @param ruleSize rules size of query. 63 * @param callback callback of query. 64 * @return 0 means success, others means failure. 65 */ 66 int OH_HiSysEvent_Query(const HiSysEventQueryArg* arg, HiSysEventQueryRule rules[], size_t ruleSize, 67 HiSysEventQueryCallback* callback); 68 69 /** 70 * @brief Define the rule of the watcher. 71 */ 72 struct HiSysEventWatchRule { 73 char domain[MAX_LENGTH_OF_EVENT_DOMAIN]; 74 char name[MAX_LENGTH_OF_EVENT_NAME]; 75 char tag[MAX_LENGTH_OF_EVENT_TAG]; 76 int ruleType; 77 int eventType; 78 }; 79 typedef struct HiSysEventWatchRule HiSysEventWatchRule; 80 81 struct HiSysEventWatcher { 82 void (*OnEvent) (HiSysEventRecordC record); 83 void (*OnServiceDied) (); 84 }; 85 typedef struct HiSysEventWatcher HiSysEventWatcher; 86 87 /** 88 * @brief Add a watcher on event writing. 89 * @param watcher event watcher. 90 * @param rules rules for watcher. 91 * @param ruleSize size of watch rules. 92 * @return 0 means success, others means failure. 93 */ 94 int OH_HiSysEvent_Add_Watcher(HiSysEventWatcher* watcher, HiSysEventWatchRule rules[], size_t ruleSize); 95 96 /** 97 * @brief Remove a watcher. 98 * @param watcher event watcher. 99 * @return 0 means success, others means failure. 100 */ 101 int OH_HiSysEvent_Remove_Watcher(HiSysEventWatcher* watcher); 102 103 #ifdef __cplusplus 104 } 105 #endif 106 #endif // HISYSEVENT_INTERFACES_NATIVE_INNERKITS_HISYSEVENT_MANAGER_INCLUDE_HISYSEVENT_MANAGER_C_H 107