2019-10-29 15:24:57 +01:00
|
|
|
#include "vkvm.h"
|
|
|
|
#include "internal.h"
|
2019-11-06 13:41:24 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <csignal>
|
2019-10-29 15:24:57 +01:00
|
|
|
|
|
|
|
void initialize(int pid) {
|
2019-11-04 23:17:15 +01:00
|
|
|
impl.sharedMemoryPid = pid;
|
2019-11-07 12:58:37 +01:00
|
|
|
impl.sharedMemoryKey = 12345;
|
2019-11-04 23:17:15 +01:00
|
|
|
impl.sharedMemorySize = 0;
|
2019-10-29 15:24:57 +01:00
|
|
|
}
|
2019-11-06 13:41:24 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2019-11-07 12:41:01 +01:00
|
|
|
impl.eventTable.push_back(handler);
|
|
|
|
|
2019-11-06 13:41:24 +01:00
|
|
|
onSignal(signum, [](int sig){
|
|
|
|
if(sig >= SIGUSR1){
|
|
|
|
if((sig - SIGUSR1) < impl.eventTable.size()){
|
|
|
|
impl.eventTable[sig - SIGUSR1]();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|