diff options
author | daniel <danieruru@gmail.com> | 2013-01-10 17:29:54 +0900 |
---|---|---|
committer | daniel <danieruru@gmail.com> | 2013-01-10 17:29:54 +0900 |
commit | 54329a7c7f740171d1594c6c6195277c2924f31f (patch) | |
tree | 8089149ac2898a8224b69135028c50ca79969b2e | |
parent | a7f61f8769d7c704e409e511687d450608c220d1 (diff) |
Interrupt channel work
-rw-r--r-- | libvxi11client/client.c | 18 | ||||
-rw-r--r-- | libvxi11client/libvxi11client.c | 10 | ||||
-rw-r--r-- | vxi11_server.c | 38 | ||||
-rw-r--r-- | vxi11_svc.c | 384 |
4 files changed, 233 insertions, 217 deletions
diff --git a/libvxi11client/client.c b/libvxi11client/client.c index 2d050aa..9656e4d 100644 --- a/libvxi11client/client.c +++ b/libvxi11client/client.c @@ -1,4 +1,5 @@ #include <stdio.h> +#include <stdlib.h> #include "libvxi11client.h" #define IDENTIFY "*IDN?" @@ -124,13 +125,18 @@ int main(int argc, char *argv[]) { printf("\n"); // create interrupt channel - err = vxi11_create_intr_chan(); - - // destroy interrupt channel - if ((err = vxi11_destroy_intr_chan()) > 0) - printf("destroyed interrupt channel\n"); + printf("-- Testing interrupt channel --\n"); + if ((err = vxi11_create_intr_chan() > 0)) { + printf("Created interrupt channel\n"); + // destroy interrupt channel + if ((err = vxi11_destroy_intr_chan()) > 0) + printf("Destroyed interrupt channel\n"); + else + printf("Error destroying interrupt channel; %s\n", geterrorstring(err)); + } else - printf("Error destroying interrupt channel; %s\n", geterrorstring(err)); + printf("Error creating interrupt channel; %s\n", geterrorstring(err)); + printf("\n"); // docmd if ((err = vxi11_docmd(0x00, false)) > 0) diff --git a/libvxi11client/libvxi11client.c b/libvxi11client/libvxi11client.c index f19f81c..7b69fc5 100644 --- a/libvxi11client/libvxi11client.c +++ b/libvxi11client/libvxi11client.c @@ -66,7 +66,7 @@ int vxi11_open(char* address, char* device) { if (clnt_control(clnt, CLGET_SERVER_ADDR, (char*) &serveraddr)) { #ifdef DEBUG char addressstring[INET_ADDRSTRLEN]; - *inet_ntop(AF_INET, &serveraddr.sin_addr, addressstring, sizeof(addressstring)); + inet_ntop(AF_INET, &serveraddr.sin_addr, addressstring, sizeof(addressstring)); printf("Remote is %s\n", addressstring); #endif serveraddr.sin_port = linkresp->abortPort; @@ -288,8 +288,12 @@ int vxi11_unlock() { int vxi11_create_intr_chan() { if (clnt == NULL) return 0; - Device_RemoteFunc remotefunc = { .hostAddr = 0x0, .hostPort = 0x0, .progNum = 0x0, .progVers = 0x0, .progFamily = - DEVICE_TCP }; + + struct sockaddr_in myaddress; + get_myaddress(&myaddress); + + Device_RemoteFunc remotefunc = { .hostAddr = myaddress.sin_addr.s_addr, .hostPort = 0x0, .progNum = DEVICE_INTR, + .progVers = DEVICE_INTR_VERSION, .progFamily = DEVICE_TCP }; Device_Error* error = create_intr_chan_1(&remotefunc, clnt); if (error != NULL && error->error == 0) return 1; diff --git a/vxi11_server.c b/vxi11_server.c index d6007c1..906613f 100644 --- a/vxi11_server.c +++ b/vxi11_server.c @@ -1,16 +1,17 @@ -/* - * This is sample code generated by rpcgen. - * These are only templates and you can use them - * as a guideline for developing your own functions. - */ - #include "vxi11.h" -#include "stdio.h" #include "globals.h" +#include <stdio.h> +#include <rpc/rpc.h> #include <stdbool.h> #include <sys/socket.h> #include <netinet/in.h> +#define DEBUG + +#ifdef DEBUG +#include <stdlib.h> +#endif + #define ERR_SYNTAXERROR 1 #define ERR_DEVICENOTACCESSIBLE 3 #define ERR_INVALIDLINKINDENTIFIER 4 @@ -214,8 +215,15 @@ destroy_link_1_svc(Device_Link *argp, struct svc_req *rqstp) { Device_Error * create_intr_chan_1_svc(Device_RemoteFunc *argp, struct svc_req *rqstp) { - printf("create_intr_chan_1_svc()\n"); static Device_Error result; + printf("create_intr_chan_1_svc()\n"); + +#ifdef DEBUG + char clientaddressstring[INET_ADDRSTRLEN]; + inet_ntop(AF_INET, &argp->hostAddr, clientaddressstring, sizeof(clientaddressstring)); + printf("Client %s is asking for an interrupt connection on port %u\n", clientaddressstring, ntohs(argp->hostPort)); +#endif + result.error = 0; return &result; } @@ -228,9 +236,11 @@ destroy_intr_chan_1_svc(void *argp, struct svc_req *rqstp) { return &result; } -void * -device_intr_srq_1_svc(Device_SrqParms *argp, struct svc_req *rqstp) { - printf("device_intr_srq_1_svc()\n"); - static char * result; - return (void *) &result; -} +/** + void * + device_intr_srq_1_svc(Device_SrqParms *argp, struct svc_req *rqstp) { + printf("device_intr_srq_1_svc()\n"); + static char * result; + return (void *) &result; + } + **/ diff --git a/vxi11_svc.c b/vxi11_svc.c index 29d63d7..96a967f 100644 --- a/vxi11_svc.c +++ b/vxi11_svc.c @@ -11,9 +11,7 @@ #define SIG_PF void(*)(int) #endif -static void -device_async_1(struct svc_req *rqstp, register SVCXPRT *transp) -{ +static void device_async_1(struct svc_req *rqstp, register SVCXPRT *transp) { union { Device_Link device_abort_1_arg; } argument; @@ -22,39 +20,37 @@ device_async_1(struct svc_req *rqstp, register SVCXPRT *transp) char *(*local)(char *, struct svc_req *); switch (rqstp->rq_proc) { - case NULLPROC: - (void) svc_sendreply (transp, (xdrproc_t) xdr_void, (char *)NULL); - return; - - case device_abort: - _xdr_argument = (xdrproc_t) xdr_Device_Link; - _xdr_result = (xdrproc_t) xdr_Device_Error; - local = (char *(*)(char *, struct svc_req *)) device_abort_1_svc; - break; - - default: - svcerr_noproc (transp); - return; + case NULLPROC: + (void) svc_sendreply(transp, (xdrproc_t) xdr_void, (char *) NULL); + return; + + case device_abort: + _xdr_argument = (xdrproc_t) xdr_Device_Link; + _xdr_result = (xdrproc_t) xdr_Device_Error; + local = (char *(*)(char *, struct svc_req *)) device_abort_1_svc; + break; + + default: + svcerr_noproc(transp); + return; } - memset ((char *)&argument, 0, sizeof (argument)); - if (!svc_getargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) { - svcerr_decode (transp); + memset((char *) &argument, 0, sizeof(argument)); + if (!svc_getargs(transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) { + svcerr_decode(transp); return; } - result = (*local)((char *)&argument, rqstp); + result = (*local)((char *) &argument, rqstp); if (result != NULL && !svc_sendreply(transp, (xdrproc_t) _xdr_result, result)) { - svcerr_systemerr (transp); + svcerr_systemerr(transp); } - if (!svc_freeargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) { - fprintf (stderr, "%s", "unable to free arguments"); - exit (1); + if (!svc_freeargs(transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) { + fprintf(stderr, "%s", "unable to free arguments"); + exit(1); } return; } -static void -device_core_1(struct svc_req *rqstp, register SVCXPRT *transp) -{ +static void device_core_1(struct svc_req *rqstp, register SVCXPRT *transp) { union { Create_LinkParms create_link_1_arg; Device_WriteParms device_write_1_arg; @@ -76,208 +72,208 @@ device_core_1(struct svc_req *rqstp, register SVCXPRT *transp) char *(*local)(char *, struct svc_req *); switch (rqstp->rq_proc) { - case NULLPROC: - (void) svc_sendreply (transp, (xdrproc_t) xdr_void, (char *)NULL); - return; - - case create_link: - _xdr_argument = (xdrproc_t) xdr_Create_LinkParms; - _xdr_result = (xdrproc_t) xdr_Create_LinkResp; - local = (char *(*)(char *, struct svc_req *)) create_link_1_svc; - break; - - case device_write: - _xdr_argument = (xdrproc_t) xdr_Device_WriteParms; - _xdr_result = (xdrproc_t) xdr_Device_WriteResp; - local = (char *(*)(char *, struct svc_req *)) device_write_1_svc; - break; - - case device_read: - _xdr_argument = (xdrproc_t) xdr_Device_ReadParms; - _xdr_result = (xdrproc_t) xdr_Device_ReadResp; - local = (char *(*)(char *, struct svc_req *)) device_read_1_svc; - break; - - case device_readstb: - _xdr_argument = (xdrproc_t) xdr_Device_GenericParms; - _xdr_result = (xdrproc_t) xdr_Device_ReadStbResp; - local = (char *(*)(char *, struct svc_req *)) device_readstb_1_svc; - break; - - case device_trigger: - _xdr_argument = (xdrproc_t) xdr_Device_GenericParms; - _xdr_result = (xdrproc_t) xdr_Device_Error; - local = (char *(*)(char *, struct svc_req *)) device_trigger_1_svc; - break; - - case device_clear: - _xdr_argument = (xdrproc_t) xdr_Device_GenericParms; - _xdr_result = (xdrproc_t) xdr_Device_Error; - local = (char *(*)(char *, struct svc_req *)) device_clear_1_svc; - break; - - case device_remote: - _xdr_argument = (xdrproc_t) xdr_Device_GenericParms; - _xdr_result = (xdrproc_t) xdr_Device_Error; - local = (char *(*)(char *, struct svc_req *)) device_remote_1_svc; - break; - - case device_local: - _xdr_argument = (xdrproc_t) xdr_Device_GenericParms; - _xdr_result = (xdrproc_t) xdr_Device_Error; - local = (char *(*)(char *, struct svc_req *)) device_local_1_svc; - break; - - case device_lock: - _xdr_argument = (xdrproc_t) xdr_Device_LockParms; - _xdr_result = (xdrproc_t) xdr_Device_Error; - local = (char *(*)(char *, struct svc_req *)) device_lock_1_svc; - break; - - case device_unlock: - _xdr_argument = (xdrproc_t) xdr_Device_Link; - _xdr_result = (xdrproc_t) xdr_Device_Error; - local = (char *(*)(char *, struct svc_req *)) device_unlock_1_svc; - break; - - case device_enable_srq: - _xdr_argument = (xdrproc_t) xdr_Device_EnableSrqParms; - _xdr_result = (xdrproc_t) xdr_Device_Error; - local = (char *(*)(char *, struct svc_req *)) device_enable_srq_1_svc; - break; - - case device_docmd: - _xdr_argument = (xdrproc_t) xdr_Device_DocmdParms; - _xdr_result = (xdrproc_t) xdr_Device_DocmdResp; - local = (char *(*)(char *, struct svc_req *)) device_docmd_1_svc; - break; - - case destroy_link: - _xdr_argument = (xdrproc_t) xdr_Device_Link; - _xdr_result = (xdrproc_t) xdr_Device_Error; - local = (char *(*)(char *, struct svc_req *)) destroy_link_1_svc; - break; - - case create_intr_chan: - _xdr_argument = (xdrproc_t) xdr_Device_RemoteFunc; - _xdr_result = (xdrproc_t) xdr_Device_Error; - local = (char *(*)(char *, struct svc_req *)) create_intr_chan_1_svc; - break; - - case destroy_intr_chan: - _xdr_argument = (xdrproc_t) xdr_void; - _xdr_result = (xdrproc_t) xdr_Device_Error; - local = (char *(*)(char *, struct svc_req *)) destroy_intr_chan_1_svc; - break; - - default: - svcerr_noproc (transp); - return; + case NULLPROC: + (void) svc_sendreply(transp, (xdrproc_t) xdr_void, (char *) NULL); + return; + + case create_link: + _xdr_argument = (xdrproc_t) xdr_Create_LinkParms; + _xdr_result = (xdrproc_t) xdr_Create_LinkResp; + local = (char *(*)(char *, struct svc_req *)) create_link_1_svc; + break; + + case device_write: + _xdr_argument = (xdrproc_t) xdr_Device_WriteParms; + _xdr_result = (xdrproc_t) xdr_Device_WriteResp; + local = (char *(*)(char *, struct svc_req *)) device_write_1_svc; + break; + + case device_read: + _xdr_argument = (xdrproc_t) xdr_Device_ReadParms; + _xdr_result = (xdrproc_t) xdr_Device_ReadResp; + local = (char *(*)(char *, struct svc_req *)) device_read_1_svc; + break; + + case device_readstb: + _xdr_argument = (xdrproc_t) xdr_Device_GenericParms; + _xdr_result = (xdrproc_t) xdr_Device_ReadStbResp; + local = (char *(*)(char *, struct svc_req *)) device_readstb_1_svc; + break; + + case device_trigger: + _xdr_argument = (xdrproc_t) xdr_Device_GenericParms; + _xdr_result = (xdrproc_t) xdr_Device_Error; + local = (char *(*)(char *, struct svc_req *)) device_trigger_1_svc; + break; + + case device_clear: + _xdr_argument = (xdrproc_t) xdr_Device_GenericParms; + _xdr_result = (xdrproc_t) xdr_Device_Error; + local = (char *(*)(char *, struct svc_req *)) device_clear_1_svc; + break; + + case device_remote: + _xdr_argument = (xdrproc_t) xdr_Device_GenericParms; + _xdr_result = (xdrproc_t) xdr_Device_Error; + local = (char *(*)(char *, struct svc_req *)) device_remote_1_svc; + break; + + case device_local: + _xdr_argument = (xdrproc_t) xdr_Device_GenericParms; + _xdr_result = (xdrproc_t) xdr_Device_Error; + local = (char *(*)(char *, struct svc_req *)) device_local_1_svc; + break; + + case device_lock: + _xdr_argument = (xdrproc_t) xdr_Device_LockParms; + _xdr_result = (xdrproc_t) xdr_Device_Error; + local = (char *(*)(char *, struct svc_req *)) device_lock_1_svc; + break; + + case device_unlock: + _xdr_argument = (xdrproc_t) xdr_Device_Link; + _xdr_result = (xdrproc_t) xdr_Device_Error; + local = (char *(*)(char *, struct svc_req *)) device_unlock_1_svc; + break; + + case device_enable_srq: + _xdr_argument = (xdrproc_t) xdr_Device_EnableSrqParms; + _xdr_result = (xdrproc_t) xdr_Device_Error; + local = (char *(*)(char *, struct svc_req *)) device_enable_srq_1_svc; + break; + + case device_docmd: + _xdr_argument = (xdrproc_t) xdr_Device_DocmdParms; + _xdr_result = (xdrproc_t) xdr_Device_DocmdResp; + local = (char *(*)(char *, struct svc_req *)) device_docmd_1_svc; + break; + + case destroy_link: + _xdr_argument = (xdrproc_t) xdr_Device_Link; + _xdr_result = (xdrproc_t) xdr_Device_Error; + local = (char *(*)(char *, struct svc_req *)) destroy_link_1_svc; + break; + + case create_intr_chan: + _xdr_argument = (xdrproc_t) xdr_Device_RemoteFunc; + _xdr_result = (xdrproc_t) xdr_Device_Error; + local = (char *(*)(char *, struct svc_req *)) create_intr_chan_1_svc; + break; + + case destroy_intr_chan: + _xdr_argument = (xdrproc_t) xdr_void; + _xdr_result = (xdrproc_t) xdr_Device_Error; + local = (char *(*)(char *, struct svc_req *)) destroy_intr_chan_1_svc; + break; + + default: + svcerr_noproc(transp); + return; } - memset ((char *)&argument, 0, sizeof (argument)); - if (!svc_getargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) { - svcerr_decode (transp); + memset((char *) &argument, 0, sizeof(argument)); + if (!svc_getargs(transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) { + svcerr_decode(transp); return; } - result = (*local)((char *)&argument, rqstp); + result = (*local)((char *) &argument, rqstp); if (result != NULL && !svc_sendreply(transp, (xdrproc_t) _xdr_result, result)) { - svcerr_systemerr (transp); - } - if (!svc_freeargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) { - fprintf (stderr, "%s", "unable to free arguments"); - exit (1); + svcerr_systemerr(transp); } - return; -} - -static void -device_intr_1(struct svc_req *rqstp, register SVCXPRT *transp) -{ - union { - Device_SrqParms device_intr_srq_1_arg; - } argument; - char *result; - xdrproc_t _xdr_argument, _xdr_result; - char *(*local)(char *, struct svc_req *); - - switch (rqstp->rq_proc) { - case NULLPROC: - (void) svc_sendreply (transp, (xdrproc_t) xdr_void, (char *)NULL); - return; - - case device_intr_srq: - _xdr_argument = (xdrproc_t) xdr_Device_SrqParms; - _xdr_result = (xdrproc_t) xdr_void; - local = (char *(*)(char *, struct svc_req *)) device_intr_srq_1_svc; - break; - - default: - svcerr_noproc (transp); - return; - } - memset ((char *)&argument, 0, sizeof (argument)); - if (!svc_getargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) { - svcerr_decode (transp); - return; - } - result = (*local)((char *)&argument, rqstp); - if (result != NULL && !svc_sendreply(transp, (xdrproc_t) _xdr_result, result)) { - svcerr_systemerr (transp); - } - if (!svc_freeargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) { - fprintf (stderr, "%s", "unable to free arguments"); - exit (1); + if (!svc_freeargs(transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) { + fprintf(stderr, "%s", "unable to free arguments"); + exit(1); } return; } -void vxi_main () -{ +/* + static void + device_intr_1(struct svc_req *rqstp, register SVCXPRT *transp) + { + union { + Device_SrqParms device_intr_srq_1_arg; + } argument; + char *result; + xdrproc_t _xdr_argument, _xdr_result; + char *(*local)(char *, struct svc_req *); + + switch (rqstp->rq_proc) { + case NULLPROC: + (void) svc_sendreply (transp, (xdrproc_t) xdr_void, (char *)NULL); + return; + + case device_intr_srq: + _xdr_argument = (xdrproc_t) xdr_Device_SrqParms; + _xdr_result = (xdrproc_t) xdr_void; + local = (char *(*)(char *, struct svc_req *)) device_intr_srq_1_svc; + break; + + default: + svcerr_noproc (transp); + return; + } + memset ((char *)&argument, 0, sizeof (argument)); + if (!svc_getargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) { + svcerr_decode (transp); + return; + } + result = (*local)((char *)&argument, rqstp); + if (result != NULL && !svc_sendreply(transp, (xdrproc_t) _xdr_result, result)) { + svcerr_systemerr (transp); + } + if (!svc_freeargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) { + fprintf (stderr, "%s", "unable to free arguments"); + exit (1); + } + return; + }*/ + +void vxi_main() { printf("VXI service started\n"); register SVCXPRT *transp; - pmap_unset (DEVICE_ASYNC, DEVICE_ASYNC_VERSION); - pmap_unset (DEVICE_CORE, DEVICE_CORE_VERSION); - pmap_unset (DEVICE_INTR, DEVICE_INTR_VERSION); + pmap_unset(DEVICE_ASYNC, DEVICE_ASYNC_VERSION); + pmap_unset(DEVICE_CORE, DEVICE_CORE_VERSION); + //pmap_unset(DEVICE_INTR, DEVICE_INTR_VERSION); transp = svcudp_create(RPC_ANYSOCK); if (transp == NULL) { - fprintf (stderr, "%s", "cannot create udp service."); + fprintf(stderr, "%s", "cannot create udp service."); exit(1); } if (!svc_register(transp, DEVICE_ASYNC, DEVICE_ASYNC_VERSION, device_async_1, IPPROTO_UDP)) { - fprintf (stderr, "%s", "unable to register (DEVICE_ASYNC, DEVICE_ASYNC_VERSION, udp)."); + fprintf(stderr, "%s", "unable to register (DEVICE_ASYNC, DEVICE_ASYNC_VERSION, udp)."); exit(1); } if (!svc_register(transp, DEVICE_CORE, DEVICE_CORE_VERSION, device_core_1, IPPROTO_UDP)) { - fprintf (stderr, "%s", "unable to register (DEVICE_CORE, DEVICE_CORE_VERSION, udp)."); - exit(1); - } - if (!svc_register(transp, DEVICE_INTR, DEVICE_INTR_VERSION, device_intr_1, IPPROTO_UDP)) { - fprintf (stderr, "%s", "unable to register (DEVICE_INTR, DEVICE_INTR_VERSION, udp)."); + fprintf(stderr, "%s", "unable to register (DEVICE_CORE, DEVICE_CORE_VERSION, udp)."); exit(1); } + //if (!svc_register(transp, DEVICE_INTR, DEVICE_INTR_VERSION, device_intr_1, IPPROTO_UDP)) { + // fprintf (stderr, "%s", "unable to register (DEVICE_INTR, DEVICE_INTR_VERSION, udp)."); + // exit(1); + //} transp = svctcp_create(RPC_ANYSOCK, 0, 0); if (transp == NULL) { - fprintf (stderr, "%s", "cannot create tcp service."); + fprintf(stderr, "%s", "cannot create tcp service."); exit(1); } if (!svc_register(transp, DEVICE_ASYNC, DEVICE_ASYNC_VERSION, device_async_1, IPPROTO_TCP)) { - fprintf (stderr, "%s", "unable to register (DEVICE_ASYNC, DEVICE_ASYNC_VERSION, tcp)."); + fprintf(stderr, "%s", "unable to register (DEVICE_ASYNC, DEVICE_ASYNC_VERSION, tcp)."); exit(1); } if (!svc_register(transp, DEVICE_CORE, DEVICE_CORE_VERSION, device_core_1, IPPROTO_TCP)) { - fprintf (stderr, "%s", "unable to register (DEVICE_CORE, DEVICE_CORE_VERSION, tcp)."); - exit(1); - } - if (!svc_register(transp, DEVICE_INTR, DEVICE_INTR_VERSION, device_intr_1, IPPROTO_TCP)) { - fprintf (stderr, "%s", "unable to register (DEVICE_INTR, DEVICE_INTR_VERSION, tcp)."); + fprintf(stderr, "%s", "unable to register (DEVICE_CORE, DEVICE_CORE_VERSION, tcp)."); exit(1); } + //if (!svc_register(transp, DEVICE_INTR, DEVICE_INTR_VERSION, device_intr_1, IPPROTO_TCP)) { + // fprintf (stderr, "%s", "unable to register (DEVICE_INTR, DEVICE_INTR_VERSION, tcp)."); + // exit(1); + //} - svc_run (); - fprintf (stderr, "%s", "svc_run returned"); + svc_run(); + fprintf(stderr, "%s", "svc_run returned"); } |