Apollo 10.0
自动驾驶开放平台
apollo::bridge::UDPBridgeMultiReceiverComponent类 参考final

#include <udp_bridge_multi_receiver_component.h>

类 apollo::bridge::UDPBridgeMultiReceiverComponent 继承关系图:
apollo::bridge::UDPBridgeMultiReceiverComponent 的协作图:

Public 成员函数

 UDPBridgeMultiReceiverComponent ()
 
 ~UDPBridgeMultiReceiverComponent ()=default
 
bool Init () override
 
std::string Name () const
 
std::shared_ptr< ProtoDiserializedBufBaseCreateBridgeProtoBuf (const BridgeHeader &header)
 
bool IsProtoExist (const BridgeHeader &header)
 
bool IsTimeout (double time_stamp)
 
void MsgDispatcher ()
 
bool InitSession (uint16_t port)
 
bool MsgHandle (int fd)
 
- Public 成员函数 继承自 apollo::cyber::Component< M0, M1, M2, M3 >
 Component ()
 
 ~Component () override
 
bool Initialize (const ComponentConfig &config) override
 init the component by protobuf object.
 
bool Process (const std::shared_ptr< M0 > &msg0, const std::shared_ptr< M1 > &msg1, const std::shared_ptr< M2 > &msg2, const std::shared_ptr< M3 > &msg3)
 
- Public 成员函数 继承自 apollo::cyber::ComponentBase
virtual ~ComponentBase ()
 
virtual bool Initialize (const TimerComponentConfig &config)
 
virtual void Shutdown ()
 
template<typename T >
bool GetProtoConfig (T *config) const
 

额外继承的成员函数

- Public 类型 继承自 apollo::cyber::ComponentBase
template<typename M >
using Reader = cyber::Reader< M >
 
- Protected 成员函数 继承自 apollo::cyber::ComponentBase
virtual void Clear ()
 
const std::string & ConfigFilePath () const
 
void LoadConfigFiles (const ComponentConfig &config)
 
void LoadConfigFiles (const TimerComponentConfig &config)
 
- Protected 属性 继承自 apollo::cyber::ComponentBase
std::atomic< bool > is_shutdown_ = {false}
 
std::shared_ptr< Nodenode_ = nullptr
 
std::string config_file_path_ = ""
 
std::vector< std::shared_ptr< ReaderBase > > readers_
 

详细描述

在文件 udp_bridge_multi_receiver_component.h43 行定义.

构造及析构函数说明

◆ UDPBridgeMultiReceiverComponent()

apollo::bridge::UDPBridgeMultiReceiverComponent::UDPBridgeMultiReceiverComponent ( )

◆ ~UDPBridgeMultiReceiverComponent()

apollo::bridge::UDPBridgeMultiReceiverComponent::~UDPBridgeMultiReceiverComponent ( )
default

成员函数说明

◆ CreateBridgeProtoBuf()

std::shared_ptr< ProtoDiserializedBufBase > apollo::bridge::UDPBridgeMultiReceiverComponent::CreateBridgeProtoBuf ( const BridgeHeader header)

在文件 udp_bridge_multi_receiver_component.cc59 行定义.

60 {
61 std::shared_ptr<ProtoDiserializedBufBase> proto_buf;
62 if (IsTimeout(header.GetTimeStamp())) {
63 std::vector<std::shared_ptr<ProtoDiserializedBufBase>>::iterator itor =
64 proto_list_.begin();
65 for (; itor != proto_list_.end();) {
66 if ((*itor)->IsTheProto(header)) {
67 itor = proto_list_.erase(itor);
68 break;
69 }
70 ++itor;
71 }
72 return proto_buf;
73 }
74
75 for (auto proto : proto_list_) {
76 if (proto->IsTheProto(header)) {
77 return proto;
78 }
79 }
80
82 if (!proto_buf) {
83 return proto_buf;
84 }
85 proto_buf->Initialize(header, node_);
86 proto_list_.push_back(proto_buf);
87 return proto_buf;
88}
static std::shared_ptr< ProtoDiserializedBufBase > CreateObj(const BridgeHeader &header)
std::shared_ptr< Node > node_

◆ Init()

bool apollo::bridge::UDPBridgeMultiReceiverComponent::Init ( )
overridevirtual

实现了 apollo::cyber::ComponentBase.

在文件 udp_bridge_multi_receiver_component.cc29 行定义.

29 {
30 AINFO << "UDP bridge multi :receiver init, startin...";
32 if (!this->GetProtoConfig(&udp_bridge_remote)) {
33 AINFO << "load udp bridge component proto param failed";
34 return false;
35 }
36 bind_port_ = udp_bridge_remote.bind_port();
37 enable_timeout_ = udp_bridge_remote.enable_timeout();
38 ADEBUG << "UDP Bridge remote port is: " << bind_port_;
39
40 if (!InitSession((uint16_t)bind_port_)) {
41 return false;
42 }
43 ADEBUG << "initialize session successful.";
45 return true;
46}
bool GetProtoConfig(T *config) const
#define ADEBUG
Definition log.h:41
#define AINFO
Definition log.h:42

◆ InitSession()

bool apollo::bridge::UDPBridgeMultiReceiverComponent::InitSession ( uint16_t  port)

