| #pragma once |
| |
| #include "MctpEndpoint.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 MctpDevice& other) = delete; |
| MctpReactorDevice(MctpDevice&& other) = delete; |
| ~MctpReactorDevice() override = default; |
| |
| 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; |
| 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<MctpEndpoint> endpoint; |
| std::unique_ptr<sdbusplus::bus::match_t> removeMatch; |
| }; |