Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 3 | #include "sensors/sensor.hpp" |
| 4 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 5 | #include <sdbusplus/bus.hpp> |
| 6 | #include <sdbusplus/server.hpp> |
Patrick Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame^] | 7 | |
| 8 | #include <map> |
| 9 | #include <memory> |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 10 | #include <string> |
| 11 | #include <vector> |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 12 | |
| 13 | /* |
| 14 | * The SensorManager holds all sensors across all zones. |
| 15 | */ |
| 16 | class SensorManager |
| 17 | { |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 18 | public: |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 19 | SensorManager(sdbusplus::bus::bus& pass, sdbusplus::bus::bus& host) : |
| 20 | _passiveListeningBus(&pass), _hostSensorBus(&host) |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 21 | { |
| 22 | // manager gets its interface from the bus. :D |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 23 | sdbusplus::server::manager::manager(*_hostSensorBus, SensorRoot); |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 24 | } |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 25 | |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 26 | SensorManager() = default; |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 27 | ~SensorManager() = default; |
| 28 | SensorManager(const SensorManager&) = delete; |
| 29 | SensorManager& operator=(const SensorManager&) = delete; |
| 30 | SensorManager(SensorManager&&) = default; |
| 31 | SensorManager& operator=(SensorManager&&) = default; |
Patrick Venture | fe75b19 | 2018-06-08 11:19:43 -0700 | [diff] [blame] | 32 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 33 | /* |
| 34 | * Add a Sensor to the Manager. |
| 35 | */ |
Patrick Venture | ffc5ca7 | 2018-10-30 22:34:53 -0700 | [diff] [blame] | 36 | void addSensor(const std::string& type, const std::string& name, |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 37 | std::unique_ptr<Sensor> sensor); |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 38 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 39 | // 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 Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 44 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 45 | sdbusplus::bus::bus& getPassiveBus(void) |
| 46 | { |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 47 | return *_passiveListeningBus; |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 48 | } |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 49 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 50 | sdbusplus::bus::bus& getHostBus(void) |
| 51 | { |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 52 | return *_hostSensorBus; |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 53 | } |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 54 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 55 | private: |
| 56 | std::map<std::string, std::unique_ptr<Sensor>> _sensorMap; |
| 57 | std::map<std::string, std::vector<std::string>> _sensorTypeList; |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 58 | |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 59 | sdbusplus::bus::bus* _passiveListeningBus; |
| 60 | sdbusplus::bus::bus* _hostSensorBus; |
Patrick Venture | fe75b19 | 2018-06-08 11:19:43 -0700 | [diff] [blame] | 61 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 62 | static constexpr auto SensorRoot = "/xyz/openbmc_project/extsensors"; |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 63 | }; |