1 /*
2  * Copyright (c) 2021 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 DISTRIBUTEDDATAMGR_DFX_TYPES_H
17 #define DISTRIBUTEDDATAMGR_DFX_TYPES_H
18 
19 #include <string>
20 #include <memory>
21 #include "db_meta_callback_delegate.h"
22 
23 namespace OHOS {
24 namespace DistributedDataDfx {
25 struct ModuleName {
26     static const inline std::string DEVICE = "DEVICE";
27     static const inline std::string USER = "USER";
28 };
29 
30 enum class Fault {
31     // Service Fault
32     SF_SERVICE_PUBLISH = 0,
33     SF_GET_SERVICE = 1,
34     SF_CREATE_DIR = 2,
35     SF_DATABASE_CONFIG = 3,
36     SF_PROCESS_LABEL = 4,
37     SF_INIT_DELEGATE = 5,
38 
39     // Runtime Fault
40     RF_OPEN_DB = 20,
41     RF_CLOSE_DB = 21,
42     RF_DELETE_DB = 22,
43     RF_DATA_SUBSCRIBE = 23,
44     RF_DATA_UNSUBSCRIBE = 24,
45     RF_CREATE_SNAPSHOT = 25,
46     RF_RELEASE_SNAPSHOT = 26,
47     RF_KEY_STORE_DAMAGE = 27,
48     RF_KEY_STORE_LOST = 28,
49     RF_DB_ROM = 29,
50     RF_GET_DB = 30,
51     RF_SUBCRIBE =  31,
52     RF_UNSUBCRIBE =  32,
53     RF_REPORT_THERAD_ERROR = 33,
54 
55     // Communication Fault
56     CF_CREATE_SESSION = 40,
57     CF_CREATE_PIPE = 41,
58     CF_SEND_PIPE_BROKEN = 42,
59     CF_REV_PIPE_BROKEN = 43,
60     CF_SERVICE_DIED = 44,
61     CF_CREATE_ZDN = 45,
62     CF_QUERY_ZDN = 46,
63 
64     // Database Fault
65     DF_DB_DAMAGE = 60,
66     DF_DB_REKEY_FAILED = 61,
67     DF_DB_CORRUPTED = 62,
68 };
69 
70 enum class FaultType {
71     SERVICE_FAULT = 0,
72     RUNTIME_FAULT = 1,
73     DATABASE_FAULT = 2,
74     COMM_FAULT = 3,
75 };
76 
77 enum class BehaviourType {
78     DATABASE_BACKUP = 0,
79     DATABASE_RECOVERY = 1,
80 };
81 
82 enum class SecurityInfo {
83     PERMISSIONS_APPID_FAILE = 0,
84     PERMISSIONS_DEVICEID_FAILE = 1,
85     PERMISSIONS_TOKENID_FAILE = 2,
86     SENSITIVE_LEVEL_FAILE = 3,
87 };
88 
89 struct FaultMsg {
90     FaultType faultType;
91     std::string moduleName;
92     std::string interfaceName;
93     Fault errorType;
94 };
95 
96 struct DBFaultMsg {
97     std::string appId;
98     std::string storeId;
99     std::string moduleName;
100     Fault errorType;
101 };
102 
103 struct CommFaultMsg {
104     std::string userId;
105     std::string appId;
106     std::string storeId;
107     std::vector<std::string> deviceId;
108     std::vector<int32_t> errorCode;
109 };
110 
111 struct SecurityPermissionsMsg {
112     std::string userId;
113     std::string appId;
114     std::string storeId;
115     std::string deviceId;
116     SecurityInfo securityInfo;
117 };
118 
119 struct SecuritySensitiveLevelMsg {
120     std::string deviceId;
121     int deviceSensitiveLevel;
122     int optionSensitiveLevel;
123     SecurityInfo securityInfo;
124 };
125 
126 struct BehaviourMsg {
127     std::string userId;
128     std::string appId;
129     std::string storeId;
130     BehaviourType behaviourType;
131     std::string extensionInfo;
132 };
133 
134 struct UdmfBehaviourMsg {
135     std::string appId;
136     std::string channel;
137     int64_t dataSize;
138     std::string dataType;
139     std::string operation;
140     std::string result;
141 };
142 
143 struct VisitStat {
144     std::string appId;
145     std::string interfaceName;
GetKeyVisitStat146     KVSTORE_API std::string GetKey() const
147     {
148         return appId + interfaceName;
149     }
150 };
151 
152 struct TrafficStat {
153     std::string appId;
154     std::string deviceId;
155     int sendSize;
156     int receivedSize;
GetKeyTrafficStat157     KVSTORE_API std::string GetKey() const
158     {
159         return appId + deviceId;
160     }
161 };
162 
163 struct DbStat {
164     std::string userId;
165     std::string appId;
166     std::string storeId;
167     int dbSize;
168     std::shared_ptr<DistributedKv::DbMetaCallbackDelegate> delegate;
169 
GetKeyDbStat170     KVSTORE_API std::string GetKey() const
171     {
172         return userId + appId + storeId;
173     }
174 };
175 
176 struct DbPerformanceStat {
177     std::string appId;
178     std::string storeId;
179     uint64_t currentTime;
180     uint64_t completeTime;
181     int size;
182     std::string srcDevId;
183     std::string dstDevId;
184 };
185 
186 struct ApiPerformanceStat {
187     std::string interfaceName;
188     uint64_t costTime;
189     uint64_t averageTime;
190     uint64_t worstTime;
GetKeyApiPerformanceStat191     KVSTORE_API std::string GetKey() const
192     {
193         return interfaceName;
194     }
195 };
196 
197 enum class ReportStatus {
198     SUCCESS = 0,
199     ERROR = 1,
200 };
201 }  // namespace DistributedDataDfx
202 }  // namespace OHOS
203 #endif // DISTRIBUTEDDATAMGR_DFX_TYPES_H
204