From b39a1943193c25f01894f473679b2424fe2e8778 Mon Sep 17 00:00:00 2001 From: "@Nurullah.Damla" Date: Thu, 21 Nov 2019 12:54:50 +0100 Subject: [PATCH] Toml eingebunden, Configfile erstellt und configuriert, Bugfix --- CMakeLists.txt | 5 +++++ res/config.toml | 15 +++++++++++++++ src/SharedMemory.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++ src/SharedMemory.h | 2 ++ 4 files changed, 68 insertions(+) create mode 100644 res/config.toml diff --git a/CMakeLists.txt b/CMakeLists.txt index 55b3da3..8b6b4ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,8 @@ set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "bin" "doc" " project(Shared_Memory) set(CMAKE_CXX_STANDARD 14) +#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") +set(CMAKE_CXX_COMPILER "clang++") file(GLOB_RECURSE SOURCES src/*.cpp) file(GLOB_RECURSE HEADERS src/*.hpp) @@ -32,3 +34,6 @@ target_link_libraries(UnitTests Catch2::Catch2) include(CTest) include(Catch) catch_discover_tests(UnitTests) + +#toml +include_directories(lib/toml) diff --git a/res/config.toml b/res/config.toml new file mode 100644 index 0000000..e91e65f --- /dev/null +++ b/res/config.toml @@ -0,0 +1,15 @@ +#defaultKey = 12345 +newKey = 0 +layoutVersion = 0 +width = 0 +height = 0 +mode = 0 +redrawInterval = 0 +timerInterruptInterval = 0 +backgroundColor = 0 +foregroundColor = 0 +charactersPerRow = 0 +charactersPerColumn = 0 +font = 0 +mousePositionX = 0 +mousePositionY = 0 \ No newline at end of file diff --git a/src/SharedMemory.cpp b/src/SharedMemory.cpp index 558c602..81a43a2 100644 --- a/src/SharedMemory.cpp +++ b/src/SharedMemory.cpp @@ -2,6 +2,11 @@ #include "SharedMemory.h" #include #include +#include +#include + + + key_t changedKey() { @@ -15,6 +20,10 @@ key_t changedKey() std::cout <<"New Key is -> " << newKey << std::endl; keyFile << newKey; keyFile.close(); + + auto config = cpptoml::parse_file("res/config.toml"); + newKey = config->get_as("newKey").value_or(0); //toml + return key_t(newKey); } @@ -83,3 +92,40 @@ void deleteSharedMemory(void) } } +void getConfig(){ + auto config = cpptoml::parse_file("res/config.toml"); + + int layoutVersion = config->get_as("layoutVersion").value_or(0); + int width = config->get_as("width").value_or(0); + int height = config->get_as("height").value_or(0); + int mode = config->get_as("mode").value_or(0); + int timerInterruptInterval = config->get_as("timerInterruptInterval").value_or(0); + int backgroundColor = config->get_as("backgroundColor").value_or(0); + int foregroundColor = config->get_as("foregroundColor").value_or(0); + int charactersPerRow = config->get_as("charactersPerRow").value_or(0); + int charactersPerColumn = config->get_as("charactersPerColumn").value_or(0); + int font = config->get_as("font").value_or(0); + int mousePositionX = config->get_as("mousePositionX").value_or(0); + int mousePositionY = config->get_as("mousePositionY").value_or(0); + + /* + //convert to hex + std::string result; + std::stringstream ss; + ss << std::hex << result; + ss >> result; + */ + + vkvm::setLayoutVersion((vkvm::LayoutVersion) layoutVersion); + vkvm::setWidth(width); + vkvm::setHeight(height); + vkvm::setMode((vkvm::GraphicMode) mode); + vkvm::setTimerInterruptInterval(timerInterruptInterval); + vkvm::setBackgroundColor(vkvm::Color(backgroundColor)); + vkvm::setForegroundColor(vkvm::Color(foregroundColor)); + vkvm::setCharactersPerRow(charactersPerRow); + vkvm::setCharactersPerColumn(charactersPerColumn); + vkvm::setFont(vkvm::FontType(font,"",0,0)); + vkvm::setMousePosition(mousePositionX, mousePositionY); +} + diff --git a/src/SharedMemory.h b/src/SharedMemory.h index 26a4d1d..32732d4 100644 --- a/src/SharedMemory.h +++ b/src/SharedMemory.h @@ -14,4 +14,6 @@ void deleteSharedMemory(void); void initSharedMemory(void); key_t changedKey(); std::string getAnswerFromUser(); +//Config File +#define configFile "res/config.toml"; #endif //SHARED_MEMORY_H