/** * @file include/ActivMiddleware/ActivFramework/KernelBypass/UdpReceiver.h * * @brief Header file for the base kernel bypass UdpReceiver class. */ #if (!defined ACTIV_FRAMEWORK_KERNEL_BYPASS_UDP_RECEIVER_H) #define ACTIV_FRAMEWORK_KERNEL_BYPASS_UDP_RECEIVER_H #include "ActivMiddleware/ActivFramework/External.h" #include "ActivMiddleware/ActivBase/Ip/UdpDatagramInfo.h" #include "ActivMiddleware/ActivFramework/KernelBypass/Mode.h" #include "ActivMiddleware/ActivFramework/KernelBypass/Statistics.h" #include "ActivMiddleware/CxxYZ/memory.h" //! Activ namespace. namespace Activ { // Forwards declarations. class ManagedEndPoint; //! KernelBypass namespace. namespace KernelBypass { class Distributor; class HardwareFilter; class UdpFilter; //! Class to receive data destined for a single UDP address/port. class UdpReceiver { public: //! OnDatagram callback function definition. typedef UdpDatagramCallbackFunction CallbackFunction; /** * @brief Construct a kernel bypass UDP receiver. The receiver will be initially disabled. * * @param managedEndPoint * @param mode * @param callbackFunction * @param interfaceAddress * @param destinationAddress * @param destinationPort * * @retval Pointer to a UdpReceiver if required for the mode. * * @throw Exception */ ACTIV_FRAMEWORK_API UdpReceiver(ManagedEndPoint &managedEndPoint, const Mode mode, const CallbackFunction &callbackFunction, const String &interfaceAddress, const String &destinationAddress, const uint16_t destinationPort); //! Destructor. ACTIV_FRAMEWORK_API ~UdpReceiver(); //! Enable the receiver. ACTIV_FRAMEWORK_API void Enable(); //! Disable the receiver. ACTIV_FRAMEWORK_API void Disable(); //! Is timestamping enabled? ACTIV_FRAMEWORK_API bool IsTimestampingEnabled() const; const UdpDatagramCallbackFunction &GetCallbackFunction() const; /** * @brief Enable logging per interface. * * This setting only takes effect when applied before any Receivers have been instantiated. * * @param managedEndPoint * @param isEnabled whether to enable interface logging. */ ACTIV_FRAMEWORK_API static void SetInterfaceLoggingEnabled(ManagedEndPoint &managedEndPoint, const bool isEnabled); /** * @brief Set a callback function to be invoked when the statistics have been logged. * * A callback will be received for each interface. * * @param managedEndPoint * @param callbackFunction a CxxYZ::function wrapping the callback. The parameters it receives are the interface name, * the statistics and a uint64_t containing the buffer peak packet size since the last callback for that interface. */ ACTIV_FRAMEWORK_API static void SetOnStatisticsLogCallback(ManagedEndPoint &managedEndPoint, const StatisticsLogCallback &callbackFunction); private: template void Initialize(ManagedEndPoint &managedEndPoint, const UdpFilter &udpFilter); Distributor * m_pDistributor; UdpDatagramCallbackFunction m_callbackFunction; int m_interfaceId; String m_interfaceName; bool m_isEnabled; ///< Whether this receiver is enabled. CxxYZ::unique_ptr m_pHardwareFilter; }; // --------------------------------------------------------------------------------------------------------------------------------- inline const UdpDatagramCallbackFunction &UdpReceiver::GetCallbackFunction() const { return m_callbackFunction; } } // namespace KernelBypass } // namespace Activ #endif // (!defined ACTIV_FRAMEWORK_KERNEL_BYPASS_UDP_RECEIVER_H)