+ everything namespaced

~ fixed clang-tidy errors
This commit is contained in:
Johannes Theiner 2019-11-13 13:37:49 +01:00
parent 5aa0a7862f
commit c8569eb3b4
28 changed files with 847 additions and 789 deletions

View File

@ -5,11 +5,11 @@ bool=false
# explicitly set IFS to contain only a line feed # explicitly set IFS to contain only a line feed
IFS=' IFS='
' '
filelist="$(find . -not \( -path './*build*' -prune \) -type f ! -name "$(printf "*\n*")")" filelist="$(find . -not \( -path './*build*' -prune \) -not \( -path './include' -prune \) -not \( -path './lib' -prune \) -type f ! -name "$(printf "*\n*")")"
for file in $filelist; do for file in $filelist; do
if echo "$file" | grep -q -E ".*(\.cpp|\.h|\.hpp)$" ; then if echo "$file" | grep -q -E ".*(\.cpp|\.h|\.hpp)$" ; then
#Extra check missing dependencies due to clang-tidy doesn't toggle exit code. #Extra check missing dependencies due to clang-tidy doesn't toggle exit code.
clang_tidy_lib_check="$(clang-tidy -warnings-as-errors='*' -header-filter='.*,-cpptoml.hpp' -checks='*,-llvm-header-guard,-fuchsia-statically-constructed-objects,-fuchsia-default-arguments,-fuchsia-default-arguments-calls,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-bounds-constant-array-index,-bugprone-narrowing-conversions,-cppcoreguidelines-narrowing-conversions,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-hicpp-signed-bitwise,-bugprone-exception-escape,-cppcoreguidelines-pro-type-member-init,-cppcoreguidelines-pro-type-cstyle-cast,-hicpp-member-init' "$file" -- -I. -std=c++14 2>&1)" clang_tidy_lib_check="$(clang-tidy -warnings-as-errors='*' -header-filter='.*,-cpptoml.hpp' -checks='*,-llvm-header-guard,-fuchsia-statically-constructed-objects,-fuchsia*,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-bounds-constant-array-index,-bugprone-narrowing-conversions,-cppcoreguidelines-narrowing-conversions,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-hicpp-signed-bitwise,-bugprone-exception-escape,-cppcoreguidelines-pro-type-member-init,-cppcoreguidelines-pro-type-cstyle-cast,-hicpp-member-init,-google-readability-namespace-comments,-llvm-namespace-comment' "$file" -- -I. -std=c++14 2>&1)"
for tidy_line in $clang_tidy_lib_check; do for tidy_line in $clang_tidy_lib_check; do
echo "$tidy_line" | grep -q -v -E "^Error while processing*" echo "$tidy_line" | grep -q -v -E "^Error while processing*"
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then

View File

@ -17,7 +17,7 @@ set(CMAKE_CXX_CLANG_TIDY clang-tidy;-header-filter=.;-checks=*;)
file(GLOB_RECURSE SOURCES src/*.cpp) file(GLOB_RECURSE SOURCES src/*.cpp)
file(GLOB_RECURSE HEADERS src/*.h) file(GLOB_RECURSE HEADERS src/*.hpp)
file(GLOB_RECURSE TESTS test/*.cpp) file(GLOB_RECURSE TESTS test/*.cpp)
include_directories(src) include_directories(src)
include_directories(test) include_directories(test)

View File

@ -1,32 +1,33 @@
#include "Color.hpp"
#include "Color.h" namespace vkvm {
Color::Color(unsigned char red, unsigned char green, unsigned char blue) noexcept Color::Color(unsigned char red, unsigned char green, unsigned char blue) noexcept
: red(red), green(green), blue(blue){ : red(red), green(green), blue(blue) {
} }
unsigned char Color::getRed() { auto Color::getRed() -> unsigned char {
return red; return red;
} }
unsigned char Color::getGreen() { auto Color::getGreen() -> unsigned char {
return green; return green;
} }
unsigned char Color::getBlue() { auto Color::getBlue() -> unsigned char {
return blue; return blue;
} }
void Color::setRed(unsigned char value) { auto Color::setRed(unsigned char value) -> void {
red = value; red = value;
} }
void Color::setGreen(unsigned char value) { auto Color::setGreen(unsigned char value) -> void {
green = value; green = value;
} }
void Color::setBlue(unsigned char value) {
blue = value;
}
auto Color::setBlue(unsigned char value) -> void {
blue = value;
}
}

View File

@ -1,33 +0,0 @@
#ifndef LIBRARY_COLOR_H
#define LIBRARY_COLOR_H
/**
* color values represented as rgb values.
* @author Johannes Theiner
* @since 0.1.0
*/
class Color {
private:
unsigned char red;
unsigned char green;
unsigned char blue;
public:
Color(unsigned char red, unsigned char green, unsigned char blue) noexcept;
unsigned char getRed();
unsigned char getGreen();
unsigned char getBlue();
void setRed(unsigned char value);
void setGreen(unsigned char value);
void setBlue(unsigned char value);
};
const static Color black = Color(0, 0, 0);
const static Color white = Color(255, 255, 255);
#endif

40
src/Color.hpp Normal file
View File

@ -0,0 +1,40 @@
#ifndef LIBRARY_COLOR_HPP
#define LIBRARY_COLOR_HPP
namespace vkvm {
/**
* color values represented as rgb values.
* @author Johannes Theiner
* @since 0.1.0
*/
class Color {
private:
unsigned char red;
unsigned char green;
unsigned char blue;
public:
Color(unsigned char red, unsigned char green, unsigned char blue) noexcept;
auto getRed() -> unsigned char;
auto getGreen() -> unsigned char;
auto getBlue() -> unsigned char;
auto setRed(unsigned char value) -> void;
auto setGreen(unsigned char value) -> void;
auto setBlue(unsigned char value) -> void;
};
const static Color black = Color(0, 0, 0);
const static Color white = Color(255, 255, 255);
}
#endif

View File

@ -1,20 +0,0 @@
#ifndef LIBRARY_EVENTTYPE_H
#define LIBRARY_EVENTTYPE_H
/**
* types of events.
* @since 0.1.0
* @uthor Johannes Theiner
*/
enum EventType {
Timer = 1,
MouseMove = 2,
MouseButton = 3,
KeyDown = 4,
KeyUp = 5,
UpdateControlRegisters = 6,
Redraw = 7,
RenderText = 8
};
#endif

24
src/EventType.hpp Normal file
View File

@ -0,0 +1,24 @@
#ifndef LIBRARY_EVENTTYPE_HPP
#define LIBRARY_EVENTTYPE_HPP
namespace vkvm {
/**
* types of events.
* @since 0.1.0
* @uthor Johannes Theiner
*/
enum EventType {
Timer = 1,
MouseMove = 2,
MouseButton = 3,
KeyDown = 4,
KeyUp = 5,
UpdateControlRegisters = 6,
Redraw = 7,
RenderText = 8
};
}
#endif

View File

@ -1,25 +1,28 @@
#include "FontType.h" #include "FontType.hpp"
namespace vkvm {
FontType::FontType(int id, std::string name, int height, int width) noexcept { FontType::FontType(int id, std::string name, int height, int width) noexcept {
this->id = id; this->id = id;
this->name = std::move(name); this->name = std::move(name);
this->height = height; this->height = height;
this->width = width; this->width = width;
} }
int FontType::getId() const{ auto FontType::getId() const -> int {
return id; return id;
} }
std::string FontType::getName() const{ auto FontType::getName() const -> std::string {
return name; return name;
} }
int FontType::getHeight() const{ auto FontType::getHeight() const -> int {
return height; return height;
} }
int FontType::getWidth() const{ auto FontType::getWidth() const -> int {
return width; return width;
} }
}

View File

@ -1,27 +0,0 @@
#ifndef LIBRARY_FONT_H
#define LIBRARY_FONT_H
#include <string>
#include <utility>
class FontType {
private:
int id;
std::string name;
int height;
int width;
public:
FontType(int id, std::string name, int height, int width) noexcept;
int getId() const;
std::string getName() const;
int getHeight() const;
int getWidth() const;
};
const static FontType font_1 = FontType(1, "DummyFont", 10, 5);
#endif

35
src/FontType.hpp Normal file
View File

@ -0,0 +1,35 @@
#ifndef LIBRARY_FONT_H
#define LIBRARY_FONT_H
#include <string>
#include <utility>
namespace vkvm {
class FontType {
private:
int id;
std::string name;
int height;
int width;
public:
FontType(int id, std::string name, int height, int width) noexcept;
auto getId() const -> int;
auto getName() const -> std::string;
auto getHeight() const -> int;
auto getWidth() const -> int;
};
const static FontType font_1 = FontType(1, "DummyFont", 10, 5);
}
#endif

View File

@ -1,16 +0,0 @@
#ifndef LIBRARY_GRAPHICMODE_H
#define LIBRARY_GRAPHICMODE_H
/**
* all possible graphics modes.
* @author Johannes Theiner
* @since 0.1.0
*/
enum GraphicMode {
Text = 1,
TwoColors = 2,
Gray_256 = 3,
TrueColor = 4,
};
#endif

19
src/GraphicMode.hpp Normal file
View File

@ -0,0 +1,19 @@
#ifndef LIBRARY_GRAPHICMODE_HPP
#define LIBRARY_GRAPHICMODE_HPP
namespace vkvm {
/**
* all possible graphics modes.
* @author Johannes Theiner
* @since 0.1.0
*/
enum GraphicMode {
Text = 1,
TwoColors = 2,
Gray_256 = 3,
TrueColor = 4,
};
}
#endif

View File

@ -1,9 +1,11 @@
#include "KeyCode.hpp"
#include "KeyCode.h" namespace vkvm {
KeyCode::KeyCode(int value) noexcept : value(value) {} KeyCode::KeyCode(int value) noexcept : value(value) {}
auto KeyCode::getValue() -> int {
return value;
}
int KeyCode::getValue() {
return value;
} }

