Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Williams | 8f8ba39 | 2017-05-05 15:47:39 -0500 | [diff] [blame] | 3 | #include <functional> |
Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 4 | #include <sdbusplus/bus.hpp> |
| 5 | #include "xyz/openbmc_project/State/Chassis/server.hpp" |
| 6 | |
| 7 | namespace phosphor |
| 8 | { |
| 9 | namespace state |
| 10 | { |
| 11 | namespace manager |
| 12 | { |
| 13 | |
Patrick Williams | 8f8ba39 | 2017-05-05 15:47:39 -0500 | [diff] [blame] | 14 | using ChassisInherit = sdbusplus::server::object::object< |
| 15 | sdbusplus::xyz::openbmc_project::State::server::Chassis>; |
| 16 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 17 | |
Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 18 | /** @class Chassis |
| 19 | * @brief OpenBMC chassis state management implementation. |
| 20 | * @details A concrete implementation for xyz.openbmc_project.State.Chassis |
| 21 | * DBus API. |
| 22 | */ |
Patrick Williams | 8f8ba39 | 2017-05-05 15:47:39 -0500 | [diff] [blame] | 23 | class Chassis : public ChassisInherit |
Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 24 | { |
| 25 | public: |
| 26 | /** @brief Constructs Chassis State Manager |
| 27 | * |
Andrew Geissler | dff50ed | 2016-12-13 20:39:04 -0600 | [diff] [blame] | 28 | * @note This constructor passes 'true' to the base class in order to |
| 29 | * defer dbus object registration until we can run |
| 30 | * determineInitialState() and set our properties |
| 31 | * |
Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 32 | * @param[in] bus - The Dbus bus object |
Andrew Geissler | dff50ed | 2016-12-13 20:39:04 -0600 | [diff] [blame] | 33 | * @param[in] instance - The instance of this object |
Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 34 | * @param[in] objPath - The Dbus object path |
| 35 | */ |
| 36 | Chassis(sdbusplus::bus::bus& bus, |
| 37 | const char* busName, |
| 38 | const char* objPath) : |
Patrick Williams | 8f8ba39 | 2017-05-05 15:47:39 -0500 | [diff] [blame] | 39 | ChassisInherit(bus, objPath, true), |
Andrew Geissler | 2ec3a7e | 2016-12-13 22:01:28 -0600 | [diff] [blame] | 40 | bus(bus), |
Andrew Geissler | 0029a5d | 2017-01-24 14:48:35 -0600 | [diff] [blame] | 41 | systemdSignals(bus, |
Patrick Williams | 8f8ba39 | 2017-05-05 15:47:39 -0500 | [diff] [blame] | 42 | sdbusRule::type::signal() + |
| 43 | sdbusRule::member("JobRemoved") + |
| 44 | sdbusRule::path("/org/freedesktop/systemd1") + |
| 45 | sdbusRule::interface( |
| 46 | "org.freedesktop.systemd1.Manager"), |
| 47 | std::bind(std::mem_fn(&Chassis::sysStateChange), |
| 48 | this, std::placeholders::_1)) |
Andrew Geissler | dff50ed | 2016-12-13 20:39:04 -0600 | [diff] [blame] | 49 | { |
Andrew Geissler | 0029a5d | 2017-01-24 14:48:35 -0600 | [diff] [blame] | 50 | subscribeToSystemdSignals(); |
| 51 | |
Andrew Geissler | dff50ed | 2016-12-13 20:39:04 -0600 | [diff] [blame] | 52 | determineInitialState(); |
| 53 | |
| 54 | // We deferred this until we could get our property correct |
| 55 | this->emit_object_added(); |
| 56 | } |
| 57 | |
Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 58 | /** @brief Set value of RequestedPowerTransition */ |
| 59 | Transition requestedPowerTransition(Transition value) override; |
| 60 | |
| 61 | /** @brief Set value of CurrentPowerState */ |
| 62 | PowerState currentPowerState(PowerState value) override; |
| 63 | |
| 64 | private: |
Andrew Geissler | 0029a5d | 2017-01-24 14:48:35 -0600 | [diff] [blame] | 65 | /** @brief Determine initial chassis state and set internally */ |
| 66 | void determineInitialState(); |
| 67 | |
| 68 | /** |
| 69 | * @brief subscribe to the systemd signals |
| 70 | * |
| 71 | * This object needs to capture when it's systemd targets complete |
| 72 | * so it can keep it's state updated |
| 73 | * |
| 74 | **/ |
| 75 | void subscribeToSystemdSignals(); |
| 76 | |
Andrew Geissler | ce80f24 | 2017-01-24 13:25:33 -0600 | [diff] [blame] | 77 | /** @brief Execute the transition request |
| 78 | * |
| 79 | * This function calls the appropriate systemd target for the input |
| 80 | * transition. |
| 81 | * |
| 82 | * @param[in] tranReq - Transition requested |
| 83 | */ |
| 84 | void executeTransition(Transition tranReq); |
| 85 | |
Josh D. King | 697474c | 2017-03-02 11:15:55 -0600 | [diff] [blame] | 86 | /** |
| 87 | * @brief Determine if target is active |
| 88 | * |
| 89 | * This function determines if the target is active and |
| 90 | * helps prevent misleading log recorded states. |
| 91 | * |
| 92 | * @param[in] target - Target string to check on |
| 93 | * |
| 94 | * @return boolean corresponding to state active |
| 95 | **/ |
| 96 | bool stateActive(const std::string& target); |
| 97 | |
Andrew Geissler | 0029a5d | 2017-01-24 14:48:35 -0600 | [diff] [blame] | 98 | /** @brief Check if systemd state change is relevant to this object |
Andrew Geissler | 2ec3a7e | 2016-12-13 22:01:28 -0600 | [diff] [blame] | 99 | * |
Andrew Geissler | 0029a5d | 2017-01-24 14:48:35 -0600 | [diff] [blame] | 100 | * Instance specific interface to handle the detected systemd state |
| 101 | * change |
Andrew Geissler | 2ec3a7e | 2016-12-13 22:01:28 -0600 | [diff] [blame] | 102 | * |
Andrew Geissler | 0029a5d | 2017-01-24 14:48:35 -0600 | [diff] [blame] | 103 | * @param[in] msg - Data associated with subscribed signal |
Andrew Geissler | 2ec3a7e | 2016-12-13 22:01:28 -0600 | [diff] [blame] | 104 | * |
| 105 | */ |
Patrick Williams | 8f8ba39 | 2017-05-05 15:47:39 -0500 | [diff] [blame] | 106 | int sysStateChange(sdbusplus::message::message& msg); |
Andrew Geissler | 2ec3a7e | 2016-12-13 22:01:28 -0600 | [diff] [blame] | 107 | |
Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 108 | /** @brief Persistent sdbusplus DBus connection. */ |
| 109 | sdbusplus::bus::bus& bus; |
Andrew Geissler | 2ec3a7e | 2016-12-13 22:01:28 -0600 | [diff] [blame] | 110 | |
Andrew Geissler | 0029a5d | 2017-01-24 14:48:35 -0600 | [diff] [blame] | 111 | /** @brief Used to subscribe to dbus systemd signals **/ |
Patrick Williams | 8f8ba39 | 2017-05-05 15:47:39 -0500 | [diff] [blame] | 112 | sdbusplus::bus::match_t systemdSignals; |
Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | } // namespace manager |
| 116 | } // namespace state |
| 117 | } // namespace phosphor |