9 std::string message(data.begin(), data.end());
12 (*plugin)->Execute(message);
17 std::vector<uint8_t> data(message.begin(), message.end());
23 std::shared_ptr<rapidjson::Document>
config, udp::endpoint target_socket,
31 std::make_shared<std::function<
void(std::vector<uint8_t>)>>(std::bind(
38 (*plugin)->Shutdown();
42 ROS_DEBUG(
"Succeeded in unloading all plugins");
49 return {
false, 0,
"invalid config parameters"};
52 auto callback = std::make_shared<std::function<void(std::string)>>(std::bind(
55 for (rapidjson::Value::ConstValueIterator itr =
config_->Begin();
57 if (!itr->HasMember(
"plugin_name"))
continue;
58 std::string plugin_name = (*itr)[
"plugin_name"].GetString();
63 std::shared_ptr<rapidjson::Document> parameter(
new rapidjson::Document);
64 parameter->CopyFrom(*itr, parameter->GetAllocator());
65 plugin->Initialize(std::move(parameter), callback);
66 ROS_DEBUG(
"plugin %s has been loaded successfully", plugin_name.c_str());
70 std::ostringstream stream;
71 stream <<
"Failed to load " << plugin_name << ex.what();
72 std::string message = stream.str();
73 char* data = (
char*)malloc(strlen(message.c_str()) + 1);
74 ROS_ERROR(
"plugin load error: %s", message.c_str());
75 strcpy(data, message.c_str());
76 return {
false, 0, (
const char*)data};
83 return {
true,
socket_->Port(),
""};
88 Component<fruit::Annotated<StringAnnotation, PluginRouterFactory>>
90 return createComponent()
91 .bind<fruit::Annotated<StringAnnotation, PluginRouter>,
Component< fruit::Annotated< StringAnnotation, PluginRouterFactory > > getStringPluginRouterComponent()
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_plugins(std::string message)
udp::endpoint target_socket_
std::unique_ptr< Socket > socket_
virtual uint16_t Port() override
Component< SocketFactory > getUdpSocketComponent()
std::vector< boost::shared_ptr< skyway_plugin::SkyWayStringPlugin > > plugins_
void observe_socket(std::vector< uint8_t > data)
virtual PluginResult TryStart() override
pluginlib::ClassLoader< skyway_plugin::SkyWayStringPlugin > plugin_loader_
StringPluginRouter()=delete
std::shared_ptr< rapidjson::Document > config_