View File

@ -1,17 +0,0 @@
#ifndef LIBRARY_KEYCODE_H
#define LIBRARY_KEYCODE_H
#include <sys/types.h>
class KeyCode {
private:
int value;
public:
explicit KeyCode(int value) noexcept;
int getValue();
};
const static KeyCode Backspace = KeyCode(8);
const static KeyCode tabulator = KeyCode(9);
#endif

22
src/KeyCode.hpp Normal file
View File

@ -0,0 +1,22 @@
#ifndef LIBRARY_KEYCODE_HPP
#define LIBRARY_KEYCODE_HPP
#include <sys/types.h>
namespace vkvm {
class KeyCode {
private:
int value;
public:
explicit KeyCode(int value) noexcept;
auto getValue() -> int;
};
const static KeyCode Backspace = KeyCode(8);
const static KeyCode tabulator = KeyCode(9);
}
#endif

View File

@ -1,8 +0,0 @@
#ifndef LIBRARY_LAYOUTVERSION_H
#define LIBRARY_LAYOUTVERSION_H
enum LayoutVersion {
V1 = 1
};
#endif

12
src/LayoutVersion.hpp Normal file
View File

@ -0,0 +1,12 @@
#ifndef LIBRARY_LAYOUTVERSION_HPP
#define LIBRARY_LAYOUTVERSION_HPP
namespace vkvm {
enum LayoutVersion {
V1 = 1
};
}
#endif

View File

