#ifndef PORT_DISPATCHER_HPP_YZ0UTAUF #define PORT_DISPATCHER_HPP_YZ0UTAUF #include #include #include #include #include #include #include namespace vanetza { namespace btp { class PortDispatcher : public geonet::TransportInterface { public: class PromiscuousHook { public: /** * Called when a BTP packet is received, regardless of its destination port * \param indication BTP data indication * \param packet Read-only view of packet */ virtual void tap_packet(const DataIndication&, const UpPacket&) = 0; virtual ~PromiscuousHook() {} }; /** * Register a handler for incoming BTP-A (interactive) packets * \param port BTP-A destination port * \param interface Handler for given destination port * \note Use a nullptr as handler to disable dispatching of destination port * \note Only one handler can be registered per port */ void set_interactive_handler(port_type, IndicationInterface*); /** * Register a handler for incoming BTP-B (non-interactive) packets * \param port BTP-B destination port * \param interface Handler for given destination port * \note Use a nullptr as handler to disable dispatching of destination port * \note Only one handler can be registered per port */ void set_non_interactive_handler(port_type, IndicationInterface*); /** * Add a hook listening for all incoming BTP packets * \param hook A hook implementing the promiscuous hook interface * \note Each registered hook is invoked only once per indication */ void add_promiscuous_hook(PromiscuousHook* hook); /** * Remove promiscuous hook * \param hook pointer to previously added hook */ void remove_promiscuous_hook(PromiscuousHook*); // Implementation of geonet::TransportInterface void indicate(const geonet::DataIndication&, std::unique_ptr) override; /** * Hook invoked for all indicated but undispatched packets * \note BTP data indication can be nullptr */ Hook hook_undispatched; private: typedef std::unordered_map port_map; typedef std::list hook_list; port_map m_interactive_handlers; port_map m_non_interactive_handlers; hook_list m_promiscuous_hooks; }; } // namespace btp } // namespace vanetza #endif /* PORT_DISPATCHER_HPP_YZ0UTAUF */