blob: e02e1c9776bfbfd062cd2c367a657d20ce34f162 [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
Patrick Venturea0764872020-08-08 07:48:43 -070013namespace pid_control
14{
15
Patrick Venture863b9242018-03-08 08:29:23 -080016/*
17 * The SensorManager holds all sensors across all zones.
18 */
19class SensorManager
20{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070021 public:
Patrick Williamsb228bc32022-07-22 19:26:56 -050022 SensorManager(sdbusplus::bus_t& pass, sdbusplus::bus_t& host) :
James Feist1fe08952019-05-07 09:17:16 -070023 _passiveListeningBus(&pass), _hostSensorBus(&host)
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070024 {
25 // manager gets its interface from the bus. :D
Patrick Williamsb228bc32022-07-22 19:26:56 -050026 sdbusplus::server::manager_t(*_hostSensorBus, SensorRoot);
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070027 }
Patrick Venture863b9242018-03-08 08:29:23 -080028
James Feist1fe08952019-05-07 09:17:16 -070029 SensorManager() = default;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070030 ~SensorManager() = default;
31 SensorManager(const SensorManager&) = delete;
32 SensorManager& operator=(const SensorManager&) = delete;
33 SensorManager(SensorManager&&) = default;
34 SensorManager& operator=(SensorManager&&) = default;
Patrick Venturefe75b192018-06-08 11:19:43 -070035
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070036 /*
37 * Add a Sensor to the Manager.
38 */
Patrick Ventureffc5ca72018-10-30 22:34:53 -070039 void addSensor(const std::string& type, const std::string& name,
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070040 std::unique_ptr<Sensor> sensor);
Patrick Venture863b9242018-03-08 08:29:23 -080041
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070042 // TODO(venture): Should implement read/write by name.
43 Sensor* getSensor(const std::string& name) const
44 {
45 return _sensorMap.at(name).get();
46 }
Patrick Venture863b9242018-03-08 08:29:23 -080047
Patrick Williamsb228bc32022-07-22 19:26:56 -050048 sdbusplus::bus_t& getPassiveBus(void)
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070049 {
James Feist1fe08952019-05-07 09:17:16 -070050 return *_passiveListeningBus;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070051 }
Patrick Venture863b9242018-03-08 08:29:23 -080052
Patrick Williamsb228bc32022-07-22 19:26:56 -050053 sdbusplus::bus_t& getHostBus(void)
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070054 {
James Feist1fe08952019-05-07 09:17:16 -070055 return *_hostSensorBus;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070056 }
Patrick Venture863b9242018-03-08 08:29:23 -080057
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070058 private:
59 std::map<std::string, std::unique_ptr<Sensor>> _sensorMap;
60 std::map<std::string, std::vector<std::string>> _sensorTypeList;
Patrick Venture863b9242018-03-08 08:29:23 -080061
Patrick Williamsb228bc32022-07-22 19:26:56 -050062 sdbusplus::bus_t* _passiveListeningBus;
63 sdbusplus::bus_t* _hostSensorBus;
Patrick Venturefe75b192018-06-08 11:19:43 -070064
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070065 static constexpr auto SensorRoot = "/xyz/openbmc_project/extsensors";
Patrick Venture863b9242018-03-08 08:29:23 -080066};
Patrick Venturea0764872020-08-08 07:48:43 -070067
68} // namespace pid_control