Skip to content

Commit

Permalink
Automate mapping table generation for plugins
Browse files Browse the repository at this point in the history
Add plugin name in plugins.conf to enable the plugin
Mapping table will generate object for the respective plugin and register the service
  • Loading branch information
Rjasuja committed Nov 8, 2017
1 parent 110df51 commit 010a7a0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions grpc/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ target_link_libraries(dronecore_server
dl
)

include(autogenerate_plugin_container.cmake)

include_directories(
${Protobuf_INCLUDE_DIRS}
${GRPC_INCLUDE_DIRS}
Expand Down
10 changes: 10 additions & 0 deletions grpc/server/autogenerate_plugin_container.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
file(STRINGS ../proto/plugins.conf plugins_list)

foreach(plugin ${plugins_list})
string(SUBSTRING ${plugin} 0 1 FIRST_LETTER)
string(TOUPPER ${FIRST_LETTER} FIRST_LETTER)
string(REGEX REPLACE "^.(.*)" "${FIRST_LETTER}\\1" class_name "${plugin}")
set(PLUGIN_MAP_APPEND_STRING "${PLUGIN_MAP_APPEND_STRING} map[\"${plugin}\"] = &createInstances<${class_name}RPCImpl>;\n")
endforeach()

configure_file(dronecore_server.cpp.in dronecore_server.cpp)
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,12 @@ void RunServer()
DroneCoreRPCImpl service;

map_type map;
map["action"] = &createInstances<ActionRPCImpl>;
map["mission"] = &createInstances<MissionRPCImpl>;
map["telemetry"] = &createInstances<TelemetryRPCImpl>;

std::string plugin;
std::fstream file;
file.open("../proto/plugins.conf");
std::vector<::grpc::Service *> list;
${PLUGIN_MAP_APPEND_STRING}

while (file >> plugin) {
auto service_obj = map[plugin](&dc);
list.push_back(service_obj);
Expand Down

0 comments on commit 010a7a0

Please sign in to comment.