diff options
author | daniel <danieruru@gmail.com> | 2013-01-11 13:58:36 +0900 |
---|---|---|
committer | daniel <danieruru@gmail.com> | 2013-01-11 13:58:36 +0900 |
commit | 2287a7ca37de5dadf9eda790e3afa96262cb9e76 (patch) | |
tree | 3b39e28804e9193adad45d30fbe6be7e60fe2124 | |
parent | cacd8ba78d2c17286507d0bae498c136dba19c9c (diff) |
add callback for interrupt
-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); |