1 /* 2 * Copyright (c) 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 OHOS_DISTRIBUTED_DATA_NATIVE_GDB_DB_STORE_MANAGER_H 16 #define OHOS_DISTRIBUTED_DATA_NATIVE_GDB_DB_STORE_MANAGER_H 17 #include <map> 18 #include <mutex> 19 20 #include "db_store_impl.h" 21 22 namespace OHOS::DistributedDataAip { 23 class StoreManager { 24 public: 25 static StoreManager &GetInstance(); 26 ~StoreManager(); 27 std::shared_ptr<DBStore> GetDBStore(const StoreConfig &config, int &errCode); 28 void Clear(); 29 bool Delete(const std::string &path); 30 31 private: 32 StoreManager(); 33 bool DeleteFile(const std::string &path); 34 int SetSecurityLabel(const StoreConfig &config); 35 std::string GetSecurityLevelValue(SecurityLevel securityLevel); 36 std::string GetFileSecurityLevel(const std::string &filePath); 37 bool IsValidName(const std::string& name); 38 bool IsValidSecurityLevel(const int32_t securityLevel); 39 std::mutex mutex_; 40 std::string bundleName_; 41 std::map<std::string, std::weak_ptr<DBStoreImpl>> storeCache_; 42 static constexpr const char *GRD_POST_FIXES[] = { 43 "", 44 ".redo", 45 ".undo", 46 ".ctrl", 47 ".ctrl.dwr", 48 ".safe", 49 ".map", 50 ".corruptedflg", 51 }; 52 }; 53 } // namespace OHOS::DistributedDataAip 54 #endif