• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2024 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 "config_process.h"
17 
18 #include "verification/public_internal.h"
19 #include "verification/config/context/context.h"
20 
21 #include "runtime/include/mem/panda_string.h"
22 
23 #include <unordered_map>
24 
25 namespace {
26 
27 using ark::verifier::Config;
28 using ark::verifier::config::Section;
29 
ProcessConfigSection(Config * cfg,const Section & section,const ark::PandaString & path="")30 bool ProcessConfigSection(Config *cfg, const Section &section, const ark::PandaString &path = "")
31 {
32     auto &sectionHandlers = cfg->debugCfg.sectionHandlers;
33     if (sectionHandlers.count(path) > 0) {
34         return sectionHandlers.at(path)(cfg, section);
35     }
36     for (const auto &s : section.sections) {
37         if (!ProcessConfigSection(cfg, s, path + "." + s.name)) {
38             return false;
39         }
40     }
41     return true;
42 }
43 
44 }  // namespace
45 
46 namespace ark::verifier::config {
47 
RegisterConfigHandler(Config * cfg,const PandaString & path,callable<bool (Config *,const Section &)> handler)48 void RegisterConfigHandler(Config *cfg, const PandaString &path, callable<bool(Config *, const Section &)> handler)
49 {
50     auto &sectionHandlers = cfg->debugCfg.sectionHandlers;
51     sectionHandlers[path] = handler;
52 }
53 
ProcessConfig(Config * cfg,const Section & section)54 bool ProcessConfig(Config *cfg, const Section &section)
55 {
56     return ProcessConfigSection(cfg, section, section.name);
57 }
58 
59 }  // namespace ark::verifier::config
60