Skip to content

Commit

Permalink
cmake/tools: generate grpc_server, list plugins
Browse files Browse the repository at this point in the history
This is refactoring around the way the plugins are built into the mavsdk
library as well as the mavsdk_server executable.

The changes contain the following:
- Auto-generation of grpc_server.h and grpc_server.cpp from jinja2
  templates. This means that the mavsdk_server is always in sync and
  new plugins don't have to be added to it manually anymore.
- As a side effects this removes the ugly rewriting of CMakeLists.txt
  based on the auto-generated plugins and instead uses a separate
  plugins.txt file that is used throughout.
- The cmake variable ENABLED_PLUGINS can be used to manually select the
  plugins to be built for users requiring to do so.
  • Loading branch information
julianoes committed Jun 30, 2022
1 parent 0f04519 commit 002839b
Show file tree
Hide file tree
Showing 10 changed files with 780 additions and 79 deletions.
10 changes: 10 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ else()
set(lib_path "lib")
endif()

if (ENABLED_PLUGINS)
message(STATUS "Manually enabled plugins:")
foreach(plugin ${ENABLED_PLUGINS})
message(STATUS " - ${plugin}")
endforeach()
else()
message(STATUS "All plugins enabled")
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/plugins.txt" ENABLED_PLUGINS)
endif()

add_subdirectory(mavsdk)

include(cmake/static_analyzers.cmake)
Expand Down
35 changes: 5 additions & 30 deletions src/mavsdk/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,33 +1,8 @@
add_subdirectory(action)
add_subdirectory(action_server)
add_subdirectory(calibration)
add_subdirectory(camera)
add_subdirectory(camera_server)
add_subdirectory(component_information)
add_subdirectory(component_information_server)
add_subdirectory(failure)
add_subdirectory(follow_me)
add_subdirectory(ftp)
add_subdirectory(geofence)
add_subdirectory(gimbal)
add_subdirectory(info)
add_subdirectory(log_files)
add_subdirectory(manual_control)
foreach(plugin ${ENABLED_PLUGINS})
add_subdirectory(${plugin})
endforeach()

# Don't forget about mavlink_passthrough which is not auto-generated.
add_subdirectory(mavlink_passthrough)
add_subdirectory(mission)
add_subdirectory(mission_raw)
add_subdirectory(mission_raw_server)
add_subdirectory(mocap)
add_subdirectory(offboard)
add_subdirectory(param)
add_subdirectory(param_server)
add_subdirectory(server_utility)
add_subdirectory(shell)
add_subdirectory(telemetry)
add_subdirectory(tracking_server)
add_subdirectory(transponder)
add_subdirectory(rtk)
add_subdirectory(telemetry_server)
add_subdirectory(tune)

set(UNIT_TEST_SOURCES ${UNIT_TEST_SOURCES} PARENT_SCOPE)
41 changes: 11 additions & 30 deletions src/mavsdk_server/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,6 @@
cmake_minimum_required(VERSION 3.10.2)

set(COMPONENTS_LIST
action
action_server
calibration
camera
camera_server
core
failure
follow_me
ftp
geofence
gimbal
info log_files
manual_control
mission
mission_raw
mission_raw_server
mocap offboard
param
param_server
server_utility
shell
telemetry
telemetry_server
tracking_server
tune
transponder
)

