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