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 #include "config_factory.h" 16 #include <fstream> 17 namespace OHOS { 18 namespace DistributedData { ConfigFactory()19ConfigFactory::ConfigFactory() : file_(std::string(CONF_PATH) + "/config.json") 20 { 21 } 22 ~ConfigFactory()23ConfigFactory::~ConfigFactory() 24 { 25 } 26 GetInstance()27ConfigFactory &ConfigFactory::GetInstance() 28 { 29 static ConfigFactory factory; 30 if (!factory.isInited) { 31 factory.Initialize(); 32 } 33 return factory; 34 } 35 Initialize()36int32_t ConfigFactory::Initialize() 37 { 38 std::string jsonStr; 39 std::ifstream fin(file_); 40 while (fin.good()) { 41 std::string line; 42 std::getline(fin, line); 43 jsonStr += line; 44 } 45 config_.Unmarshall(jsonStr); 46 isInited = true; 47 return 0; 48 } 49 GetComponentConfig()50std::vector<ComponentConfig> *ConfigFactory::GetComponentConfig() 51 { 52 return config_.components; 53 } 54 GetNetworkConfig()55NetworkConfig *ConfigFactory::GetNetworkConfig() 56 { 57 return config_.networks; 58 } 59 GetCheckerConfig()60CheckerConfig *ConfigFactory::GetCheckerConfig() 61 { 62 return config_.bundleChecker; 63 } 64 GetGlobalConfig()65GlobalConfig *ConfigFactory::GetGlobalConfig() 66 { 67 return &config_; 68 } 69 GetDirectoryConfig()70DirectoryConfig *ConfigFactory::GetDirectoryConfig() 71 { 72 return config_.directory; 73 } 74 GetBackupConfig()75BackupConfig *ConfigFactory::GetBackupConfig() 76 { 77 return config_.backup; 78 } 79 GetCloudConfig()80CloudConfig *ConfigFactory::GetCloudConfig() 81 { 82 return config_.cloud; 83 } 84 GetAppIdMappingConfig()85std::vector<AppIdMappingConfig> *ConfigFactory::GetAppIdMappingConfig() 86 { 87 return config_.appIdMapping; 88 } 89 GetThreadConfig()90ThreadConfig *ConfigFactory::GetThreadConfig() 91 { 92 return config_.thread; 93 } 94 GetDataShareConfig()95DataShareConfig *ConfigFactory::GetDataShareConfig() 96 { 97 return config_.dataShare; 98 } 99 GetDeviceSyncAppWhiteListConfig()100DeviceSyncAppWhiteListConfig *ConfigFactory::GetDeviceSyncAppWhiteListConfig() 101 { 102 return config_.deviceSyncAppWhiteList; 103 } 104 GetSyncAppsConfig()105AppAccessCheckConfig *ConfigFactory::GetSyncAppsConfig() 106 { 107 return config_.syncAppList; 108 } 109 } // namespace DistributedData 110 } // namespace OHOS