@ -1,6 +1,3 @@
//
// Created by Cigerxwin Chaker on 05.11.19.
//
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
@ -12,93 +9,96 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include "SharedMemoryAccess.h" /* header is important for the shmID. name could be different. maybe not needed cause: (shmget(memory_access_key, NULL, 0)) */ #include "SharedMemoryAccess.hpp" /* header is important for the shmID. name could be different. maybe not needed cause: (shmget(memory_access_key, NULL, 0)) */
#include "internal.h" #include "internal.hpp"
constexpr int PERM = 0666; /* access rights */ namespace vkvm {
constexpr int LOCK = -1; constexpr int PERM = 0666; /* access rights */
constexpr int UNLOCK = 1; constexpr int LOCK = -1;
constexpr int SEM_KEY = 123458L; constexpr int UNLOCK = 1;
constexpr int SEM_KEY = 123458L;
//int memoryAccessKey; /* var type is int. but could be another type. */ //TODO: look after type in sharedmemory group //int memoryAccessKey; /* var type is int. but could be another type. */ //TODO: look after type in sharedmemory group
int semId; int semId;
struct sembuf semaphore; struct sembuf semaphore;
std::vector<char> localSharedMemory; std::vector<char> localSharedMemory;
int initSemaphore() { auto initSemaphore() -> int {
/* Testen, ob das Semaphor bereits existiert */ /* Testen, ob das Semaphor bereits existiert */
semId = semget(SEM_KEY, 0, IPC_PRIVATE); semId = semget(SEM_KEY, 0, IPC_PRIVATE);
if (semId < 0) {
/* ... existiert noch nicht, also anlegen */
/* Alle Zugriffsrechte der Dateikreierungsmaske */
/* erlauben */
umask(0);
semId = semget(SEM_KEY, 1, IPC_CREAT | IPC_EXCL | PERM);
if (semId < 0) { if (semId < 0) {
/* ... existiert noch nicht, also anlegen */
/* Alle Zugriffsrechte der Dateikreierungsmaske */
/* erlauben */
umask(0);
semId = semget(SEM_KEY, 1, IPC_CREAT | IPC_EXCL | PERM);
if (semId < 0) {
return -1;
}
/* Semaphor mit 1 initialisieren */
if (semctl(semId, 0, SETVAL, 1) == -1){
return -1;
}
}
return 1;
}
auto semaphoreOperation(int op) -> int {
semaphore.sem_op = static_cast<int16_t>(op);
semaphore.sem_flg = SEM_UNDO;
if (semop(semId, &semaphore, 1) == -1) {
perror(" semop ");
return -1; return -1;
} }
/* Semaphor mit 1 initialisieren */ return 1;
if (semctl(semId, 0, SETVAL, 1) == -1){ }
return -1;
auto writeSharedMemory(char *data, int size, int offset) -> void {
lockSharedMemory();
memcpy(getSharedMemory() + offset, data, size);
unlockSharedMemory();
}
auto getSharedMemory() -> char * {
bool useLocal = false;
if(!useLocal){
int shmId = shmget(impl.sharedMemoryKey, NULL, 0);
if(shmId < 0) {
//no shared memory found
useLocal = true;
} else {
return (char *) shmat(shmId, NULL, 0);
}
} }
}
return 1;
}
int semaphoreOperation(int op) { if(useLocal) {
semaphore.sem_op = static_cast<int16_t>(op); //using a local buffer for shared memory testing
semaphore.sem_flg = SEM_UNDO; if (localSharedMemory.empty()) {
if (semop(semId, &semaphore, 1) == -1) { initSemaphore();
perror(" semop "); localSharedMemory.resize(impl.sharedMemorySize * 1024);
return -1; }
} return &localSharedMemory[0];
return 1;
}
void writeSharedMemory(char *data, int size, int offset) {
lockSharedMemory();
memcpy(getSharedMemory() + offset, data, size);
unlockSharedMemory();
}
char *getSharedMemory() {
bool useLocal = false;
if(!useLocal){
int shmId = shmget(impl.sharedMemoryKey, NULL, 0);
if(shmId < 0) {
//no shared memory found
useLocal = true;
} else {
return (char *) shmat(shmId, NULL, 0);
} }
} }
if(useLocal) { auto getSharedMemory(char *address, int size, int offset) -> void {
//using a local buffer for shared memory testing lockSharedMemory();
if (localSharedMemory.empty()) { memcpy(address, getSharedMemory() + offset, size);
initSemaphore(); unlockSharedMemory();
localSharedMemory.resize(impl.sharedMemorySize * 1024);
}
return &localSharedMemory[0];
} }
}
void getSharedMemory(char *address, int size, int offset) { auto getSharedMemorySize() -> int {
lockSharedMemory(); return impl.sharedMemorySize;
memcpy(address, getSharedMemory() + offset, size); }
unlockSharedMemory();
}
int getSharedMemorySize() { auto lockSharedMemory() -> void {
return impl.sharedMemorySize; semaphoreOperation(LOCK);
} }
void lockSharedMemory() { auto unlockSharedMemory() -> void {
semaphoreOperation(LOCK); semaphoreOperation(UNLOCK);
} }
void unlockSharedMemory() { }
semaphoreOperation(UNLOCK);
}

View File

@ -1,17 +1,14 @@
//
// Created by Cigerxwin Chaker on 05.11.19.
//
#ifndef LIBRARY_SHAREDMEMORYACCESSS_H #ifndef LIBRARY_SHAREDMEMORYACCESSS_H
#define LIBRARY_SHAREDMEMORYACCESSS_H #define LIBRARY_SHAREDMEMORYACCESSS_H
int initSemaphore(); namespace vkvm {
auto initSemaphore() -> int;
/** /**
* use lock and unlock when writing * use lock and unlock when writing
* @return pointer to the shared memory * @return pointer to the shared memory
*/ */
char *getSharedMemory(); auto getSharedMemory() -> char *;
/** /**
* use lock and unlock when writing, * use lock and unlock when writing,
@ -20,17 +17,17 @@ char *getSharedMemory();
* @param size of data * @param size of data
* @param offset where the data is written on the shared memory * @param offset where the data is written on the shared memory
*/ */
void getSharedMemory(char *address, int size, int offset); auto getSharedMemory(char *address, int size, int offset) -> void;
/** /**
* *
* @return the size of the shared memory * @return the size of the shared memory
*/ */
int getSharedMemorySize(); auto getSharedMemorySize() -> int;
void lockSharedMemory(); auto lockSharedMemory() -> void;
void unlockSharedMemory(); auto unlockSharedMemory() -> void;
/** /**
* *
@ -38,6 +35,7 @@ void unlockSharedMemory();
* @param size of data * @param size of data
* @param offset where the data is written on the shared memory * @param offset where the data is written on the shared memory
*/ */
void writeSharedMemory(char *data, int size, int offset); auto writeSharedMemory(char *data, int size, int offset) -> void;
}
#endif //LIBRARY_SHAREDMEMORYACCESSS_H #endif

View File

