blob: da6f7e5120979c4ea8c66d39a9a01466d78777dc [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 Barth8db0f6f2017-02-23 10:16:57 -060015typedef enum presenceState
16{
17 NOT_PRESENT,
18 PRESENT,
19 UNKNOWN
20} presenceState;
21
Matthew Barth293477d2017-02-17 15:39:36 -060022class FanEnclosure
23{
Matthew Barth1562ac72017-02-20 16:01:21 -060024 using Property = std::string;
25 using Value = sdbusplus::message::variant<bool, int64_t, std::string>;
26 // Association between property and its value
27 using PropertyMap = std::map<Property, Value>;
28 using Interface = std::string;
29 // Association between interface and the dbus property
30 using InterfaceMap = std::map<Interface, PropertyMap>;
31 using Object = sdbusplus::message::object_path;
32 // Association between object and the interface
33 using ObjectMap = std::map<Object, InterfaceMap>;
34
Matthew Barth293477d2017-02-17 15:39:36 -060035 public:
36 FanEnclosure() = delete;
37 FanEnclosure(const FanEnclosure&) = delete;
38 FanEnclosure(FanEnclosure&&) = default;
39 FanEnclosure& operator=(const FanEnclosure&) = delete;
Matthew Barthb8034452017-02-17 16:39:46 -060040 FanEnclosure& operator=(FanEnclosure&&) = delete;
Matthew Barth293477d2017-02-17 15:39:36 -060041 ~FanEnclosure() = default;
42
Matthew Barthb8034452017-02-17 16:39:46 -060043 FanEnclosure(sdbusplus::bus::bus& bus,
44 const phosphor::fan::Properties& fanProp) :
45 bus(bus),
46 invPath(std::get<0>(fanProp)),
47 fanDesc(std::get<1>(fanProp))
48 {
49 //Add this fan to inventory
Matthew Barth736d1432017-02-20 16:09:21 -060050 updInventory();
Matthew Barthb8034452017-02-17 16:39:46 -060051 }
52
Matthew Barthcd4f4d12017-02-17 17:48:56 -060053 void updInventory();
Matthew Barthd6403822017-02-17 17:10:19 -060054 void addSensor(
55 std::unique_ptr<Sensor>&& sensor);
56
Matthew Barth293477d2017-02-17 15:39:36 -060057 private:
Matthew Barthb8034452017-02-17 16:39:46 -060058 sdbusplus::bus::bus& bus;
59 const std::string invPath;
60 const std::string fanDesc;
Matthew Barthd6403822017-02-17 17:10:19 -060061 std::vector<std::unique_ptr<Sensor>> sensors;
Matthew Barth8db0f6f2017-02-23 10:16:57 -060062 presenceState presState = UNKNOWN;
Matthew Barthb8034452017-02-17 16:39:46 -060063
Matthew Barth8db0f6f2017-02-23 10:16:57 -060064 presenceState getCurPresState();
Matthew Barth736d1432017-02-20 16:09:21 -060065 //TODO openbmc/openbmc#1299 - Move getInvService() to a utility file
66 std::string getInvService();
Matthew Barth8db0f6f2017-02-23 10:16:57 -060067 ObjectMap getObjectMap(bool curPresState);
Matthew Barth293477d2017-02-17 15:39:36 -060068
69};
70
71} // namespace presence
72} // namespace fan
73} // namespace phosphor