test for write and read of shared memory in main.cpp
This commit is contained in:
parent
121ae391c0
commit
bf6546e3b8
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#include "../src/SharedMemory.h"
|
||||
#include <sys/shm.h>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <SharedMemoryAccess.h>
|
||||
|
||||
|
||||
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;
|
||||
}
|
Loading…
Reference in New Issue