blob: 740ef00f37fe025a4cc03d0a1909d10b92ac165f [file] [log] [blame]
Patrick Venture863b9242018-03-08 08:29:23 -08001#pragma once
2
Patrick Venture863b9242018-03-08 08:29:23 -08003#include "sensors/sensor.hpp"
4
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07005#include <sdbusplus/bus.hpp>
6#include <sdbusplus/server.hpp>
Patrick Venturea83a3ec2020-08-04 09:52:05 -07007
8#include <map>
9#include <memory>
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070010#include <string>
11#include <vector>
Patrick Venture863b9242018-03-08 08:29:23 -080012
13/*
14 * The SensorManager holds all sensors across all zones.
15 */
16class SensorManager
17{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070018 public:
James Feist1fe08952019-05-07 09:17:16 -070019 SensorManager(sdbusplus::bus::bus& pass, sdbusplus::bus::bus& host) :
20 _passiveListeningBus(&pass), _hostSensorBus(&host)
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070021 {
22 // manager gets its interface from the bus. :D
James Feist1fe08952019-05-07 09:17:16 -070023 sdbusplus::server::manager::manager(*_hostSensorBus, SensorRoot);
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070024 }
Patrick Venture863b9242018-03-08 08:29:23 -080025
James Feist1fe08952019-05-07 09:17:16 -070026 SensorManager() = default;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070027 ~SensorManager() = default;
28 SensorManager(const SensorManager&) = delete;
29 SensorManager& operator=(const SensorManager&) = delete;
30 SensorManager(SensorManager&&) = default;
31 SensorManager& operator=(SensorManager&&) = default;
Patrick Venturefe75b192018-06-08 11:19:43 -070032
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070033 /*
34 * Add a Sensor to the Manager.
35 */
Patrick Ventureffc5ca72018-10-30 22:34:53 -070036 void addSensor(const std::string& type, const std::string& name,
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070037 std::unique_ptr<Sensor> sensor);
Patrick Venture863b9242018-03-08 08:29:23 -080038
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070039 // TODO(venture): Should implement read/write by name.
40 Sensor* getSensor(const std::string& name) const
41 {
42 return _sensorMap.at(name).get();
43 }
Patrick Venture863b9242018-03-08 08:29:23 -080044
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070045 sdbusplus::bus::bus& getPassiveBus(void)
46 {
James Feist1fe08952019-05-07 09:17:16 -070047 return *_passiveListeningBus;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070048 }
Patrick Venture863b9242018-03-08 08:29:23 -080049
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070050 sdbusplus::bus::bus& getHostBus(void)
51 {
James Feist1fe08952019-05-07 09:17:16 -070052 return *_hostSensorBus;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070053 }
Patrick Venture863b9242018-03-08 08:29:23 -080054
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070055 private:
56 std::map<std::string, std::unique_ptr<Sensor>> _sensorMap;
57 std::map<std::string, std::vector<std::string>> _sensorTypeList;
Patrick Venture863b9242018-03-08 08:29:23 -080058
James Feist1fe08952019-05-07 09:17:16 -070059 sdbusplus::bus::bus* _passiveListeningBus;
60 sdbusplus::bus::bus* _hostSensorBus;
Patrick Venturefe75b192018-06-08 11:19:43 -070061
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070062 static constexpr auto SensorRoot = "/xyz/openbmc_project/extsensors";
Patrick Venture863b9242018-03-08 08:29:23 -080063};