• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2022 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 #include "bootstrap.h"
17 
18 #include <dlfcn.h>
19 
20 #include "checker/checker_manager.h"
21 #include "config_factory.h"
22 #include "directory_manager.h"
23 namespace OHOS {
24 namespace DistributedData {
GetInstance()25 Bootstrap &Bootstrap::GetInstance()
26 {
27     static Bootstrap bootstrap;
28     return bootstrap;
29 }
30 
GetProcessLabel()31 std::string Bootstrap::GetProcessLabel()
32 {
33     auto *global = ConfigFactory::GetInstance().GetGlobalConfig();
34     if (global == nullptr || global->processLabel.empty()) {
35         return DEFAULT_LABEL;
36     }
37     return global->processLabel;
38 }
39 
LoadComponents()40 void Bootstrap::LoadComponents()
41 {
42     auto *comps = ConfigFactory::GetInstance().GetComponentConfig();
43     if (comps == nullptr) {
44         return;
45     }
46     for (auto &comp : *comps) {
47         auto handle = dlopen(comp.lib.c_str(), RTLD_LAZY);
48         auto ctor = (Constructor)dlsym(handle, comp.constructor.c_str());
49         if (ctor == nullptr) {
50             continue;
51         }
52         ctor(comp.params.c_str());
53     }
54 }
55 
LoadCheckers()56 void Bootstrap::LoadCheckers()
57 {
58     auto *checkers = ConfigFactory::GetInstance().GetCheckerConfig();
59     if (checkers == nullptr) {
60         return;
61     }
62     CheckerManager::GetInstance().LoadCheckers(checkers->checkers);
63     for (const auto &trust : checkers->trusts) {
64         auto *checker = CheckerManager::GetInstance().GetChecker(trust.checker);
65         if (checker == nullptr) {
66             continue;
67         }
68         checker->SetTrustInfo(trust);
69     }
70 }
71 
LoadNetworks()72 void Bootstrap::LoadNetworks()
73 {
74 }
LoadDirectory()75 void Bootstrap::LoadDirectory()
76 {
77     auto *global = ConfigFactory::GetInstance().GetGlobalConfig();
78     if (global == nullptr || global->directory == nullptr) {
79         return;
80     }
81     for (const auto &strategy : global->directory->strategy) {
82         DirectoryManager::GetInstance().AddParams(strategy);
83     }
84     DirectoryManager::GetInstance().SetCurrentVersion(global->directory->currentStrategyVersion);
85 }
86 } // namespace DistributedData
87 } // namespace OHOS