blob: 12a04a47384d64aff3d8428ee94de723d5bb04ef [file] [log] [blame]
Josh D. Kingbdd9cb72016-12-19 11:13:43 -06001#include <iostream>
Josh D. King5162a7b2016-12-19 16:15:00 -06002#include <string>
Josh D. King6db38222016-12-19 14:52:40 -06003#include <log.hpp>
Josh D. Kingbdd9cb72016-12-19 11:13:43 -06004#include "bmc_state_manager.hpp"
5
6namespace phosphor
7{
8namespace state
9{
10namespace manager
11{
12
Josh D. King6db38222016-12-19 14:52:40 -060013// When you see server:: you know we're referencing our base class
14namespace server = sdbusplus::xyz::openbmc_project::State::server;
15
16using namespace phosphor::logging;
17
Josh D. King5162a7b2016-12-19 16:15:00 -060018/* Map a transition to it's systemd target */
19const std::map<server::BMC::Transition, const char*> SYSTEMD_TABLE =
20{
21 {server::BMC::Transition::Reboot, "reboot.target"}
22};
23
Josh D. King6db38222016-12-19 14:52:40 -060024constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1";
25constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1";
26constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager";
27
28void BMC::subscribeToSystemdSignals()
29{
30 auto method = this->bus.new_method_call(SYSTEMD_SERVICE,
31 SYSTEMD_OBJ_PATH,
32 SYSTEMD_INTERFACE,
33 "Subscribe");
34 this->bus.call(method);
35
36 return;
37}
38
Josh D. King5162a7b2016-12-19 16:15:00 -060039void BMC::executeTransition(const Transition tranReq)
40{
41 //Check to make sure it can be found
42 auto iter = SYSTEMD_TABLE.find(tranReq);
43 if (iter == SYSTEMD_TABLE.end()) return;
44
45 const auto& sysdUnit = iter->second;
46
47 auto method = this->bus.new_method_call(SYSTEMD_SERVICE,
48 SYSTEMD_OBJ_PATH,
49 SYSTEMD_INTERFACE,
50 "StartUnit");
51
52 method.append(sysdUnit, "replace");
53
54 this->bus.call(method);
55
56 return;
57}
58
Josh D. King6db38222016-12-19 14:52:40 -060059BMC::Transition BMC::requestedBMCTransition(Transition value)
60{
61 log<level::INFO>(
62 "Setting the RequestedBMCTransition field",
63 entry("REQUESTED_BMC_TRANSITION=0x%s",
64 convertForMessage(value).c_str()));
Josh D. King6db38222016-12-19 14:52:40 -060065
Josh D. King5162a7b2016-12-19 16:15:00 -060066 executeTransition(value);
67 return server::BMC::requestedBMCTransition(value);
Josh D. King6db38222016-12-19 14:52:40 -060068}
69
70
Josh D. Kingbdd9cb72016-12-19 11:13:43 -060071} // namespace manager
72} // namespace state
73} // namepsace phosphor
74