mirror of
https://github.com/eclipse-openvehicle-api/openvehicle-api.git
synced 2026-04-15 09:38:16 +00:00
36
examples/configuration_example/CMakeLists.txt
Normal file
36
examples/configuration_example/CMakeLists.txt
Normal file
@@ -0,0 +1,36 @@
|
||||
project(ConfigurationTestApp)
|
||||
|
||||
# Use new policy for project version settings and default warning level
|
||||
cmake_policy(SET CMP0048 NEW) # requires CMake 3.14
|
||||
cmake_policy(SET CMP0092 NEW) # requires CMake 3.15
|
||||
|
||||
# Use C++17 support
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
|
||||
add_executable(configuration_example src/configuration_example.cpp)
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
if (WIN32)
|
||||
target_link_libraries(configuration_example Ws2_32 Winmm Rpcrt4.lib)
|
||||
else()
|
||||
target_link_libraries(configuration_example ${CMAKE_DL_LIBS} rt ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
else()
|
||||
target_link_libraries(configuration_example Rpcrt4.lib)
|
||||
endif()
|
||||
|
||||
# Include link to export directory of SDV V-API development include files location
|
||||
include_directories(${SDV_FRAMEWORK_DEV_INCLUDE})
|
||||
|
||||
# Copy the config files
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/config/test_configuration_example.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config)
|
||||
|
||||
target_link_libraries(configuration_example
|
||||
${CMAKE_DL_LIBS}
|
||||
)
|
||||
|
||||
add_test(NAME configuration_example COMMAND configuration_example )
|
||||
|
||||
# Build dependencies
|
||||
add_dependencies(configuration_example configuration_component_example)
|
||||
@@ -0,0 +1,19 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "configuration_component_example.sdv"
|
||||
Class = "Configuration_Example"
|
||||
Message = "It's me"
|
||||
### the following is a valid JSON structure in a muliline string
|
||||
JSONConfig = """{
|
||||
"Logging": {
|
||||
"Sinks": [ { "Type": "Stdout", "Level": "Info" } ]
|
||||
},
|
||||
}"""
|
||||
Id = 42
|
||||
Pi = 3.1415926
|
||||
Boolean = true
|
||||
Array = [ 1, 2, 3 , 5 , 7, 11, 13, 17 ]
|
||||
Table = { a = 77, b = 1.2, c = "this is a string" }
|
||||
|
||||
49
examples/configuration_example/src/configuration_example.cpp
Normal file
49
examples/configuration_example/src/configuration_example.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <support/app_control.h>
|
||||
#include <thread>
|
||||
|
||||
/**
|
||||
* @brief check if SDV_FRAMEWORK_RUNTIME environment variable exists
|
||||
* @return Return true if environment variable is found otherwise false
|
||||
*/
|
||||
bool IsSDVFrameworkEnvironmentSet()
|
||||
{
|
||||
const char* envVariable = std::getenv("SDV_FRAMEWORK_RUNTIME");
|
||||
if (envVariable)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#if defined(_WIN32) && defined(_UNICODE)
|
||||
extern "C" int wmain()
|
||||
#else
|
||||
extern "C" int main()
|
||||
#endif
|
||||
{
|
||||
sdv::app::CAppControl appcontrol;
|
||||
if (!IsSDVFrameworkEnvironmentSet())
|
||||
{
|
||||
// if SDV_FRAMEWORK_RUNTIME environment variable is not set we need to set the Framework Runtime directory
|
||||
appcontrol.SetFrameworkRuntimeDirectory("../../bin");
|
||||
}
|
||||
auto bResult = appcontrol.Startup("");
|
||||
appcontrol.SetConfigMode();
|
||||
|
||||
bResult &= appcontrol.AddConfigSearchDir("config");
|
||||
bResult &= appcontrol.LoadConfig("test_configuration_example.toml") == sdv::core::EConfigProcessResult::successful;
|
||||
|
||||
if (!bResult)
|
||||
{
|
||||
std::cout << "Exit, Could not load configuration component." << std::endl;
|
||||
appcontrol.Shutdown();
|
||||
}
|
||||
|
||||
appcontrol.SetRunningMode();
|
||||
|
||||
appcontrol.Shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user