9 std::string message(data.begin(), data.end());
10 std::shared_ptr<rapidjson::Document> doc(
new rapidjson::Document);
11 doc->Parse(message.c_str());
13 if (doc->HasParseError()) {
14 ROS_ERROR(
"invalid json message: %s", message.c_str());
15 ROS_ERROR(
"error location: %ld", doc->GetErrorOffset());
17 rapidjson::GetParseError_En(doc->GetParseError()));
22 (*plugin)->Execute(doc);
27 std::shared_ptr<rapidjson::Document> doc) {
29 Writer<StringBuffer> writer(buffer);
31 std::string
s(buffer.GetString(), buffer.GetSize());
32 std::vector<uint8_t> data(
s.begin(),
s.end());
38 udp::endpoint target_socket,
40 : plugin_loader_(
"skyway",
"skyway_plugin::SkyWayJsonPlugin"),
41 config_(
std::move(config)),
42 target_socket_(target_socket) {
46 std::make_shared<std::function<
void(std::vector<uint8_t>)>>(std::bind(
53 (*plugin)->Shutdown();
57 ROS_DEBUG(
"Succeeded in unloading all plugins");
63 return {
false, 0,
"invalid config parameters"};
66 auto callback = std::make_shared<
67 std::function<void(std::shared_ptr<rapidjson::Document>)>>(std::bind(
70 for (rapidjson::Value::ConstValueIterator itr =
config_->Begin();
72 if (!itr->HasMember(
"plugin_name"))
continue;
73 std::string plugin_name = (*itr)[
"plugin_name"].GetString();
78 std::shared_ptr<rapidjson::Document> parameter(
new rapidjson::Document);
79 parameter->CopyFrom(*itr, parameter->GetAllocator());
80 plugin->Initialize(std::move(parameter), callback);
82 ROS_DEBUG(
"plugin %s has been loaded successfully", plugin_name.c_str());
85 std::ostringstream stream;
86 stream <<
"Failed to load " << plugin_name << ex.what();
87 std::string message = stream.str();
88 char* data = (
char*)malloc(strlen(message.c_str()) + 1);
89 ROS_ERROR(
"plugin load error: %s", message.c_str());
90 strcpy(data, message.c_str());
92 return {
false, 0, (
const char*)data};
99 return {
true,
socket_->Port(),
""};
104 Component<fruit::Annotated<JsonAnnotation, PluginRouterFactory>>
106 return createComponent()