Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Toggles and Debug Symbols for Release Build #338

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ else()
add_definitions(-D_WIN32_WINNT=0x600)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267 /wd4244")
add_compile_options("$<$<NOT:$<CONFIG:Debug>>:/Zi>")
add_link_options("$<$<NOT:$<CONFIG:Debug>>:/DEBUG>")
add_link_options("$<$<NOT:$<CONFIG:Debug>>:/OPT:REF>")
add_link_options("$<$<NOT:$<CONFIG:Debug>>:/OPT:ICF>")
endif()

find_package(Threads REQUIRED)
Expand Down Expand Up @@ -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}
Expand All @@ -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}
Expand Down
49 changes: 49 additions & 0 deletions src/feature_toggles.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "feature_toggles.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <map>

// Function to read feature configurations from an INI file
void FeatureConfig::readConfigFromFile(const std::string& filePath) {
ni-sujain marked this conversation as resolved.
Show resolved Hide resolved
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;
}
27 changes: 27 additions & 0 deletions src/feature_toggles.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <iostream>
#include <fstream>
#include <sstream>
#include <map>

class FeatureConfig {
private:
std::map<std::string, bool> 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;
};
4 changes: 4 additions & 0 deletions src/lv_interop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <cstring>
#include <memory>
#include <grpcpp/grpcpp.h>
#include "feature_toggles.h"

#ifndef _WIN32
#include <dlfcn.h>
Expand Down Expand Up @@ -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");
CPattar-NI marked this conversation as resolved.
Show resolved Hide resolved

if (NumericArrayResizeImp != nullptr)
{
return;
Expand Down
Loading