diff --git a/src/SharedMemoryAccess.cpp b/src/SharedMemoryAccess.cpp index 636b09c..456e47b 100644 --- a/src/SharedMemoryAccess.cpp +++ b/src/SharedMemoryAccess.cpp @@ -57,16 +57,9 @@ int semaphoreOperation(int op) { } void writeSharedMemory(char *data, int size, int offset) { - int shmId = shmget(impl.sharedMemoryKey, 0, 0); // dont init just get the ID if already existing. - if (shmId >= 0) { - std::cout << "writing" << std::endl; - auto *shm_pointer = reinterpret_cast(shmat(shmId, nullptr, 0)); - semaphoreOperation(LOCK); - memcpy(shm_pointer + offset, data, size); - shmdt(shm_pointer); //close shm_pointer - semaphoreOperation(UNLOCK); - std::cout << "writing successed" << std::endl; - } + lockSharedMemory(); + memcpy(getSharedMemory() + offset, data, size); + unlockSharedMemory(); } char *getSharedMemory() { diff --git a/src/log.cpp b/src/log.cpp index 4e053f5..c70fc0a 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -71,7 +71,7 @@ void logTime(){ } //log the message -void log(const std::string &msg, LogLevel level) { +void log(LogLevel level, const std::string &msg) { if(level >= logLevel) { std::string levelName = getLevelName(level); const int maxLevelNameLength = 8; diff --git a/src/log.h b/src/log.h index 6b7f94f..049e28d 100644 --- a/src/log.h +++ b/src/log.h @@ -2,6 +2,7 @@ #define LIBRARY_LOG_H #include +#include enum LogLevel{ DEBUG = 1, @@ -17,7 +18,26 @@ enum LogLevel{ * @author Julian Hinxlage * @since 0.1.0 */ -void log(const std::string &msg, LogLevel level = LogLevel::INFO); +void log(LogLevel level, const std::string &msg); + + +template +static void buildString(std::stringstream &stream, T t) { + stream << t; +} + +template +static void buildString(std::stringstream &stream, T t, Ts... ts) { + stream << t; + buildString(stream, ts...); +} + +template +static void log(LogLevel level, T... t){ + std::stringstream stream; + buildString(stream, t...); + log(level, stream.str()); +} /** diff --git a/src/vkvm.h b/src/vkvm.h index 6d581b4..86a0663 100644 --- a/src/vkvm.h +++ b/src/vkvm.h @@ -7,6 +7,7 @@ #include "FontType.h" #include "KeyCode.h" #include "LayoutVersion.h" +#include "log.h" #include #include