@ -1,78 +1,83 @@
#include "internal.h" #include "internal.hpp"
#include "SharedMemoryAccess.h" #include "SharedMemoryAccess.hpp"
#include "vkvm.h" #include "vkvm.hpp"
#include <csignal> #include <csignal>
#include <sys/shm.h> #include <sys/shm.h>
Impl impl;
void sendSignal(pid_t pid, int signalNumber) { namespace vkvm {
kill(pid, signalNumber);
}
void onSignal(int signalNumber, void(*callback)(int)) { Impl impl;
signal(signalNumber, callback);
}
InterruptEntry *getInterrupTable(){ auto sendSignal(pid_t pid, int signalNumber) -> void {
return reinterpret_cast<InterruptEntry*>(getSharedMemory() + sizeof(Registers) + impl.reservedSize); kill(pid, signalNumber);
}
Registers *getRegisters(){
return reinterpret_cast<Registers*>(getSharedMemory());
}
char *getTextArea(){
return ((getSharedMemory() + sizeof(Registers) + impl.reservedSize) +
sizeof(InterruptEntry) * impl.interruptEntyCount);
}
char *getPixelArea(){
return (((getSharedMemory() + sizeof(Registers) + impl.reservedSize) +
sizeof(InterruptEntry) * impl.interruptEntyCount) +
getCharactersPerRow() * getCharactersPerColumn());
}
bool callEvent(EventType type) {
auto ivt = getInterrupTable();
if(ivt[type].pid != 0){
sendSignal(ivt[type].pid, ivt[type].signum);
} }
return true;
}
void setLayoutVersion(LayoutVersion newValue) { auto onSignal(int signalNumber, void(*callback)(int)) -> void {
lockSharedMemory(); signal(signalNumber, callback);
getRegisters()->layout_version = newValue;
unlockSharedMemory();
}
void setCharactersPerColumn(int newValue) {
lockSharedMemory();
getRegisters()->characters_per_column = newValue;
unlockSharedMemory();
}
void setCharactersPerRow(int newValue) {
lockSharedMemory();
getRegisters()->characters_per_row = newValue;
unlockSharedMemory();
}
void setMousePosition(int x, int y) {
lockSharedMemory();
getRegisters()->mouse_pos_x = x;
getRegisters()->mouse_pos_y = y;
unlockSharedMemory();
}
void buttonPressed(KeyCode keyCode) {
lockSharedMemory();
auto reg = getRegisters();
if(reg->keyboardBuffer_index_write == sizeof(reg->keyboardBuffer)){
reg->keyboardBuffer_index_write = 0;
} }
reg->keyboardBuffer[reg->keyboardBuffer_index_write++] = keyCode.getValue();
unlockSharedMemory(); auto getInterrupTable() -> InterruptEntry * {
return reinterpret_cast<InterruptEntry *>(getSharedMemory() + sizeof(Registers) + impl.reservedSize);
}
auto getRegisters() -> Registers * {
return reinterpret_cast<Registers *>(getSharedMemory());
}
auto getTextArea() -> char * {
return ((getSharedMemory() + sizeof(Registers) + impl.reservedSize) +
sizeof(InterruptEntry) * impl.interruptEntyCount);
}
auto getPixelArea() -> char * {
return (((getSharedMemory() + sizeof(Registers) + impl.reservedSize) +
sizeof(InterruptEntry) * impl.interruptEntyCount) +
getCharactersPerRow() * getCharactersPerColumn());
}
auto callEvent(EventType type) -> bool {
auto ivt = getInterrupTable();
if (ivt[type].pid != 0) {
sendSignal(ivt[type].pid, ivt[type].signum);
}
return true;
}
auto setLayoutVersion(LayoutVersion newValue) -> void {
lockSharedMemory();
getRegisters()->layout_version = newValue;
unlockSharedMemory();
}
auto setCharactersPerColumn(int newValue) -> void {
lockSharedMemory();
getRegisters()->characters_per_column = newValue;
unlockSharedMemory();
}
auto setCharactersPerRow(int newValue) -> void {
lockSharedMemory();
getRegisters()->characters_per_row = newValue;
unlockSharedMemory();
}
auto setMousePosition(int x, int y) -> void {
lockSharedMemory();
getRegisters()->mouse_pos_x = x;
getRegisters()->mouse_pos_y = y;
unlockSharedMemory();
}
auto buttonPressed(KeyCode keyCode) -> void {
lockSharedMemory();
auto reg = getRegisters();
if (reg->keyboardBuffer_index_write == sizeof(reg->keyboardBuffer)) {
reg->keyboardBuffer_index_write = 0;
}
reg->keyboardBuffer[reg->keyboardBuffer_index_write++] = keyCode.getValue();
unlockSharedMemory();
}
} }

View File

@ -1,126 +0,0 @@
#ifndef LIBRARY_INTERNAL_H
#define LIBRARY_INTERNAL_H
#include "EventType.h"
#include "KeyCode.h"
#include "LayoutVersion.h"
#include "GraphicMode.h"
#include "Color.h"
#include <sys/types.h>
#include <vector>
#include <functional>
/**
* the Control Registers
* @author Julian Hinxlage
* @since 0.1.0
*/
struct Registers {
int layout_version;
int trigger_reset;
int width_pixels;
int height_pixels;
GraphicMode graphicMode;
int autoRedrawInterval;
int timerInterruptInterval;
Color background_color;
Color foreground_color;
int characters_per_row;
int characters_per_column;
int textMode_font;
int textMode_font_width;
int textMode_font_height;
int mouse_pos_x;
int mouse_pos_y;
short keyboardBuffer[16];
int keyboardBuffer_index_write;
int keyboardBuffer_index_read;
};
struct InterruptEntry {
int pid;
int signum;
};
/**
* internal values for the library.
*/
struct Impl {
int sharedMemoryPid;
key_t sharedMemoryKey;
int sharedMemorySize;
int interruptEntyCount = 64;
int reservedSize = 1024;
std::vector<std::function<void()>> eventTable;
};
extern Impl impl;
/**
* send a signal to a process
* @param pid of the process to which the signal is send
* @param signalNumber
*/
void sendSignal(pid_t pid, int signalNumber);
/**
* calls the callback if a signal is received
* @param signalNumber
*/
void onSignal(int signalNumber, void(*callback)(int));
InterruptEntry *getInterrupTable();
Registers *getRegisters();
char *getTextArea();
char *getPixelArea();
/**
* set layout version.
* @param newValue new layout version number.
*/
void setLayoutVersion(LayoutVersion newValue);
/**
* set characters per column for current font.
* @param newValue characters per column.
*/
void setCharactersPerColumn(int newValue);
/**
* set characters per row for current font.
* @param newValue
*/
void setCharactersPerRow(int newValue);
/**
* call a specific event.
* @param type
* @return true if there is a handler registered.
*/
bool callEvent(EventType type);
/**
* set mouse position to x,y value.
* @param x x coordinate
* @param y y coordinate
*/
void setMousePosition(int x, int y);
/**
* register pressed button.
* @param keyCode pressed key.
*/
void buttonPressed(KeyCode keyCode);
// Shared Memory Layout
// --------------------------------------------------------------------
// struct ControlRegisters
// char reserved[1024]
// Interrupt Vector Table [64]
// text area [max_textMode_width * max_textMode_height]
// pixel area [max_height_pixels * max_height_pixels * sizeof(uint_32)]
#endif

132
src/internal.hpp Normal file
View File

