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