Bitte geben Sie eine Commit-Beschreibung für Ihre Änderungen ein. Zeilen,
This commit is contained in:
parent
2334b55dd4
commit
46b3c0adf7
@ -1,20 +1,14 @@
|
|||||||
|
#include "../src/SharedMemory.h"
|
||||||
|
#include "vkvm.hpp"
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sys/shm.h>
|
#include <sys/shm.h>
|
||||||
#include <csignal>
|
|
||||||
|
|
||||||
#include "../src/SharedMemory.h"
|
|
||||||
#include "vkvm.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
vkvm::initialize(0);
|
vkvm::initialize(0);
|
||||||
initSharedMemory();
|
initSharedMemory();
|
||||||
struct sigaction sigIntHandler;
|
|
||||||
sigIntHandler.sa_handler = deleteSharedMemory;
|
|
||||||
sigemptyset(&sigIntHandler.sa_mask);
|
|
||||||
sigIntHandler.sa_flags = 0;
|
|
||||||
sigaction(SIGINT, &sigIntHandler, nullptr);
|
|
||||||
vkvm::setDefaultValues();
|
vkvm::setDefaultValues();
|
||||||
std::atexit(deleteSharedMemory);
|
std::atexit(deleteSharedMemory);
|
||||||
std::string eingabe;
|
std::string eingabe;
|
||||||
|
@ -1,16 +1,11 @@
|
|||||||
#include <cstdlib>
|
|
||||||
#include "SharedMemory.h"
|
#include "SharedMemory.h"
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <cpptoml.h>
|
#include <cpptoml.h>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
#include <vkvm.hpp>
|
#include <vkvm.hpp>
|
||||||
|
|
||||||
|
key_t changedKey() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
key_t changedKey()
|
|
||||||
{
|
|
||||||
std::ofstream keyFile;
|
std::ofstream keyFile;
|
||||||
keyFile.open("/tmp/vkvmKey.log", std::ofstream::out | std::ofstream::trunc);
|
keyFile.open("/tmp/vkvmKey.log", std::ofstream::out | std::ofstream::trunc);
|
||||||
keyFile.clear();
|
keyFile.clear();
|
||||||
@ -18,44 +13,40 @@ key_t changedKey()
|
|||||||
std::cout << "Type in a new Key for the Shared Memory Segment" << std::endl;
|
std::cout << "Type in a new Key for the Shared Memory Segment" << std::endl;
|
||||||
std::cout << "new Key#";
|
std::cout << "new Key#";
|
||||||
std::cin >> newKey;
|
std::cin >> newKey;
|
||||||
std::cout <<"New Key is -> " << newKey << std::endl;
|
std::cout << "New Key is -> " << newKey << std::endl;
|
||||||
keyFile << newKey;
|
keyFile << newKey;
|
||||||
keyFile.close();
|
keyFile.close();
|
||||||
|
|
||||||
return key_t(newKey);
|
return key_t(newKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getAnswerFromUser()
|
std::string getAnswerFromUser() {
|
||||||
{
|
std::cout << "answer# ";
|
||||||
std::cout <<"answer# ";
|
|
||||||
std::string answer;
|
std::string answer;
|
||||||
std::cin >> answer;
|
std::cin >> answer;
|
||||||
if(answer.compare("y") == 0 || answer.compare("n") == 0|| answer.compare("override") == 0) {
|
if (answer == "y" || answer == "n" || answer == "override") {
|
||||||
return answer;
|
return answer;
|
||||||
} else {
|
|
||||||
std::cout << "wrong input: pls answer with (y) for yes, (n) for no, or (override)\n";
|
|
||||||
getAnswerFromUser();
|
|
||||||
}
|
}
|
||||||
|
std::cout << "wrong input: pls answer with (y) for yes, (n) for no, or (override)\n";
|
||||||
|
getAnswerFromUser();
|
||||||
return "-0";
|
return "-0";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void initSharedMemory(void) {
|
void initSharedMemory() {
|
||||||
if(vkvm::impl.sharedMemoryKey != key_t(0)) {
|
if (vkvm::impl.sharedMemoryKey != key_t(0)) {
|
||||||
if (shmget(vkvm::impl.sharedMemoryKey, Max_Memory_Size, IPC_CREAT | IPC_EXCL | 0666) < 0)
|
if (shmget(vkvm::impl.sharedMemoryKey, Max_Memory_Size, IPC_CREAT | IPC_EXCL | 0666) < 0) {
|
||||||
{
|
|
||||||
std::cout << "Shared Memory with Key: " << vkvm::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";
|
<< "You can change the Key( type -> y or n ), or you can override the shared memory Segment(type -> override)\n";
|
||||||
std::string answer = getAnswerFromUser();
|
std::string answer = getAnswerFromUser();
|
||||||
if(answer.compare("y") == 0)
|
if (answer == "y") {
|
||||||
{
|
|
||||||
vkvm::impl.sharedMemoryKey = changedKey();
|
vkvm::impl.sharedMemoryKey = changedKey();
|
||||||
std::cout << "new Try with Key: " << vkvm::impl.sharedMemoryKey << std::endl;
|
std::cout << "new Try with Key: " << vkvm::impl.sharedMemoryKey << std::endl;
|
||||||
initSharedMemory();
|
initSharedMemory();
|
||||||
} else if(answer.compare("n") == 0) {
|
} else if (answer == "n") {
|
||||||
std::cout << "This will end shared memory" <<std::endl;
|
std::cout << "This will end shared memory" << std::endl;
|
||||||
exit(0);
|
exit(0);
|
||||||
} else if(answer.compare("override") == 0) {
|
} else if (answer == "override") {
|
||||||
deleteSharedMemory();
|
deleteSharedMemory();
|
||||||
initSharedMemory();
|
initSharedMemory();
|
||||||
}
|
}
|
||||||
@ -63,34 +54,23 @@ void initSharedMemory(void) {
|
|||||||
std::cout << "Shared Memory is (Re-) allocated with Key: " << vkvm::impl.sharedMemoryKey << std::endl;
|
std::cout << "Shared Memory is (Re-) allocated with Key: " << vkvm::impl.sharedMemoryKey << std::endl;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
std::cerr <<"key -> " << vkvm::impl.sharedMemoryKey << " is not allowed here " << std::endl;
|
std::cerr << "key -> " << vkvm::impl.sharedMemoryKey << " is not allowed here " << std::endl;
|
||||||
vkvm::impl.sharedMemoryKey = changedKey();
|
vkvm::impl.sharedMemoryKey = changedKey();
|
||||||
initSharedMemory();
|
initSharedMemory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void deleteSharedMemory(int s)
|
void deleteSharedMemory() {
|
||||||
{
|
int id = shmctl(shmget(vkvm::impl.sharedMemoryKey, 0, 0), IPC_RMID, 0);
|
||||||
std::cerr << "programm ended with Code: " << s << std::endl;
|
if (id < 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 {
|
|
||||||
std::cout << "shared Memory deleted" << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void deleteSharedMemory(void)
|
|
||||||
{
|
|
||||||
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;
|
std::cerr << "Failed to remove shared Memory, maybe not existing: try cmd: ipcs " << std::endl;
|
||||||
} else {
|
} else {
|
||||||
|
int x =0;
|
||||||
std::cout << "shared Memory deleted" << std::endl;
|
std::cout << "shared Memory deleted" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void getConfig(){
|
void getConfig() {
|
||||||
auto config = cpptoml::parse_file(configFile);
|
auto config = cpptoml::parse_file(configFile);
|
||||||
|
|
||||||
int layoutVersion = config->get_as<int>("layoutVersion").value_or(0);
|
int layoutVersion = config->get_as<int>("layoutVersion").value_or(0);
|
||||||
@ -123,7 +103,7 @@ void getConfig(){
|
|||||||
vkvm::setForegroundColor(vkvm::Color(foregroundColor));
|
vkvm::setForegroundColor(vkvm::Color(foregroundColor));
|
||||||
vkvm::setCharactersPerRow(charactersPerRow);
|
vkvm::setCharactersPerRow(charactersPerRow);
|
||||||
vkvm::setCharactersPerColumn(charactersPerColumn);
|
vkvm::setCharactersPerColumn(charactersPerColumn);
|
||||||
vkvm::setFont(vkvm::FontType(font,"",0,0));
|
vkvm::setFont(vkvm::FontType(font, "", 0, 0));
|
||||||
vkvm::setMousePosition(mousePositionX, mousePositionY);
|
vkvm::setMousePosition(mousePositionX, mousePositionY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
#ifndef SHARED_MEMORY_H
|
#ifndef SHARED_MEMORY_H
|
||||||
#define SHARED_MEMORY_H
|
#define SHARED_MEMORY_H
|
||||||
|
|
||||||
|
#include "internal.hpp" //NOLINT
|
||||||
#include <sys/shm.h>
|
#include <sys/shm.h>
|
||||||
#include <iostream>
|
|
||||||
#include "internal.hpp"
|
|
||||||
|
|
||||||
//ID-Speicherbereich
|
//ID-Speicherbereich
|
||||||
//Größe des Speicherbereichs hier 8MB (8000)
|
//Größe des Speicherbereichs hier 8MB (8000)
|
||||||
//Shared-Memory-Segment erstellen oder öffnen – shmget()
|
//Shared-Memory-Segment erstellen oder öffnen – shmget()
|
||||||
#define Max_Memory_Size 8000 * 512
|
constexpr int Max_Memory_Size (8000 * 512);
|
||||||
void deleteSharedMemory(int s);
|
void deleteSharedMemory(int s);
|
||||||
void deleteSharedMemory(void);
|
void deleteSharedMemory();
|
||||||
void initSharedMemory(void);
|
void initSharedMemory();
|
||||||
void getConfig();
|
void getConfig();
|
||||||
key_t changedKey();
|
key_t changedKey();
|
||||||
std::string getAnswerFromUser();
|
std::string getAnswerFromUser();
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#include "../src/SharedMemory.h"
|
#include "../src/SharedMemory.h"
|
||||||
#include <catch2/catch.hpp>
|
|
||||||
|
|
||||||
TEST_CASE("Demo test") {
|
TEST_CASE("Demo test") {
|
||||||
REQUIRE(42 == 42);
|
REQUIRE(42 == 42);
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
#define CATCH_CONFIG_MAIN
|
#define CATCH_CONFIG_MAIN
|
||||||
|
|
||||||
#include <catch2/catch.hpp>
|
|
||||||
|
|
||||||
//Dont touch this file.
|
//Dont touch this file.
|
||||||
// add your own tests in this directory according to https://github.com/catchorg/Catch2/blob/master/docs/tutorial.md
|
// add your own tests in this directory according to https://github.com/catchorg/Catch2/blob/master/docs/tutorial.md
|
||||||
|
Loading…
x
Reference in New Issue
Block a user