1 #pragma once
2 
3 #include "sensors/sensor.hpp"
4 
5 #include <sdbusplus/bus.hpp>
6 #include <sdbusplus/server.hpp>
7 
8 #include <map>
9 #include <memory>
10 #include <string>
11 #include <vector>
12 
13 namespace pid_control
14 {
15 
16 /*
17  * The SensorManager holds all sensors across all zones.
18  */
19 class SensorManager
20 {
21   public:
22     SensorManager(sdbusplus::bus_t& pass, sdbusplus::bus_t& host) :
23         _passiveListeningBus(&pass), _hostSensorBus(&host)
24     {
25         // manager gets its interface from the bus. :D
26         sdbusplus::server::manager_t(*_hostSensorBus, SensorRoot);
27     }
28 
29     SensorManager() = default;
30     ~SensorManager() = default;
31     SensorManager(const SensorManager&) = delete;
32     SensorManager& operator=(const SensorManager&) = delete;
33     SensorManager(SensorManager&&) = default;
34     SensorManager& operator=(SensorManager&&) = default;
35 
36     /*
37      * Add a Sensor to the Manager.
38      */
39     void addSensor(const std::string& type, const std::string& name,
40                    std::unique_ptr<Sensor> sensor);
41 
42     // TODO(venture): Should implement read/write by name.
43     Sensor* getSensor(const std::string& name) const
44     {
45         return _sensorMap.at(name).get();
46     }
47 
48     sdbusplus::bus_t& getPassiveBus(void)
49     {
50         return *_passiveListeningBus;
51     }
52 
53     sdbusplus::bus_t& getHostBus(void)
54     {
55         return *_hostSensorBus;
56     }
57 
58   private:
59     std::map<std::string, std::unique_ptr<Sensor>> _sensorMap;
60     std::map<std::string, std::vector<std::string>> _sensorTypeList;
61 
62     sdbusplus::bus_t* _passiveListeningBus;
63     sdbusplus::bus_t* _hostSensorBus;
64 
65     static constexpr auto SensorRoot = "/xyz/openbmc_project/extsensors";
66 };
67 
68 } // namespace pid_control
69