@ -0,0 +1,132 @@
#ifndef LIBRARY_INTERNAL_HPP
#define LIBRARY_INTERNAL_HPP
#include "EventType.hpp"
#include "KeyCode.hpp"
#include "LayoutVersion.hpp"
#include "GraphicMode.hpp"
#include "Color.hpp"
#include <sys/types.h>
#include <vector>
#include <functional>
namespace vkvm {
/**
* the Control Registers
* @author Julian Hinxlage
* @since 0.1.0
*/
struct Registers {
int layout_version;
int trigger_reset;
int width_pixels;
int height_pixels;
GraphicMode graphicMode;
int autoRedrawInterval;
int timerInterruptInterval;
Color background_color;
Color foreground_color;
int characters_per_row;
int characters_per_column;
int textMode_font;
int textMode_font_width;
int textMode_font_height;
int mouse_pos_x;
int mouse_pos_y;
short keyboardBuffer[16];
int keyboardBuffer_index_write;
int keyboardBuffer_index_read;
};
struct InterruptEntry {
int pid;
int signum;
};
/**
* internal values for the library.
*/
struct Impl {
int sharedMemoryPid;
key_t sharedMemoryKey;
int sharedMemorySize;
int interruptEntyCount = 64;
int reservedSize = 1024;
std::vector<std::function<void()>> eventTable;
};
extern Impl impl;
/**
* send a signal to a process
* @param pid of the process to which the signal is send
* @param signalNumber
*/
auto sendSignal(pid_t pid, int signalNumber) -> void;
/**
* calls the callback if a signal is received
* @param signalNumber
*/
auto onSignal(int signalNumber, void(*callback)(int)) -> void;
auto getInterrupTable() -> InterruptEntry *;
auto getRegisters() -> Registers *;
auto getTextArea() -> char * ;
auto getPixelArea() -> char *;
/**
* set layout version.
* @param newValue new layout version number.
*/
auto setLayoutVersion(LayoutVersion newValue) -> void;
/**
* set characters per column for current font.
* @param newValue characters per column.
*/
auto setCharactersPerColumn(int newValue) -> void;
/**
* set characters per row for current font.
* @param newValue
*/
auto setCharactersPerRow(int newValue) -> void;
/**
* call a specific event.
* @param type
* @return true if there is a handler registered.
*/
auto callEvent(EventType type) -> bool;
/**
* set mouse position to x,y value.
* @param x x coordinate
* @param y y coordinate
*/
auto setMousePosition(int x, int y) -> void;
/**
* register pressed button.
* @param keyCode pressed key.
*/
auto buttonPressed(KeyCode keyCode) -> void;
// Shared Memory Layout
// --------------------------------------------------------------------
// struct ControlRegisters
// char reserved[1024]
// Interrupt Vector Table [64]
// text area [max_textMode_width * max_textMode_height]
// pixel area [max_height_pixels * max_height_pixels * sizeof(uint_32)]
}
#endif

View File

@ -4,109 +4,111 @@
* @since 0.1.0 * @since 0.1.0
*/ */
#include "log.h" #include "log.hpp"
#include <iostream> #include <iostream>
//converts the level to a string of the level namespace vkvm {
auto getLevelName(LogLevel level){ //converts the level to a string of the level
switch(level){ auto getLevelName(LogLevel level) -> std::string {
case LogLevel::DEBUG: switch(level){
return "DEBUG"; case LogLevel::DEBUG:
case LogLevel::INFO: return "DEBUG";
return "INFO"; case LogLevel::INFO:
case LogLevel::WARNING: return "INFO";
return "WARNING"; case LogLevel::WARNING:
case LogLevel::ERROR: return "WARNING";
return "ERROR"; case LogLevel::ERROR:
case LogLevel::CRITICAL: return "ERROR";
return "CRITICAL"; case LogLevel::CRITICAL:
default: return "CRITICAL";
return "NON"; default:
return "NON";
}
} }
}
//converts the level to a ansi color code //converts the level to a ansi color code
auto getLevelColor(LogLevel level){ auto getLevelColor(LogLevel level) -> std::string {
switch(level){ switch(level){
case LogLevel::DEBUG: case LogLevel::DEBUG:
return "0;37"; return "0;37";
case LogLevel::INFO: case LogLevel::INFO:
return "0"; return "0";
case LogLevel::WARNING: case LogLevel::WARNING:
return "1;33"; return "1;33";
case LogLevel::ERROR: case LogLevel::ERROR:
return "1;31"; return "1;31";
case LogLevel::CRITICAL: case LogLevel::CRITICAL:
return "1;35"; return "1;35";
default: default:
return "0"; return "0";
}
} }
}
LogLevel logLevel = LogLevel::INFO; LogLevel logLevel = LogLevel::INFO;
//log the current time //log the current time
void logTime(){ auto logTime() -> void {
time_t rawtime; time_t rawtime;
time(&rawtime); time(&rawtime);
struct tm *timeinfo; struct tm *timeinfo;
timeinfo = localtime(&rawtime); timeinfo = localtime(&rawtime);
constexpr int decimalBase = 10; constexpr int decimalBase = 10;
if (timeinfo->tm_hour < decimalBase) { if (timeinfo->tm_hour < decimalBase) {
std::cout << "0"; std::cout << "0";
}
std::cout << timeinfo->tm_hour;
std::cout << ":";
if (timeinfo->tm_min < decimalBase) {
std::cout << "0";
}
std::cout << timeinfo->tm_min;
std::cout << ":";
if (timeinfo->tm_sec < decimalBase) {
std::cout << "0";
}
std::cout << timeinfo->tm_sec;
} }
std::cout << timeinfo->tm_hour;
std::cout << ":";
if (timeinfo->tm_min < decimalBase) {
std::cout << "0";
}
std::cout << timeinfo->tm_min;
std::cout << ":";
if (timeinfo->tm_sec < decimalBase) {
std::cout << "0";
}
std::cout << timeinfo->tm_sec;
}
//log the message //log the message
void log(LogLevel level, const std::string &msg) { auto log(LogLevel level, const std::string &msg) -> void {
if(level >= logLevel) { if(level >= logLevel) {
std::string levelName = getLevelName(level); std::string levelName = getLevelName(level);
const int maxLevelNameLength = 8; const int maxLevelNameLength = 8;
//time //time
std::cout << "["; std::cout << "[";
logTime(); logTime();
std::cout << "] "; std::cout << "] ";
//color and level name;lo //color and level name;lo
std::cout << "["; std::cout << "[";
std::cout << "\033[" << getLevelColor(level) << "m" << levelName << "\033[0m"; std::cout << "\033[" << getLevelColor(level) << "m" << levelName << "\033[0m";
std::cout << "] "; std::cout << "] ";
for (int i = levelName.size(); i < maxLevelNameLength; i++) { for (int i = levelName.size(); i < maxLevelNameLength; i++) {
std::cout << " "; std::cout << " ";
}
//message
for(char c : msg){
if(c == '\n'){
//intend newlines so that they align with the start of the message
std::cout << "\n";
const int paddingSize = 22;
for(int i = 0; i < paddingSize;i++){
std::cout << " ";
}
}else{
std::cout << c;
} }
//message
for(char c : msg){
if(c == '\n'){
//intend newlines so that they align with the start of the message
std::cout << "\n";
const int paddingSize = 22;
for(int i = 0; i < paddingSize;i++){
std::cout << " ";
}
}else{
std::cout << c;
}
}
std::cout << "\n";
} }
std::cout << "\n";
} }
}
void setLogLevel(LogLevel level) { auto setLogLevel(LogLevel level) -> void {
logLevel = level; logLevel = level;
} }
}

View File

