shared-memory/main/main.cpp

53 lines
1.7 KiB
C++
Raw Normal View History

2019-11-06 13:07:33 +01:00
#include <cstdlib>
#include <signal.h>
#include "../src/SharedMemory.h"
#include <sys/shm.h>
#include <iostream>
#include <cstring>
#include <SharedMemoryAccess.h>
2019-11-06 13:07:33 +01:00
int main(int argc, char** argv)
{
initSharedMemory();
2019-11-06 13:07:33 +01:00
struct sigaction sigIntHandler;
sigIntHandler.sa_handler = deleteSharedMemory;
sigemptyset(&sigIntHandler.sa_mask);
sigIntHandler.sa_flags = 0;
sigaction(SIGINT, &sigIntHandler, NULL);
2019-11-06 13:07:33 +01:00
std::atexit(deleteSharedMemory);
std::string eingabe = "";
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
}
//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;
}
}
2019-11-06 13:07:33 +01:00
return 0;
}