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