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