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

#include <plugin_manager.h>

apollo::dreamview::PluginManager 的协作图:

Public 类型

using DvApi = bool(PluginManager::*)(const DvPluginMsg &msg, const std::string &json_str)
 
using DvCallback = std::function< bool(const std::string &function_name, const nlohmann::json &param_json)>
 

Public 成员函数

 PluginManager (WebSocketHandler *plugin_ws)
 
void Start (DvCallback callback_api)
 
void Stop ()
 
bool IsEnabled () const
 
bool SendMsgToPlugin (const std::string &json_str)
 

详细描述

在文件 plugin_manager.h47 行定义.

成员类型定义说明

◆ DvApi

using apollo::dreamview::PluginManager::DvApi = bool (PluginManager::*)(const DvPluginMsg& msg, const std::string& json_str)

在文件 plugin_manager.h55 行定义.

◆ DvCallback

using apollo::dreamview::PluginManager::DvCallback = std::function<bool(const std::string& function_name, const nlohmann::json& param_json)>

在文件 plugin_manager.h57 行定义.

构造及析构函数说明

◆ PluginManager()

PluginManager::PluginManager ( WebSocketHandler plugin_ws)
explicit

在文件 plugin_manager.cc60 行定义.

61 : node_(cyber::CreateNode("PluginManager")),
62 enabled_(false),
63 plugin_ws_(plugin_ws) {
64 RegisterDvSupportApis();
65 RegisterPlugins();
66}
std::unique_ptr< Node > CreateNode(const std::string &node_name, const std::string &name_space)
Definition cyber.cc:33

成员函数说明

◆ IsEnabled()

bool apollo::dreamview::PluginManager::IsEnabled ( ) const
inline

在文件 plugin_manager.h65 行定义.

65{ return true; }

◆ SendMsgToPlugin()

bool PluginManager::SendMsgToPlugin ( const std::string &  json_str)

在文件 plugin_manager.cc293 行定义.

293 {
294 auto plugin_msg = std::make_shared<DvPluginMsg>();
295 if (!JsonStringToMessage(json_str, plugin_msg.get()).ok()) {
296 AERROR << "Failed to parse DvPluginMsg from json!";
297 return false;
298 }
299 // Cancel check requestId for dv_plus does not have this field
300 if (!plugin_msg->has_target() || !plugin_msg->has_name()) {
301 AERROR << "Missing required field for DvPluginMsg.";
302 return false;
303 }
304 const string plugin_name = plugin_msg->target();
305 if (!CheckPluginStatus(plugin_name)) {
306 return false;
307 }
308 const string msg_name = plugin_msg->name();
309
310 if (plugins_[plugin_name].plugin_accept_msg.find(msg_name) ==
311 plugins_[plugin_name].plugin_accept_msg.end()) {
312 AERROR << "Plugin not accept this msg!";
313 return false;
314 }
315 const string channel_location =
316 plugins_[plugin_name].plugin_accept_msg[msg_name];
317 if (plugins_[plugin_name].writers.find(channel_location) ==
318 plugins_[plugin_name].writers.end()) {
319 AERROR << "The plugin does not support communication on this channel";
320 return false;
321 }
322 FillHeader("PluginManager", plugin_msg.get());
323 plugins_[plugin_name].writers[channel_location]->Write(plugin_msg);
324 return true;
325}
#define AERROR
Definition log.h:44

◆ Start()

void PluginManager::Start ( DvCallback  callback_api)

在文件 plugin_manager.cc68 行定义.

68 {
69 callback_api_ = callback_api;
70 enabled_ = true;
71 return;
72}

◆ Stop()

void PluginManager::Stop ( )

在文件 plugin_manager.cc74 行定义.

74 {
75 if (enabled_) {
76 std::string stop_command;
77 for (auto iter = plugins_.begin(); iter != plugins_.end(); iter++) {
78 stop_command = iter->second.stop_command;
79 const int ret = std::system(stop_command.data());
80 if (ret != 0) {
81 AERROR << "Failed to stop plugin! ret: " << ret;
82 }
83 }
84 plugins_.clear();
85 // need kill all plugin process
86 }
87 enabled_ = false;
88}

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