在文件 udp_bridge_multi_receiver_component.cc48 行定义.

48 {
49 return listener_->Initialize(
51}

◆ IsProtoExist()

bool apollo::bridge::UDPBridgeMultiReceiverComponent::IsProtoExist ( const BridgeHeader header)

在文件 udp_bridge_multi_receiver_component.cc90 行定义.

90 {
91 for (auto proto : proto_list_) {
92 if (proto->IsTheProto(header)) {
93 return true;
94 }
95 }
96 return false;
97}

◆ IsTimeout()

bool apollo::bridge::UDPBridgeMultiReceiverComponent::IsTimeout ( double  time_stamp)

在文件 udp_bridge_multi_receiver_component.cc99 行定义.

99 {
100 if (enable_timeout_ == false) {
101 return false;
102 }
103 double cur_time = apollo::cyber::Clock::NowInSeconds();
104 if (cur_time < time_stamp) {
105 return true;
106 }
107 if (FLAGS_timeout < cur_time - time_stamp) {
108 return true;
109 }
110 return false;
111}
static double NowInSeconds()
gets the current time in second.
Definition clock.cc:56

◆ MsgDispatcher()

void apollo::bridge::UDPBridgeMultiReceiverComponent::MsgDispatcher ( )

在文件 udp_bridge_multi_receiver_component.cc53 行定义.

53 {
54 ADEBUG << "msg dispatcher start successful.";
55 listener_->Listen();
56}

◆ MsgHandle()

bool apollo::bridge::UDPBridgeMultiReceiverComponent::MsgHandle ( int  fd)

在文件 udp_bridge_multi_receiver_component.cc113 行定义.

113 {
114 struct sockaddr_in client_addr;
115 socklen_t sock_len = static_cast<socklen_t>(sizeof(client_addr));
116 int total_recv = 2 * FRAME_SIZE;
117 char total_buf[2 * FRAME_SIZE] = {0};
118 int bytes =
119 static_cast<int>(recvfrom(fd, total_buf, total_recv, 0,
120 (struct sockaddr *)&client_addr, &sock_len));
121 if (bytes <= 0 || bytes > total_recv) {
122 return false;
123 }
124
125 if (strncmp(total_buf, BRIDGE_HEADER_FLAG, HEADER_FLAG_SIZE) != 0) {
126 AERROR << "Header flag didn't match!";
127 return false;
128 }
129 size_t offset = HEADER_FLAG_SIZE + 1;
130
131 const char *cursor = total_buf + offset;
132 hsize header_size = *(reinterpret_cast<const hsize *>(cursor));
133 offset += sizeof(hsize) + 1;
134
135 if (header_size < offset || header_size > FRAME_SIZE) {
136 AERROR << "header size is more than FRAME_SIZE!";
137 return false;
138 }
139
140 cursor = total_buf + offset;
141 size_t buf_size = header_size - offset;
142 BridgeHeader header;
143 if (!header.Diserialize(cursor, buf_size)) {
144 AERROR << "header diserialize failed!";
145 return false;
146 }
147
148 ADEBUG << "proto name : " << header.GetMsgName().c_str();
149 ADEBUG << "proto sequence num: " << header.GetMsgID();
150 ADEBUG << "proto total frames: " << header.GetTotalFrames();
151 ADEBUG << "proto frame index: " << header.GetIndex();
152
153 std::lock_guard<std::mutex> lock(mutex_);
154 std::shared_ptr<ProtoDiserializedBufBase> proto_buf =
155 CreateBridgeProtoBuf(header);
156 if (!proto_buf) {
157 return false;
158 }
159
160 cursor = total_buf + header_size;
161 if (header.GetFramePos() > header.GetMsgSize()) {
162 return false;
163 }
164 char *buf = proto_buf->GetBuf(header.GetFramePos());
165 // check cursor size
166 if (header.GetFrameSize() < 0 ||
167 header.GetFrameSize() > (total_recv - header_size)) {
168 return false;
169 }
170 // check buf size
171 if (header.GetFrameSize() > (header.GetMsgSize() - header.GetFramePos())) {
172 return false;
173 }
174 memcpy(buf, cursor, header.GetFrameSize());
175 proto_buf->UpdateStatus(header.GetIndex());
176 if (proto_buf->IsReadyDiserialize()) {
177 proto_buf->DiserializedAndPub();
178 RemoveInvalidBuf(proto_buf->GetMsgID(), proto_buf->GetMsgName());
179 RemoveItem(&proto_list_, proto_buf);
180 }
181 return true;
182}
std::shared_ptr< ProtoDiserializedBufBase > CreateBridgeProtoBuf(const BridgeHeader &header)
#define AERROR
Definition log.h:44
constexpr uint32_t FRAME_SIZE
Definition macro.h:36
constexpr char BRIDGE_HEADER_FLAG[]
constexpr size_t HEADER_FLAG_SIZE
bool RemoveItem(std::vector< T * > *list, const T *t)
Definition util.h:47

◆ Name()

std::string apollo::bridge::UDPBridgeMultiReceiverComponent::Name ( ) const
inline

在文件 udp_bridge_multi_receiver_component.h49 行定义.

49{ return FLAGS_bridge_module_name; }

该类的文档由以下文件生成: