1 /*
2  * Copyright (c) 2023 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 HIVIEWDFX_HISYSEVENT_C_WRAPPER_H
17 #define HIVIEWDFX_HISYSEVENT_C_WRAPPER_H
18 
19 #include "hisysevent_c.h"
20 #include "hisysevent_manager_c.h"
21 #include "hisysevent_record_c.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #define MAX_EVENT_LIST_LEN 339
28 
29 #define STATUS_MEM_FREED 0
30 #define STATUS_MEM_NEED_RECYCLE 1
31 #define STATUS_NORMAL 2
32 
33 // rust ffi border redefinition adapts for struct HiSysEventParam.
34 struct HiSysEventParamWrapper {
35     char paramName[MAX_LENGTH_OF_PARAM_NAME];
36     int paramType;
37     HiSysEventParamValue paramValue;
38     unsigned int arraySize;
39 };
40 typedef struct HiSysEventParamWrapper HiSysEventParamWrapper;
41 
42 struct HiSysEventQueryRuleWrapper {
43     char domain[MAX_LENGTH_OF_EVENT_DOMAIN];
44     char eventList[MAX_EVENT_LIST_LEN];
45     unsigned int eventListSize;
46     char* condition;
47 };
48 typedef struct HiSysEventQueryRuleWrapper HiSysEventQueryRuleWrapper;
49 
50 typedef const void* OnRustCb;
51 typedef void (*OnEventWrapperCb) (OnRustCb, HiSysEventRecordC);
52 typedef void (*OnServiceDiedWrapperCb) (OnRustCb);
53 typedef void (*OnQueryWrapperCb)(OnRustCb, HiSysEventRecordC[], unsigned int);
54 typedef void (*OnCompleteWrapperCb)(OnRustCb, int, int);
55 
56 struct HiSysEventRustWatcherC {
57     OnRustCb onEventRustCb;
58     OnEventWrapperCb onEventWrapperCb;
59     OnRustCb onServiceDiedRustCb;
60     OnServiceDiedWrapperCb onServiceDiedWrapperCb;
61     int status;
62 };
63 typedef struct HiSysEventRustWatcherC HiSysEventRustWatcherC;
64 
65 struct HiSysEventRustQuerierC {
66     OnRustCb onQueryRustCb;
67     OnQueryWrapperCb onQueryWrapperCb;
68     OnRustCb onCompleteRustCb;
69     OnCompleteWrapperCb onCompleteWrapperCb;
70     int status;
71 };
72 typedef struct HiSysEventRustQuerierC HiSysEventRustQuerierC;
73 
74 // rust ffi border redefinition adapts for function HiSysEvent_Write.
75 int HiSysEventWriteWrapper(const char* func, unsigned long long line, const char* domain, const char* name,
76     int type, const HiSysEventParamWrapper params[], unsigned int size);
77 
78 // rust ffi border redefinition adapts for function OH_HiSysEvent_Add_Watcher.
79 int HiSysEventAddWatcherWrapper(HiSysEventRustWatcherC* watcher, const HiSysEventWatchRule rules[],
80     unsigned int ruleSize);
81 
82 // rust ffi border redefinition adapts for function OH_HiSysEvent_Remove_Watcher.
83 int HiSysEventRemoveWatcherWrapper(HiSysEventRustWatcherC* watcher);
84 
85 // rust ffi border redefinition adapts for function OH_HiSysEvent_Query.
86 int HiSysEventQueryWrapper(HiSysEventQueryArg* arg, const HiSysEventQueryRuleWrapper rules[],
87     unsigned int ruleSize, HiSysEventRustQuerierC* querier);
88 
89 // rust ffi border function
90 HiSysEventRecordC GetHiSysEventRecordByIndexWrapper(const HiSysEventRecordC records[], unsigned int total,
91     unsigned int index);
92 
93 // rust ffi border function
94 HiSysEventRustWatcherC* CreateRustEventWatcher(OnRustCb onEventRustCb, OnEventWrapperCb onEventWrapperCb,
95     OnRustCb onServiceDiedRustCb, OnServiceDiedWrapperCb onServiceDiedWrapperCb);
96 
97 // rust ffi border function
98 void RecycleRustEventWatcher(HiSysEventRustWatcherC* watcher);
99 
100 // rust ffi border function
101 HiSysEventRustQuerierC* CreateRustEventQuerier(OnRustCb onQueryRustCb, OnQueryWrapperCb onQueryWrapperCb,
102     OnRustCb onCompleteRustCb, OnCompleteWrapperCb onCompleteWrapperCb);
103 
104 // rust ffi border function
105 void RecycleRustEventQuerier(HiSysEventRustQuerierC* querier);
106 
107 #ifdef __cplusplus
108 }
109 #endif
110 
111 #endif //HIVIEWDFX_HISYSEVENT_C_WRAPPER_H