diff --git a/CMakeLists.txt b/CMakeLists.txt index 58a795ea..571a65df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,10 @@ else() add_definitions(-D_WIN32_WINNT=0x600) set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267 /wd4244") + add_compile_options("$<$>:/Zi>") + add_link_options("$<$>:/DEBUG>") + add_link_options("$<$>:/OPT:REF>") + add_link_options("$<$>:/OPT:ICF>") endif() find_package(Threads REQUIRED) @@ -55,21 +59,22 @@ include_directories("${CMAKE_CURRENT_BINARY_DIR}" "./src" "./third_party/grpc" " # LabVIEW support for grpc and protobuf #---------------------------------------------------------------------- add_library(labview_grpc_server SHARED - src/grpc_client.cc - src/grpc_server.cc - src/grpc_interop.cc + src/any_support.cc src/cluster_copier.cc src/event_data.cc + src/feature_toggles.cc + src/grpc_client.cc + src/grpc_interop.cc + src/grpc_load.cc + src/grpc_server.cc src/lv_interop.cc src/lv_message.cc src/lv_message_value.cc + src/lv_proto_server_reflection_plugin.cc + src/lv_proto_server_reflection_service.cc src/message_element_metadata_owner.cc - src/any_support.cc src/unpacked_fields.cc - src/grpc_load.cc - src/lv_proto_server_reflection_service.cc - src/lv_proto_server_reflection_plugin.cc - ) +) target_link_libraries(labview_grpc_server ${_REFLECTION} ${_GRPC_GRPCPP} @@ -80,8 +85,9 @@ target_link_libraries(labview_grpc_server # server VIs from a .proto file #---------------------------------------------------------------------- add_library(labview_grpc_generator SHARED - src/proto_parser.cc + src/feature_toggles.cc src/lv_interop.cc + src/proto_parser.cc ) target_link_libraries(labview_grpc_generator ${_REFLECTION} diff --git a/src/feature_toggles.cc b/src/feature_toggles.cc new file mode 100644 index 00000000..820177da --- /dev/null +++ b/src/feature_toggles.cc @@ -0,0 +1,49 @@ +#include "feature_toggles.h" +#include +#include +#include +#include + +// Function to read feature configurations from an INI file +void FeatureConfig::readConfigFromFile(const std::string& filePath) { + std::ifstream configFile(filePath); + if (!configFile.is_open()) { + return; + } + + std::string line; + std::string currentSection; // For handling INI sections + + while (std::getline(configFile, line)) { + // Trim leading and trailing whitespaces + line.erase(line.find_last_not_of(" \t") + 1); + line.erase(0, line.find_first_not_of(" \t")); + + // Skip comments and empty lines + if (line.empty() || line[0] == ';') { + continue; + } + + // Check for section header + if (line[0] == '[' && line[line.length() - 1] == ']') { + currentSection = line.substr(1, line.length() - 2); + } else { + // Parse key-value pairs + std::istringstream iss(line); + std::string key, value; + if (std::getline(iss, key, '=') && std::getline(iss, value)) { + // Append section name to key for uniqueness + std::string fullKey = currentSection.empty() ? key : currentSection + "_" + key; + featureFlags[fullKey] = (value == "true"); + } + } + } + + configFile.close(); +} + +// Function to check if a feature is enabled +bool FeatureConfig::isFeatureEnabled(const std::string& featureName) const { + auto it = featureFlags.find(featureName); + return (it != featureFlags.end()) ? it->second : false; +} \ No newline at end of file diff --git a/src/feature_toggles.h b/src/feature_toggles.h new file mode 100644 index 00000000..2fa253a9 --- /dev/null +++ b/src/feature_toggles.h @@ -0,0 +1,27 @@ +#include +#include +#include +#include + +class FeatureConfig { +private: + std::map featureFlags; + + // Constructor to initialize with default values + FeatureConfig() { + featureFlags["gRPC"] = true; // Enable gRPC by default as an example, this will never be overridden by config file + } + +public: + // Singleton instance + static FeatureConfig& getInstance() { + static FeatureConfig instance; + return instance; + } + + // Function to read feature configurations from an INI file + void readConfigFromFile(const std::string& filePath); + + // Function to check if a feature is enabled + bool isFeatureEnabled(const std::string& featureName) const; +}; \ No newline at end of file diff --git a/src/lv_interop.cc b/src/lv_interop.cc index 12159df1..87c0178c 100644 --- a/src/lv_interop.cc +++ b/src/lv_interop.cc @@ -5,6 +5,7 @@ #include #include #include +#include "feature_toggles.h" #ifndef _WIN32 #include @@ -51,6 +52,9 @@ namespace grpc_labview //--------------------------------------------------------------------- void InitCallbacks() { + // Instantiating the feature toggles singleton that will read the feature configuration file + FeatureConfig::getInstance().readConfigFromFile("feature_config.ini"); + if (NumericArrayResizeImp != nullptr) { return;