blob: a2b6dbfa97e5cada28720ffb7ad26689b4876688 [file] [log] [blame]
Andrew Geisslera90a31a2016-12-13 16:16:28 -06001#include <log.hpp>
2#include "chassis_state_manager.hpp"
3
4namespace phosphor
5{
6namespace state
7{
8namespace manager
9{
10
11// When you see server:: you know we're referencing our base class
12namespace server = sdbusplus::xyz::openbmc_project::State::server;
13
14using namespace phosphor::logging;
15
Andrew Geissler2ec3a7e2016-12-13 22:01:28 -060016/* TODO:Issue 774 - Use systemd target signals to control chassis state */
17int 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
29int 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 Geisslerdff50ed2016-12-13 20:39:04 -060041// 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
44void 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 Geisslera90a31a2016-12-13 16:16:28 -060076Chassis::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
85Chassis::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