17#ifndef CYBER_TRANSPORT_DISPATCHER_DISPATCHER_H_
18#define CYBER_TRANSPORT_DISPATCHER_DISPATCHER_H_
26#include <unordered_map>
28#include "cyber/proto/role_attributes.pb.h"
46using cyber::proto::RoleAttributes;
51template <
typename MessageT>
53 std::function<void(
const std::shared_ptr<MessageT>&,
const MessageInfo&)>;
62 template <
typename MessageT>
66 template <
typename MessageT>
71 template <
typename MessageT>
74 template <
typename MessageT>
87template <
typename MessageT>
95 std::shared_ptr<ListenerHandler<MessageT>> handler;
99 std::dynamic_pointer_cast<ListenerHandler<MessageT>>(*handler_base);
100 if (handler ==
nullptr) {
101 AERROR <<
"please ensure that readers with the same channel["
103 <<
"] in the same process have the same message type";
107 ADEBUG <<
"new reader for channel:"
112 handler->Connect(self_attr.
id(), listener);
115template <
typename MessageT>
124 std::shared_ptr<ListenerHandler<MessageT>> handler;
128 std::dynamic_pointer_cast<ListenerHandler<MessageT>>(*handler_base);
129 if (handler ==
nullptr) {
130 AERROR <<
"please ensure that readers with the same channel["
132 <<
"] in the same process have the same message type";
136 ADEBUG <<
"new reader for channel:"
141 handler->Connect(self_attr.
id(), opposite_attr.
id(), listener);
144template <
typename MessageT>
153 (*handler_base)->Disconnect(self_attr.
id());
157template <
typename MessageT>
167 (*handler_base)->Disconnect(self_attr.
id(), opposite_attr.
id());
A implementation of lock-free fixed size hash map
bool Get(K key, V **value)
static std::string GetChannelById(uint64_t id)
std::atomic< bool > is_shutdown_
void AddListener(const RoleAttributes &self_attr, const MessageListener< MessageT > &listener)
void RemoveListener(const RoleAttributes &self_attr)
bool HasChannel(uint64_t channel_id)
base::AtomicRWLock rw_lock_
AtomicHashMap< uint64_t, ListenerHandlerBasePtr > msg_listeners_
std::shared_ptr< ListenerHandlerBase > ListenerHandlerBasePtr
std::function< void(const std::shared_ptr< MessageT > &, const MessageInfo &)> MessageListener
std::shared_ptr< Dispatcher > DispatcherPtr
optional string channel_name
optional uint64 channel_id