foreach(COMPONENT_NAME ${COMPONENTS_LIST})
foreach(COMPONENT_NAME ${ENABLED_PLUGINS})
add_library(${COMPONENT_NAME}_proto_gens STATIC
${CMAKE_CURRENT_SOURCE_DIR}/generated/${COMPONENT_NAME}/${COMPONENT_NAME}.grpc.pb.cc
${CMAKE_CURRENT_SOURCE_DIR}/generated/${COMPONENT_NAME}/${COMPONENT_NAME}.pb.cc
Expand Down Expand Up @@ -76,6 +47,16 @@ target_link_libraries(mavsdk_server
${COMPONENTS_PROTOGENS}
)


foreach(plugin ${ENABLED_PLUGINS})
string(TOUPPER ${plugin} plugin_uppercase)
target_compile_options(mavsdk_server
PRIVATE
"-D${plugin_uppercase}_ENABLED"
)
endforeach()


set_target_properties(mavsdk_server
PROPERTIES COMPILE_FLAGS ${warnings}
VERSION ${MAVSDK_VERSION_STRING}
Expand Down
191 changes: 190 additions & 1 deletion src/mavsdk_server/src/grpc_server.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// WARNING: THIS FILE IS AUTOGENERATED! As such, it should not be edited.
// Edits need to be made to templates/grpc_server.cpp.j2
#include "grpc_server.h"

#include <grpc++/server_builder.h>
Expand All @@ -19,33 +21,126 @@ int GrpcServer::run()
setup_port(builder);

builder.RegisterService(&_core);

#ifdef ACTION_ENABLED
builder.RegisterService(&_action_service);
#endif

#ifdef ACTION_SERVER_ENABLED
builder.RegisterService(&_action_server_service);
#endif

#ifdef CALIBRATION_ENABLED
builder.RegisterService(&_calibration_service);
#endif

#ifdef CAMERA_ENABLED
builder.RegisterService(&_camera_service);
#endif

#ifdef CAMERA_SERVER_ENABLED
builder.RegisterService(&_camera_server_service);
#endif

#ifdef COMPONENT_INFORMATION_ENABLED
builder.RegisterService(&_component_information_service);
#endif

#ifdef COMPONENT_INFORMATION_SERVER_ENABLED
builder.RegisterService(&_component_information_server_service);
#endif

#ifdef FAILURE_ENABLED
builder.RegisterService(&_failure_service);
#endif

#ifdef FOLLOW_ME_ENABLED
builder.RegisterService(&_follow_me_service);
#endif

#ifdef FTP_ENABLED
builder.RegisterService(&_ftp_service);
#endif

#ifdef GEOFENCE_ENABLED
builder.RegisterService(&_geofence_service);
#endif

#ifdef GIMBAL_ENABLED
builder.RegisterService(&_gimbal_service);
#endif

#ifdef INFO_ENABLED
builder.RegisterService(&_info_service);
#endif

#ifdef LOG_FILES_ENABLED
builder.RegisterService(&_log_files_service);
#endif

#ifdef MANUAL_CONTROL_ENABLED
builder.RegisterService(&_manual_control_service);
#endif

#ifdef MISSION_ENABLED
builder.RegisterService(&_mission_service);
#endif

#ifdef MISSION_RAW_ENABLED
builder.RegisterService(&_mission_raw_service);
#endif

#ifdef MISSION_RAW_SERVER_ENABLED
builder.RegisterService(&_mission_raw_server_service);
#endif

#ifdef MOCAP_ENABLED
builder.RegisterService(&_mocap_service);
#endif

#ifdef OFFBOARD_ENABLED
builder.RegisterService(&_offboard_service);
#endif

#ifdef PARAM_ENABLED
builder.RegisterService(&_param_service);
#endif

#ifdef PARAM_SERVER_ENABLED
builder.RegisterService(&_param_server_service);
#endif

#ifdef RTK_ENABLED
builder.RegisterService(&_rtk_service);
#endif

#ifdef SERVER_UTILITY_ENABLED
builder.RegisterService(&_server_utility_service);
#endif

#ifdef SHELL_ENABLED
builder.RegisterService(&_shell_service);
#endif

#ifdef TELEMETRY_ENABLED
builder.RegisterService(&_telemetry_service);
#endif

#ifdef TELEMETRY_SERVER_ENABLED
builder.RegisterService(&_telemetry_server_service);
#endif

#ifdef TRACKING_SERVER_ENABLED
builder.RegisterService(&_tracking_server_service);
#endif

#ifdef TRANSPONDER_ENABLED
builder.RegisterService(&_transponder_service);
#endif

#ifdef TUNE_ENABLED
builder.RegisterService(&_tune_service);
#endif

grpc::EnableDefaultHealthCheckService(true);
_server = builder.BuildAndStart();
Expand Down Expand Up @@ -73,33 +168,127 @@ void GrpcServer::stop()
{
if (_server != nullptr) {
_core.stop();

#ifdef ACTION_ENABLED
_action_service.stop();
#endif

#ifdef ACTION_SERVER_ENABLED
_action_server_service.stop();
#endif

#ifdef CALIBRATION_ENABLED
_calibration_service.stop();
#endif

#ifdef CAMERA_ENABLED
_camera_service.stop();
#endif

#ifdef CAMERA_SERVER_ENABLED
_camera_server_service.stop();
#endif

#ifdef COMPONENT_INFORMATION_ENABLED
_component_information_service.stop();
#endif

#ifdef COMPONENT_INFORMATION_SERVER_ENABLED
_component_information_server_service.stop();
#endif

#ifdef FAILURE_ENABLED
_failure_service.stop();
#endif

#ifdef FOLLOW_ME_ENABLED
_follow_me_service.stop();
#endif

#ifdef FTP_ENABLED
_ftp_service.stop();
#endif

#ifdef GEOFENCE_ENABLED
_geofence_service.stop();
#endif

#ifdef GIMBAL_ENABLED
_gimbal_service.stop();
#endif

#ifdef INFO_ENABLED
_info_service.stop();
#endif

#ifdef LOG_FILES_ENABLED
_log_files_service.stop();
#endif

#ifdef MANUAL_CONTROL_ENABLED
_manual_control_service.stop();
#endif

#ifdef MISSION_ENABLED
_mission_service.stop();
#endif

#ifdef MISSION_RAW_ENABLED
_mission_raw_service.stop();
#endif

#ifdef MISSION_RAW_SERVER_ENABLED
_mission_raw_server_service.stop();
#endif

#ifdef MOCAP_ENABLED
_mocap_service.stop();
#endif

#ifdef OFFBOARD_ENABLED
_offboard_service.stop();
#endif

#ifdef PARAM_ENABLED
_param_service.stop();
#endif

#ifdef PARAM_SERVER_ENABLED
_param_server_service.stop();
#endif

#ifdef RTK_ENABLED
_rtk_service.stop();
#endif

#ifdef SERVER_UTILITY_ENABLED
_server_utility_service.stop();
#endif

#ifdef SHELL_ENABLED
_shell_service.stop();
#endif

#ifdef TELEMETRY_ENABLED
_telemetry_service.stop();
#endif

#ifdef TELEMETRY_SERVER_ENABLED
_telemetry_server_service.stop();
#endif

#ifdef TRACKING_SERVER_ENABLED
_tracking_server_service.stop();
_tune_service.stop();
#endif

#ifdef TRANSPONDER_ENABLED
_transponder_service.stop();
#endif

#ifdef TUNE_ENABLED
_tune_service.stop();
#endif

_server->Shutdown();
} else {
LogWarn() << "Calling 'stop()' on a non-existing server. Did you call 'run()' before?";
Expand Down
Loading

0 comments on commit 002839b

Please sign in to comment.