Apollo 10.0
自动驾驶开放平台
plugin_manager.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2019 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
17#pragma once
18
19#include <deque>
20#include <map>
21#include <memory>
22#include <string>
23#include <vector>
24
25#include "modules/dreamview/proto/dv_plugin_msg.pb.h"
26#include "modules/dreamview/proto/plugin_config.pb.h"
27
28#include "cyber/cyber.h"
30
31using apollo::dreamview::ChannelConf;
32using apollo::dreamview::DvPluginMsg;
33using apollo::dreamview::PluginConfig;
34
35namespace apollo {
36namespace dreamview {
37struct PluginInfo {
38 std::string launch_command;
39 std::string stop_command;
40 // for writer
41 std::map<std::string, std::string> plugin_accept_msg;
42 std::vector<std::string> process_command_keywords;
43 // writer 指针 根据channel调用对应writer 去写信息
44 std::map<std::string, std::shared_ptr<cyber::Writer<DvPluginMsg>>> writers;
45 std::map<std::string, std::shared_ptr<cyber::Reader<DvPluginMsg>>> readers;
46};
48 public:
55 using DvApi = bool (PluginManager::*)(const DvPluginMsg& msg,
56 const std::string& json_str);
57 using DvCallback = std::function<bool(const std::string& function_name,
58 const nlohmann::json& param_json)>;
59
60 explicit PluginManager(WebSocketHandler* plugin_ws);
61
62 void Start(DvCallback callback_api);
63 void Stop();
64
65 bool IsEnabled() const { return true; }
66 bool SendMsgToPlugin(const std::string& json_str);
67
68 private:
69 bool RegisterPlugins();
70 bool RegisterPlugin(const std::shared_ptr<PluginConfig>& plugin_config);
71 auto InitPluginReader(const ChannelConf& channel_conf,
72 const std::string& channel_prefix,
73 const std::string& plugin_name)
74 -> std::shared_ptr<cyber::Reader<DvPluginMsg>>;
75 auto InitPluginWriterAndMsg(const ChannelConf& channel_conf,
76 const std::string& channel_prefix,
77 const std::string& plugin_name)
78 -> std::shared_ptr<cyber::Writer<DvPluginMsg>>;
79 bool CheckPluginStatus(const std::string& plugin_name);
80 void RegisterDvSupportApi(const std::string& api_name, const DvApi& api);
81 void RegisterDvSupportApis();
82 bool ReceiveMsgFromPlugin(const DvPluginMsg& msg);
83 bool UpdateData(const DvPluginMsg& msg, const std::string& json_str);
84 std::map<std::string, PluginInfo> plugins_;
85 std::unique_ptr<cyber::Node> node_;
86 bool enabled_;
87 WebSocketHandler* plugin_ws_ = nullptr;
88 std::map<std::string, DvApi> dv_support_apis_;
89 DvCallback callback_api_;
90};
91
92} // namespace dreamview
93} // namespace apollo
bool(PluginManager::*)(const DvPluginMsg &msg, const std::string &json_str) DvApi
void Start(DvCallback callback_api)
std::function< bool(const std::string &function_name, const nlohmann::json &param_json)> DvCallback
The WebSocketHandler, built on top of CivetWebSocketHandler, is a websocket handler that handles diff...
class register implement
Definition arena_queue.h:37
Definition future.h:29
std::map< std::string, std::shared_ptr< cyber::Reader< DvPluginMsg > > > readers
std::vector< std::string > process_command_keywords
std::map< std::string, std::string > plugin_accept_msg
std::map< std::string, std::shared_ptr< cyber::Writer< DvPluginMsg > > > writers