blob: 212a3555ea7a4a1cfd5945f9cdc107d87ff7656f [file]
#pragma once
#include "MctpEndpoint.hpp"
#include "MctpUtil.hpp"
#include <sdbusplus/asio/connection.hpp>
#include <sdbusplus/bus/match.hpp>
#include <sdbusplus/message.hpp>
/**
* @brief An implementation of MctpDevice in terms of D-Bus interfaces exposed
* by @c mctpreactor.
*
* The construction or destruction of an MctpReactorDevice is not required to be
* correlated with signals from @c mctpreactor. For instance, EntityManager may
* expose the existence of an MCTP-capable device through its usual
* configuration mechanisms.
*/
class MctpReactorDevice :
public MctpDevice,
public std::enable_shared_from_this<MctpReactorDevice>
{
public:
MctpReactorDevice() = delete;
MctpReactorDevice(
const std::shared_ptr<sdbusplus::asio::connection>& connection,
const std::string& deviceObjectPath, std::optional<int> busNumber,
std::optional<int> address);
MctpReactorDevice(
const std::shared_ptr<sdbusplus::asio::connection>& connection,
const std::string& deviceObjectPath, const BusInfo& busInfo,
std::optional<int> busNumber, std::optional<int> address);
MctpReactorDevice(const MctpDevice& other) = delete;
MctpReactorDevice(MctpDevice&& other) = delete;
~MctpReactorDevice() override;
void setup(std::function<void(const std::error_code& ec,
const std::shared_ptr<MctpEndpoint>& ep)>&&
action) override;
void remove() override;
std::string describe() const override;
private:
static void onEndpointInterfacesRemoved(
const std::weak_ptr<MctpReactorDevice>& weak,
const std::string& endpointObjectPath, sdbusplus::message_t& msg);
void finaliseEndpoint(
const std::string& endpointObjectPath,
std::function<void(const std::error_code& ec,
const std::shared_ptr<MctpEndpoint>& ep)>&& action);
void endpointRemoved();
std::shared_ptr<sdbusplus::asio::connection> connection;
const std::string deviceObjectPath;
std::string resolvedEndpointPath;
const std::string prettyObjectName; // Suffix of deviceObjectPath.
const bool isI2cAccessible;
const int i2cBusNumber; // Invalid if isI2cAccessible is false.
const int i2cAddress; // Invalid if isI2cAccessible is false.
std::shared_ptr<MctpdEndpoint> endpoint;
std::unique_ptr<sdbusplus::bus::match_t> removeMatch;
BusInfo targetBusInfo;
std::optional<MctpCallbackToken> callbackToken;
std::function<void(const std::error_code&,
const std::shared_ptr<MctpEndpoint>&)>
savedAction;
};