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