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 <map> 20 #include <memory> 21 #include <string> 22 23 #include "db_meta_callback_delegate.h" 24 25 namespace OHOS { 26 namespace DistributedDataDfx { 27 struct ModuleName { 28 static const inline std::string DEVICE = "DEVICE"; 29 static const inline std::string USER = "USER"; 30 static const inline std::string RDB_STORE = "RDB_STORE"; 31 static const inline std::string KV_STORE = "KV_STORE"; 32 static const inline std::string CLOUD_SERVER = "CLOUD_SERVER"; 33 static const inline std::string CLOUD_SYNC_CALLBACK = "CLOUD_SYNC_CALLBACK"; 34 }; 35 36 enum class Fault { 37 // Service Fault 38 SF_SERVICE_PUBLISH = 0, 39 SF_GET_SERVICE = 1, 40 SF_CREATE_DIR = 2, 41 SF_DATABASE_CONFIG = 3, 42 SF_PROCESS_LABEL = 4, 43 SF_INIT_DELEGATE = 5, 44 45 // Runtime Fault 46 RF_OPEN_DB = 20, 47 RF_CLOSE_DB = 21, 48 RF_DELETE_DB = 22, 49 RF_DATA_SUBSCRIBE = 23, 50 RF_DATA_UNSUBSCRIBE = 24, 51 RF_CREATE_SNAPSHOT = 25, 52 RF_RELEASE_SNAPSHOT = 26, 53 RF_KEY_STORE_DAMAGE = 27, 54 RF_KEY_STORE_LOST = 28, 55 RF_DB_ROM = 29, 56 RF_GET_DB = 30, 57 RF_SUBCRIBE = 31, 58 RF_UNSUBCRIBE = 32, 59 RF_REPORT_THERAD_ERROR = 33, 60 61 // Communication Fault 62 CF_CREATE_SESSION = 40, 63 CF_CREATE_PIPE = 41, 64 CF_SEND_PIPE_BROKEN = 42, 65 CF_REV_PIPE_BROKEN = 43, 66 CF_SERVICE_DIED = 44, 67 CF_CREATE_ZDN = 45, 68 CF_QUERY_ZDN = 46, 69 70 // Database Fault 71 DF_DB_DAMAGE = 60, 72 DF_DB_REKEY_FAILED = 61, 73 DF_DB_CORRUPTED = 62, 74 75 // Cloud Sync Fault 76 CSF_CLOUD_INFO = 70, 77 CSF_SUBSCRIBE = 71, 78 CSF_UNSUBSCRIBE = 72, 79 CSF_APP_SCHEMA = 73, 80 CSF_CONNECT_CLOUD_ASSET_LOADER = 74, 81 CSF_CONNECT_CLOUD_DB = 75, 82 CSF_BATCH_INSERT = 76, 83 CSF_BATCH_UPDATE = 77, 84 CSF_BATCH_DELETE = 78, 85 CSF_BATCH_QUERY = 79, 86 CSF_LOCK = 80, 87 CSF_SHARE = 81, 88 CSF_DOWNLOAD_ASSETS = 82, 89 CSF_GS_CREATE_DISTRIBUTED_TABLE = 83, 90 CSF_GS_CLOUD_SYNC = 84, 91 }; 92 93 enum class FaultType { 94 SERVICE_FAULT = 0, 95 RUNTIME_FAULT = 1, 96 DATABASE_FAULT = 2, 97 COMM_FAULT = 3, 98 }; 99 100 enum class BehaviourType { 101 DATABASE_BACKUP = 0, 102 DATABASE_RECOVERY = 1, 103 }; 104 105 enum class SecurityInfo { 106 PERMISSIONS_APPID_FAILE = 0, 107 PERMISSIONS_DEVICEID_FAILE = 1, 108 PERMISSIONS_TOKENID_FAILE = 2, 109 SENSITIVE_LEVEL_FAILE = 3, 110 }; 111 112 struct FaultMsg { 113 FaultType faultType; 114 std::string moduleName; 115 std::string interfaceName; 116 Fault errorType; 117 }; 118 119 struct DBFaultMsg { 120 std::string appId; 121 std::string storeId; 122 std::string moduleName; 123 Fault errorType; 124 }; 125 126 struct CommFaultMsg { 127 std::string userId; 128 std::string appId; 129 std::string storeId; 130 std::vector<std::string> deviceId; 131 std::vector<int32_t> errorCode; 132 }; 133 134 struct ArkDataFaultMsg { 135 std::string faultType; 136 std::string bundleName; 137 std::string moduleName; 138 std::string storeName; 139 std::string businessType; 140 int32_t errorType; 141 std::string appendixMsg; 142 }; 143 144 struct SecurityPermissionsMsg { 145 std::string userId; 146 std::string appId; 147 std::string storeId; 148 std::string deviceId; 149 SecurityInfo securityInfo; 150 }; 151 152 struct SecuritySensitiveLevelMsg { 153 std::string deviceId; 154 int deviceSensitiveLevel; 155 int optionSensitiveLevel; 156 SecurityInfo securityInfo; 157 }; 158 159 struct BehaviourMsg { 160 std::string userId; 161 std::string appId; 162 std::string storeId; 163 BehaviourType behaviourType; 164 std::string extensionInfo; 165 }; 166 167 struct UdmfBehaviourMsg { 168 std::string appId; 169 std::string channel; 170 int64_t dataSize; 171 std::string dataType; 172 std::string operation; 173 std::string result; 174 }; 175 176 struct VisitStat { 177 std::string appId; 178 std::string interfaceName; GetKeyVisitStat179 API_EXPORT std::string GetKey() const 180 { 181 return appId + interfaceName; 182 } 183 }; 184 185 struct TrafficStat { 186 std::string appId; 187 std::string deviceId; 188 int sendSize; 189 int receivedSize; GetKeyTrafficStat190 API_EXPORT std::string GetKey() const 191 { 192 return appId + deviceId; 193 } 194 }; 195 196 struct DbStat { 197 std::string userId; 198 std::string appId; 199 std::string storeId; 200 int dbSize; 201 std::shared_ptr<DistributedKv::DbMetaCallbackDelegate> delegate; 202 GetKeyDbStat203 API_EXPORT std::string GetKey() const 204 { 205 return userId + appId + storeId; 206 } 207 }; 208 209 struct DbPerformanceStat { 210 std::string appId; 211 std::string storeId; 212 uint64_t currentTime; 213 uint64_t completeTime; 214 int size; 215 std::string srcDevId; 216 std::string dstDevId; 217 }; 218 219 struct ApiPerformanceStat { 220 std::string interfaceName; 221 uint64_t costTime; 222 uint64_t averageTime; 223 uint64_t worstTime; GetKeyApiPerformanceStat224 API_EXPORT std::string GetKey() const 225 { 226 return interfaceName; 227 } 228 }; 229 230 enum class ReportStatus { 231 SUCCESS = 0, 232 ERROR = 1, 233 }; 234 } // namespace DistributedDataDfx 235 } // namespace OHOS 236 #endif // DISTRIBUTEDDATAMGR_DFX_TYPES_H 237