提交 5017c17e 编写于 作者: S siyangy 提交者: unacao

Dreamview: move readyToPush check to message handler (#1704)

上级 d434e688
......@@ -16,8 +16,6 @@
#include "modules/dreamview/backend/simulation_world/simulation_world_updater.h"
#include <string>
#include "google/protobuf/util/json_util.h"
#include "modules/dreamview/backend/common/dreamview_gflags.h"
#include "modules/map/hdmap/hdmap_util.h"
......@@ -100,6 +98,12 @@ SimulationWorldUpdater::SimulationWorldUpdater(WebSocketHandler *websocket,
websocket_->RegisterMessageHandler(
"RequestSimulationWorld",
[this](const Json &json, WebSocketHandler::Connection *conn) {
if (!sim_world_service_.ReadyToPush()) {
AWARN_EVERY(100)
<< "Not sending simulation world as the data is not ready!";
return;
}
std::string to_send;
{
// Pay the price to copy the data instead of sending data over the
......@@ -164,18 +168,12 @@ bool SimulationWorldUpdater::ConstructRoutingRequest(
void SimulationWorldUpdater::Start() {
// start ROS timer, one-shot = false, auto-start = true
timer_ =
AdapterManager::CreateTimer(ros::Duration(kSimWorldTimeInterval),
&SimulationWorldUpdater::OnPushTimer, this);
timer_ = AdapterManager::CreateTimer(ros::Duration(kSimWorldTimeInterval),
&SimulationWorldUpdater::OnTimer, this);
}
void SimulationWorldUpdater::OnPushTimer(const ros::TimerEvent &event) {
void SimulationWorldUpdater::OnTimer(const ros::TimerEvent &event) {
sim_world_service_.Update();
if (!sim_world_service_.ReadyToPush()) {
AWARN_EVERY(100)
<< "Not sending simulation world as the data is not ready!";
return;
}
{
boost::unique_lock<boost::shared_mutex> writer_lock(mutex_);
......
......@@ -23,6 +23,7 @@
#include <boost/thread/locks.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <string>
#include "modules/common/log.h"
#include "modules/dreamview/backend/map/map_service.h"
......@@ -64,11 +65,10 @@ class SimulationWorldUpdater {
private:
/**
* @brief The callback function to get updates from SimulationWorldService,
* and push them to the frontend clients via websocket when the periodic timer
* is triggered.
* and update simulation_world_json_.
* @param event Timer event
*/
void OnPushTimer(const ros::TimerEvent &event);
void OnTimer(const ros::TimerEvent &event);
/**
* @brief The function to construct a routing request from the given json,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册