Debian Codegraph @

src/core/components/controls/amd/fan/fixed/fanfixedxmlparser.cpp

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-3.0-or-later
2 // Copyright 2019 Juan Palacios <[email protected]>
3
4 #include "fanfixedxmlparser.h"
5
6 #include "core/profilepartxmlparserprovider.h"
7 #include "fanfixed.h"
8 #include <memory>
9
10 class AMD::FanFixedXMLParser::Initializer final
11 : public AMD::FanFixedProfilePart::Exporter
12 {
13 public:
14 Initializer(AMD::FanFixedXMLParser &outer) noexcept
15 : outer_(outer)
16 {
17 }
18
19 std::optional<std::reference_wrapper<Exportable::Exporter>>
20 provideExporter(Item const &) override
21 {
22 return {};
23 }
24
25 void takeActive(bool active) override;
26 void takeFanFixedValue(units::concentration::percent_t value) override;
27 void takeFanFixedFanStop(bool enabled) override;
28 void takeFanFixedFanStartValue(units::concentration::percent_t value) override;
29
30 private:
31 AMD::FanFixedXMLParser &outer_;
32 };
33
34 void AMD::FanFixedXMLParser::Initializer::takeActive(bool active)
35 {
36 outer_.active_ = outer_.activeDefault_ = active;
37 }
38
39 void AMD::FanFixedXMLParser::Initializer::takeFanFixedValue(
40 units::concentration::percent_t value)
41 {
42 outer_.value_ = outer_.valueDefault_ = value * 100;
43 }
44
45 void AMD::FanFixedXMLParser::Initializer::takeFanFixedFanStop(bool enabled)
46 {
47 outer_.fanStop_ = outer_.fanStopDefault_ = enabled;
48 }
49
50 void AMD::FanFixedXMLParser::Initializer::takeFanFixedFanStartValue(
51 units::concentration::percent_t value)
52 {
53 outer_.fanStartValue_ = outer_.fanStartValueDefault_ = value * 100;
54 }
55
56 AMD::FanFixedXMLParser::FanFixedXMLParser() noexcept
57 : ProfilePartXMLParser(AMD::FanFixed::ItemID, *this, *this)
58 {
59 }
60
61 std::unique_ptr<Exportable::Exporter>
62 AMD::FanFixedXMLParser::factory(IProfilePartXMLParserProvider const &)
63 {
64 return nullptr;
65 }
66
67 std::unique_ptr<Exportable::Exporter> AMD::FanFixedXMLParser::initializer()
68 {
69 return std::make_unique<AMD::FanFixedXMLParser::Initializer>(*this);
70 }
71
72 std::optional<std::reference_wrapper<Exportable::Exporter>>
73 AMD::FanFixedXMLParser::provideExporter(Item const &)
74 {
75 return {};
76 }
77
78 std::optional<std::reference_wrapper<Importable::Importer>>
79 AMD::FanFixedXMLParser::provideImporter(Item const &)
80 {
81 return {};
82 }
83
84 void AMD::FanFixedXMLParser::takeActive(bool active)
85 {
86 active_ = active;
87 }
88
89 bool AMD::FanFixedXMLParser::provideActive() const
90 {
91 return active_;
92 }
93
94 void AMD::FanFixedXMLParser::takeFanFixedValue(units::concentration::percent_t value)
95 {
96 value_ = value * 100;
97 }
98
99 units::concentration::percent_t AMD::FanFixedXMLParser::provideFanFixedValue() const
100 {
101 return value_;
102 }
103
104 void AMD::FanFixedXMLParser::takeFanFixedFanStop(bool enabled)
105 {
106 fanStop_ = enabled;
107 }
108
109 bool AMD::FanFixedXMLParser::provideFanFixedFanStop() const
110 {
111 return fanStop_;
112 }
113
114 void AMD::FanFixedXMLParser::takeFanFixedFanStartValue(
115 units::concentration::percent_t value)
116 {
117 fanStartValue_ = value * 100;
118 }
119
120 units::concentration::percent_t
121 AMD::FanFixedXMLParser::provideFanFixedFanStartValue() const
122 {
123 return fanStartValue_;
124 }
125
126 void AMD::FanFixedXMLParser::appendTo(pugi::xml_node &parentNode)
127 {
128 auto pmFixedNode = parentNode.append_child(ID().c_str());
129 pmFixedNode.append_attribute("active") = active_;
130 pmFixedNode.append_attribute("value") = value_;
131 pmFixedNode.append_attribute("fanStop") = fanStop_;
132 pmFixedNode.append_attribute("fanStartValue") = fanStartValue_;
133 }
134
135 void AMD::FanFixedXMLParser::resetAttributes()
136 {
137 active_ = activeDefault_;
138 value_ = valueDefault_;
139 fanStop_ = fanStopDefault_;
140 fanStartValue_ = fanStartValueDefault_;
141 }
142
143 void AMD::FanFixedXMLParser::loadPartFrom(pugi::xml_node const &parentNode)
144 {
145 auto pmFixedNode = parentNode.find_child(
146 [&](pugi::xml_node const &node) { return node.name() == ID(); });
147
148 active_ = pmFixedNode.attribute("active").as_bool(activeDefault_);
149 value_ = pmFixedNode.attribute("value").as_int(valueDefault_);
150 fanStop_ = pmFixedNode.attribute("fanStop").as_bool(fanStopDefault_);
151 fanStartValue_ =
152 pmFixedNode.attribute("fanStartValue").as_int(fanStartValueDefault_);
153 }
154
155 bool const AMD::FanFixedXMLParser::registered_ =
156 ProfilePartXMLParserProvider::registerProvider(AMD::FanFixed::ItemID, []() {
157 return std::make_unique<AMD::FanFixedXMLParser>();
158 });