Andrew Jeffery | dae6e18 | 2021-05-21 16:23:07 +0930 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "NVMeSensor.hpp" |
| 4 | |
| 5 | #include <boost/asio/deadline_timer.hpp> |
| 6 | #include <boost/asio/io_service.hpp> |
Andrew Jeffery | dae6e18 | 2021-05-21 16:23:07 +0930 | [diff] [blame] | 7 | |
| 8 | #include <memory> |
| 9 | |
Andrew Jeffery | fa500ae | 2021-05-21 16:46:36 +0930 | [diff] [blame] | 10 | class NVMeContext : public std::enable_shared_from_this<NVMeContext> |
Andrew Jeffery | dae6e18 | 2021-05-21 16:23:07 +0930 | [diff] [blame] | 11 | { |
Andrew Jeffery | fa500ae | 2021-05-21 16:46:36 +0930 | [diff] [blame] | 12 | public: |
Andrew Jeffery | a9d1508 | 2021-05-24 13:55:12 +0930 | [diff] [blame] | 13 | NVMeContext(boost::asio::io_service& io, int rootBus) : |
| 14 | scanTimer(io), rootBus(rootBus) |
| 15 | {} |
Andrew Jeffery | dae6e18 | 2021-05-21 16:23:07 +0930 | [diff] [blame] | 16 | |
Andrew Jeffery | a9d1508 | 2021-05-24 13:55:12 +0930 | [diff] [blame] | 17 | virtual ~NVMeContext() |
| 18 | { |
| 19 | close(); |
| 20 | } |
Andrew Jeffery | dae6e18 | 2021-05-21 16:23:07 +0930 | [diff] [blame] | 21 | |
Andrew Jeffery | a9d1508 | 2021-05-24 13:55:12 +0930 | [diff] [blame] | 22 | void addSensor(std::shared_ptr<NVMeSensor> sensor) |
| 23 | { |
| 24 | sensors.emplace_back(sensor); |
| 25 | } |
Andrew Jeffery | dae6e18 | 2021-05-21 16:23:07 +0930 | [diff] [blame] | 26 | |
Andrew Jeffery | 3db6f9c | 2021-12-08 10:55:47 +1030 | [diff] [blame] | 27 | std::optional<std::shared_ptr<NVMeSensor>> |
| 28 | getSensorAtPath(const std::string& path) |
| 29 | { |
| 30 | for (auto& sensor : sensors) |
| 31 | { |
| 32 | if (sensor->configurationPath == path) |
| 33 | { |
| 34 | return sensor; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | return std::nullopt; |
| 39 | } |
| 40 | |
| 41 | void removeSensor(std::shared_ptr<NVMeSensor> sensor) |
| 42 | { |
| 43 | sensors.remove(sensor); |
| 44 | } |
| 45 | |
Andrew Jeffery | a9d1508 | 2021-05-24 13:55:12 +0930 | [diff] [blame] | 46 | virtual void pollNVMeDevices() |
| 47 | {} |
| 48 | |
| 49 | virtual void close() |
| 50 | { |
| 51 | scanTimer.cancel(); |
| 52 | } |
| 53 | |
| 54 | virtual void readAndProcessNVMeSensor() |
| 55 | {} |
| 56 | |
| 57 | virtual void processResponse(void* msg, size_t len) |
| 58 | { |
| 59 | (void)msg; |
| 60 | (void)len; |
| 61 | } |
| 62 | |
| 63 | protected: |
Andrew Jeffery | dae6e18 | 2021-05-21 16:23:07 +0930 | [diff] [blame] | 64 | boost::asio::deadline_timer scanTimer; |
Andrew Jeffery | a9d1508 | 2021-05-24 13:55:12 +0930 | [diff] [blame] | 65 | int rootBus; // Root bus for this drive |
Andrew Jeffery | dae6e18 | 2021-05-21 16:23:07 +0930 | [diff] [blame] | 66 | std::list<std::shared_ptr<NVMeSensor>> sensors; // used as a poll queue |
Andrew Jeffery | dae6e18 | 2021-05-21 16:23:07 +0930 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | using NVMEMap = boost::container::flat_map<int, std::shared_ptr<NVMeContext>>; |
| 70 | |
Andrew Jeffery | dae6e18 | 2021-05-21 16:23:07 +0930 | [diff] [blame] | 71 | NVMEMap& getNVMEMap(void); |