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