library/src/internal.hpp

135 lines
3.0 KiB
C++
Raw Normal View History

#ifndef LIBRARY_INTERNAL_HPP
#define LIBRARY_INTERNAL_HPP
2019-11-13 15:42:04 +01:00
#include "Color.hpp"
#include "EventType.hpp"
2019-11-13 15:42:04 +01:00
#include "GraphicMode.hpp"
#include "KeyCode.hpp"
#include "LayoutVersion.hpp"
2019-11-13 15:42:04 +01:00
#include <functional>
#include <sys/types.h>
#include <vector>
namespace vkvm {
/**
* the Control Registers
* @author Julian Hinxlage
* @since 0.1.0
*/
2019-11-13 15:42:04 +01:00
constexpr int keyboardBufferSize = 16;
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;
2019-11-13 15:42:04 +01:00
std::array<int16_t, keyboardBufferSize> keyboardBuffer;
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;
2019-11-13 15:42:04 +01:00
int interruptEntyCount = 64; //NOLINT
int reservedSize = 1024; //NOLINT
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 *;
2019-11-13 15:42:04 +01:00
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