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