summaryrefslogtreecommitdiffstats
path: root/presence/fan_enclosure.hpp
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@fuzziesquirrel.com>2017-04-22 14:19:45 -0400
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2017-04-24 22:53:58 -0400
commit9df0e16e00338ea267c71a2bf3c314d39e8961be (patch)
tree56bd9da5f66fe259267001c2dc4b27773c6eeecb /presence/fan_enclosure.hpp
parente73446e30576ad6dc734398ad2ca709f2263ad51 (diff)
downloadphosphor-fan-presence-9df0e16e00338ea267c71a2bf3c314d39e8961be.tar.gz
phosphor-fan-presence-9df0e16e00338ea267c71a2bf3c314d39e8961be.zip
build: Move presence to a subdirectory
Change-Id: I33b28922107b9b041de3699e4a6eebd3d05ebdef Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
Diffstat (limited to 'presence/fan_enclosure.hpp')
-rw-r--r--presence/fan_enclosure.hpp114
1 files changed, 114 insertions, 0 deletions
diff --git a/presence/fan_enclosure.hpp b/presence/fan_enclosure.hpp
new file mode 100644
index 0000000..8f5cfdf
--- /dev/null
+++ b/presence/fan_enclosure.hpp
@@ -0,0 +1,114 @@
+#pragma once
+
+#include <sdbusplus/bus.hpp>
+#include "fan_properties.hpp"
+#include "sensor_base.hpp"
+
+
+namespace phosphor
+{
+namespace fan
+{
+namespace presence
+{
+
+/**
+ * @brief Specifies the defined presence states of a fan enclosure
+ */
+typedef enum presenceState
+{
+ NOT_PRESENT,
+ PRESENT,
+ UNKNOWN
+} presenceState;
+
+/**
+ * @class FanEnclosure
+ * @brief OpenBMC fan enclosure inventory presence implementation
+ * @details Inventory is based on the fan enclosure being present or not. This
+ * class represents that fan enclosure and updates its presences status within
+ * its inventory object based on the status of all its sensors.
+ */
+class FanEnclosure
+{
+ using Property = std::string;
+ using Value = sdbusplus::message::variant<bool, int64_t, std::string>;
+ // Association between property and its value
+ using PropertyMap = std::map<Property, Value>;
+ using Interface = std::string;
+ // Association between interface and the dbus property
+ using InterfaceMap = std::map<Interface, PropertyMap>;
+ using Object = sdbusplus::message::object_path;
+ // Association between object and the interface
+ using ObjectMap = std::map<Object, InterfaceMap>;
+
+ public:
+ FanEnclosure() = delete;
+ FanEnclosure(const FanEnclosure&) = delete;
+ FanEnclosure(FanEnclosure&&) = default;
+ FanEnclosure& operator=(const FanEnclosure&) = delete;
+ FanEnclosure& operator=(FanEnclosure&&) = delete;
+ ~FanEnclosure() = default;
+
+ /**
+ * @brief Constructs Fan Enclosure Object
+ *
+ * @param[in] bus - Dbus bus object
+ * @param[in] fanProp - Fan enclosure properties
+ */
+ FanEnclosure(sdbusplus::bus::bus& bus,
+ const phosphor::fan::Properties& fanProp) :
+ bus(bus),
+ invPath(std::get<0>(fanProp)),
+ fanDesc(std::get<1>(fanProp))
+ {
+ //Add this fan to inventory
+ updInventory();
+ }
+
+ /**
+ * @brief Update inventory when the determined presence of this fan
+ * enclosure has changed
+ */
+ void updInventory();
+ /**
+ * @brief Add a sensor association to this fan enclosure
+ *
+ * @param[in] sensor - Sensor associated to this fan enclosure
+ */
+ void addSensor(
+ std::unique_ptr<Sensor>&& sensor);
+
+ private:
+ /** @brief Connection for sdbusplus bus */
+ sdbusplus::bus::bus& bus;
+ /** @brief Inventory path for this fan enclosure */
+ const std::string invPath;
+ /** @brief Description used as 'PrettyName' on inventory object */
+ const std::string fanDesc;
+ /** @brief List of sensors associated with this fan enclosure */
+ std::vector<std::unique_ptr<Sensor>> sensors;
+ /** @brief Last known presence state of this fan enclosure */
+ presenceState presState = UNKNOWN;
+
+ /**
+ * @brief Get the current presence state based on all sensors
+ *
+ * @return Current presence state determined from all sensors
+ */
+ presenceState getCurPresState();
+
+ /**
+ * @brief Construct the inventory object map
+ *
+ * @param[in] Current presence state
+ *
+ * @return The inventory object map to update inventory
+ */
+ ObjectMap getObjectMap(bool curPresState);
+
+};
+
+} // namespace presence
+} // namespace fan
+} // namespace phosphor
OpenPOWER on IntegriCloud