forked from openbmc/phosphor-host-ipmid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.cpp
More file actions
141 lines (123 loc) · 4.14 KB
/
settings.cpp
File metadata and controls
141 lines (123 loc) · 4.14 KB
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
#include "settings.hpp"
#include <ipmid/utils.hpp>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/log.hpp>
#include <sdbusplus/message/types.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
namespace settings
{
using namespace phosphor::logging;
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
constexpr auto mapperService = "xyz.openbmc_project.ObjectMapper";
constexpr auto mapperPath = "/xyz/openbmc_project/object_mapper";
constexpr auto mapperIntf = "xyz.openbmc_project.ObjectMapper";
Objects::Objects(sdbusplus::bus_t& bus, const std::vector<Interface>& filter) :
bus(bus)
{
auto depth = 0;
auto mapperCall = bus.new_method_call(mapperService, mapperPath, mapperIntf,
"GetSubTree");
mapperCall.append(root);
mapperCall.append(depth);
mapperCall.append(filter);
using Interfaces = std::vector<Interface>;
using MapperResponse = std::map<Path, std::map<Service, Interfaces>>;
MapperResponse result;
try
{
auto response = bus.call(mapperCall);
response.read(result);
}
catch (const std::exception& e)
{
log<level::ERR>("Error in mapper GetSubTree",
entry("ERROR=%s", e.what()));
elog<InternalFailure>();
}
for (auto& iter : result)
{
const auto& path = iter.first;
for (auto& interface : iter.second.begin()->second)
{
auto found = map.find(interface);
if (map.end() != found)
{
auto& paths = found->second;
paths.push_back(path);
}
else
{
map.emplace(std::move(interface), std::vector<Path>({path}));
}
}
}
}
Service Objects::service(const Path& path, const Interface& interface) const
{
using Interfaces = std::vector<Interface>;
auto mapperCall = bus.new_method_call(mapperService, mapperPath, mapperIntf,
"GetObject");
mapperCall.append(path);
mapperCall.append(Interfaces({interface}));
std::map<Service, Interfaces> result;
try
{
auto response = bus.call(mapperCall);
response.read(result);
return result.begin()->first;
}
catch (const std::exception& e)
{
log<level::ERR>("Invalid response from mapper",
entry("ERROR=%s", e.what()));
elog<InternalFailure>();
}
}
namespace boot
{
std::tuple<Path, OneTimeEnabled> setting(const Objects& objects,
const Interface& iface)
{
constexpr auto bootObjCount = 2;
constexpr auto oneTime = "one_time";
constexpr auto enabledIntf = "xyz.openbmc_project.Object.Enable";
const std::vector<Path>& paths = objects.map.at(iface);
auto count = paths.size();
if (count != bootObjCount)
{
log<level::ERR>("Exactly two objects expected",
entry("INTERFACE=%s", iface.c_str()),
entry("COUNT=%d", count));
elog<InternalFailure>();
}
size_t index = 0;
if (std::string::npos == paths[0].rfind(oneTime))
{
index = 1;
}
const Path& oneTimeSetting = paths[index];
const Path& regularSetting = paths[!index];
auto method = objects.bus.new_method_call(
objects.service(oneTimeSetting, iface).c_str(), oneTimeSetting.c_str(),
ipmi::PROP_INTF, "Get");
method.append(enabledIntf, "Enabled");
std::variant<bool> enabled;
try
{
auto reply = objects.bus.call(method);
reply.read(enabled);
}
catch (const std::exception& e)
{
log<level::ERR>("Error in getting Enabled property",
entry("OBJECT=%s", oneTimeSetting.c_str()),
entry("INTERFACE=%s", iface.c_str()),
entry("ERROR=%s", e.what()));
elog<InternalFailure>();
}
auto oneTimeEnabled = std::get<bool>(enabled);
const Path& setting = oneTimeEnabled ? oneTimeSetting : regularSetting;
return std::make_tuple(setting, oneTimeEnabled);
}
} // namespace boot
} // namespace settings