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() 20 : file_(std::string(CONF_PATH) + "/config.json") 21 { 22 } 23 ~ConfigFactory()24ConfigFactory::~ConfigFactory() 25 { 26 } 27 GetInstance()28ConfigFactory &ConfigFactory::GetInstance() 29 { 30 static ConfigFactory factory; 31 if (!factory.isInited) { 32 factory.Initialize(); 33 } 34 return factory; 35 } 36 Initialize()37int32_t ConfigFactory::Initialize() 38 { 39 std::string jsonStr; 40 std::ifstream fin(file_); 41 while (fin.good()) { 42 std::string line; 43 std::getline(fin, line); 44 jsonStr += line; 45 } 46 config_.Unmarshall(jsonStr); 47 isInited = true; 48 return 0; 49 } 50 GetComponentConfig()51std::vector<ComponentConfig> *ConfigFactory::GetComponentConfig() 52 { 53 return config_.components; 54 } 55 GetNetworkConfig()56NetworkConfig *ConfigFactory::GetNetworkConfig() 57 { 58 return config_.networks; 59 } 60 GetCheckerConfig()61CheckerConfig *ConfigFactory::GetCheckerConfig() 62 { 63 return config_.bundleChecker; 64 } 65 GetGlobalConfig()66GlobalConfig *ConfigFactory::GetGlobalConfig() 67 { 68 return &config_; 69 } 70 GetDirectoryConfig()71DirectoryConfig *ConfigFactory::GetDirectoryConfig() 72 { 73 return config_.directory; 74 } 75 GetBackupConfig()76BackupConfig *ConfigFactory::GetBackupConfig() 77 { 78 return config_.backup; 79 } 80 GetCloudConfig()81CloudConfig *ConfigFactory::GetCloudConfig() 82 { 83 return config_.cloud; 84 } 85 GetAppIdMappingConfig()86std::vector<AppIdMappingConfig> *ConfigFactory::GetAppIdMappingConfig() 87 { 88 return config_.appIdMapping; 89 } 90 } // namespace DistributedData 91 } // namespace OHOS 92