Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 1 | #include <iostream> |
Josh D. King | 5162a7b | 2016-12-19 16:15:00 -0600 | [diff] [blame^] | 2 | #include <string> |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 3 | #include <log.hpp> |
Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 4 | #include "bmc_state_manager.hpp" |
| 5 | |
| 6 | namespace phosphor |
| 7 | { |
| 8 | namespace state |
| 9 | { |
| 10 | namespace manager |
| 11 | { |
| 12 | |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 13 | // When you see server:: you know we're referencing our base class |
| 14 | namespace server = sdbusplus::xyz::openbmc_project::State::server; |
| 15 | |
| 16 | using namespace phosphor::logging; |
| 17 | |
Josh D. King | 5162a7b | 2016-12-19 16:15:00 -0600 | [diff] [blame^] | 18 | /* Map a transition to it's systemd target */ |
| 19 | const std::map<server::BMC::Transition, const char*> SYSTEMD_TABLE = |
| 20 | { |
| 21 | {server::BMC::Transition::Reboot, "reboot.target"} |
| 22 | }; |
| 23 | |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 24 | constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1"; |
| 25 | constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1"; |
| 26 | constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager"; |
| 27 | |
| 28 | void 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. King | 5162a7b | 2016-12-19 16:15:00 -0600 | [diff] [blame^] | 39 | void 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. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 59 | BMC::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. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 65 | |
Josh D. King | 5162a7b | 2016-12-19 16:15:00 -0600 | [diff] [blame^] | 66 | executeTransition(value); |
| 67 | return server::BMC::requestedBMCTransition(value); |
Josh D. King | 6db3822 | 2016-12-19 14:52:40 -0600 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | |
Josh D. King | bdd9cb7 | 2016-12-19 11:13:43 -0600 | [diff] [blame] | 71 | } // namespace manager |
| 72 | } // namespace state |
| 73 | } // namepsace phosphor |
| 74 | |