1 /*
2  * Copyright (c) 2023-2024 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 #ifndef HIAPPEVENT_INTERFACES_NATIVE_INNER_API_INCLUDE_BASE_TYPE_H
16 #define HIAPPEVENT_INTERFACES_NATIVE_INNER_API_INCLUDE_BASE_TYPE_H
17 
18 #include <string>
19 #include <unordered_set>
20 #include <vector>
21 
22 namespace OHOS {
23 namespace HiviewDFX {
24 class AppEventPack;
25 namespace HiAppEvent {
26 struct UserId {
27     std::string name;
28     std::string value;
29 };
30 
31 struct UserProperty {
32     std::string name;
33     std::string value;
34 };
35 
36 struct TriggerCondition {
37     /* Triggered by the number of events */
38     int row = 0;
39 
40     /* Triggered by the size of events. Note: Only watcher.onTrigger is supported */
41     int size = 0;
42 
43     /* Triggered periodically */
44     int timeout = 0;
45 
46     /* Triggered by application startup */
47     bool onStartup = false;
48 
49     /* Triggered by switching to the background */
50     bool onBackground = false;
51 
52     std::string ToString() const;
53 };
54 
55 struct EventConfig {
56     /* Specifies the event domain that can be reported */
57     std::string domain;
58 
59     /* Specifies the event name that can be reported */
60     std::string name;
61 
62     /* Specifies whether the event is a real-time report event */
63     bool isRealTime = false;
64 
65     bool IsValidEvent(std::shared_ptr<AppEventPack> event) const;
66 
67     bool IsRealTimeEvent(std::shared_ptr<AppEventPack> event) const;
68 
69     std::string ToString() const;
70 };
71 
72 struct ReportConfig {
73     /* The report name */
74     std::string name;
75 
76     /* Enable the developer to debug */
77     bool debugMode = false;
78 
79     /* The server location information */
80     std::string routeInfo;
81 
82     /* The application ID */
83     std::string appId;
84 
85     /* The condition for triggering reporting */
86     TriggerCondition triggerCond;
87 
88     /* The user id names that can be reported */
89     std::unordered_set<std::string> userIdNames;
90 
91     /* The user property names that can be reported */
92     std::unordered_set<std::string> userPropertyNames;
93 
94     /* Event configurations to report */
95     std::vector<EventConfig> eventConfigs;
96 
97     /* The report configId */
98     int configId = 0;
99 
100     /* Custom config data */
101     std::unordered_map<std::string, std::string> customConfigs;
102 
103     std::string ToString() const;
104 };
105 } // namespace HiAppEvent
106 } // namespace HiviewDFX
107 } // namespace OHOS
108 #endif // HIAPPEVENT_INTERFACES_NATIVE_INNER_API_INCLUDE_BASE_TYPE_H
109