Vanetza
 
Loading...
Searching...
No Matches
port_dispatcher.hpp
1#ifndef PORT_DISPATCHER_HPP_YZ0UTAUF
2#define PORT_DISPATCHER_HPP_YZ0UTAUF
3
4#include <vanetza/btp/data_interface.hpp>
5#include <vanetza/btp/header.hpp>
6#include <vanetza/common/hook.hpp>
7#include <vanetza/geonet/transport_interface.hpp>
8#include <vanetza/net/packet.hpp>
9#include <list>
10#include <unordered_map>
11
12namespace vanetza
13{
14
15namespace btp
16{
17
19{
20public:
22 {
23 public:
24 /**
25 * Called when a BTP packet is received, regardless of its destination port
26 * \param indication BTP data indication
27 * \param packet Read-only view of packet
28 */
29 virtual void tap_packet(const DataIndication&, const UpPacket&) = 0;
30 virtual ~PromiscuousHook() {}
31 };
32
33 /**
34 * Register a handler for incoming BTP-A (interactive) packets
35 * \param port BTP-A destination port
36 * \param interface Handler for given destination port
37 * \note Use a nullptr as handler to disable dispatching of destination port
38 * \note Only one handler can be registered per port
39 */
41
42 /**
43 * Register a handler for incoming BTP-B (non-interactive) packets
44 * \param port BTP-B destination port
45 * \param interface Handler for given destination port
46 * \note Use a nullptr as handler to disable dispatching of destination port
47 * \note Only one handler can be registered per port
48 */
50
51 /**
52 * Add a hook listening for all incoming BTP packets
53 * \param hook A hook implementing the promiscuous hook interface
54 * \note Each registered hook is invoked only once per indication
55 */
56 void add_promiscuous_hook(PromiscuousHook* hook);
57
58 /**
59 * Remove promiscuous hook
60 * \param hook pointer to previously added hook
61 */
62 void remove_promiscuous_hook(PromiscuousHook*);
63
64 // Implementation of geonet::TransportInterface
65 void indicate(const geonet::DataIndication&, std::unique_ptr<UpPacket>) override;
66
67 /**
68 * Hook invoked for all indicated but undispatched packets
69 * \note BTP data indication can be nullptr
70 */
72
73private:
74 typedef std::unordered_map<port_type, IndicationInterface*> port_map;
75 typedef std::list<PromiscuousHook*> hook_list;
76
77 port_map m_interactive_handlers;
78 port_map m_non_interactive_handlers;
79 hook_list m_promiscuous_hooks;
80};
81
82} // namespace btp
83} // namespace vanetza
84
85#endif /* PORT_DISPATCHER_HPP_YZ0UTAUF */
86
virtual void tap_packet(const DataIndication &, const UpPacket &)=0
void add_promiscuous_hook(PromiscuousHook *hook)
void remove_promiscuous_hook(PromiscuousHook *)
void set_interactive_handler(port_type, IndicationInterface *)
Hook< const geonet::DataIndication &, const btp::DataIndication * > hook_undispatched
void set_non_interactive_handler(port_type, IndicationInterface *)