summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmake/FindProtobufC.cmake72
-rw-r--r--include/ouroboros/CMakeLists.txt2
-rw-r--r--src/lib/CMakeLists.txt10
-rw-r--r--src/lib/irmd_messages.proto37
4 files changed, 118 insertions, 3 deletions
diff --git a/cmake/FindProtobufC.cmake b/cmake/FindProtobufC.cmake
new file mode 100644
index 00000000..cae9f1c3
--- /dev/null
+++ b/cmake/FindProtobufC.cmake
@@ -0,0 +1,72 @@
+function(PROTOBUF_GENERATE_C SRCS HDRS)
+ if(NOT ARGN)
+ message(SEND_ERROR "Error: PROTOBUF_GENERATE_C() called without any proto files")
+ return()
+ endif()
+
+ if(PROTOBUF_GENERATE_C_APPEND_PATH)
+ # Create an include path for each file specified
+ foreach(FIL ${ARGN})
+ get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
+ get_filename_component(ABS_PATH ${ABS_FIL} PATH)
+ list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
+ if(${_contains_already} EQUAL -1)
+ list(APPEND _protobuf_include_path -I ${ABS_PATH})
+ endif()
+ endforeach()
+ else()
+ set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR})
+ endif()
+
+ set(${SRCS})
+ set(${HDRS})
+ foreach(FIL ${ARGN})
+ get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
+ get_filename_component(FIL_WE ${FIL} NAME_WE)
+
+ list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb-c.cc")
+ list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb-c.h")
+
+ add_custom_command(
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb-c.cc"
+ "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb-c.h"
+ COMMAND ${PROTOBUF_PROTOC_C_EXECUTABLE}
+ ARGS --c_out=${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL}
+ DEPENDS ${ABS_FIL} ${PROTOBUF_PROTOC_C_EXECUTABLE}
+ COMMENT "Running C protocol buffer compiler on ${FIL}"
+ VERBATIM )
+ endforeach()
+
+ set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)
+ set(${SRCS} ${${SRCS}} PARENT_SCOPE)
+ set(${HDRS} ${${HDRS}} PARENT_SCOPE)
+endfunction()
+
+# By default have PROTOBUF_GENERATE_C macro pass -I to protoc
+# for each directory where a proto file is referenced.
+if(NOT DEFINED PROTOBUF_GENERATE_C_APPEND_PATH)
+ set(PROTOBUF_GENERATE_C_APPEND_PATH TRUE)
+endif()
+
+# Find library
+find_library(PROTOBUF_C_LIBRARY
+ NAMES libprotobuf-c.so libprotobuf-c
+)
+mark_as_advanced(PROTOBUF_C_LIBRARY)
+
+# Find the include directory
+find_path(PROTOBUF_C_INCLUDE_DIR
+ google/protobuf-c/protobuf-c.h
+)
+mark_as_advanced(PROTOBUF_C_INCLUDE_DIR)
+
+# Find the protoc-c Executable
+find_program(PROTOBUF_PROTOC_C_EXECUTABLE
+ NAMES protoc-c
+ DOC "The Google Protocol Buffers C Compiler"
+)
+mark_as_advanced(PROTOBUF_PROTOC_C_EXECUTABLE)
+
+find_package(PackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(ProtobufC DEFAULT_MSG
+ PROTOBUF_C_LIBRARY PROTOBUF_C_INCLUDE_DIR PROTOBUF_PROTOC_C_EXECUTABLE)
diff --git a/include/ouroboros/CMakeLists.txt b/include/ouroboros/CMakeLists.txt
index a196140b..cc6b9103 100644
--- a/include/ouroboros/CMakeLists.txt
+++ b/include/ouroboros/CMakeLists.txt
@@ -20,4 +20,4 @@ set(HEADER_FILES
)
install(FILES ${HEADER_FILES} "${CMAKE_CURRENT_BINARY_DIR}/config.h"
- DESTINATION include/ouroboros)
+ DESTINATION include/ouroboros)
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index 7ce98bf2..e05dce8b 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -3,6 +3,12 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${CMAKE_BINARY_DIR}/include)
+find_package(ProtobufC REQUIRED)
+
+include_directories(${PROTOBUF_INCLUDE_DIRS})
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
+protobuf_generate_c(PROTO_SRCS PROTO_HDRS irmd_messages.proto)
find_library(LIBRT_LIBRARIES rt)
if(NOT LIBRT_LIBRARIES)
@@ -30,8 +36,8 @@ set(SOURCE_FILES
utils.c
)
-add_library(ouroboros SHARED ${SOURCE_FILES})
-target_link_libraries(ouroboros rt pthread)
+add_library(ouroboros SHARED ${SOURCE_FILES} ${PROTO_SRCS} ${PROTO_HDRS})
+target_link_libraries(ouroboros rt pthread ${PROTOBUF_LIBRARIES})
include(MacroAddCompileFlags)
if (CMAKE_BUILD_TYPE MATCHES Debug)
diff --git a/src/lib/irmd_messages.proto b/src/lib/irmd_messages.proto
new file mode 100644
index 00000000..c61d1b6d
--- /dev/null
+++ b/src/lib/irmd_messages.proto
@@ -0,0 +1,37 @@
+enum irm_msg_code {
+ IRM_CREATE_IPCP = 1;
+ IRM_DESTROY_IPCP = 2;
+ IRM_BOOTSTRAP_IPCP = 3;
+ IRM_ENROLL_IPCP = 4;
+ IRM_REG_IPCP = 5;
+ IRM_UNREG_IPCP = 6;
+ IRM_AP_REG = 7;
+ IRM_AP_REG_R = 8;
+ IRM_AP_UNREG = 9;
+ IRM_FLOW_ACCEPT = 10;
+ IRM_FLOW_ACCEPT_R = 11;
+ IRM_FLOW_ALLOC_RESP = 12;
+ IRM_FLOW_ALLOC = 13;
+ IRM_FLOW_ALLOC_R = 14;
+ IRM_FLOW_ALLOC_RES = 15;
+ IRM_FLOW_ALLOC_RES_R = 16;
+ IRM_FLOW_DEALLOC = 17;
+ IRM_FLOW_CONTROL = 18;
+ IRM_FLOW_WRITE = 19;
+ IRM_FLOW_READ = 20;
+};
+
+message irm_msg {
+ required irm_msg_code code = 1;
+ optional string ap_name = 2;
+ optional uint32 api_id = 3;
+ optional string ae_name = 4;
+ optional string ipcp_type = 5;
+ // Missing dif_config field here
+ repeated string dif_name = 7;
+ optional int32 fd = 8;
+ optional int32 result = 9;
+ // Missing qos_spec here
+ optional int32 oflags = 10;
+ optional string dst_ap_name = 11;
+};