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), |
Andrew Geissler | 0029a5d | 2017-01-24 14:48:35 -0600 | [diff] [blame] | 39 | systemdSignals(bus, |
| 40 | "type='signal'," |
| 41 | "member='JobRemoved'," |
| 42 | "path='/org/freedesktop/systemd1'," |
| 43 | "interface='org.freedesktop.systemd1.Manager'", |
| 44 | sysStateChangeSignal, |
| 45 | this) |
Andrew Geissler | dff50ed | 2016-12-13 20:39:04 -0600 | [diff] [blame] | 46 | { |
Andrew Geissler | 0029a5d | 2017-01-24 14:48:35 -0600 | [diff] [blame] | 47 | subscribeToSystemdSignals(); |
| 48 | |
Andrew Geissler | dff50ed | 2016-12-13 20:39:04 -0600 | [diff] [blame] | 49 | determineInitialState(); |
| 50 | |
| 51 | // We deferred this until we could get our property correct |
| 52 | this->emit_object_added(); |
| 53 | } |
| 54 | |
Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 55 | /** @brief Set value of RequestedPowerTransition */ |
| 56 | Transition requestedPowerTransition(Transition value) override; |
| 57 | |
| 58 | /** @brief Set value of CurrentPowerState */ |
| 59 | PowerState currentPowerState(PowerState value) override; |
| 60 | |
| 61 | private: |
Andrew Geissler | 0029a5d | 2017-01-24 14:48:35 -0600 | [diff] [blame] | 62 | /** @brief Determine initial chassis state and set internally */ |
| 63 | void determineInitialState(); |
| 64 | |
| 65 | /** |
| 66 | * @brief subscribe to the systemd signals |
| 67 | * |
| 68 | * This object needs to capture when it's systemd targets complete |
| 69 | * so it can keep it's state updated |
| 70 | * |
| 71 | **/ |
| 72 | void subscribeToSystemdSignals(); |
| 73 | |
Andrew Geissler | ce80f24 | 2017-01-24 13:25:33 -0600 | [diff] [blame] | 74 | /** @brief Execute the transition request |
| 75 | * |
| 76 | * This function calls the appropriate systemd target for the input |
| 77 | * transition. |
| 78 | * |
| 79 | * @param[in] tranReq - Transition requested |
| 80 | */ |
| 81 | void executeTransition(Transition tranReq); |
| 82 | |
Josh D. King | 697474c | 2017-03-02 11:15:55 -0600 | [diff] [blame^] | 83 | /** |
| 84 | * @brief Determine if target is active |
| 85 | * |
| 86 | * This function determines if the target is active and |
| 87 | * helps prevent misleading log recorded states. |
| 88 | * |
| 89 | * @param[in] target - Target string to check on |
| 90 | * |
| 91 | * @return boolean corresponding to state active |
| 92 | **/ |
| 93 | bool stateActive(const std::string& target); |
| 94 | |
Andrew Geissler | 0029a5d | 2017-01-24 14:48:35 -0600 | [diff] [blame] | 95 | /** @brief Callback function on systemd state changes |
Andrew Geissler | 2ec3a7e | 2016-12-13 22:01:28 -0600 | [diff] [blame] | 96 | * |
Andrew Geissler | 0029a5d | 2017-01-24 14:48:35 -0600 | [diff] [blame] | 97 | * Will just do a call into the appropriate object for processing |
Andrew Geissler | 2ec3a7e | 2016-12-13 22:01:28 -0600 | [diff] [blame] | 98 | * |
Andrew Geissler | 0029a5d | 2017-01-24 14:48:35 -0600 | [diff] [blame] | 99 | * @param[in] msg - Data associated with subscribed signal |
| 100 | * @param[in] userData - Pointer to this object instance |
| 101 | * @param[out] retError - Not used but required with signal API |
Andrew Geissler | 2ec3a7e | 2016-12-13 22:01:28 -0600 | [diff] [blame] | 102 | * |
| 103 | */ |
Andrew Geissler | 0029a5d | 2017-01-24 14:48:35 -0600 | [diff] [blame] | 104 | static int sysStateChangeSignal(sd_bus_message* msg, |
| 105 | void* userData, |
| 106 | sd_bus_error* retError); |
Andrew Geissler | 2ec3a7e | 2016-12-13 22:01:28 -0600 | [diff] [blame] | 107 | |
Andrew Geissler | 0029a5d | 2017-01-24 14:48:35 -0600 | [diff] [blame] | 108 | /** @brief Check if systemd state change is relevant to this object |
Andrew Geissler | 2ec3a7e | 2016-12-13 22:01:28 -0600 | [diff] [blame] | 109 | * |
Andrew Geissler | 0029a5d | 2017-01-24 14:48:35 -0600 | [diff] [blame] | 110 | * Instance specific interface to handle the detected systemd state |
| 111 | * change |
Andrew Geissler | 2ec3a7e | 2016-12-13 22:01:28 -0600 | [diff] [blame] | 112 | * |
Andrew Geissler | 0029a5d | 2017-01-24 14:48:35 -0600 | [diff] [blame] | 113 | * @param[in] msg - Data associated with subscribed signal |
| 114 | * @param[out] retError - Not used but required with signal API |
Andrew Geissler | 2ec3a7e | 2016-12-13 22:01:28 -0600 | [diff] [blame] | 115 | * |
| 116 | */ |
Andrew Geissler | 0029a5d | 2017-01-24 14:48:35 -0600 | [diff] [blame] | 117 | int sysStateChange(sd_bus_message* msg, |
| 118 | sd_bus_error* retError); |
Andrew Geissler | 2ec3a7e | 2016-12-13 22:01:28 -0600 | [diff] [blame] | 119 | |
Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 120 | /** @brief Persistent sdbusplus DBus connection. */ |
| 121 | sdbusplus::bus::bus& bus; |
Andrew Geissler | 2ec3a7e | 2016-12-13 22:01:28 -0600 | [diff] [blame] | 122 | |
Andrew Geissler | 0029a5d | 2017-01-24 14:48:35 -0600 | [diff] [blame] | 123 | /** @brief Used to subscribe to dbus systemd signals **/ |
| 124 | sdbusplus::server::match::match systemdSignals; |
Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 125 | }; |
| 126 | |
| 127 | } // namespace manager |
| 128 | } // namespace state |
| 129 | } // namespace phosphor |