17 #ifndef CYBER_NODE_READER_BASE_H_ 18 #define CYBER_NODE_READER_BASE_H_ 23 #include <unordered_map> 48 explicit ReaderBase(
const proto::RoleAttributes& role_attr)
58 virtual bool Init() = 0;
81 virtual bool Empty()
const = 0;
118 virtual void GetWriters(std::vector<proto::RoleAttributes>* writers) {}
167 template <
typename MessageT>
178 auto GetReceiver(
const proto::RoleAttributes& role_attr) ->
179 typename std::shared_ptr<transport::Receiver<MessageT>>;
182 std::unordered_map<std::string,
183 typename std::shared_ptr<transport::Receiver<MessageT>>>
185 std::mutex receiver_map_mutex_;
195 template <
typename MessageT>
198 template <
typename MessageT>
200 const proto::RoleAttributes& role_attr) ->
201 typename std::shared_ptr<transport::Receiver<MessageT>> {
202 std::lock_guard<std::mutex> lock(receiver_map_mutex_);
205 const std::string& channel_name = role_attr.channel_name();
206 if (receiver_map_.count(channel_name) == 0) {
207 receiver_map_[channel_name] =
209 role_attr, [](
const std::shared_ptr<MessageT>& msg,
211 const proto::RoleAttributes& reader_attr) {
215 TransPerf::DISPATCH, reader_attr.channel_id(),
218 reader_attr.channel_id(), msg);
220 TransPerf::NOTIFY, reader_attr.channel_id(),
224 return receiver_map_[channel_name];
230 #endif // CYBER_NODE_READER_BASE_H_
One Channel is related to one Receiver. ReceiverManager is in charge of attaching one Receiver to its...
Definition: reader_base.h:168
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
auto GetReceiver(const proto::RoleAttributes &role_attr) -> typename std::shared_ptr< transport::Receiver< MessageT >>
Get the Receiver object.
Definition: reader_base.h:199
std::atomic< bool > init_
Definition: reader_base.h:155
uint64_t ChannelId() const
Get Reader's Channel id.
Definition: reader_base.h:134
virtual uint32_t PendingQueueSize() const =0
Get the value of pending queue size.
const proto::QosProfile & QosProfile() const
Get qos profile. You can see qos description.
Definition: reader_base.h:141
#define DECLARE_SINGLETON(classname)
Definition: macros.h:52
const std::string & GetChannelName() const
Get Reader's Channel name.
Definition: reader_base.h:125
Definition: message_info.h:30
virtual bool HasWriter()
Query is there any writer that publish the subscribed channel.
Definition: reader_base.h:111
TransPerf
Definition: perf_event.h:34
virtual ~ReaderBase()
Definition: reader_base.h:50
Definition: global_data.h:40
Definition: perf_event_cache.h:36
~ReceiverManager()
Definition: reader_base.h:170
bool IsInit() const
Query whether the Reader is initialized.
Definition: reader_base.h:151
virtual void GetWriters(std::vector< proto::RoleAttributes > *writers)
Get all writers pushlish the channel we subscribes.
Definition: reader_base.h:118
Base Class for Reader Reader is identified by one apollo::cyber::proto::RoleAttribute, it contains the channel_name, channel_id that we subscribe, and host_name, process_id and node that we are located, and qos that describes our transportation quality.
Definition: reader_base.h:46
virtual void ClearData()=0
Clear local data.
virtual void Observe()=0
Get stored data.
virtual double GetDelaySec() const =0
Get time interval of since last receive message.
ReaderBase(const proto::RoleAttributes &role_attr)
Definition: reader_base.h:48
virtual bool Empty() const =0
Query whether the Reader has data to be handled.
virtual bool Init()=0
Init the Reader object.
proto::RoleAttributes role_attr_
Definition: reader_base.h:154
virtual bool HasReceived() const =0
Query whether we have received data since last clear.
virtual void Shutdown()=0
Shutdown the Reader object.