Apollo 10.0
自动驾驶开放平台
udp_bridge_receiver_component.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16#pragma once
17
18#include <netinet/in.h>
19#include <sys/socket.h>
20
21#include <cstdlib>
22#include <iostream>
23#include <memory>
24#include <string>
25#include <vector>
26
27#include "modules/bridge/proto/udp_bridge_remote_info.pb.h"
28#include "modules/common_msgs/chassis_msgs/chassis.pb.h"
29
32#include "cyber/cyber.h"
33#include "cyber/init.h"
40
41namespace apollo {
42namespace bridge {
43
44#define RECEIVER_BRIDGE_COMPONENT_REGISTER(pb_msg) \
45 CYBER_REGISTER_COMPONENT(UDPBridgeReceiverComponent<pb_msg>)
46
47template <typename T>
49 public:
52
53 bool Init() override;
54
55 std::string Name() const { return FLAGS_bridge_module_name; }
56 bool MsgHandle(int fd);
57
58 private:
59 bool InitSession(uint16_t port);
60 void MsgDispatcher();
61 bool IsProtoExist(const BridgeHeader &header);
62 BridgeProtoDiserializedBuf<T> *CreateBridgeProtoBuf(
63 const BridgeHeader &header);
64 bool IsTimeout(double time_stamp);
65 bool RemoveInvalidBuf(uint32_t msg_id);
66
67 private:
68 common::monitor::MonitorLogBuffer monitor_logger_buffer_;
69 unsigned int bind_port_ = 0;
70 std::string proto_name_ = "";
71 std::string topic_name_ = "";
72 bool enable_timeout_ = true;
73 std::shared_ptr<cyber::Writer<T>> writer_;
74 std::mutex mutex_;
75
76 std::shared_ptr<UDPListener<UDPBridgeReceiverComponent<T>>> listener_ =
77 std::make_shared<UDPListener<UDPBridgeReceiverComponent<T>>>();
78
79 std::vector<BridgeProtoDiserializedBuf<T> *> proto_list_;
80};
81
83} // namespace bridge
84} // namespace apollo
The class of MonitorLogBuffer
class register implement
Definition arena_queue.h:37
#define RECEIVER_BRIDGE_COMPONENT_REGISTER(pb_msg)