#pragma once #include #include #include namespace inaf::oasbo::PacketMonitors { /** * @brief The BasePacketMonitor class is an abstract base class for packet monitors in the DAQ system. * * This class provides a common interface for packet monitoring functionality. * Derived classes must implement the monit(), printStats(), and reset() methods. * The class also provides methods to access and retrieve statistics related to the monitored packets. */ class BasePacketMonitor { protected: std::map stats; /**< A map to store statistics related to the monitored packets. */ public: /** * @brief Monitors a packet. * * This pure virtual method is used to monitor a packet. * Derived classes must implement this method to define the monitoring behavior. * * @param packet The packet to be monitored. */ virtual void monit(PacketLib::BasePacket &packet) = 0; /** * @brief Prints the statistics related to the monitored packets. * * This pure virtual method is used to print the statistics related to the monitored packets. * Derived classes must implement this method to define the printing behavior. */ virtual void printStats() = 0; /** * @brief Resets the statistics related to the monitored packets. * * This pure virtual method is used to reset the statistics related to the monitored packets. * Derived classes must implement this method to define the resetting behavior. */ virtual void reset() = 0; /** * @brief Retrieves the statistics map. * * This method returns the map containing the statistics related to the monitored packets. * * @return The map containing the statistics related to the monitored packets. */ virtual std::map getStatsMap() const { return stats; } /** * @brief Retrieves a specific statistic. * * This method retrieves a specific statistic from the statistics map. * If the statistic is not found, it returns std::nullopt. * * @param stat The name of the statistic to retrieve. * @return An optional string containing the value of the statistic, or std::nullopt if the statistic is not found. */ std::optional getStat(std::string stat) const { try { return this->stats.at(stat); } catch (const std::out_of_range&) { return std::nullopt; } } /** * @brief Default destructor. */ virtual ~BasePacketMonitor() = default; }; }