Skip to content

Commit

Permalink
Merge pull request #10 from ichiro-its/feature/create-grpc-service
Browse files Browse the repository at this point in the history
[Sprint 22/23 / PD-405] [[Feature] Add implementation GRPC
  • Loading branch information
FaaizHaikal authored Jun 5, 2024
2 parents 9c851ef + 79b43e6 commit 6aa0552
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 2 deletions.
64 changes: 62 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
cmake_minimum_required(VERSION 3.5)

project(ninshiki_interfaces)

if(NOT CMAKE_C_STANDARD)
Expand All @@ -17,12 +16,73 @@ endif()
find_package(ament_cmake REQUIRED)
find_package(rosidl_default_generators REQUIRED)

set(protobuf_MODULE_COMPATIBLE TRUE)
find_package(Protobuf CONFIG REQUIRED)
message(STATUS "Using protobuf ${Protobuf_VERSION}")

find_package(gRPC CONFIG REQUIRED)
message(STATUS "Using gRPC ${gRPC_VERSION}")

file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/proto)
add_custom_command(
OUTPUT
"${CMAKE_CURRENT_BINARY_DIR}/proto/ninshiki.pb.cc"
"${CMAKE_CURRENT_BINARY_DIR}/proto/ninshiki.pb.h"
"${CMAKE_CURRENT_BINARY_DIR}/proto/ninshiki.grpc.pb.cc"
"${CMAKE_CURRENT_BINARY_DIR}/proto/ninshiki.grpc.pb.h"
COMMAND $<TARGET_FILE:protobuf::protoc>
ARGS
--grpc_out "${CMAKE_CURRENT_BINARY_DIR}/proto"
--cpp_out "${CMAKE_CURRENT_BINARY_DIR}/proto"
-I ${CMAKE_CURRENT_SOURCE_DIR}/proto
--plugin=protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>
${CMAKE_CURRENT_SOURCE_DIR}/proto/ninshiki.proto
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/proto/ninshiki.proto
)

add_library(ninshiki_proto SHARED
"${CMAKE_CURRENT_BINARY_DIR}/proto/ninshiki.pb.cc"
"${CMAKE_CURRENT_BINARY_DIR}/proto/ninshiki.pb.h"
"${CMAKE_CURRENT_BINARY_DIR}/proto/ninshiki.grpc.pb.cc"
"${CMAKE_CURRENT_BINARY_DIR}/proto/ninshiki.grpc.pb.h"
)

target_compile_options(ninshiki_proto PRIVATE -fPIC)
target_compile_features(ninshiki_proto PUBLIC cxx_std_17)

target_link_libraries(ninshiki_proto PUBLIC
protobuf::libprotobuf
)

rosidl_generate_interfaces(${PROJECT_NAME}
"msg/DetectedObject.msg"
"msg/DetectedObjects.msg"
"msg/Point.msg"
"msg/Contour.msg"
"msg/Contours.msg")
"msg/Contours.msg"
"msg/ColorSetting.msg")

install (
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/proto/
DESTINATION include/${PROJECT_NAME}
)

install (
TARGETS ninshiki_proto
EXPORT ninshiki_proto
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
endif()

ament_export_dependencies(rosidl_default_runtime)

ament_export_dependencies(rosidl_default_runtime protobuf gRPC)
ament_export_targets(ninshiki_proto HAS_LIBRARY_TARGET)
ament_package()
7 changes: 7 additions & 0 deletions msg/ColorSetting.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
string name
int32 min_hue
int32 max_hue
int32 min_saturation
int32 max_saturation
int32 min_value
int32 max_value
27 changes: 27 additions & 0 deletions proto/ninshiki.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
syntax = "proto3";

package ninshiki_interfaces.proto;

service Config {
rpc GetColorSetting (Empty) returns (ConfigColor) {}

rpc SaveColorSetting (ConfigColor) returns (Empty) {}

rpc SetColorSetting (ColorSetting) returns (Empty) {}
}

message Empty {}

message ConfigColor {
string json_color = 1;
}

message ColorSetting {
string name = 1;
int32 min_hue = 2;
int32 max_hue = 3;
int32 min_saturation = 4;
int32 max_saturation = 5;
int32 min_value = 6;
int32 max_value = 7;
}

0 comments on commit 6aa0552

Please sign in to comment.