Apollo 10.0
自动驾驶开放平台
apollo::dreamview::ChannelsUpdater类 参考

A wrapper around WebSocketHandler to keep pushing specified channels info to frontend via websocket. 更多...

#include <channels_updater.h>

类 apollo::dreamview::ChannelsUpdater 继承关系图:
apollo::dreamview::ChannelsUpdater 的协作图:

Public 类型

using ReaderMap = std::unordered_map< std::string, ChannelUpdater >
 

Public 成员函数

 ChannelsUpdater (WebSocketHandler *websocket)
 Constructor with the websocket handler.
 
 ~ChannelsUpdater () override
 
void StartStream (const double &time_interval_ms, const std::string &channel_name="", nlohmann::json *subscribe_param=nullptr) override
 Start data flow.
 
void StopStream (const std::string &channel_name="") override
 Stop data flow.
 
void PublishMessage (const std::string &channel_name="") override
 Publish Message to dreamview frontend.
 
- Public 成员函数 继承自 apollo::dreamview::UpdaterBase
 UpdaterBase ()
 Updaterbase
 
virtual ~UpdaterBase ()
 

详细描述

A wrapper around WebSocketHandler to keep pushing specified channels info to frontend via websocket.

在文件 channels_updater.h53 行定义.

成员类型定义说明

◆ ReaderMap

using apollo::dreamview::ChannelsUpdater::ReaderMap = std::unordered_map<std::string, ChannelUpdater>

在文件 channels_updater.h55 行定义.

构造及析构函数说明

◆ ChannelsUpdater()

apollo::dreamview::ChannelsUpdater::ChannelsUpdater ( WebSocketHandler websocket)
explicit

Constructor with the websocket handler.

参数
websocketPointer of the websocket handler that has been attached to the server.

在文件 channels_updater.cc36 行定义.

37 : node_(cyber::CreateNode("channels_info_updater")),
38 websocket_(websocket) {}
std::unique_ptr< Node > CreateNode(const std::string &node_name, const std::string &name_space)
Definition cyber.cc:33

◆ ~ChannelsUpdater()

apollo::dreamview::ChannelsUpdater::~ChannelsUpdater ( )
inlineoverride

在文件 channels_updater.h62 行定义.

62 {
63 if (timer_initialized_) {
64 timer_->Stop();
65 }
66 }

成员函数说明

◆ PublishMessage()

void apollo::dreamview::ChannelsUpdater::PublishMessage ( const std::string &  channel_name = "")
overridevirtual

Publish Message to dreamview frontend.

实现了 apollo::dreamview::UpdaterBase.

在文件 channels_updater.cc40 行定义.

40 {
41 if (channel_updaters_.count(channel_name) == 0) {
42 AERROR << "Failed to publish channel info for channel has not been "
43 "registered!";
44 return;
45 }
46 if (GetThrottleFlag()) {
47 // Can continue to send data stream
48 return;
49 }
50 // lock to avoid excessive stream data
51 ControlThrottle(true);
52 std::string channel_data_str =
53 channel_updaters_[channel_name].channel_data_str;
54 StreamData stream_data;
55 std::string stream_data_string;
56 stream_data.set_action("stream");
57 stream_data.set_data_name("cyber");
58 std::vector<uint8_t> byte_data(channel_data_str.begin(),
59 channel_data_str.end());
60 stream_data.set_data(&(byte_data[0]), byte_data.size());
61 stream_data.set_type("cyber");
62 stream_data.set_channel_name(channel_name);
63 stream_data.SerializeToString(&stream_data_string);
64 websocket_->BroadcastBinaryData(stream_data_string);
65}
bool BroadcastBinaryData(const std::string &data, bool skippable=false)
Sends the provided binary data to all the connected clients.
#define AERROR
Definition log.h:44

◆ StartStream()

void apollo::dreamview::ChannelsUpdater::StartStream ( const double &  time_interval_ms,
const std::string &  channel_name = "",
nlohmann::json *  subscribe_param = nullptr 
)
overridevirtual

Start data flow.

参数
time_interval_msData stream sending frequency. 0 means single subscribe
subscribe_paramsubscribe some updater may need extra params

实现了 apollo::dreamview::UpdaterBase.

在文件 channels_updater.cc79 行定义.

81 {
82 if (!timer_initialized_) {
83 timer_.reset(new cyber::Timer(
84 time_interval_ms, [this]() { this->ControlThrottle(false); }, false));
85 timer_->Start();
86 }
87 SubscribeChannel(channel_name);
88}

◆ StopStream()

void apollo::dreamview::ChannelsUpdater::StopStream ( const std::string &  channel_name = "")
overridevirtual

Stop data flow.

实现了 apollo::dreamview::UpdaterBase.

在文件 channels_updater.cc113 行定义.

113 {
114 if (channel_name.empty()) {
115 AERROR << "Unsubscribe channelsInfo must bring channel param.";
116 return;
117 }
118 if (channel_updaters_.count(channel_name) == 0) {
119 AERROR << "This channel is unsubscribed,no need to unsubscribe.";
120 return;
121 }
122 node_->DeleteReader(channel_name);
123 channel_updaters_.erase(channel_name);
124 return;
125}

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