@ -1,50 +0,0 @@
#ifndef LIBRARY_LOG_H
#define LIBRARY_LOG_H
#include <string>
#include <sstream>
enum LogLevel{
DEBUG = 1,
INFO = 2,
WARNING = 3,
ERROR = 4,
CRITICAL = 5,
OFF = 6
};
/**
* log the messgae with logLevel and timestamp
* @author Julian Hinxlage
* @since 0.1.0
*/
void log(LogLevel level, const std::string &msg);
template<typename T>
static void buildString(std::stringstream &stream, T t) {
stream << t;
}
template<typename T, typename... Ts>
static void buildString(std::stringstream &stream, T t, Ts... ts) {
stream << t;
buildString(stream, ts...);
}
template<typename... T>
static void log(LogLevel level, T... t){
std::stringstream stream;
buildString(stream, t...);
log(level, stream.str());
}
/**
* set the logLevel, the log function will use this to determine if the message is logged
* @author Julian Hinxlage
* @since 0.1.0
*/
void setLogLevel(LogLevel level);
#endif //LIBRARY_LOG_H

52
src/log.hpp Normal file
View File

@ -0,0 +1,52 @@
#ifndef LIBRARY_LOG_HPP
#define LIBRARY_LOG_HPP
#include <string>
#include <sstream>
namespace vkvm {
enum LogLevel{
DEBUG = 1,
INFO = 2,
WARNING = 3,
ERROR = 4,
CRITICAL = 5,
OFF = 6
};
/**
* log the messgae with logLevel and timestamp
* @author Julian Hinxlage
* @since 0.1.0
*/
auto log(LogLevel level, const std::string &msg) -> void;
template<typename T>
static auto buildString(std::stringstream &stream, T t) -> void {
stream << t;
}
template<typename T, typename... Ts>
static auto buildString(std::stringstream &stream, T t, Ts... ts) -> void {
stream << t;
buildString(stream, ts...);
}
template<typename... T>
static auto log(LogLevel level, T... t) -> void {
std::stringstream stream;
buildString(stream, t...);
log(level, stream.str());
}
/**
* set the logLevel, the log function will use this to determine if the message is logged
* @author Julian Hinxlage
* @since 0.1.0
*/
auto setLogLevel(LogLevel level) -> void;
}
#endif

View File

