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 | a9d1508 | 2021-05-24 13:55:12 +0930 | [diff] [blame] | 27 | virtual void pollNVMeDevices() |
| 28 | {} |
| 29 | |
| 30 | virtual void close() |
| 31 | { |
| 32 | scanTimer.cancel(); |
| 33 | } |
| 34 | |
| 35 | virtual void readAndProcessNVMeSensor() |
| 36 | {} |
| 37 | |
| 38 | virtual void processResponse(void* msg, size_t len) |
| 39 | { |
| 40 | (void)msg; |
| 41 | (void)len; |
| 42 | } |
| 43 | |
| 44 | protected: |
Andrew Jeffery | dae6e18 | 2021-05-21 16:23:07 +0930 | [diff] [blame] | 45 | boost::asio::deadline_timer scanTimer; |
Andrew Jeffery | a9d1508 | 2021-05-24 13:55:12 +0930 | [diff] [blame] | 46 | int rootBus; // Root bus for this drive |
Andrew Jeffery | dae6e18 | 2021-05-21 16:23:07 +0930 | [diff] [blame] | 47 | std::list<std::shared_ptr<NVMeSensor>> sensors; // used as a poll queue |
Andrew Jeffery | dae6e18 | 2021-05-21 16:23:07 +0930 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | using NVMEMap = boost::container::flat_map<int, std::shared_ptr<NVMeContext>>; |
| 51 | |
Andrew Jeffery | dae6e18 | 2021-05-21 16:23:07 +0930 | [diff] [blame] | 52 | NVMEMap& getNVMEMap(void); |