blob: 411b3021da8cc766fe6e30fe3ecf2d757f295933 [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 <map>
6#include <memory>
7#include <sdbusplus/bus.hpp>
8#include <sdbusplus/server.hpp>
9#include <string>
10#include <vector>
Patrick Venture863b9242018-03-08 08:29:23 -080011
12/*
13 * The SensorManager holds all sensors across all zones.
14 */
15class SensorManager
16{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070017 public:
James Feist1fe08952019-05-07 09:17:16 -070018 SensorManager(sdbusplus::bus::bus& pass, sdbusplus::bus::bus& host) :
19 _passiveListeningBus(&pass), _hostSensorBus(&host)
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070020 {
21 // manager gets its interface from the bus. :D
James Feist1fe08952019-05-07 09:17:16 -070022 sdbusplus::server::manager::manager(*_hostSensorBus, SensorRoot);
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070023 }
Patrick Venture863b9242018-03-08 08:29:23 -080024
James Feist1fe08952019-05-07 09:17:16 -070025 SensorManager() = default;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070026 ~SensorManager() = default;
27 SensorManager(const SensorManager&) = delete;
28 SensorManager& operator=(const SensorManager&) = delete;
29 SensorManager(SensorManager&&) = default;
30 SensorManager& operator=(SensorManager&&) = default;
Patrick Venturefe75b192018-06-08 11:19:43 -070031
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070032 /*
33 * Add a Sensor to the Manager.
34 */
Patrick Ventureffc5ca72018-10-30 22:34:53 -070035 void addSensor(const std::string& type, const std::string& name,
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070036 std::unique_ptr<Sensor> sensor);
Patrick Venture863b9242018-03-08 08:29:23 -080037
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070038 // TODO(venture): Should implement read/write by name.
39 Sensor* getSensor(const std::string& name) const
40 {
41 return _sensorMap.at(name).get();
42 }
Patrick Venture863b9242018-03-08 08:29:23 -080043
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070044 sdbusplus::bus::bus& getPassiveBus(void)
45 {
James Feist1fe08952019-05-07 09:17:16 -070046 return *_passiveListeningBus;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070047 }
Patrick Venture863b9242018-03-08 08:29:23 -080048
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070049 sdbusplus::bus::bus& getHostBus(void)
50 {
James Feist1fe08952019-05-07 09:17:16 -070051 return *_hostSensorBus;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070052 }
Patrick Venture863b9242018-03-08 08:29:23 -080053
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070054 private:
55 std::map<std::string, std::unique_ptr<Sensor>> _sensorMap;
56 std::map<std::string, std::vector<std::string>> _sensorTypeList;
Patrick Venture863b9242018-03-08 08:29:23 -080057
James Feist1fe08952019-05-07 09:17:16 -070058 sdbusplus::bus::bus* _passiveListeningBus;
59 sdbusplus::bus::bus* _hostSensorBus;
Patrick Venturefe75b192018-06-08 11:19:43 -070060
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070061 static constexpr auto SensorRoot = "/xyz/openbmc_project/extsensors";
Patrick Venture863b9242018-03-08 08:29:23 -080062};