diff --git a/main/main.cpp b/main/main.cpp index 33b3f4e..752fcef 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -3,20 +3,22 @@ #include "../src/SharedMemory.h" #include #include -#include "vkvm.h" +#include "vkvm.hpp" int main(int argc, char** argv) { - initialize(0); + vkvm::initialize(0); initSharedMemory(); struct sigaction sigIntHandler; sigIntHandler.sa_handler = deleteSharedMemory; sigemptyset(&sigIntHandler.sa_mask); sigIntHandler.sa_flags = 0; sigaction(SIGINT, &sigIntHandler, nullptr); - setDefaultValues(); + vkvm::setDefaultValues(); std::atexit(deleteSharedMemory); std::string eingabe; + + while(eingabe != "exit") { std::cout << "cmd# "; std::cin >> eingabe; @@ -24,7 +26,7 @@ int main(int argc, char** argv) { if(eingabe == "info") { std::cout << "OUTPUT ------------------------ OUTPUT\n" << std::endl; - std::cout << "memory ID: " << shmget(impl.sharedMemoryKey, 0, 0) << std::endl; + std::cout << "memory ID: " << shmget(vkvm::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 @@ -32,7 +34,7 @@ int main(int argc, char** argv) { } else if(eingabe == "write") { std::cout << "text: "; std::cin >> eingabe; - setText(eingabe); + vkvm::setText(eingabe); //write a bitMap for example 2 (width) * 2 (high) * 3 (color) in Schared Memory /* char bitMap[12] = {0}; @@ -41,7 +43,7 @@ int main(int argc, char** argv) { writeSharedMemory(bitMap, sizeof(bitMap),1); */ } else if(eingabe == "read") { - auto str = getText(); + auto str = vkvm::getText(); std::cout << str << std::endl; /* char content[12] = {0}; diff --git a/src/SharedMemory.cpp b/src/SharedMemory.cpp index ff81723..558c602 100644 --- a/src/SharedMemory.cpp +++ b/src/SharedMemory.cpp @@ -34,16 +34,16 @@ std::string getAnswerFromUser() void initSharedMemory(void) { - if(impl.sharedMemoryKey != key_t(0)) { - if (shmget(impl.sharedMemoryKey, Max_Memory_Size, IPC_CREAT | IPC_EXCL | 0666) < 0) + if(vkvm::impl.sharedMemoryKey != key_t(0)) { + if (shmget(vkvm::impl.sharedMemoryKey, Max_Memory_Size, IPC_CREAT | IPC_EXCL | 0666) < 0) { - std::cout << "Shared Memory with Key: " << impl.sharedMemoryKey << " is already in use\n" + std::cout << "Shared Memory with Key: " << vkvm::impl.sharedMemoryKey << " is already in use\n" <<"You can change the Key( type -> y or n ), or you can override the shared memory Segment(type -> override)\n"; std::string answer = getAnswerFromUser(); if(answer.compare("y") == 0) { - impl.sharedMemoryKey = changedKey(); - std::cout << "new Try with Key:c " << impl.sharedMemoryKey << std::endl; + vkvm::impl.sharedMemoryKey = changedKey(); + std::cout << "new Try with Key:c " << vkvm::impl.sharedMemoryKey << std::endl; initSharedMemory(); } else if(answer.compare("n") == 0) { std::cout << "This will end shared memory" < " << impl.sharedMemoryKey << " is not allowed here " << std::endl; - impl.sharedMemoryKey = changedKey(); + std::cerr <<"key -> " << vkvm::impl.sharedMemoryKey << " is not allowed here " << std::endl; + vkvm::impl.sharedMemoryKey = changedKey(); initSharedMemory(); } } @@ -65,7 +65,7 @@ void initSharedMemory(void) { void deleteSharedMemory(int s) { std::cerr << "programm ended with Code: " << s << std::endl; - if (shmctl(shmget(impl.sharedMemoryKey, 0, 0), IPC_RMID, 0) < 0 ) + if (shmctl(shmget(vkvm::impl.sharedMemoryKey, 0, 0), IPC_RMID, 0) < 0 ) { std::cerr << "Failed to remove shared Memory, maybe not existing: try cmd: ipcs, then delete with ipcrm -m $memID " << std::endl; } else { @@ -75,7 +75,7 @@ void deleteSharedMemory(int s) void deleteSharedMemory(void) { - if (shmctl(shmget(impl.sharedMemoryKey, 0, 0), IPC_RMID, 0) < 0 ) + if (shmctl(shmget(vkvm::impl.sharedMemoryKey, 0, 0), IPC_RMID, 0) < 0 ) { std::cerr << "Failed to remove shared Memory, maybe not existing: try cmd: ipcs " << std::endl; } else { diff --git a/src/SharedMemory.h b/src/SharedMemory.h index 344aacc..26a4d1d 100644 --- a/src/SharedMemory.h +++ b/src/SharedMemory.h @@ -2,7 +2,7 @@ #define SHARED_MEMORY_H #include #include -#include "internal.h" +#include "internal.hpp" //ID-Speicherbereich //Größe des Speicherbereichs hier 8MB (8000)