2019-10-29 15:24:57 +01:00
|
|
|
#include "internal.h"
|
2019-11-07 16:34:15 +01:00
|
|
|
#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(){
|
2019-11-07 16:34:15 +01:00
|
|
|
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;
|
|
|
|
}
|
2019-11-07 16:34:15 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|