Matthew Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Matthew Barth | b803445 | 2017-02-17 16:39:46 -0600 | [diff] [blame] | 3 | #include <sdbusplus/bus.hpp> |
| 4 | #include "fan_properties.hpp" |
Matthew Barth | d640382 | 2017-02-17 17:10:19 -0600 | [diff] [blame] | 5 | #include "sensor_base.hpp" |
Matthew Barth | b803445 | 2017-02-17 16:39:46 -0600 | [diff] [blame] | 6 | |
Matthew Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 7 | |
| 8 | namespace phosphor |
| 9 | { |
| 10 | namespace fan |
| 11 | { |
| 12 | namespace presence |
| 13 | { |
| 14 | |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 15 | /** |
| 16 | * @brief Specifies the defined presence states of a fan enclosure |
| 17 | */ |
Matthew Barth | 8db0f6f | 2017-02-23 10:16:57 -0600 | [diff] [blame] | 18 | typedef enum presenceState |
| 19 | { |
| 20 | NOT_PRESENT, |
| 21 | PRESENT, |
| 22 | UNKNOWN |
| 23 | } presenceState; |
| 24 | |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 25 | /** |
| 26 | * @class FanEnclosure |
| 27 | * @brief OpenBMC fan enclosure inventory presence implementation |
| 28 | * @details Inventory is based on the fan enclosure being present or not. This |
| 29 | * class represents that fan enclosure and updates its presences status within |
| 30 | * its inventory object based on the status of all its sensors. |
| 31 | */ |
Matthew Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 32 | class FanEnclosure |
| 33 | { |
Matthew Barth | 1562ac7 | 2017-02-20 16:01:21 -0600 | [diff] [blame] | 34 | using Property = std::string; |
| 35 | using Value = sdbusplus::message::variant<bool, int64_t, std::string>; |
| 36 | // Association between property and its value |
| 37 | using PropertyMap = std::map<Property, Value>; |
| 38 | using Interface = std::string; |
| 39 | // Association between interface and the dbus property |
| 40 | using InterfaceMap = std::map<Interface, PropertyMap>; |
| 41 | using Object = sdbusplus::message::object_path; |
| 42 | // Association between object and the interface |
| 43 | using ObjectMap = std::map<Object, InterfaceMap>; |
| 44 | |
Matthew Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 45 | public: |
| 46 | FanEnclosure() = delete; |
| 47 | FanEnclosure(const FanEnclosure&) = delete; |
| 48 | FanEnclosure(FanEnclosure&&) = default; |
| 49 | FanEnclosure& operator=(const FanEnclosure&) = delete; |
Matthew Barth | b803445 | 2017-02-17 16:39:46 -0600 | [diff] [blame] | 50 | FanEnclosure& operator=(FanEnclosure&&) = delete; |
Matthew Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 51 | ~FanEnclosure() = default; |
| 52 | |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 53 | /** |
| 54 | * @brief Constructs Fan Enclosure Object |
| 55 | * |
| 56 | * @param[in] bus - Dbus bus object |
| 57 | * @param[in] fanProp - Fan enclosure properties |
| 58 | */ |
Matthew Barth | b803445 | 2017-02-17 16:39:46 -0600 | [diff] [blame] | 59 | FanEnclosure(sdbusplus::bus::bus& bus, |
| 60 | const phosphor::fan::Properties& fanProp) : |
| 61 | bus(bus), |
| 62 | invPath(std::get<0>(fanProp)), |
| 63 | fanDesc(std::get<1>(fanProp)) |
| 64 | { |
| 65 | //Add this fan to inventory |
Matthew Barth | 736d143 | 2017-02-20 16:09:21 -0600 | [diff] [blame] | 66 | updInventory(); |
Matthew Barth | b803445 | 2017-02-17 16:39:46 -0600 | [diff] [blame] | 67 | } |
| 68 | |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 69 | /** |
| 70 | * @brief Update inventory when the determined presence of this fan |
| 71 | * enclosure has changed |
| 72 | */ |
Matthew Barth | cd4f4d1 | 2017-02-17 17:48:56 -0600 | [diff] [blame] | 73 | void updInventory(); |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 74 | /** |
| 75 | * @brief Add a sensor association to this fan enclosure |
| 76 | * |
| 77 | * @param[in] sensor - Sensor associated to this fan enclosure |
| 78 | */ |
Matthew Barth | d640382 | 2017-02-17 17:10:19 -0600 | [diff] [blame] | 79 | void addSensor( |
| 80 | std::unique_ptr<Sensor>&& sensor); |
| 81 | |
Matthew Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 82 | private: |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 83 | /** @brief Connection for sdbusplus bus */ |
Matthew Barth | b803445 | 2017-02-17 16:39:46 -0600 | [diff] [blame] | 84 | sdbusplus::bus::bus& bus; |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 85 | /** @brief Inventory path for this fan enclosure */ |
Matthew Barth | b803445 | 2017-02-17 16:39:46 -0600 | [diff] [blame] | 86 | const std::string invPath; |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 87 | /** @brief Description used as 'PrettyName' on inventory object */ |
Matthew Barth | b803445 | 2017-02-17 16:39:46 -0600 | [diff] [blame] | 88 | const std::string fanDesc; |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 89 | /** @brief List of sensors associated with this fan enclosure */ |
Matthew Barth | d640382 | 2017-02-17 17:10:19 -0600 | [diff] [blame] | 90 | std::vector<std::unique_ptr<Sensor>> sensors; |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 91 | /** @brief Last known presence state of this fan enclosure */ |
Matthew Barth | 8db0f6f | 2017-02-23 10:16:57 -0600 | [diff] [blame] | 92 | presenceState presState = UNKNOWN; |
Matthew Barth | b803445 | 2017-02-17 16:39:46 -0600 | [diff] [blame] | 93 | |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 94 | /** |
| 95 | * @brief Get the current presence state based on all sensors |
| 96 | * |
| 97 | * @return Current presence state determined from all sensors |
| 98 | */ |
Matthew Barth | 8db0f6f | 2017-02-23 10:16:57 -0600 | [diff] [blame] | 99 | presenceState getCurPresState(); |
Matthew Barth | 736d143 | 2017-02-20 16:09:21 -0600 | [diff] [blame] | 100 | //TODO openbmc/openbmc#1299 - Move getInvService() to a utility file |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 101 | /** |
| 102 | * @brief Get the inventory service name from the mapper object |
| 103 | * |
| 104 | * @return The inventory manager service name |
| 105 | */ |
Matthew Barth | 736d143 | 2017-02-20 16:09:21 -0600 | [diff] [blame] | 106 | std::string getInvService(); |
Matthew Barth | 5c15b79 | 2017-03-01 11:17:00 -0600 | [diff] [blame] | 107 | /** |
| 108 | * @brief Construct the inventory object map |
| 109 | * |
| 110 | * @param[in] Current presence state |
| 111 | * |
| 112 | * @return The inventory object map to update inventory |
| 113 | */ |
Matthew Barth | 8db0f6f | 2017-02-23 10:16:57 -0600 | [diff] [blame] | 114 | ObjectMap getObjectMap(bool curPresState); |
Matthew Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 115 | |
| 116 | }; |
| 117 | |
| 118 | } // namespace presence |
| 119 | } // namespace fan |
| 120 | } // namespace phosphor |