library/src/internal.cpp

79 lines
2.0 KiB
C++
Raw Normal View History

#include "internal.h"
#include "SharedMemoryAccess.h"
#include "vkvm.h"
2019-11-06 12:47:34 +01:00
#include <csignal>
2019-11-12 14:07:02 +01:00
#include <sys/shm.h>
2019-11-06 12:47:34 +01:00
2019-11-07 12:41:01 +01:00
Impl impl;
2019-11-06 12:47:34 +01:00
void sendSignal(pid_t pid, int signalNumber) {
kill(pid, signalNumber);
}
void onSignal(int signalNumber, void(*callback)(int)) {
signal(signalNumber, callback);
}
2019-11-06 13:41:24 +01:00
InterruptEntry *getInterrupTable(){
2019-11-12 14:07:02 +01:00
return reinterpret_cast<InterruptEntry*>(getSharedMemory() + sizeof(Registers) + impl.reservedSize);
}
Registers *getRegisters(){
2019-11-12 14:07:02 +01:00
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());
2019-11-06 13:41:24 +01:00
}
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) {
lockSharedMemory();
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) {
2019-11-12 14:07:02 +01:00
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();
}