10 (*plugin)->Execute(data);
20 std::shared_ptr<rapidjson::Document>
config, udp::endpoint target_socket,
28 std::make_shared<std::function<
void(std::vector<uint8_t>)>>(std::bind(
35 (*plugin)->Shutdown();
39 ROS_DEBUG(
"Succeeded in unloading all plugins");
45 return {
false, 0,
"invalid config parameters"};
50 std::make_shared<std::function<void(std::vector<uint8_t>)>>(std::bind(
53 for (rapidjson::Value::ConstValueIterator itr =
config_->Begin();
55 if (!itr->HasMember(
"plugin_name"))
continue;
56 std::string plugin_name = (*itr)[
"plugin_name"].GetString();
61 std::shared_ptr<rapidjson::Document> parameter(
new rapidjson::Document);
62 parameter->CopyFrom(*itr, parameter->GetAllocator());
63 plugin->Initialize(std::move(parameter), callback);
65 ROS_DEBUG(
"plugin %s has been loaded successfully", plugin_name.c_str());
68 std::ostringstream stream;
69 stream <<
"Failed to load " << plugin_name << ex.what();
70 std::string message = stream.str();
71 char* data = (
char*)malloc(strlen(message.c_str()) + 1);
72 ROS_ERROR(
"plugin load error: %s", message.c_str());
73 strcpy(data, message.c_str());
74 return {.is_success =
false, 0, .error_message = (
const char*)data};
81 return {
true,
socket_->Port(),
""};
86 Component<fruit::Annotated<BinaryAnnotation, PluginRouterFactory>>
88 return createComponent()
89 .bind<fruit::Annotated<BinaryAnnotation, PluginRouter>,
virtual uint16_t Port() override
void observe_plugins(std::vector< uint8_t > data)
boost::shared_ptr< T > createInstance(const std::string &lookup_name)
std::function< std::unique_ptr< Socket >(udp::endpoint, std::shared_ptr< std::function< void(std::vector< uint8_t >)> >)> SocketFactory
void observe_socket(std::vector< uint8_t > data)
Component< fruit::Annotated< BinaryAnnotation, PluginRouterFactory > > getBinaryPluginRouterComponent()
pluginlib::ClassLoader< skyway_plugin::SkyWayBinaryPlugin > plugin_loader_
BinaryPluginRouter()=delete
std::shared_ptr< rapidjson::Document > config_
std::unique_ptr< Socket > socket_
udp::endpoint target_socket_
virtual PluginResult TryStart() override
Component< SocketFactory > getUdpSocketComponent()
std::vector< boost::shared_ptr< skyway_plugin::SkyWayBinaryPlugin > > plugins_