blob: 675b6c7c2579bdd92fba2eb9f75253bcfe30785a [file] [log] [blame]
#pragma once
#include "common/types.hpp"
#include "common/utils.hpp"
#include <libpldm/pldm.h>
#include <sdbusplus/bus/match.hpp>
#include <filesystem>
#include <initializer_list>
#include <vector>
namespace pldm
{
const std::string emptyUUID = "00000000-0000-0000-0000-000000000000";
constexpr const char* MCTPService = "xyz.openbmc_project.MCTP";
constexpr const char* MCTPInterface = "xyz.openbmc_project.MCTP.Endpoint";
constexpr const char* MCTPPath = "/xyz/openbmc_project/mctp";
/** @class MctpDiscoveryHandlerIntf
*
* This abstract class defines the APIs for MctpDiscovery class has common
* interface to execute function from different Manager Classes
*/
class MctpDiscoveryHandlerIntf
{
public:
virtual void handleMctpEndpoints(const MctpInfos& mctpInfos) = 0;
virtual void handleRemovedMctpEndpoints(const MctpInfos& mctpInfos) = 0;
virtual ~MctpDiscoveryHandlerIntf() {}
};
class MctpDiscovery
{
public:
MctpDiscovery() = delete;
MctpDiscovery(const MctpDiscovery&) = delete;
MctpDiscovery(MctpDiscovery&&) = delete;
MctpDiscovery& operator=(const MctpDiscovery&) = delete;
MctpDiscovery& operator=(MctpDiscovery&&) = delete;
~MctpDiscovery() = default;
/** @brief Constructs the MCTP Discovery object to handle discovery of
* MCTP enabled devices
*
* @param[in] bus - reference to systemd bus
* @param[in] list - initializer list to the MctpDiscoveryHandlerIntf
*/
explicit MctpDiscovery(
sdbusplus::bus::bus& bus,
std::initializer_list<MctpDiscoveryHandlerIntf*> list);
/** @brief reference to the systemd bus */
sdbusplus::bus_t& bus;
/** @brief Used to watch for new MCTP endpoints */
sdbusplus::bus::match_t mctpEndpointAddedSignal;
/** @brief Used to watch for the removed MCTP endpoints */
sdbusplus::bus::match_t mctpEndpointRemovedSignal;
/** @brief List of handlers need to notify when new MCTP
* Endpoint is Added/Removed */
std::vector<MctpDiscoveryHandlerIntf*> handlers;
/** @brief The existing MCTP endpoints */
MctpInfos existingMctpInfos;
/** @brief Callback function when MCTP endpoints addedInterface
* D-Bus signal raised.
*
* @param[in] msg - Data associated with subscribed signal
*/
void discoverEndpoints(sdbusplus::message_t& msg);
/** @brief Callback function when MCTP endpoint removedInterface
* D-Bus signal raised.
*
* @param[in] msg - Data associated with subscribed signal
*/
void removeEndpoints(sdbusplus::message_t& msg);
/** @brief Helper function to invoke registered handlers for
* the added MCTP endpoints
*
* @param[in] mctpInfos - information of discovered MCTP endpoints
*/
void handleMctpEndpoints(const MctpInfos& mctpInfos);
/** @brief Helper function to invoke registered handlers for
* the removed MCTP endpoints
*
* @param[in] mctpInfos - information of removed MCTP endpoints
*/
void handleRemovedMctpEndpoints(const MctpInfos& mctpInfos);
/** @brief Get list of MctpInfos in MCTP control interface.
*
* @param[in] mctpInfos - information of discovered MCTP endpoints
*/
void getMctpInfos(MctpInfos& mctpInfos);
/** @brief Get list of new MctpInfos in addedInterace D-Bus signal message.
*
* @param[in] msg - addedInterace D-Bus signal message
* @param[in] mctpInfos - information of added MCTP endpoints
*/
void getAddedMctpInfos(sdbusplus::message_t& msg, MctpInfos& mctpInfos);
/** @brief Add new MctpInfos to existingMctpInfos.
*
* @param[in] mctpInfos - information of new MCTP endpoints
*/
void addToExistingMctpInfos(const MctpInfos& mctpInfos);
/** @brief Erase the removed MCTP endpoint from existingMctpInfos.
*
* @param[in] mctpInfos - the remaining MCTP endpoints
* @param[out] removedInfos - the removed MCTP endpoints
*/
void removeFromExistingMctpInfos(MctpInfos& mctpInfos,
MctpInfos& removedInfos);
private:
static constexpr uint8_t mctpTypePLDM = 1;
};
} // namespace pldm