Apollo 11.0
自动驾驶开放平台
channels_updater.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2023 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
21#pragma once
22#include <memory>
23#include <string>
24#include <unordered_map>
25
26#include <boost/thread/locks.hpp>
27#include <boost/thread/shared_mutex.hpp>
28
29#include "cyber/common/log.h"
30#include "cyber/cyber.h"
37namespace apollo {
38namespace dreamview {
39
41
43 std::shared_ptr<apollo::cyber::Reader<RawMessage>> reader;
44 std::string channel_data_str;
46};
47
54 public:
55 using ReaderMap = std::unordered_map<std::string, ChannelUpdater>;
61 explicit ChannelsUpdater(WebSocketHandler *websocket);
62 ~ChannelsUpdater() override {
63 if (timer_initialized_) {
64 timer_->Stop();
65 }
66 }
67 void StartStream(const double &time_interval_ms,
68 const std::string &channel_name = "",
69 nlohmann::json *subscribe_param = nullptr) override;
70 void StopStream(const std::string& channel_name = "") override;
71 void PublishMessage(const std::string& channel_name = "") override;
72
73 private:
74 bool SubscribeChannel(const std::string &channel_name);
75 void ControlThrottle(bool add_lock);
76 bool GetThrottleFlag();
77 std::unique_ptr<cyber::Node> node_;
78 WebSocketHandler *websocket_ = nullptr;
79 ReaderMap channel_updaters_;
80 // Channel data stream string by channels.
81 bool timer_initialized_ = false;
82 // Add channel timer to control channel data stream frequency.
83 std::unique_ptr<cyber::Timer> timer_;
84 // Channel data stream throttle flag
85 bool throttle = false;
86 mutable boost::shared_mutex throttle_mutex_;
87};
88
89} // namespace dreamview
90} // namespace apollo
A wrapper around WebSocketHandler to keep pushing specified channels info to frontend via websocket.
void StopStream(const std::string &channel_name="") override
Stop data flow.
void StartStream(const double &time_interval_ms, const std::string &channel_name="", nlohmann::json *subscribe_param=nullptr) override
Start data flow.
std::unordered_map< std::string, ChannelUpdater > ReaderMap
void PublishMessage(const std::string &channel_name="") override
Publish Message to dreamview frontend.
Base Class for all data updater.
The WebSocketHandler, built on top of CivetWebSocketHandler, is a websocket handler that handles diff...
class register implement
Definition arena_queue.h:37
std::shared_ptr< apollo::cyber::Reader< RawMessage > > reader