diff options
-rw-r--r-- | libvxi11client/client.c | 8 | ||||
-rw-r--r-- | libvxi11client/libvxi11client.c | 21 | ||||
-rw-r--r-- | libvxi11client/libvxi11client.h | 2 |
3 files changed, 24 insertions, 7 deletions
diff --git a/libvxi11client/client.c b/libvxi11client/client.c index 804ef91..77554f2 100644 --- a/libvxi11client/client.c +++ b/libvxi11client/client.c @@ -27,6 +27,10 @@ static char* geterrorstring(int errorcode) { } } +static void interruptcallback(void) { + printf("Interrupt fired\n"); +} + int main(int argc, char *argv[]) { printf("VXI-11 test client\n"); @@ -137,7 +141,7 @@ int main(int argc, char *argv[]) { printf("Created interrupt channel\n"); // enable interrupts - if ((err = vxi11_enable_srq(true, "handle")) > 0) + if ((err = vxi11_enable_srq(true, "handle", interruptcallback)) > 0) printf("Enabled interrupts\n"); else printf("Error enabling interrupts; %s\n", geterrorstring(err)); @@ -145,7 +149,7 @@ int main(int argc, char *argv[]) { sleep(10); // disable interrupts - if ((err = vxi11_enable_srq(false, NULL)) > 0) + if ((err = vxi11_enable_srq(false, NULL, NULL)) > 0) printf("Disabled interrupts\n"); else printf("Error disabling interrupts; %s\n", geterrorstring(err)); diff --git a/libvxi11client/libvxi11client.c b/libvxi11client/libvxi11client.c index b212487..e33cb24 100644 --- a/libvxi11client/libvxi11client.c +++ b/libvxi11client/libvxi11client.c @@ -28,6 +28,7 @@ static CLIENT* abortclnt = NULL; static Device_Link link; static GThread* interruptthread; static bool interruptchannelopen = false; +static void (*interruptcallback)(void) = NULL; static void killinterruptthreadandwait() { #ifdef DEBUG @@ -43,6 +44,11 @@ device_intr_srq_1_svc(Device_SrqParms *argp, struct svc_req *rqstp) { #ifdef DEBUG printf("device_intr_srq_1_svc()\n"); #endif + + if (interruptcallback != NULL) { + interruptcallback(); + } + static char * result; return (void *) &result; } @@ -474,7 +480,7 @@ int vxi11_destroy_intr_chan() { * enable interrupts */ -int vxi11_enable_srq(bool enable, char* handle) { +int vxi11_enable_srq(bool enable, char* handle, void (*callback)(void)) { if (!interruptchannelopen) return 0; else if (clnt == NULL) @@ -483,9 +489,16 @@ int vxi11_enable_srq(bool enable, char* handle) { return 0; Device_EnableSrqParms params = { .lid = link, .enable = enable }; - if (handle != NULL) { - params.handle.handle_val = handle; - params.handle.handle_len = strlen(handle); + if (enable) { + if (handle != NULL) { + params.handle.handle_val = handle; + params.handle.handle_len = strlen(handle); + } + interruptcallback = callback; + } + else { + params.handle.handle_val = NULL; + params.handle.handle_len = 0; } Device_Error* error = device_enable_srq_1(¶ms, clnt); if (error != NULL && error->error == 0) { diff --git a/libvxi11client/libvxi11client.h b/libvxi11client/libvxi11client.h index bf247a5..5d25fae 100644 --- a/libvxi11client/libvxi11client.h +++ b/libvxi11client/libvxi11client.h @@ -28,6 +28,6 @@ int vxi11_remote(bool waitforlock); int vxi11_readstatusbyte(bool waitforlock); int vxi11_create_intr_chan(void); int vxi11_destroy_intr_chan(void); -int vxi11_enable_srq(bool enable, char* handle); +int vxi11_enable_srq(bool enable, char* handle, void (*callback)(void)); int vxi11_docmd(unsigned long cmd, bool waitforlock); int vxi11_close(void); |