31 lines
687 B
C++
31 lines
687 B
C++
#include "vkvm.h"
|
|
#include "internal.h"
|
|
#include <unistd.h>
|
|
#include <csignal>
|
|
|
|
void initialize(int pid) {
|
|
impl.sharedMemoryPid = pid;
|
|
impl.sharedMemoryKey = 12345;
|
|
impl.sharedMemorySize = 0;
|
|
}
|
|
|
|
bool registerEvent(EventType type, std::function<void()> handler) {
|
|
int signum = SIGUSR1 + impl.eventTable.size();
|
|
|
|
auto ivt = getInterrupTable();
|
|
ivt[type].pid = getpid();
|
|
ivt[type].signum = signum;
|
|
|
|
impl.eventTable.push_back(handler);
|
|
|
|
onSignal(signum, [](int sig){
|
|
if(sig >= SIGUSR1){
|
|
if((sig - SIGUSR1) < impl.eventTable.size()){
|
|
impl.eventTable[sig - SIGUSR1]();
|
|
}
|
|
}
|
|
});
|
|
|
|
return true;
|
|
}
|