@ -1,196 +1,199 @@
#include "SharedMemoryAccess.h" #include "SharedMemoryAccess.hpp"
#include "internal.h" #include "internal.hpp"
#include "vkvm.h" #include "vkvm.hpp"
#include <csignal> #include <csignal>
#include <unistd.h> #include <unistd.h>
// NOLINT namespace vkvm {
void initialize(int pid) { // NOLINT
impl.sharedMemoryPid = pid; auto initialize(int pid) -> void {
impl.sharedMemoryKey = 12345;// NOLINT impl.sharedMemoryPid = pid;
impl.sharedMemorySize = 8000;// NOLINT impl.sharedMemoryKey = 12345;// NOLINT
initSemaphore(); impl.sharedMemorySize = 8000;// NOLINT
setDefaultValues(); initSemaphore();
} setDefaultValues();
void setDefaultValues(){
if(getSharedMemory() != nullptr) {
//set default values
setCharactersPerRow(60);// NOLINT
setCharactersPerColumn(20);// NOLINT
setHeight(600);// NOLINT
setWidth(800);// NOLINT
setMousePosition(42, 42);// NOLINT
setBackgroundColor(Color(200, 50, 20));// NOLINT
setForegroundColor(Color(20, 200, 50));// NOLINT
setMode(GraphicMode::TrueColor);// NOLINT
setRedrawInterval(20);// NOLINT
setTimerInterruptInterval(10);// NOLINT
} }
}
bool registerEvent(EventType type, const std::function<void()> &handler) { auto setDefaultValues() -> void {
int signum = SIGUSR1 + impl.eventTable.size(); if(getSharedMemory() != nullptr) {
auto ivt = getInterrupTable(); //set default values
setCharactersPerRow(60);// NOLINT
setCharactersPerColumn(20);// NOLINT
setHeight(600);// NOLINT
setWidth(800);// NOLINT
setMousePosition(42, 42);// NOLINT
setBackgroundColor(Color(200, 50, 20));// NOLINT
setForegroundColor(Color(20, 200, 50));// NOLINT
setMode(GraphicMode::TrueColor);// NOLINT
setRedrawInterval(20);// NOLINT
setTimerInterruptInterval(10);// NOLINT
}
}
lockSharedMemory(); auto registerEvent(EventType type, const std::function<void()> &handler) -> bool {
int signum = SIGUSR1 + impl.eventTable.size();
auto ivt = getInterrupTable();
ivt[type].pid = getpid(); lockSharedMemory();
ivt[type].signum = signum;
impl.eventTable.push_back(handler);
onSignal(signum, [](int sig){ ivt[type].pid = getpid();
if(sig >= SIGUSR1){ ivt[type].signum = signum;
if((sig - SIGUSR1) < impl.eventTable.size()){ impl.eventTable.push_back(handler);
impl.eventTable[sig - SIGUSR1]();
onSignal(signum, [](int sig){
if(sig >= SIGUSR1){
if((sig - SIGUSR1) < impl.eventTable.size()){
impl.eventTable[sig - SIGUSR1]();
}
} }
} });
});
unlockSharedMemory(); unlockSharedMemory();
return true; return true;
}
bool setPixel(int x, int y, Color color) {
char *ptr = getPixelArea() + (y * getWidth() + x) * 3;
ptr[0] = color.getRed();
ptr[1] = color.getGreen();
ptr[2] = color.getBlue();
return false;
}
Color getPixel(int x, int y) {
//TODO(julian): other than RGB colores
//only RGB colores for now
unsigned char *ptr = reinterpret_cast<unsigned char *>(getPixelArea()) + (y * getWidth() + x) * 3;
return {ptr[0], ptr[1], ptr[2]};
}
bool setText(std::string text) {
lockSharedMemory();
char *ptr = getTextArea();
for(int i = 0; i < static_cast<int>(text.size());i++){
if(i >= getCharactersPerColumn() * getCharactersPerRow()){
break;
}
ptr[i] = text[i];
} }
if(text.size() < getCharactersPerColumn() * getCharactersPerRow()){
ptr[text.size()] = '\0'; auto setPixel(int x, int y, Color color) -> bool {
char *ptr = getPixelArea() + (y * getWidth() + x) * 3;
ptr[0] = color.getRed();
ptr[1] = color.getGreen();
ptr[2] = color.getBlue();
return false;
} }
unlockSharedMemory();
return true;
}
std::string getText() { auto getPixel(int x, int y) -> Color {
return std::string (getTextArea()); //TODO(julian): other than RGB colores
} //only RGB colores for now
unsigned char *ptr = reinterpret_cast<unsigned char *>(getPixelArea()) + (y * getWidth() + x) * 3;
return {ptr[0], ptr[1], ptr[2]};
}
LayoutVersion getLayoutVersion() { auto setText(std::string text) -> bool {
return static_cast<LayoutVersion>(getRegisters()->layout_version); lockSharedMemory();
} char *ptr = getTextArea();
for(int i = 0; i < static_cast<int>(text.size());i++){
if(i >= getCharactersPerColumn() * getCharactersPerRow()){
break;
}
ptr[i] = text[i];
}
if(text.size() < getCharactersPerColumn() * getCharactersPerRow()){
ptr[text.size()] = '\0';
}
unlockSharedMemory();
return true;
}
void reset() { auto getText() -> std::string {
//TODO(julian): reset return std::string (getTextArea());
} }
int getWidth() { auto getLayoutVersion() -> LayoutVersion {
return getRegisters()->width_pixels; return static_cast<LayoutVersion>(getRegisters()->layout_version);
} }
void setWidth(int newValue) { auto reset() -> void {
lockSharedMemory(); //TODO(julian): reset
getRegisters()->width_pixels = newValue; }
unlockSharedMemory();
}
int getHeight() { auto getWidth() -> int {
return getRegisters()->height_pixels; return getRegisters()->width_pixels;
} }
void setHeight(int newValue) { auto setWidth(int newValue) -> void {
lockSharedMemory(); lockSharedMemory();
getRegisters()->height_pixels = newValue; getRegisters()->width_pixels = newValue;
unlockSharedMemory(); unlockSharedMemory();
} }
GraphicMode getMode() { auto getHeight() -> int {
return getRegisters()->graphicMode; return getRegisters()->height_pixels;
} }
void setMode(GraphicMode newValue) { auto setHeight(int newValue) -> void {
lockSharedMemory(); lockSharedMemory();
getRegisters()->graphicMode = newValue; getRegisters()->height_pixels = newValue;
unlockSharedMemory(); unlockSharedMemory();
} }
int getRedrawInterval() { auto getMode() -> GraphicMode {
return getRegisters()->autoRedrawInterval; return getRegisters()->graphicMode;
} }
void setRedrawInterval(int newValue) { auto setMode(GraphicMode newValue) -> void {
lockSharedMemory(); lockSharedMemory();
getRegisters()->autoRedrawInterval = newValue; getRegisters()->graphicMode = newValue;
unlockSharedMemory(); unlockSharedMemory();
} }
int getTimerInterruptInterval() { auto getRedrawInterval() -> int {
return getRegisters()->timerInterruptInterval; return getRegisters()->autoRedrawInterval;
} }
void setTimerInterruptInterval(int newValue) { auto setRedrawInterval(int newValue) -> void {
lockSharedMemory(); lockSharedMemory();
getRegisters()->timerInterruptInterval = newValue; getRegisters()->autoRedrawInterval = newValue;
unlockSharedMemory(); unlockSharedMemory();
} }
Color getBackgroundColor() { auto getTimerInterruptInterval() -> int {
return getRegisters()->background_color; return getRegisters()->timerInterruptInterval;
} }
void setBackgroundColor(Color newValue) { auto setTimerInterruptInterval(int newValue) -> void {
lockSharedMemory(); lockSharedMemory();
getRegisters()->background_color = newValue; getRegisters()->timerInterruptInterval = newValue;
unlockSharedMemory(); unlockSharedMemory();
} }
Color getForegroundColor() { auto getBackgroundColor() -> Color {
return getRegisters()->foreground_color; return getRegisters()->background_color;
} }
void setForegroundColor(Color newValue) { auto setBackgroundColor(Color newValue) -> void {
lockSharedMemory(); lockSharedMemory();
getRegisters()->foreground_color = newValue; getRegisters()->background_color = newValue;
unlockSharedMemory(); unlockSharedMemory();
} }
int getCharactersPerRow() { auto getForegroundColor() -> Color {
return getRegisters()->characters_per_row; return getRegisters()->foreground_color;
} }
int getCharactersPerColumn() { auto setForegroundColor(Color newValue) -> void {
return getRegisters()->characters_per_column; lockSharedMemory();
} getRegisters()->foreground_color = newValue;
unlockSharedMemory();
}
FontType getFont() { auto getCharactersPerRow() -> int {
//TODO(julian): get font properly return getRegisters()->characters_per_row;
return font_1; }
}
void setFont(const FontType &newValue) { auto getCharactersPerColumn() -> int {
//TODO(julian): setFont properly return getRegisters()->characters_per_column;
lockSharedMemory(); }
getRegisters()->textMode_font = newValue.getId();
unlockSharedMemory();
}
std::pair<int, int> getMousePosition() { auto getFont() -> FontType {
return {getRegisters()->mouse_pos_x, getRegisters()->mouse_pos_y}; //TODO(julian): get font properly
} return font_1;
}
KeyCode getLastPressedKey() { auto setFont(const FontType &newValue) -> void {
//TODO(julian): get key properly //TODO(julian): setFont properly
return KeyCode(0); lockSharedMemory();
} getRegisters()->textMode_font = newValue.getId();
unlockSharedMemory();
}
auto getMousePosition() -> Coordinates {
return {getRegisters()->mouse_pos_x, getRegisters()->mouse_pos_y};
}
auto getLastPressedKey() -> KeyCode {
//TODO(julian): get key properly
return KeyCode(0);
}
}

View File

