Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 1 | #include <log.hpp> |
| 2 | #include "chassis_state_manager.hpp" |
| 3 | |
| 4 | namespace phosphor |
| 5 | { |
| 6 | namespace state |
| 7 | { |
| 8 | namespace manager |
| 9 | { |
| 10 | |
| 11 | // When you see server:: you know we're referencing our base class |
| 12 | namespace server = sdbusplus::xyz::openbmc_project::State::server; |
| 13 | |
| 14 | using namespace phosphor::logging; |
| 15 | |
Andrew Geissler | 2ec3a7e | 2016-12-13 22:01:28 -0600 | [diff] [blame] | 16 | /* TODO:Issue 774 - Use systemd target signals to control chassis state */ |
| 17 | int Chassis::handlePgoodOn(sd_bus_message* /*msg*/, void* usrData, |
| 18 | sd_bus_error* retError) |
| 19 | { |
| 20 | log<level::INFO>("Pgood has turned on", |
| 21 | entry("CHASSIS_CURRENT_POWER_STATE=%s", |
| 22 | convertForMessage(PowerState::On).c_str())); |
| 23 | auto chassisInst = static_cast<Chassis*>(usrData); |
| 24 | chassisInst->currentPowerState(PowerState::On); |
| 25 | |
| 26 | return 0; |
| 27 | } |
| 28 | |
| 29 | int Chassis::handlePgoodOff(sd_bus_message* /*msg*/, void* usrData, |
| 30 | sd_bus_error* retError) |
| 31 | { |
| 32 | log<level::INFO>("Pgood has turned off", |
| 33 | entry("CHASSIS_CURRENT_POWER_STATE=%s", |
| 34 | convertForMessage(PowerState::Off).c_str())); |
| 35 | auto chassisInst = static_cast<Chassis*>(usrData); |
| 36 | chassisInst->currentPowerState(PowerState::Off); |
| 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | |
Andrew Geissler | dff50ed | 2016-12-13 20:39:04 -0600 | [diff] [blame] | 41 | // TODO - Will be rewritten once sdbusplus client bindings are in place |
| 42 | // and persistent storage design is in place and sdbusplus |
| 43 | // has read property function |
| 44 | void Chassis::determineInitialState() |
| 45 | { |
| 46 | sdbusplus::message::variant<int> pgood = -1; |
| 47 | auto method = this->bus.new_method_call("org.openbmc.control.Power", |
| 48 | "/org/openbmc/control/power0", |
| 49 | "org.freedesktop.DBus.Properties", |
| 50 | "Get"); |
| 51 | |
| 52 | method.append("org.openbmc.control.Power", "pgood"); |
| 53 | auto reply = this->bus.call(method); |
| 54 | reply.read(pgood); |
| 55 | |
| 56 | if(pgood == 1) |
| 57 | { |
| 58 | log<level::INFO>("Initial Chassis State will be On", |
| 59 | entry("CHASSIS_CURRENT_POWER_STATE=%s", |
| 60 | convertForMessage(PowerState::On).c_str())); |
| 61 | server::Chassis::currentPowerState(PowerState::On); |
| 62 | server::Chassis::requestedPowerTransition(Transition::On); |
| 63 | } |
| 64 | else |
| 65 | { |
| 66 | log<level::INFO>("Initial Chassis State will be Off", |
| 67 | entry("CHASSIS_CURRENT_POWER_STATE=%s", |
| 68 | convertForMessage(PowerState::Off).c_str())); |
| 69 | server::Chassis::currentPowerState(PowerState::Off); |
| 70 | server::Chassis::requestedPowerTransition(Transition::Off); |
| 71 | } |
| 72 | |
| 73 | return; |
| 74 | } |
| 75 | |
Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 76 | Chassis::Transition Chassis::requestedPowerTransition(Transition value) |
| 77 | { |
| 78 | |
| 79 | log<level::INFO>("Change to Chassis Requested Power State", |
| 80 | entry("CHASSIS_REQUESTED_POWER_STATE=%s", |
| 81 | convertForMessage(value).c_str())); |
| 82 | return server::Chassis::requestedPowerTransition(value); |
| 83 | } |
| 84 | |
| 85 | Chassis::PowerState Chassis::currentPowerState(PowerState value) |
| 86 | { |
| 87 | log<level::INFO>("Change to Chassis Power State", |
| 88 | entry("CHASSIS_CURRENT_POWER_STATE=%s", |
| 89 | convertForMessage(value).c_str())); |
| 90 | return server::Chassis::currentPowerState(value); |
| 91 | } |
| 92 | |
| 93 | } // namespace manager |
| 94 | } // namespace state |
| 95 | } // namepsace phosphor |