blob: 6fcd27546a787ed6855c37d8e337662f39619593 [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:
James Feist1fe08952019-05-07 09:17:16 -070022 SensorManager(sdbusplus::bus::bus& pass, sdbusplus::bus::bus& host) :
23 _passiveListeningBus(&pass), _hostSensorBus(&host)
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070024 {
25 // manager gets its interface from the bus. :D
James Feist1fe08952019-05-07 09:17:16 -070026 sdbusplus::server::manager::manager(*_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 Ventureda4a5dd2018-08-31 09:42:48 -070048 sdbusplus::bus::bus& getPassiveBus(void)
49 {
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 Ventureda4a5dd2018-08-31 09:42:48 -070053 sdbusplus::bus::bus& getHostBus(void)
54 {
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
James Feist1fe08952019-05-07 09:17:16 -070062 sdbusplus::bus::bus* _passiveListeningBus;
63 sdbusplus::bus::bus* _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