summaryrefslogtreecommitdiffstats
path: root/src/gnmi
diff options
context:
space:
mode:
Diffstat (limited to 'src/gnmi')
-rw-r--r--src/gnmi/CMakeLists.txt47
-rw-r--r--src/gnmi/gnmidata.cpp11
-rw-r--r--src/gnmi/gnmidata.h11
-rw-r--r--src/gnmi/proto/CMakeLists.txt69
4 files changed, 68 insertions, 70 deletions
diff --git a/src/gnmi/CMakeLists.txt b/src/gnmi/CMakeLists.txt
index e373827..6a28529 100644
--- a/src/gnmi/CMakeLists.txt
+++ b/src/gnmi/CMakeLists.txt
@@ -17,25 +17,19 @@
cmake_minimum_required(VERSION 2.8)
project(gNMI-server)
-set(CMAKE_CXX_STANDARD 17)
-# set compiler option
-set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
-set(CMAKE_C_FLAGS "-Wall -std=c++17")
-set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -O2")
-set(CMAKE_C_FLAGS_DEBUG "-g -O0")
-set(CMAKE_INSTALL_LIBDIR "/usr/lib")
+#C++11 is required by gNMI
+set(CMAKE_CXX_STANDARD 11)
+
+# DEPENDENCIES
+##############
# Cmake find modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../cmake")
-find_package(PUGIXML REQUIRED)
-find_package(JSONCPP REQUIRED)
-find_package(PkgConfig)
-
-
-pkg_check_modules(SYSREPO REQUIRED libsysrepo)
-
-add_subdirectory(proto)
+find_package(PUGIXML REQUIRED) #use FindPUGIXML.cmake
+find_package(JSONCPP REQUIRED) #use FindJSONCPP.cmake
+find_package(PkgConfig) #official cmake module
+pkg_check_modules(SYSREPO REQUIRED libsysrepo) #PkgConfig cmake module maccro
if(LIBPUGIXML_FOUND)
message ("PUGIXML found")
@@ -49,6 +43,23 @@ else()
message (FATAL_ERROR "Cannot find LIBJSONCPP")
endif()
+# DEPENDENCIES & COMPILATION OF GNMI PROTO
+##########################################
+
+# set compiler and linker flags
+set(RIGOROUS_C_FLAGS "-Wlogical-op -Wold-style-cast -Wuseless-cast")
+set(CMAKE_CXX_FLAGS "-Wall -Wextra -std=c++11 ${RIGOROUS_C_FLAGS}")
+set(CMAKE_CXX_FLAGS_RELEASE "-Wall -Wextra -std=c++11 -DNDEBUG -O2 ${RIGOROUS_C_FLAGS}")
+set(CMAKE_CXX_FLAGS_DEBUG "-Wall -Wextra -std=c++11 -g -O0 ${RIGOROUS_C_FLAGS}")
+
+add_subdirectory(proto)
+
+# COMPILER & LINKER
+###################
+
+# Generate a compile_commands.json with compile options
+set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
+
set(GNMI_SRC main.cpp
log.cpp
gnmiserver.cpp
@@ -65,9 +76,13 @@ target_include_directories(gnmi_server PRIVATE ${PROTOBUF_INCLUDE_DIR}
${LIBJSONCPP_INCLUDE_DIR}
${SYSREPO_INCLUDE_DIRS})
-target_link_libraries(gnmi_server proto
+# link gnmi_server executable with protobuf, grpc, pugixml, sysrepo libraries
+target_link_libraries(gnmi_server gnmi
${LIBPUGIXML_LIBRARY}
${LIBJSONCPP_LIBRARY}
${SYSREPO_LIBRARIES})
+# INSTALL
+#########
+
install(TARGETS gnmi_server RUNTIME DESTINATION bin)
diff --git a/src/gnmi/gnmidata.cpp b/src/gnmi/gnmidata.cpp
index 5ee53c4..ae2bb18 100644
--- a/src/gnmi/gnmidata.cpp
+++ b/src/gnmi/gnmidata.cpp
@@ -24,7 +24,8 @@ gNMIData::ValueType gNMIData::dataType() const
void gNMIData::clean()
{
dtype = ValueType::UnknownVal;
- value = {};
+ strData = "";
+ intData = 0;
xpath = "";
}
@@ -46,13 +47,13 @@ void gNMIData::setXPath(const std::string& str, xPathType type)
void gNMIData::setValue(const std::string& str)
{
dtype = ValueType::dStringVal;
- value = str;
+ strData = str;
}
void gNMIData::setValue(int val)
{
dtype = ValueType::dIntVal;
- value = val;
+ intData = val;
}
std::string gNMIData::getXPath(gNMIData::xPathType type) const
@@ -78,7 +79,7 @@ std::string gNMIData::getStr() const
return std::to_string(getInt());
case ValueType::dStringVal:
- return std::get<std::string>(value);
+ return strData;
case ValueType::UnknownVal:
default:
@@ -91,7 +92,7 @@ std::string gNMIData::getStr() const
int gNMIData::getInt() const
{
- return std::get<int>(value);
+ return intData;
}
std::string gNMIData::convertToSyrepoPath() const
diff --git a/src/gnmi/gnmidata.h b/src/gnmi/gnmidata.h
index e4c15d2..82c60c8 100644
--- a/src/gnmi/gnmidata.h
+++ b/src/gnmi/gnmidata.h
@@ -18,7 +18,6 @@
#define GNMIDATA_H
#include <string>
-#include <variant>
/**
* @todo write docs
@@ -38,14 +37,7 @@ public:
};
public:
- /**
- * Default constructor
- */
gNMIData() = default;
-
- /**
- * Destructor
- */
~gNMIData() = default;
ValueType dataType() const;
@@ -64,7 +56,8 @@ private:
private:
ValueType dtype = ValueType::UnknownVal;
- std::variant<int, std::string> value;
+ int intData;
+ std::string strData;
std::string xpath;
};
diff --git a/src/gnmi/proto/CMakeLists.txt b/src/gnmi/proto/CMakeLists.txt
index 8e70f77..e68a2c9 100644
--- a/src/gnmi/proto/CMakeLists.txt
+++ b/src/gnmi/proto/CMakeLists.txt
@@ -1,52 +1,41 @@
-set(protobuf_MODULE_COMPATIBLE TRUE)
+# DEPENDENCIES
+##############
-find_package(Protobuf REQUIRED)
+# Require at least Protobuf 3 for gNMI
+find_package(Protobuf 3.0.0 REQUIRED) #official cmake module
include_directories(${PROTOBUF_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
message(STATUS "Using protobuf ${protobuf_VERSION}")
-set(_PROTOBUF_LIBPROTOBUF ${PROTOBUF_LIBRARIES})
-set(_PROTOBUF_PROTOC ${PROTOBUF_PROTOC_EXECUTABLE})
+# Require at least gRPC 1.12.0, maybe earlier can be used
-find_package(gRPC CONFIG REQUIRED)
-set(_GRPC_GRPCPP gRPC::grpc++)
-set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
+# Official gRPCConfig.cmake installed by gRPC only if compiled with cmake
+# Use our own FindGRPC.cmake instead
+find_package(GRPC 1.12.0 REQUIRED)
+get_filename_component(gnmi_proto "gnmi.proto" ABSOLUTE)
+get_filename_component(gnmi_ext_proto "gnmi_ext.proto" ABSOLUTE)
-set(PROTOS
- gnmi.proto
- gnmi_ext.proto
-)
+# GENERATION OF SOURCE FILES
+############################
-get_filename_component(hw_proto "gnmi.proto" ABSOLUTE)
-get_filename_component(hw_proto_path "${hw_proto}" PATH)
-get_filename_component(gnmi_ext_proto "gnmi_ext.proto" ABSOLUTE)
-get_filename_component(gnmi_ext_proto_path "${gnmi_ext_proto}" PATH)
-
-# Generated sources
-set(hw_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/gnmi.pb.cc")
-set(hw_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/gnmi.pb.h")
-set(hw_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/gnmi.grpc.pb.cc")
-set(hw_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/gnmi.grpc.pb.h")
-set(gnmi_ext_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/gnmi_ext.pb.cc")
-set(gnmi_ext_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/gnmi_ext.pb.h")
-set(gnmi_ext_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/gnmi_ext.grpc.pb.cc")
-set(gnmi_ext_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/gnmi_ext.grpc.pb.h")
-
-add_custom_command(
- OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}" "${gnmi_ext_proto_srcs}" "${gnmi_ext_proto_hdrs}" "${gnmi_ext_grpc_srcs}" "${gnmi_ext_grpc_hdrs}"
- COMMAND ${_PROTOBUF_PROTOC}
- ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
- --cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
- -I "${hw_proto_path}" "${gnmi_ext_path}"
- --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
- "${hw_proto}" "${gnmi_ext_proto}"
- DEPENDS "${hw_proto}" "${gnmi_ext_proto}")
-
-# Include generated *.pb.h files
+# Official generator
+protobuf_generate_cpp(gnmi_proto_srcs gnmi_proto_hdrs ${gnmi_proto})
+protobuf_generate_cpp(gnmi_ext_proto_srcs gnmi_ext_proto_hdrs ${gnmi_ext_proto})
+
+# Custom generator: Official `protobuf_generate_cpp` can't use grpc plugins
+PROTOBUF_GENERATE_GRPC_CPP(gnmi_grpc_srcs gnmi_grpc_hdrs ${gnmi_proto})
+PROTOBUF_GENERATE_GRPC_CPP(gnmi_ext_grpc_srcs gnmi_ext_grpc_hdrs ${gnmi_ext_proto})
+
+# LINK OPTIONS FOR GNMI-SERVER
+##############################
+
+# Include generated protobuf C++ files
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
-add_library(proto ${hw_proto_srcs} ${hw_grpc_srcs}
- ${gnmi_ext_proto_srcs} ${gnmi_ext_grpc_srcs})
-target_link_libraries(proto ${_GRPC_GRPCPP} ${_PROTOBUF_LIBPROTOBUF})
+#Create a new library named gnmi
+add_library(gnmi ${gnmi_grpc_srcs} ${gnmi_ext_grpc_srcs} ${gnmi_proto_srcs} ${gnmi_ext_proto_srcs})
+#Link our new gnmi library with grpc and protobuf libraries
+target_link_libraries(gnmi ${GRPCPP_LIBRARY} ${PROTOBUF_LIBRARIES})