library/src/internal.h

126 lines
2.6 KiB
C++

#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