library/src/internal.cpp

85 lines
2.5 KiB
C++
Raw Normal View History

#include "internal.hpp"
#include "SharedMemoryAccess.hpp"
#include "vkvm.hpp"
2019-11-06 12:47:34 +01:00
#include <csignal>
namespace vkvm {
2019-11-06 12:47:34 +01:00
Impl impl;
2019-11-06 13:41:24 +01:00
auto sendSignal(pid_t pid, int signalNumber) -> void {
kill(pid, signalNumber);
}
auto onSignal(int signalNumber, void(*callback)(int)) -> void {
signal(signalNumber, callback);
}
auto getInterrupTable() -> InterruptEntry * {
return reinterpret_cast<InterruptEntry *>(getSharedMemory() + sizeof(Registers) + impl.reservedSize);
}
auto getRegisters() -> Registers * {
return reinterpret_cast<Registers *>(getSharedMemory());
}
2019-11-06 13:41:24 +01:00
auto getTextArea() -> char * {
return ((getSharedMemory() + sizeof(Registers) + impl.reservedSize) +
sizeof(InterruptEntry) * impl.interruptEntyCount);
2019-11-06 13:41:24 +01:00
}
auto getPixelArea() -> char * {
return (((getSharedMemory() + sizeof(Registers) + impl.reservedSize) +
sizeof(InterruptEntry) * impl.interruptEntyCount) +
getCharactersPerRow() * getCharactersPerColumn());
}
auto callEvent(EventType type) -> bool {
auto ivt = getInterrupTable();
for(int i = 0; i < impl.interruptEntrysPerEventType;i++){
auto &entry= ivt[type * impl.interruptEntrysPerEventType + i];
if (entry.pid != 0) {
sendSignal(entry.pid, entry.signum);
}
}
return true;
}
auto setLayoutVersion(LayoutVersion newValue) -> void {
lockSharedMemory();
getRegisters()->layout_version = newValue;
unlockSharedMemory();
}
auto setCharactersPerColumn(int newValue) -> void {
lockSharedMemory();
getRegisters()->characters_per_column = newValue;
unlockSharedMemory();
}
auto setCharactersPerRow(int newValue) -> void {
lockSharedMemory();
getRegisters()->characters_per_row = newValue;
unlockSharedMemory();
}
auto setMousePosition(int x, int y) -> void {
lockSharedMemory();
getRegisters()->mouse_pos_x = x;
getRegisters()->mouse_pos_y = y;
unlockSharedMemory();
2019-11-12 14:07:02 +01:00
}
auto buttonPressed(KeyCode keyCode) -> void {
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();
}
}