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()
21             : _passiveListeningBus(std::move(sdbusplus::bus::new_default())),
22               _hostSensorBus(std::move(sdbusplus::bus::new_default()))
23         {
24             // Create a manger for the sensor root because we own it.
25             static constexpr auto SensorRoot = "/xyz/openbmc_project/extsensors";
26             sdbusplus::server::manager::manager(_hostSensorBus, SensorRoot);
27         }
28 
29         /*
30          * Add a Sensor to the Manager.
31          */
32         void addSensor(
33             std::string type,
34             std::string name,
35             std::unique_ptr<Sensor> sensor)
36         {
37             _sensorMap[name] = std::move(sensor);
38 
39             auto entry = _sensorTypeList.find(type);
40             if (entry == _sensorTypeList.end())
41             {
42                 _sensorTypeList[type] = {};
43             }
44 
45             _sensorTypeList[type].push_back(name);
46         }
47 
48         // TODO(venture): Should implement read/write by name.
49         std::unique_ptr<Sensor>& getSensor(std::string name)
50         {
51             return _sensorMap.at(name);
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 
72 std::shared_ptr<SensorManager> BuildSensors(
73     std::map<std::string, struct sensor>& Config);
74 
75 std::shared_ptr<SensorManager> BuildSensorsFromConfig(std::string& path);
76