-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathocc_dbus.cpp
247 lines (205 loc) · 6.05 KB
/
occ_dbus.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#include "occ_dbus.hpp"
#include "utils.hpp"
#include <phosphor-logging/lg2.hpp>
#include <iostream>
namespace open_power
{
namespace occ
{
namespace dbus
{
using namespace std::string_literals;
const auto defaultChassisPath =
"/xyz/openbmc_project/inventory/system/chassis"s;
const auto chassisInterface = "xyz.openbmc_project.Inventory.Item.Chassis"s;
bool OccDBusSensors::setMaxValue(const std::string& path, double value)
{
if (path.empty())
{
return false;
}
if (!sensors.contains(path))
{
sensors.emplace(
path, std::make_unique<SensorIntf>(utils::getBus(), path.c_str()));
}
sensors.at(path)->maxValue(value);
return true;
}
double OccDBusSensors::getMaxValue(const std::string& path) const
{
if (sensors.find(path) != sensors.end())
{
return sensors.at(path)->maxValue();
}
throw std::invalid_argument("Failed to get MaxValue property.");
}
bool OccDBusSensors::setMinValue(const std::string& path, double value)
{
if (path.empty())
{
return false;
}
if (!sensors.contains(path))
{
sensors.emplace(
path, std::make_unique<SensorIntf>(utils::getBus(), path.c_str()));
}
sensors.at(path)->minValue(value);
return true;
}
double OccDBusSensors::getMinValue(const std::string& path) const
{
if (sensors.find(path) != sensors.end())
{
return sensors.at(path)->minValue();
}
throw std::invalid_argument("Failed to get MinValue property.");
}
bool OccDBusSensors::setValue(const std::string& path, double value)
{
if (path.empty())
{
return false;
}
if (!sensors.contains(path))
{
sensors.emplace(
path, std::make_unique<SensorIntf>(utils::getBus(), path.c_str()));
}
sensors.at(path)->value(value);
return true;
}
double OccDBusSensors::getValue(const std::string& path) const
{
if (sensors.find(path) != sensors.end())
{
return sensors.at(path)->value();
}
throw std::invalid_argument("Failed to get Value property.");
}
bool OccDBusSensors::setUnit(const std::string& path, const std::string& value)
{
if (path.empty())
{
return false;
}
if (!sensors.contains(path))
{
sensors.emplace(
path, std::make_unique<SensorIntf>(utils::getBus(), path.c_str()));
}
try
{
sensors.at(path)->unit(SensorIntf::convertUnitFromString(value));
}
catch (const std::exception& e)
{
lg2::error("set Unit propety failed: error={ERR}", "ERR", e.what());
return false;
}
return true;
}
std::string OccDBusSensors::getUnit(const std::string& path) const
{
if (sensors.find(path) != sensors.end())
{
try
{
return SensorIntf::convertUnitToString(sensors.at(path)->unit());
}
catch (const std::exception& e)
{
lg2::error("get Unit propety failed: error={ERR}", "ERR", e.what());
}
}
throw std::invalid_argument("Failed to get Unit property.");
}
bool OccDBusSensors::setOperationalStatus(const std::string& path, bool value)
{
if (path.empty())
{
return false;
}
if (!operationalStatus.contains(path))
{
operationalStatus.emplace(path, std::make_unique<OperationalStatusIntf>(
utils::getBus(), path.c_str()));
}
operationalStatus.at(path)->functional(value);
return true;
}
bool OccDBusSensors::getOperationalStatus(const std::string& path) const
{
if (operationalStatus.find(path) != operationalStatus.end())
{
return operationalStatus.at(path)->functional();
}
throw std::invalid_argument("Failed to get OperationalStatus property.");
}
void OccDBusSensors::setChassisAssociation(
const std::string& path, const std::vector<std::string>& fTypes)
{
using AssociationsEntry = std::tuple<std::string, std::string, std::string>;
using AssociationsProperty = std::vector<AssociationsEntry>;
using PropVariant = sdbusplus::xyz::openbmc_project::Association::server::
Definitions::PropertiesVariant;
if (chassisPath.empty())
{
chassisPath = getChassisPath();
}
AssociationsProperty associations;
for (const auto& fType : fTypes)
{
associations.emplace_back("chassis", fType, chassisPath);
}
PropVariant value{std::move(associations)};
std::map<std::string, PropVariant> properties;
properties.emplace("Associations", std::move(value));
chassisAssociations.emplace(
path, std::make_unique<AssociationIntf>(utils::getBus(), path.c_str(),
properties));
}
std::string OccDBusSensors::getChassisPath()
{
try
{
auto paths = utils::getSubtreePaths(std::vector{chassisInterface});
// For now, support either 1 chassis, or multiple as long as one
// of them has the standard name, which we will use. If this ever
// fails, then someone would have to figure out how to identify the
// chassis the OCCs are on.
if (paths.size() == 1)
{
return paths[0];
}
else if (std::find(paths.begin(), paths.end(), defaultChassisPath) ==
paths.end())
{
lg2::error("Could not find a chassis out of {NUM} chassis objects",
"NUM", paths.size());
// Can't throw an exception here, the sdeventplus timer
// just catches it.
abort();
}
}
catch (const std::exception& e)
{
lg2::error("Error looking up chassis objects: {ERR}", "ERR", e.what());
abort();
}
return defaultChassisPath;
}
bool OccDBusSensors::hasDvfsTemp(const std::string& path) const
{
return dvfsTemps.find(path) != dvfsTemps.end();
}
void OccDBusSensors::setDvfsTemp(const std::string& path, double value)
{
dvfsTemps[path] =
std::make_unique<SensorIntf>(utils::getBus(), path.c_str());
dvfsTemps[path]->value(value);
}
} // namespace dbus
} // namespace occ
} // namespace open_power