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 RUNTIME_CONFIG_H 17 #define RUNTIME_CONFIG_H 18 19 #include <memory> 20 #include <mutex> 21 22 #include "auto_launch_export.h" 23 #include "db_info_handle.h" 24 #include "cloud/icloud_data_translate.h" 25 #include "iprocess_communicator.h" 26 #include "iprocess_system_api_adapter.h" 27 #include "ithread_pool.h" 28 #include "store_types.h" 29 namespace DistributedDB { 30 enum class DBType { 31 DB_KV, 32 DB_RELATION, 33 }; 34 35 class RuntimeConfig final { 36 public: 37 DB_API RuntimeConfig() = default; 38 DB_API ~RuntimeConfig() = default; 39 40 DB_API static DBStatus SetProcessLabel(const std::string &appId, const std::string &userId); 41 42 DB_API static DBStatus SetProcessCommunicator(const std::shared_ptr<IProcessCommunicator> &inCommunicator); 43 44 DB_API static DBStatus SetPermissionCheckCallback(const PermissionCheckCallbackV2 &callback); 45 46 DB_API static DBStatus SetPermissionCheckCallback(const PermissionCheckCallbackV3 &callback); 47 48 DB_API static DBStatus SetProcessSystemAPIAdapter(const std::shared_ptr<IProcessSystemApiAdapter> &adapter); 49 50 DB_API static void Dump(int fd, const std::vector<std::u16string> &args); 51 52 DB_API static DBStatus SetSyncActivationCheckCallback(const SyncActivationCheckCallback &callback); 53 54 DB_API static DBStatus NotifyUserChanged(); 55 56 DB_API static DBStatus SetSyncActivationCheckCallback(const SyncActivationCheckCallbackV2 &callback); 57 58 DB_API static DBStatus SetPermissionConditionCallback(const PermissionConditionCallback &callback); 59 60 DB_API static bool IsProcessSystemApiAdapterValid(); 61 62 DB_API static void SetDBInfoHandle(const std::shared_ptr<DBInfoHandle> &handle); 63 64 DB_API static void NotifyDBInfos(const DeviceInfos &devInfos, const std::vector<DBInfo> &dbInfos); 65 66 DB_API static void SetTranslateToDeviceIdCallback(const TranslateToDeviceIdCallback &callback); 67 68 DB_API static void SetAutoLaunchRequestCallback(const AutoLaunchRequestCallback &callback, DBType type); 69 70 DB_API static std::string GetStoreIdentifier(const std::string &userId, const std::string &appId, 71 const std::string &storeId, bool syncDualTupleMode = false); 72 73 DB_API static void ReleaseAutoLaunch(const std::string &userId, const std::string &appId, 74 const std::string &storeId, DBType type); 75 76 DB_API static void SetThreadPool(const std::shared_ptr<IThreadPool> &threadPool); 77 78 DB_API static void SetCloudTranslate(const std::shared_ptr<ICloudDataTranslate> &dataTranslate); 79 private: 80 static std::mutex communicatorMutex_; 81 static std::mutex multiUserMutex_; 82 static std::shared_ptr<IProcessCommunicator> processCommunicator_; 83 }; 84 } // namespace DistributedDB 85 86 #endif // RUNTIME_CONFIG_H