Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <sdbusplus/bus.hpp> |
| 4 | #include "xyz/openbmc_project/State/Chassis/server.hpp" |
| 5 | |
| 6 | namespace phosphor |
| 7 | { |
| 8 | namespace state |
| 9 | { |
| 10 | namespace manager |
| 11 | { |
| 12 | |
| 13 | /** @class Chassis |
| 14 | * @brief OpenBMC chassis state management implementation. |
| 15 | * @details A concrete implementation for xyz.openbmc_project.State.Chassis |
| 16 | * DBus API. |
| 17 | */ |
| 18 | class Chassis : public sdbusplus::server::object::object< |
| 19 | sdbusplus::xyz::openbmc_project::State::server::Chassis> |
| 20 | { |
| 21 | public: |
| 22 | /** @brief Constructs Chassis State Manager |
| 23 | * |
Andrew Geissler | dff50ed | 2016-12-13 20:39:04 -0600 | [diff] [blame] | 24 | * @note This constructor passes 'true' to the base class in order to |
| 25 | * defer dbus object registration until we can run |
| 26 | * determineInitialState() and set our properties |
| 27 | * |
Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 28 | * @param[in] bus - The Dbus bus object |
Andrew Geissler | dff50ed | 2016-12-13 20:39:04 -0600 | [diff] [blame] | 29 | * @param[in] instance - The instance of this object |
Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 30 | * @param[in] objPath - The Dbus object path |
| 31 | */ |
| 32 | Chassis(sdbusplus::bus::bus& bus, |
| 33 | const char* busName, |
| 34 | const char* objPath) : |
| 35 | sdbusplus::server::object::object< |
| 36 | sdbusplus::xyz::openbmc_project::State::server::Chassis>( |
Andrew Geissler | dff50ed | 2016-12-13 20:39:04 -0600 | [diff] [blame] | 37 | bus, objPath, true), |
Andrew Geissler | 2ec3a7e | 2016-12-13 22:01:28 -0600 | [diff] [blame] | 38 | bus(bus), |
| 39 | pgoodOn(bus, |
| 40 | "type='signal',member='PowerGood'", |
| 41 | Chassis::handlePgoodOn, |
| 42 | this), |
| 43 | pgoodOff(bus, |
| 44 | "type='signal',member='PowerLost'", |
| 45 | Chassis::handlePgoodOff, |
| 46 | this) |
Andrew Geissler | dff50ed | 2016-12-13 20:39:04 -0600 | [diff] [blame] | 47 | { |
| 48 | determineInitialState(); |
| 49 | |
| 50 | // We deferred this until we could get our property correct |
| 51 | this->emit_object_added(); |
| 52 | } |
| 53 | |
| 54 | /** @brief Determine initial chassis state and set internally */ |
| 55 | void determineInitialState(); |
Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 56 | |
| 57 | /** @brief Set value of RequestedPowerTransition */ |
| 58 | Transition requestedPowerTransition(Transition value) override; |
| 59 | |
| 60 | /** @brief Set value of CurrentPowerState */ |
| 61 | PowerState currentPowerState(PowerState value) override; |
| 62 | |
| 63 | private: |
Andrew Geissler | 2ec3a7e | 2016-12-13 22:01:28 -0600 | [diff] [blame] | 64 | /** @brief Callback function for pgood going to on state |
| 65 | * |
| 66 | * Update chassis object state to reflect pgood going to on state |
| 67 | * |
| 68 | * @param[in] msg - Data associated with subscribed signal |
| 69 | * @param[in] userData - Pointer to this object instance |
| 70 | * @param[in] retError - Return error data |
| 71 | * |
| 72 | */ |
| 73 | static int handlePgoodOn(sd_bus_message* msg, |
| 74 | void* userData, |
| 75 | sd_bus_error* retError); |
| 76 | |
| 77 | /** @brief Callback function for pgood going to off state |
| 78 | * |
| 79 | * Update chassis object state to reflect pgood going to off state |
| 80 | * |
| 81 | * @param[in] msg - Data associated with subscribed signal |
| 82 | * @param[in] userData - Pointer to this object instance |
| 83 | * @param[in] retError - Return error data |
| 84 | * |
| 85 | */ |
| 86 | static int handlePgoodOff(sd_bus_message* msg, |
| 87 | void* userData, |
| 88 | sd_bus_error* retError); |
| 89 | |
Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 90 | /** @brief Persistent sdbusplus DBus connection. */ |
| 91 | sdbusplus::bus::bus& bus; |
Andrew Geissler | 2ec3a7e | 2016-12-13 22:01:28 -0600 | [diff] [blame] | 92 | |
| 93 | /** @brief Used to subscribe to dbus pgood on state changes */ |
| 94 | sdbusplus::server::match::match pgoodOn; |
| 95 | |
| 96 | /** @brief Used to subscribe to dbus pgood off state changes */ |
| 97 | sdbusplus::server::match::match pgoodOff; |
Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | } // namespace manager |
| 101 | } // namespace state |
| 102 | } // namespace phosphor |