blob: 1c8d241da31fd81db7255010d57380c65304d322 [file] [log] [blame]
Matthew Barth293477d2017-02-17 15:39:36 -06001#pragma once
2
Matthew Barthb8034452017-02-17 16:39:46 -06003#include <sdbusplus/bus.hpp>
4#include "fan_properties.hpp"
Matthew Barthd6403822017-02-17 17:10:19 -06005#include "sensor_base.hpp"
Matthew Barthb8034452017-02-17 16:39:46 -06006
Matthew Barth293477d2017-02-17 15:39:36 -06007
8namespace phosphor
9{
10namespace fan
11{
12namespace presence
13{
14
Matthew Barth5c15b792017-03-01 11:17:00 -060015/**
16 * @brief Specifies the defined presence states of a fan enclosure
17 */
Matthew Barth8db0f6f2017-02-23 10:16:57 -060018typedef enum presenceState
19{
20 NOT_PRESENT,
21 PRESENT,
22 UNKNOWN
23} presenceState;
24
Matthew Barth5c15b792017-03-01 11:17:00 -060025/**
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 Barth293477d2017-02-17 15:39:36 -060032class FanEnclosure
33{
Matthew Barth1562ac72017-02-20 16:01:21 -060034 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 Barth293477d2017-02-17 15:39:36 -060045 public:
46 FanEnclosure() = delete;
47 FanEnclosure(const FanEnclosure&) = delete;
48 FanEnclosure(FanEnclosure&&) = default;
49 FanEnclosure& operator=(const FanEnclosure&) = delete;
Matthew Barthb8034452017-02-17 16:39:46 -060050 FanEnclosure& operator=(FanEnclosure&&) = delete;
Matthew Barth293477d2017-02-17 15:39:36 -060051 ~FanEnclosure() = default;
52
Matthew Barth5c15b792017-03-01 11:17:00 -060053 /**
54 * @brief Constructs Fan Enclosure Object
55 *
56 * @param[in] bus - Dbus bus object
57 * @param[in] fanProp - Fan enclosure properties
58 */
Matthew Barthb8034452017-02-17 16:39:46 -060059 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 Barth736d1432017-02-20 16:09:21 -060066 updInventory();
Matthew Barthb8034452017-02-17 16:39:46 -060067 }
68
Matthew Barth5c15b792017-03-01 11:17:00 -060069 /**
70 * @brief Update inventory when the determined presence of this fan
71 * enclosure has changed
72 */
Matthew Barthcd4f4d12017-02-17 17:48:56 -060073 void updInventory();
Matthew Barth5c15b792017-03-01 11:17:00 -060074 /**
75 * @brief Add a sensor association to this fan enclosure
76 *
77 * @param[in] sensor - Sensor associated to this fan enclosure
78 */
Matthew Barthd6403822017-02-17 17:10:19 -060079 void addSensor(
80 std::unique_ptr<Sensor>&& sensor);
81
Matthew Barth293477d2017-02-17 15:39:36 -060082 private:
Matthew Barth5c15b792017-03-01 11:17:00 -060083 /** @brief Connection for sdbusplus bus */
Matthew Barthb8034452017-02-17 16:39:46 -060084 sdbusplus::bus::bus& bus;
Matthew Barth5c15b792017-03-01 11:17:00 -060085 /** @brief Inventory path for this fan enclosure */
Matthew Barthb8034452017-02-17 16:39:46 -060086 const std::string invPath;
Matthew Barth5c15b792017-03-01 11:17:00 -060087 /** @brief Description used as 'PrettyName' on inventory object */
Matthew Barthb8034452017-02-17 16:39:46 -060088 const std::string fanDesc;
Matthew Barth5c15b792017-03-01 11:17:00 -060089 /** @brief List of sensors associated with this fan enclosure */
Matthew Barthd6403822017-02-17 17:10:19 -060090 std::vector<std::unique_ptr<Sensor>> sensors;
Matthew Barth5c15b792017-03-01 11:17:00 -060091 /** @brief Last known presence state of this fan enclosure */
Matthew Barth8db0f6f2017-02-23 10:16:57 -060092 presenceState presState = UNKNOWN;
Matthew Barthb8034452017-02-17 16:39:46 -060093
Matthew Barth5c15b792017-03-01 11:17:00 -060094 /**
95 * @brief Get the current presence state based on all sensors
96 *
97 * @return Current presence state determined from all sensors
98 */
Matthew Barth8db0f6f2017-02-23 10:16:57 -060099 presenceState getCurPresState();
Matthew Barth736d1432017-02-20 16:09:21 -0600100 //TODO openbmc/openbmc#1299 - Move getInvService() to a utility file
Matthew Barth5c15b792017-03-01 11:17:00 -0600101 /**
102 * @brief Get the inventory service name from the mapper object
103 *
104 * @return The inventory manager service name
105 */
Matthew Barth736d1432017-02-20 16:09:21 -0600106 std::string getInvService();
Matthew Barth5c15b792017-03-01 11:17:00 -0600107 /**
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 Barth8db0f6f2017-02-23 10:16:57 -0600114 ObjectMap getObjectMap(bool curPresState);
Matthew Barth293477d2017-02-17 15:39:36 -0600115
116};
117
118} // namespace presence
119} // namespace fan
120} // namespace phosphor