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 16 #ifndef COLLABORATION_EDIT_DB_STORE_MANAGER_H 17 #define COLLABORATION_EDIT_DB_STORE_MANAGER_H 18 19 #include <map> 20 #include <mutex> 21 22 #include "db_error.h" 23 #include "db_store.h" 24 #include "db_store_config.h" 25 #include "db_thread_pool.h" 26 #include "napi_cloud_db.h" 27 28 namespace OHOS::CollaborationEdit { 29 class DBStoreManager { 30 public: 31 static DBStoreManager &GetInstance(); 32 DBStoreManager(); 33 ~DBStoreManager(); 34 std::shared_ptr<DBStore> GetDBStore(const DBStoreConfig &config); 35 int DeleteDBStore(const DBStoreConfig &config); 36 int32_t SetCloudDb(std::shared_ptr<DBStore> dbStore, NapiCloudDb *napiCloudDb); 37 void InitThreadPool(); 38 39 static GRD_ThreadPoolT threadPool_; 40 private: 41 std::shared_ptr<DBStore> OpenDBStore(const DBStoreConfig &config); 42 int RemoveDir(const char *dir); 43 static void Schedule(void *func, void *param); 44 45 std::mutex mutex_; 46 std::map<std::string, std::shared_ptr<DBStore>> storeCache_; 47 48 std::mutex threadPoolMutex_; 49 static std::shared_ptr<ExecutorPool> executorPool_; 50 static std::shared_ptr<DBStoreMgrThreadPool> executors_; 51 }; 52 } // namespace OHOS::CollaborationEdit 53 #endif // COLLABORATION_EDIT_DB_STORE_MANAGER_H 54