From bf6546e3b851d1e03c5e3173fd3ece5ad0ea6598 Mon Sep 17 00:00:00 2001 From: Shaohua Tong Date: Fri, 8 Nov 2019 18:31:42 +0100 Subject: [PATCH 1/7] test for write and read of shared memory in main.cpp --- CMakeLists.txt | 1 + main/main.cpp | 39 +++++++++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c40c64..6c14a86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ set(LIB_PATH "${CMAKE_SOURCE_DIR}/../library") include_directories(${LIB_PATH}/include) add_executable(SharedMemory ${SOURCES} ${HEADERS} main/main.cpp) + target_link_libraries(SharedMemory ${LIB_PATH}/lib/liblibrary.a) diff --git a/main/main.cpp b/main/main.cpp index fdf836c..4ea5b9f 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -3,6 +3,8 @@ #include "../src/SharedMemory.h" #include #include +#include +#include int main(int argc, char** argv) @@ -19,16 +21,33 @@ int main(int argc, char** argv) while(eingabe != "exit") { std::cout << "cmd# "; std::cin >> eingabe; - //if verschieden information ausgaben - if(eingabe == "info") - { - std::cout << "OUTPUT ------------------------ OUTPUT\n" << std::endl; - std::cout << "memory ID: " << shmget(impl.sharedMemoryKey, 0, 0) << std::endl; - std::cout << "Max memory Size: " << Max_Memory_Size << std::endl; - std::cout << "OUTPUT ------------------------ OUTPUT\n" << std::endl; - //Memory that is used now - //outprint of all memory - } + //if verschieden information ausgaben + if(eingabe == "info") + { + std::cout << "OUTPUT ------------------------ OUTPUT\n" << std::endl; + std::cout << "memory ID: " << shmget(impl.sharedMemoryKey, 0, 0) << std::endl; + std::cout << "Max memory Size: " << Max_Memory_Size << std::endl; + std::cout << "OUTPUT ------------------------ OUTPUT\n" << std::endl; + //Memory that is used now + //outprint of all memory + } + + //Test for write and read + if(eingabe == "write") { + //write a bitMap for example 2 (width) * 2 (high) * 3 (color) in Schared Memory + char bitMap[12] = {0}; + for(int i = 0; i < sizeof(bitMap); i++) + bitMap[i] = 'y'; + writeSharedMemory(bitMap, sizeof(bitMap),1); + } + + if(eingabe == "read") { + char content[12] = {0}; + std::cout << "key "<< impl.sharedMemoryKey << std::endl; + getSharedMemory(content, sizeof(content), 1); + + std::cout << content << std::endl; + } } return 0; } \ No newline at end of file From 6eda059c5135b4275aef890313278bb45d5a65d8 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Tue, 12 Nov 2019 11:08:10 +0000 Subject: [PATCH 2/7] ~ CI: clang_tidy step now contains catch2 & fltk --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index eb1309a..522f05f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,7 +9,7 @@ stages: clang_tidy: - image: jhasse/clang-tidy + image: joethei/clang_tidy stage: style tags: - docker-ci From f89d2ef5b682a82a6a6fbf02042a6332a0b0ae09 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Tue, 12 Nov 2019 11:40:52 +0000 Subject: [PATCH 3/7] ~ default argument calls are now allowed --- .ci/clang-tidy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/clang-tidy.sh b/.ci/clang-tidy.sh index eae5b12..c20c8fb 100644 --- a/.ci/clang-tidy.sh +++ b/.ci/clang-tidy.sh @@ -9,7 +9,7 @@ filelist="$(find . -not \( -path './client/cpptoml/*' -prune \) -type f ! -name for file in $filelist; do if echo "$file" | grep -q -E ".*\.cpp$" ; then #Extra check missing dependencies due to clang-tidy doesn't toggle exit code. - clang_tidy_lib_check="$(clang-tidy -warnings-as-errors='*' -header-filter='.*,-cpptoml.hpp' -checks='*,-llvm-header-guard,-fuchsia-statically-constructed-objects,-fuchsia-default-arguments,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-bounds-constant-array-index,-bugprone-narrowing-conversions,-cppcoreguidelines-narrowing-conversions,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-hicpp-signed-bitwise,-bugprone-exception-escape,-cppcoreguidelines-pro-type-member-init,-cppcoreguidelines-pro-type-cstyle-cast,-hicpp-member-init' "$file" -- -I. -std=c++14 2>&1)" + clang_tidy_lib_check="$(clang-tidy -warnings-as-errors='*' -header-filter='.*,-cpptoml.hpp' -checks='*,-llvm-header-guard,-fuchsia-statically-constructed-objects,-fuchsia-default-arguments,-fuchsia-default-argument-calls,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-bounds-constant-array-index,-bugprone-narrowing-conversions,-cppcoreguidelines-narrowing-conversions,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-hicpp-signed-bitwise,-bugprone-exception-escape,-cppcoreguidelines-pro-type-member-init,-cppcoreguidelines-pro-type-cstyle-cast,-hicpp-member-init' "$file" -- -I. -std=c++14 2>&1)" for tidy_line in $clang_tidy_lib_check; do echo "$tidy_line" | grep -q -v -E "^Error while processing*" if [ $? -eq 1 ]; then From 80ae989b2ba64d8d3a0ee052e56b48758ca8bfbd Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Tue, 12 Nov 2019 15:23:14 +0100 Subject: [PATCH 4/7] ~clang tidy checks all fies now --- .ci/clang-tidy.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.ci/clang-tidy.sh b/.ci/clang-tidy.sh index c20c8fb..913c79a 100644 --- a/.ci/clang-tidy.sh +++ b/.ci/clang-tidy.sh @@ -5,11 +5,11 @@ bool=false # explicitly set IFS to contain only a line feed IFS=' ' -filelist="$(find . -not \( -path './client/cpptoml/*' -prune \) -type f ! -name "$(printf "*\n*")")" +filelist="$(find . -not \( -path './*build*' -prune \) -type f ! -name "$(printf "*\n*")")" for file in $filelist; do - if echo "$file" | grep -q -E ".*\.cpp$" ; then + if echo "$file" | grep -q -E ".*(\.cpp|\.h|\.hpp)$" ; then #Extra check missing dependencies due to clang-tidy doesn't toggle exit code. - clang_tidy_lib_check="$(clang-tidy -warnings-as-errors='*' -header-filter='.*,-cpptoml.hpp' -checks='*,-llvm-header-guard,-fuchsia-statically-constructed-objects,-fuchsia-default-arguments,-fuchsia-default-argument-calls,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-bounds-constant-array-index,-bugprone-narrowing-conversions,-cppcoreguidelines-narrowing-conversions,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-hicpp-signed-bitwise,-bugprone-exception-escape,-cppcoreguidelines-pro-type-member-init,-cppcoreguidelines-pro-type-cstyle-cast,-hicpp-member-init' "$file" -- -I. -std=c++14 2>&1)" + clang_tidy_lib_check="$(clang-tidy -warnings-as-errors='*' -header-filter='.*,-cpptoml.hpp' -checks='*,-llvm-header-guard,-fuchsia-statically-constructed-objects,-fuchsia-default-arguments,-fuchsia-default-arguments-calls,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-bounds-constant-array-index,-bugprone-narrowing-conversions,-cppcoreguidelines-narrowing-conversions,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-hicpp-signed-bitwise,-bugprone-exception-escape,-cppcoreguidelines-pro-type-member-init,-cppcoreguidelines-pro-type-cstyle-cast,-hicpp-member-init' "$file" -- -I. -std=c++14 2>&1)" for tidy_line in $clang_tidy_lib_check; do echo "$tidy_line" | grep -q -v -E "^Error while processing*" if [ $? -eq 1 ]; then From 3671c2c3e1bcb41c4ac57a6794e39ed1550cd1ee Mon Sep 17 00:00:00 2001 From: Julian Hinxlage Date: Tue, 12 Nov 2019 16:22:55 +0100 Subject: [PATCH 5/7] + write and read text in shared memory ~ initialize library --- main/main.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/main/main.cpp b/main/main.cpp index 4ea5b9f..476abf9 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -5,19 +5,23 @@ #include #include #include +#include "vkvm.h" -int main(int argc, char** argv) -{ +int main(int argc, char** argv) { + initialize(0); + initSharedMemory(); struct sigaction sigIntHandler; sigIntHandler.sa_handler = deleteSharedMemory; sigemptyset(&sigIntHandler.sa_mask); sigIntHandler.sa_flags = 0; - sigaction(SIGINT, &sigIntHandler, NULL); + sigaction(SIGINT, &sigIntHandler, nullptr); + + setDefaultValues(); std::atexit(deleteSharedMemory); - std::string eingabe = ""; + std::string eingabe; while(eingabe != "exit") { std::cout << "cmd# "; std::cin >> eingabe; @@ -34,19 +38,28 @@ int main(int argc, char** argv) //Test for write and read if(eingabe == "write") { + std::cout << "text: "; + std::cin >> eingabe; + setText(eingabe); //write a bitMap for example 2 (width) * 2 (high) * 3 (color) in Schared Memory + /* char bitMap[12] = {0}; for(int i = 0; i < sizeof(bitMap); i++) bitMap[i] = 'y'; writeSharedMemory(bitMap, sizeof(bitMap),1); + */ } if(eingabe == "read") { + auto str = getText(); + std::cout << str << std::endl; + /* char content[12] = {0}; std::cout << "key "<< impl.sharedMemoryKey << std::endl; getSharedMemory(content, sizeof(content), 1); std::cout << content << std::endl; + */ } } return 0; From 0c248186141f1eb58cf107024160385afc7c1520 Mon Sep 17 00:00:00 2001 From: cigerxwinchaker Date: Tue, 12 Nov 2019 17:26:21 +0100 Subject: [PATCH 6/7] =?UTF-8?q?=C3=A4nderungen=20f=C3=BCr=20den=20memoryac?= =?UTF-8?q?cess=20key=20Cigerxwin=20Chaker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/main.cpp | 2 ++ src/SharedMemory.cpp | 10 +++++++--- src/SharedMemory.h | 2 ++ src/key.log | 1 + 4 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 src/key.log diff --git a/main/main.cpp b/main/main.cpp index fdf836c..1bef42a 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -28,6 +28,8 @@ int main(int argc, char** argv) std::cout << "OUTPUT ------------------------ OUTPUT\n" << std::endl; //Memory that is used now //outprint of all memory + } else if (eingabe != "exit"){ + std::cout << eingabe << " <- is not a known command" << std::endl; } } return 0; diff --git a/src/SharedMemory.cpp b/src/SharedMemory.cpp index 77520f6..ff81723 100644 --- a/src/SharedMemory.cpp +++ b/src/SharedMemory.cpp @@ -1,14 +1,20 @@ #include #include "SharedMemory.h" #include +#include key_t changedKey() { + std::ofstream keyFile; + keyFile.open("key.log", std::ofstream::out | std::ofstream::trunc); + keyFile.clear(); int newKey; std::cout << "Type in a new Key for the Shared Memory Segment" << std::endl; std::cout << "new Key#"; std::cin >> newKey; std::cout <<"New Key is -> " << newKey << std::endl; + keyFile << newKey; + keyFile.close(); return key_t(newKey); } @@ -36,9 +42,7 @@ void initSharedMemory(void) { std::string answer = getAnswerFromUser(); if(answer.compare("y") == 0) { - std::cout << "Please type in a new Key:\n"; - std::cout << "#"; - std::cin >> impl.sharedMemoryKey; + impl.sharedMemoryKey = changedKey(); std::cout << "new Try with Key:c " << impl.sharedMemoryKey << std::endl; initSharedMemory(); } else if(answer.compare("n") == 0) { diff --git a/src/SharedMemory.h b/src/SharedMemory.h index 96aefca..344aacc 100644 --- a/src/SharedMemory.h +++ b/src/SharedMemory.h @@ -12,4 +12,6 @@ void deleteSharedMemory(int s); void deleteSharedMemory(void); void initSharedMemory(void); +key_t changedKey(); +std::string getAnswerFromUser(); #endif //SHARED_MEMORY_H diff --git a/src/key.log b/src/key.log new file mode 100644 index 0000000..bd41cba --- /dev/null +++ b/src/key.log @@ -0,0 +1 @@ +12345 \ No newline at end of file From 5fd9a70a7231140901b043808292ecac86a6a9f7 Mon Sep 17 00:00:00 2001 From: Zakarya Boudouar Date: Tue, 12 Nov 2019 21:54:38 +0000 Subject: [PATCH 7/7] Update README.md --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index ad5a2dd..d4f2712 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,13 @@ # vKVM Shared Memory +Shared memory is a kernel-managed memory area that can be read and written by the graphical user interface , Text Renderer and the Library. + +## Features + +- set shared memory keys +- Manage the shared memory + + ## Installation Use the installation script provided in the Scripts repository @@ -7,3 +15,17 @@ to install the full package. Installing a single component is currently not supported. +## Usage + +mkdir build +cd build +cmake .. +make + +## Description + +changedKey(): create new Key for the Shared Memory. +getAnswerFromUser(): ask the User if he want to chgange the Key of Shared Memory. +initSharedMemory(): create Shared Memory and make it available t o use it +deleteSharedMemory(int s): delete the Shared memory. +deleteSharedMemory(): delete the Shared memory.