blob: f7216f141687d5a181c16d300d0e5f0d228a91c5 [file] [log] [blame]
Andrew Jefferydae6e182021-05-21 16:23:07 +09301#pragma once
2
3#include "NVMeSensor.hpp"
4
5#include <boost/asio/deadline_timer.hpp>
6#include <boost/asio/io_service.hpp>
Andrew Jefferydae6e182021-05-21 16:23:07 +09307
8#include <memory>
9
Andrew Jefferyfa500ae2021-05-21 16:46:36 +093010class NVMeContext : public std::enable_shared_from_this<NVMeContext>
Andrew Jefferydae6e182021-05-21 16:23:07 +093011{
Andrew Jefferyfa500ae2021-05-21 16:46:36 +093012 public:
Andrew Jefferya9d15082021-05-24 13:55:12 +093013 NVMeContext(boost::asio::io_service& io, int rootBus) :
14 scanTimer(io), rootBus(rootBus)
15 {}
Andrew Jefferydae6e182021-05-21 16:23:07 +093016
Andrew Jefferya9d15082021-05-24 13:55:12 +093017 virtual ~NVMeContext()
18 {
19 close();
20 }
Andrew Jefferydae6e182021-05-21 16:23:07 +093021
Andrew Jefferya9d15082021-05-24 13:55:12 +093022 void addSensor(std::shared_ptr<NVMeSensor> sensor)
23 {
24 sensors.emplace_back(sensor);
25 }
Andrew Jefferydae6e182021-05-21 16:23:07 +093026
Andrew Jefferya9d15082021-05-24 13:55:12 +093027 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 Jefferydae6e182021-05-21 16:23:07 +093045 boost::asio::deadline_timer scanTimer;
Andrew Jefferya9d15082021-05-24 13:55:12 +093046 int rootBus; // Root bus for this drive
Andrew Jefferydae6e182021-05-21 16:23:07 +093047 std::list<std::shared_ptr<NVMeSensor>> sensors; // used as a poll queue
Andrew Jefferydae6e182021-05-21 16:23:07 +093048};
49
50using NVMEMap = boost::container::flat_map<int, std::shared_ptr<NVMeContext>>;
51
Andrew Jefferydae6e182021-05-21 16:23:07 +093052NVMEMap& getNVMEMap(void);