+ register and call event
This commit is contained in:
parent
daa65080e6
commit
2dec86e752
|
@ -35,3 +35,15 @@ void sendSignal(pid_t pid, int signalNumber) {
|
|||
void onSignal(int signalNumber, void(*callback)(int)) {
|
||||
signal(signalNumber, callback);
|
||||
}
|
||||
|
||||
InterruptEntry *getInterrupTable(){
|
||||
return (InterruptEntry*)((char*)getSharedMemory() + sizeof(Registers) + 1024/*reserved*/);
|
||||
}
|
||||
|
||||
bool callEvent(EventType type) {
|
||||
auto ivt = getInterrupTable();
|
||||
if(ivt[type].pid != 0){
|
||||
sendSignal(ivt[type].pid, ivt[type].signum);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#include "GraphicMode.h"
|
||||
#include "Color.h"
|
||||
#include <sys/types.h>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
/**
|
||||
* the Control Registers
|
||||
|
@ -47,7 +49,10 @@ struct Impl {
|
|||
int sharedMemoryPid;
|
||||
key_t sharedMemoryKey;
|
||||
int sharedMemorySize;
|
||||
int interruptEntyCount = 64;
|
||||
std::vector<std::function<void()>> eventTable;
|
||||
};
|
||||
|
||||
extern Impl impl;
|
||||
|
||||
void *getSharedMemory();
|
||||
|
@ -67,6 +72,9 @@ void sendSignal(pid_t pid, int signalNumber);
|
|||
*/
|
||||
void onSignal(int signalNumber, void(*callback)(int));
|
||||
|
||||
|
||||
InterruptEntry *getInterrupTable();
|
||||
|
||||
/**
|
||||
* set layout version.
|
||||
* @param newValue new layout version number.
|
||||
|
|
20
src/vkvm.cpp
20
src/vkvm.cpp
|
@ -1,8 +1,28 @@
|
|||
#include "vkvm.h"
|
||||
#include "internal.h"
|
||||
#include <unistd.h>
|
||||
#include <csignal>
|
||||
|
||||
void initialize(int pid) {
|
||||
impl.sharedMemoryPid = pid;
|
||||
impl.sharedMemoryKey = 892348;
|
||||
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;
|
||||
|
||||
onSignal(signum, [](int sig){
|
||||
if(sig >= SIGUSR1){
|
||||
if((sig - SIGUSR1) < impl.eventTable.size()){
|
||||
impl.eventTable[sig - SIGUSR1]();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue