Debian Codegraph @

src/core/sysmodel.cpp

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-3.0-or-later
2 // Copyright 2019 Juan Palacios <[email protected]>
3
4 #include "sysmodel.h"
5
6 #include "core/exportable.h"
7 #include "core/importable.h"
8 #include "core/isyscomponent.h"
9 #include "info/iswinfo.h"
10
11 SysModel::SysModel(std::shared_ptr<ISWInfo> swInfo,
12 std::vector<std::unique_ptr<ISysComponent>> &&components) noexcept
13 : id_{ISysModel::ItemID}
14 , swInfo_(std::move(swInfo))
15 , components_(std::move(components))
16 {
17 }
18
19 void SysModel::init()
20 {
21 for (auto &component : components_)
22 component->init();
23 }
24
25 void SysModel::preInit(ICommandQueue &ctlCmds)
26 {
27 for (auto &component : components_)
28 component->preInit(ctlCmds);
29 }
30
31 void SysModel::postInit(ICommandQueue &ctlCmds)
32 {
33 for (auto &component : components_)
34 component->postInit(ctlCmds);
35 }
36
37 void SysModel::sync(ICommandQueue &ctlCmds)
38 {
39 for (auto &component : components_)
40 component->sync(ctlCmds);
41 }
42
43 void SysModel::updateSensors(
44 std::unordered_map<std::string, std::unordered_set<std::string>> const &ignored)
45 {
46 for (auto &component : components_)
47 component->updateSensors(ignored);
48 }
49
50 std::vector<std::pair<std::string, std::vector<std::pair<std::string, std::string>>>>
51 SysModel::info() const
52 {
53 std::vector<std::pair<std::string, std::vector<std::pair<std::string, std::string>>>>
54 info;
55
56 info.emplace_back(softwareInfo());
57
58 for (auto const &component : components_)
59 info.emplace_back(component->componentInfo());
60
61 return info;
62 }
63
64 std::string const &SysModel::ID() const
65 {
66 return id_;
67 }
68
69 void SysModel::importWith(Importable::Importer &i)
70 {
71 auto importer = i.provideImporter(*this);
72 if (importer.has_value()) {
73 for (auto &component : components_)
74 component->importWith(*importer);
75 }
76 }
77
78 void SysModel::exportWith(Exportable::Exporter &e) const
79 {
80 auto exporter = e.provideExporter(*this);
81 if (exporter.has_value()) {
82 for (auto const &component : components_)
83 component->exportWith(*exporter);
84 }
85 }
86
87 std::pair<std::string, std::vector<std::pair<std::string, std::string>>>
88 SysModel::softwareInfo() const
89 {
90 std::pair<std::string, std::vector<std::pair<std::string, std::string>>> info;
91
92 info.first = "Software";
93
94 auto swInfoKeys = swInfo_->keys();
95 for (auto &swInfoKey : swInfoKeys)
96 info.second.emplace_back(swInfoKey, swInfo_->info(swInfoKey));
97
98 return info;
99 }