2019-11-06 13:07:33 +01:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <signal.h>
|
2019-11-07 17:59:06 +01:00
|
|
|
#include "../src/SharedMemory.h"
|
|
|
|
#include <sys/shm.h>
|
|
|
|
#include <iostream>
|
2019-11-13 13:49:02 +01:00
|
|
|
#include "vkvm.hpp"
|
2019-10-16 16:21:27 +02:00
|
|
|
|
2019-11-06 13:07:33 +01:00
|
|
|
|
2019-11-12 16:22:55 +01:00
|
|
|
int main(int argc, char** argv) {
|
2019-11-13 13:49:02 +01:00
|
|
|
vkvm::initialize(0);
|
2019-11-07 17:59:06 +01:00
|
|
|
initSharedMemory();
|
2019-11-06 13:07:33 +01:00
|
|
|
struct sigaction sigIntHandler;
|
|
|
|
sigIntHandler.sa_handler = deleteSharedMemory;
|
|
|
|
sigemptyset(&sigIntHandler.sa_mask);
|
|
|
|
sigIntHandler.sa_flags = 0;
|
2019-11-12 16:22:55 +01:00
|
|
|
sigaction(SIGINT, &sigIntHandler, nullptr);
|
2019-11-13 13:49:02 +01:00
|
|
|
vkvm::setDefaultValues();
|
2019-11-06 13:07:33 +01:00
|
|
|
std::atexit(deleteSharedMemory);
|
2019-11-12 16:22:55 +01:00
|
|
|
std::string eingabe;
|
2019-12-04 13:26:49 +01:00
|
|
|
getConfig();
|
2019-11-07 17:59:06 +01:00
|
|
|
while(eingabe != "exit") {
|
|
|
|
std::cout << "cmd# ";
|
|
|
|
std::cin >> eingabe;
|
|
|
|
//if verschieden information ausgaben
|
|
|
|
if(eingabe == "info")
|
|
|
|
{
|
2019-11-07 18:05:59 +01:00
|
|
|
std::cout << "OUTPUT ------------------------ OUTPUT\n" << std::endl;
|
2019-11-13 13:49:02 +01:00
|
|
|
std::cout << "memory ID: " << shmget(vkvm::impl.sharedMemoryKey, 0, 0) << std::endl;
|
2019-11-07 17:59:06 +01:00
|
|
|
std::cout << "Max memory Size: " << Max_Memory_Size << std::endl;
|
2019-11-07 18:05:59 +01:00
|
|
|
std::cout << "OUTPUT ------------------------ OUTPUT\n" << std::endl;
|
2019-11-07 17:59:06 +01:00
|
|
|
//Memory that is used now
|
|
|
|
//outprint of all memory
|
2019-11-12 18:36:16 +01:00
|
|
|
} else if(eingabe == "write") {
|
2019-11-12 16:22:55 +01:00
|
|
|
std::cout << "text: ";
|
|
|
|
std::cin >> eingabe;
|
2019-11-13 13:49:02 +01:00
|
|
|
vkvm::setText(eingabe);
|
2019-11-08 18:31:42 +01:00
|
|
|
//write a bitMap for example 2 (width) * 2 (high) * 3 (color) in Schared Memory
|
2019-11-12 16:22:55 +01:00
|
|
|
/*
|
2019-11-08 18:31:42 +01:00
|
|
|
char bitMap[12] = {0};
|
|
|
|
for(int i = 0; i < sizeof(bitMap); i++)
|
|
|
|
bitMap[i] = 'y';
|
|
|
|
writeSharedMemory(bitMap, sizeof(bitMap),1);
|
2019-11-12 16:22:55 +01:00
|
|
|
*/
|
2019-11-12 18:36:16 +01:00
|
|
|
} else if(eingabe == "read") {
|
2019-11-13 13:49:02 +01:00
|
|
|
auto str = vkvm::getText();
|
2019-11-12 16:22:55 +01:00
|
|
|
std::cout << str << std::endl;
|
|
|
|
/*
|
2019-11-08 18:31:42 +01:00
|
|
|
char content[12] = {0};
|
|
|
|
std::cout << "key "<< impl.sharedMemoryKey << std::endl;
|
|
|
|
getSharedMemory(content, sizeof(content), 1);
|
|
|
|
|
|
|
|
std::cout << content << std::endl;
|
2019-11-12 16:22:55 +01:00
|
|
|
*/
|
2019-11-12 18:36:16 +01:00
|
|
|
} else if (eingabe != "exit"){
|
2019-11-12 17:26:21 +01:00
|
|
|
std::cout << eingabe << " <- is not a known command" << std::endl;
|
2019-11-07 17:59:06 +01:00
|
|
|
}
|
|
|
|
}
|
2019-11-06 13:07:33 +01:00
|
|
|
return 0;
|
2019-10-16 16:21:27 +02:00
|
|
|
}
|