blob: f5ac50f8517da40015346240e3337df68ec601fa [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
Ed Tanousf8b6e552025-06-27 13:27:50 -07008#include <functional>
Patrick Venturea83a3ec2020-08-04 09:52:05 -07009#include <map>
10#include <memory>
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070011#include <string>
12#include <vector>
Patrick Venture863b9242018-03-08 08:29:23 -080013
Patrick Venturea0764872020-08-08 07:48:43 -070014namespace pid_control
15{
16
Patrick Venture863b9242018-03-08 08:29:23 -080017/*
18 * The SensorManager holds all sensors across all zones.
19 */
20class SensorManager
21{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070022 public:
Patrick Williamsb228bc32022-07-22 19:26:56 -050023 SensorManager(sdbusplus::bus_t& pass, sdbusplus::bus_t& host) :
Patrick Williamse3c60772025-04-07 17:53:42 -040024 _passiveListeningBus(pass), _hostSensorBus(host)
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070025 {
26 // manager gets its interface from the bus. :D
Patrick Williamse3c60772025-04-07 17:53:42 -040027 sdbusplus::server::manager_t(_hostSensorBus, SensorRoot);
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070028 }
Patrick Venture863b9242018-03-08 08:29:23 -080029
Patrick Williamse3c60772025-04-07 17:53:42 -040030 SensorManager() = delete;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070031 ~SensorManager() = default;
32 SensorManager(const SensorManager&) = delete;
33 SensorManager& operator=(const SensorManager&) = delete;
34 SensorManager(SensorManager&&) = default;
35 SensorManager& operator=(SensorManager&&) = default;
Patrick Venturefe75b192018-06-08 11:19:43 -070036
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070037 /*
38 * Add a Sensor to the Manager.
39 */
Patrick Ventureffc5ca72018-10-30 22:34:53 -070040 void addSensor(const std::string& type, const std::string& name,
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070041 std::unique_ptr<Sensor> sensor);
Patrick Venture863b9242018-03-08 08:29:23 -080042
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070043 // TODO(venture): Should implement read/write by name.
44 Sensor* getSensor(const std::string& name) const
45 {
46 return _sensorMap.at(name).get();
47 }
Patrick Venture863b9242018-03-08 08:29:23 -080048
Patrick Williamsb228bc32022-07-22 19:26:56 -050049 sdbusplus::bus_t& getPassiveBus(void)
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070050 {
Patrick Williamse3c60772025-04-07 17:53:42 -040051 return _passiveListeningBus;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070052 }
Patrick Venture863b9242018-03-08 08:29:23 -080053
Patrick Williamsb228bc32022-07-22 19:26:56 -050054 sdbusplus::bus_t& getHostBus(void)
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070055 {
Patrick Williamse3c60772025-04-07 17:53:42 -040056 return _hostSensorBus;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070057 }
Patrick Venture863b9242018-03-08 08:29:23 -080058
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070059 private:
60 std::map<std::string, std::unique_ptr<Sensor>> _sensorMap;
61 std::map<std::string, std::vector<std::string>> _sensorTypeList;
Patrick Venture863b9242018-03-08 08:29:23 -080062
Patrick Williamse3c60772025-04-07 17:53:42 -040063 std::reference_wrapper<sdbusplus::bus_t> _passiveListeningBus;
64 std::reference_wrapper<sdbusplus::bus_t> _hostSensorBus;
Patrick Venturefe75b192018-06-08 11:19:43 -070065
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070066 static constexpr auto SensorRoot = "/xyz/openbmc_project/extsensors";
Patrick Venture863b9242018-03-08 08:29:23 -080067};
Patrick Venturea0764872020-08-08 07:48:43 -070068
69} // namespace pid_control