blob: 9403fc58d1a237335e3d93ae38fa5e1891893e72 [file]
#pragma once
#include "MctpEndpoint.hpp"
#include "NVMeIntf.hpp"
#include "NVMeSubsys.hpp"
#include <chrono>
#include <memory>
class NVMeDevice : public std::enable_shared_from_this<NVMeDevice>
{
struct Private
{};
public:
static std::shared_ptr<NVMeDevice> create(const std::string& name,
NVMeIntf intf)
{
return std::make_shared<NVMeDevice>(Private(), name, std::move(intf));
}
static std::shared_ptr<NVMeDevice>
create(boost::asio::io_context& io, const std::string& name,
const std::shared_ptr<MctpDevice>& dev, NVMeIntf intf,
std::chrono::seconds gracePeriod = std::chrono::seconds(5))
{
return std::make_shared<NVMeDevice>(Private(), io, name, dev,
std::move(intf), gracePeriod);
}
NVMeDevice(Private /*unused*/, const std::string& name, NVMeIntf intf) :
name(name), intf(std::move(intf))
{}
NVMeDevice(Private /*unused*/, boost::asio::io_context& io,
const std::string& name, const std::shared_ptr<MctpDevice>& dev,
NVMeIntf intf, std::chrono::seconds gracePeriod) :
name(name), dev(dev), intf(std::move(intf)), timer(io),
gracePeriod{gracePeriod}
{}
~NVMeDevice() = default;
void start();
void stop();
private:
void setup();
void restart();
void degraded(const std::shared_ptr<MctpEndpoint>& ep);
void available(const std::shared_ptr<MctpEndpoint>& ep);
void removed(const std::shared_ptr<MctpEndpoint>& ep);
void finalize(const std::error_code& ec,
const std::shared_ptr<MctpEndpoint>& ep);
std::string name;
std::shared_ptr<MctpDevice> dev;
NVMeIntf intf;
std::optional<boost::asio::steady_timer> timer;
std::optional<std::chrono::seconds> gracePeriod;
bool recovering{};
bool gracePeriodActive{};
};