blob: 7f24e17056e3f1f57e71c5eaad9ab5d60fa68333 [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>
7#include <boost/asio/ip/tcp.hpp>
8
9#include <memory>
10
Andrew Jefferyfa500ae2021-05-21 16:46:36 +093011class NVMeContext : public std::enable_shared_from_this<NVMeContext>
Andrew Jefferydae6e182021-05-21 16:23:07 +093012{
Andrew Jefferyfa500ae2021-05-21 16:46:36 +093013 public:
Andrew Jefferydae6e182021-05-21 16:23:07 +093014 NVMeContext(boost::asio::io_service& io, int rootBus);
15
16 virtual ~NVMeContext();
17
Andrew Jefferyfa500ae2021-05-21 16:46:36 +093018 void addSensor(std::shared_ptr<NVMeSensor> sensor);
19 virtual void pollNVMeDevices();
20 virtual void close();
21 virtual void readAndProcessNVMeSensor();
22 virtual void processResponse(void* msg, size_t len);
Andrew Jefferydae6e182021-05-21 16:23:07 +093023
Andrew Jefferyfa500ae2021-05-21 16:46:36 +093024 private:
Andrew Jefferydae6e182021-05-21 16:23:07 +093025 boost::asio::deadline_timer scanTimer;
26 int rootBus; // Root bus for this drive
27 boost::asio::deadline_timer mctpResponseTimer;
28 boost::asio::ip::tcp::socket nvmeSlaveSocket;
29 std::list<std::shared_ptr<NVMeSensor>> sensors; // used as a poll queue
Andrew Jefferyfa500ae2021-05-21 16:46:36 +093030
31 void readResponse();
Andrew Jefferydae6e182021-05-21 16:23:07 +093032};
33
34using NVMEMap = boost::container::flat_map<int, std::shared_ptr<NVMeContext>>;
35
36namespace nvmeMCTP
37{
38void init(void);
39}
40
41NVMEMap& getNVMEMap(void);