library/src/internal.cpp

73 lines
1.7 KiB
C++
Raw Normal View History

#include "internal.h"
#include "SharedMemoryAccess.h"
#include "vkvm.h"
2019-11-04 23:17:15 +01:00
#include <sys/shm.h>
2019-11-06 12:47:34 +01:00
#include <csignal>
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(){
return (InterruptEntry*)(getSharedMemory() + sizeof(Registers) + impl.reservedSize);
}
Registers *getRegisters(){
return (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) {
//TODO
}