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 VisitStat { 135 std::string appId; 136 std::string interfaceName; GetKeyVisitStat137 KVSTORE_API std::string GetKey() const 138 { 139 return appId + interfaceName; 140 } 141 }; 142 143 struct TrafficStat { 144 std::string appId; 145 std::string deviceId; 146 int sendSize; 147 int receivedSize; GetKeyTrafficStat148 KVSTORE_API std::string GetKey() const 149 { 150 return appId + deviceId; 151 } 152 }; 153 154 struct DbStat { 155 std::string userId; 156 std::string appId; 157 std::string storeId; 158 int dbSize; 159 std::shared_ptr<DistributedKv::DbMetaCallbackDelegate> delegate; 160 GetKeyDbStat161 KVSTORE_API std::string GetKey() const 162 { 163 return userId + appId + storeId; 164 } 165 }; 166 167 struct DbPerformanceStat { 168 std::string appId; 169 std::string storeId; 170 uint64_t currentTime; 171 uint64_t completeTime; 172 int size; 173 std::string srcDevId; 174 std::string dstDevId; 175 }; 176 177 struct ApiPerformanceStat { 178 std::string interfaceName; 179 uint64_t costTime; 180 uint64_t averageTime; 181 uint64_t worstTime; GetKeyApiPerformanceStat182 KVSTORE_API std::string GetKey() const 183 { 184 return interfaceName; 185 } 186 }; 187 188 enum class ReportStatus { 189 SUCCESS = 0, 190 ERROR = 1, 191 }; 192 } // namespace DistributedDataDfx 193 } // namespace OHOS 194 #endif // DISTRIBUTEDDATAMGR_DFX_TYPES_H 195