@ -1,30 +1,34 @@
#ifndef LIBRARY_VKVM_H #ifndef LIBRARY_VKVM_HPP
#define LIBRARY_VKVM_H #define LIBRARY_VKVM_HPP
#include "Color.h" #include "Color.hpp"
#include "EventType.h" #include "EventType.hpp"
#include "GraphicMode.h" #include "GraphicMode.hpp"
#include "FontType.h" #include "FontType.hpp"
#include "KeyCode.h" #include "KeyCode.hpp"
#include "LayoutVersion.h" #include "LayoutVersion.hpp"
#include "log.h" #include "log.hpp"
#include <functional> #include <functional>
#include <string> #include <string>
/** namespace vkvm {
/**
* @since 0.1.0 * @since 0.1.0
* @author Johannes Theiner * @author Johannes Theiner
*/ */
//TODO: better documentation struct Coordinates {
int x;
int y;
};
/** /**
* initialize the connection with the shared-memory application * initialize the connection with the shared-memory application
* @param pid pip of shared-memory application * @param pid pip of shared-memory application
*/ */
void initialize(int pid); auto initialize(int pid) -> void;
void setDefaultValues(); auto setDefaultValues() -> void;
/** /**
* set pixel at a x,y position to a certain color. * set pixel at a x,y position to a certain color.
@ -33,7 +37,7 @@ void setDefaultValues();
* @param color color of pixel * @param color color of pixel
* @return true if operation succeeded, false if it failed. * @return true if operation succeeded, false if it failed.
*/ */
bool setPixel(int x, int y, Color color); auto setPixel(int x, int y, Color color) -> bool;
/** /**
* get color of pixel at x,y position * get color of pixel at x,y position
@ -41,7 +45,7 @@ bool setPixel(int x, int y, Color color);
* @param y y coordinate of pixel * @param y y coordinate of pixel
* @return color of pixel * @return color of pixel
*/ */
Color getPixel(int x, int y); auto getPixel(int x, int y) -> Color;
/** /**
* register handler for event. * register handler for event.
@ -49,19 +53,19 @@ Color getPixel(int x, int y);
* @param handler function to call. * @param handler function to call.
* @return true if handler could be registered, false if it failed. * @return true if handler could be registered, false if it failed.
*/ */
bool registerEvent(EventType type, const std::function<void()> &handler); auto registerEvent(EventType type, const std::function<void()> &handler) -> bool;
/** /**
* set displayed text in Text mode * set displayed text in Text mode
* @param text text to display * @param text text to display
* @return if text could be set, false if it could not be set. * @return if text could be set, false if it could not be set.
*/ */
bool setText(std::string text); auto setText(std::string text) -> bool;
/** /**
* get currently saved/displayed text. * get currently saved/displayed text.
*/ */
std::string getText(); auto getText() -> std::string;
//Control registers start here //Control registers start here
@ -71,71 +75,71 @@ std::string getText();
* get version of the used layout * get version of the used layout
* @return layout version * @return layout version
*/ */
LayoutVersion getLayoutVersion(); auto getLayoutVersion() -> LayoutVersion;
/** /**
* reset all values to default. * reset all values to default.
*/ */
void reset(); auto reset() -> void;
/** /**
* get width of window. * get width of window.
* @return width of window. * @return width of window.
*/ */
int getWidth(); auto getWidth() -> int;
/** /**
* set width of window. * set width of window.
* @param newValue new width for window. * @param newValue new width for window.
*/ */
void setWidth(int newValue); auto setWidth(int newValue) -> void;
/** /**
* get height for window. * get height for window.
* @return height of window. * @return height of window.
*/ */
int getHeight(); auto getHeight() -> int;
/** /**
* set height of window. * set height of window.
* @param newValue new height for window. * @param newValue new height for window.
*/ */
void setHeight(int newValue); auto setHeight(int newValue) -> void;
/** /**
* get graphics display mode. * get graphics display mode.
* @return GraphicMode. * @return GraphicMode.
*/ */
GraphicMode getMode(); auto getMode() -> GraphicMode;
/** /**
* set new graphics display mode. * set new graphics display mode.
* @param newValue new graphics display mode. * @param newValue new graphics display mode.
*/ */
void setMode(GraphicMode newValue); auto setMode(GraphicMode newValue) -> void;
/** /**
* get interval between redraws in milliseconds. * get interval between redraws in milliseconds.
*/ */
int getRedrawInterval(); auto getRedrawInterval() -> int;
/** /**
* set interval between redraws. * set interval between redraws.
* @param newValue new interval in milliseconds. * @param newValue new interval in milliseconds.
*/ */
void setRedrawInterval(int newValue); auto setRedrawInterval(int newValue) -> void;
/** /**
* get time between timer interrupts. * get time between timer interrupts.
* @return time between interrupts in milliseconds. * @return time between interrupts in milliseconds.
*/ */
int getTimerInterruptInterval(); auto getTimerInterruptInterval() -> int;
/** /**
* set time between timer interrupts. * set time between timer interrupts.
* @param newValue new time between interrupts in milliseconds. * @param newValue new time between interrupts in milliseconds.
*/ */
void setTimerInterruptInterval(int newValue); auto setTimerInterruptInterval(int newValue) -> void;
//black/white mode //black/white mode
@ -143,25 +147,25 @@ void setTimerInterruptInterval(int newValue);
* get background color in two color mode. * get background color in two color mode.
* @return background color. * @return background color.
*/ */
Color getBackgroundColor(); auto getBackgroundColor() -> Color;
/** /**
* set background color in two color mode. * set background color in two color mode.
* @param newValue new background color. * @param newValue new background color.
*/ */
void setBackgroundColor(Color newValue); auto setBackgroundColor(Color newValue) -> void;
/** /**
* get foreground color in two color mode. * get foreground color in two color mode.
* @return foreground color. * @return foreground color.
*/ */
Color getForegroundColor(); auto getForegroundColor() -> Color;
/** /**
* set foreground color in two color mode. * set foreground color in two color mode.
* @param newValue new foreground color. * @param newValue new foreground color.
*/ */
void setForegroundColor(Color newValue); auto setForegroundColor(Color newValue) -> void;
//text mode //text mode
@ -169,36 +173,37 @@ void setForegroundColor(Color newValue);
* get characters per row in text mode. * get characters per row in text mode.
* @return characters per row. * @return characters per row.
*/ */
int getCharactersPerRow(); auto getCharactersPerRow() -> int;
/** /**
* get characters per column in text mode. * get characters per column in text mode.
* @return characters per column. * @return characters per column.
*/ */
int getCharactersPerColumn(); auto getCharactersPerColumn() -> int;
/** /**
* get currently used font in text mode. * get currently used font in text mode.
* @return currently used font. * @return currently used font.
*/ */
FontType getFont(); auto getFont() -> FontType;
/** /**
* set text mode font. * set text mode font.
* @param newValue new text mode font. * @param newValue new text mode font.
*/ */
void setFont(const FontType &newValue); auto setFont(const FontType &newValue) -> void;
/** /**
* get current mouse position * get current mouse position
* @return mouse position as x,y pair * @return mouse position as x,y pair
*/ */
std::pair<int, int> getMousePosition(); auto getMousePosition() -> Coordinates;
/** /**
* get key code of last key press. * get key code of last key press.
* @return KeyCode of last key press. * @return KeyCode of last key press.
*/ */
KeyCode getLastPressedKey(); auto getLastPressedKey() -> KeyCode;
}
#endif #endif

View File

@ -1,10 +1,10 @@
#include "catch2/catch.hpp" #include "catch2/catch.hpp"
#include "../src/vkvm.h" #include "../src/vkvm.hpp"
TEST_CASE("add works") { TEST_CASE("add works") {
initialize(0); vkvm::initialize(0);
setText("Hello World"); vkvm::setText("Hello World");
SECTION("equals") { SECTION("equals") {
REQUIRE(getText() == "Hello World"); REQUIRE(vkvm::getText() == "Hello World");
} }
} }