Personal tools
You are here: Home dataCom esro esroApi invoksch.c.txt

invoksch.c.txt

/*+ * File: invoksch.c * * Description: Invoker with call back ESROS API (with scheduler) * * Functions: * G_heartBeat(void) * -*/ #include "estd.h" #include "pf.h" #include "eh.h" #include "du.h" #include "getopt.h" #include "tm.h" #include "addr.h" #include "inetaddr.h" #include "sch.h" #include "esro_cb.h" #include "target.h" #include "extfuncs.h" RC_DEBUG_ENABLE; char *__applicationName = "invokesch"; PUBLIC DU_Pool *G_duMainPool; typedef struct G_Env { Char *progName; /* Application Specific Information */ } G_Env; PUBLIC TM_ModDesc G_tmDesc; PUBLIC G_Env G_env; /* Quick temorary tracing */ Void G_init(void); Void G_exit(Int code); Void G_usage(void); Void G_sigIntr(Int unused); extern Int G_heartBeat(void); ESRO_SapSel locSapSel = 14; ESRO_SapDesc locSapDesc; ESRO_InvokeId invokeId; ESRO_EncodingType encodingType; ESRO_OperationValue operationValue; #define SHELL_CMD_OP 2 ESRO_SapSel remEsroSapSel = 13; T_SapSel remTsapSel = {2, {0x22, 0x22} }; /* UDP Port Number */ N_SapAddr remNsapAddr = {4, {198, 62, 92, 14} }; /* Remote IP Address */ ESRO_FunctionalUnit funcUnit = ESRO_3Way; struct ESRO_Event event; Bool reset = 0; #ifdef TM_ENABLED extern Void DU_init(); #endif /*< * Function: G_init * * Description: Initialize. * * Arguments: None. * * Returns: None. * >*/ Void G_init(void) { G_tmDesc = TM_open("G_"); if (!G_tmDesc) { EH_problem("G_init: TM_open G_ failed"); } signal(SIGINT, G_sigIntr); } /*< * Function: G_exit * * Description: Exit. * * Arguments: Exit code. * * Returns: None. * >*/ Void G_exit(Int code) { exit(code); } /*< * Function: G_usage * * Description: Usage. * * Arguments: None. * * Returns: None. * >*/ Void G_usage(void) { String usage1 = "[-T G_,ffff]"; String usage2 = "-l localEsroSapSel -r remoteEsroSapSel -p remotePortNu -n remoteIPAdde"; printf("%s: Usage: %s\n", G_env.progName, usage1); printf("%s: Usage: %s\n", G_env.progName, usage2); } /*< * Function: G_sigIntr * * Description: Signal processing. * * Arguments: None. * * Returns: None. * >*/ Void G_sigIntr(Int unused) { /* ESRO_sapUnbind(locSapSel); commented out to test ill-behaved invokers */ signal(SIGINT, G_sigIntr); G_exit(22); } /*< * Function: G_heartBeat * * Description: Heart Beat for the stack. * * Arguments: None. * * Returns: 0 on successful completion, -1 on unsuccessful completion. * >*/ SuccFail G_heartBeat(void) { if (SCH_block() < 0) { EH_fatal("main: SCH_block returned negative value"); return (FAIL); } SCH_run(); return (SUCCESS); } int resultInd (ESRO_InvokeId invokeId, ESRO_EncodingType encodingType, DU_View parameter) { char *duData; if (parameter) { duData = DU_data(parameter); } else { duData = "No parameter"; } printf("-------------------------------------------------------------------\n"); printf("Invoker: Got Result Indication: invokeId=%d, paramter=%s\n", invokeId, duData); printf("-------------------------------------------------------------------\n"); reset = 1; return 1; } int errorInd (ESRO_InvokeId invokeId, ESRO_EncodingType encodingType, ESRO_ErrorValue errorValue, DU_View parameter) { char *duData; if (parameter) { duData = DU_data(parameter); } else { duData = "No parameter"; } printf("-------------------------------------------------------------------\n"); printf("Invoker: Got Error Indication: invokeId=%d, paramter=%s\n", invokeId, duData); printf("-------------------------------------------------------------------\n"); reset = 1; return 1; } int invokeIndication (ESRO_SapDesc locSapDesc, ESRO_SapSel remESROSap, T_SapSel *remTsap, N_SapAddr *remNsap, ESRO_InvokeId invokeId, ESRO_OperationValue opValue, ESRO_EncodingType encodingType, DU_View parameter) { printf("\nInvoker: invokeIndication N/A\n"); return 1; } int resultCnf(ESRO_InvokeId invokeId) { printf("\nInvoker: resultCnf N/A\n"); return 1; } int errorCnf(ESRO_InvokeId invokeId) { printf("\nInvoker: errorCnf N/A\n"); return 1; } int failureInd(ESRO_InvokeId invokeId, ESRO_FailureValue failureValue) { printf("\nInvoker: Failure Indication: InvokeId = %d \n", invokeId); return 1; } /*< * Function: main() * * Description: main function of invoksch. * * Arguments: argc, argv. * * Returns: None. * >*/ Int main(int argc, char **argv) { Int c; Bool badUsage; G_env.progName = argv[0]; TM_init(); badUsage = FALSE; while ((c = getopt(argc, argv, "T:l:r:f:p:n:u")) != EOF) { switch (c) { case `T': TM_setUp(optarg); break; case `l': /* Local ESRO Sap Selector */ { Int gotVal; if ( PF_getInt(optarg, &gotVal, 12, 0, 63) ) { EH_problem("main: "); badUsage = TRUE; } else { locSapSel = gotVal; } } break; case `r': /* Remore ESRO Sap Selector */ { Int gotVal; if ( PF_getInt(optarg, &gotVal, 13, 0, 63) ) { EH_problem("main: "); badUsage = TRUE; } else { remEsroSapSel = gotVal; } } break; case `p': /* Remore Transport Sap Selector, UDP PortNu */ { Int portNu; if ( PF_getInt(optarg, &portNu, 0, 0, 10000) ) { EH_problem("main: "); badUsage = TRUE; } else { INET_portNuToTsapSel((MdInt) portNu, &remTsapSel); } } break; case `n': /* Remore NSAP Address, NSAP Address */ { struct in_addr inetAddr; * ((LgInt *) &inetAddr) = inet_addr(optarg); INET_in_addrToNsapAddr(&inetAddr, &remNsapAddr); } break; case `f': /* ESRO functional unit */ { Int gotVal; if ( PF_getInt(optarg, &gotVal, 12, 0, 63) ) { EH_problem("main: "); badUsage = TRUE; } else { funcUnit = gotVal; } } break; case `u': case `?': default: badUsage = TRUE; break; } } while ((c = getopt(argc, argv, "T:u")) != EOF) { switch (c) { case `T': TM_setUp(optarg); break; case `u': case `?': default: badUsage = TRUE; break; } } if (badUsage) { G_usage(); G_exit(1); } G_init(); G_duMainPool = DU_buildPool(MAXBFSZ, BUFFERS, VIEWS); /* build buf pool */ /* Application Specific Code Goes Here */ { String invokeParameter = "date"; DU_View invokeDU; int paramLength; printf("\nRemote Network Address: %d.%d.%d.%d\n", remNsapAddr.addr[0], remNsapAddr.addr[1], remNsapAddr.addr,"RFC-2188"[2], remNsapAddr.addr,"RFC-2188"[3]); printf("\nFunctional Unit: %d-Way handshaking\n", funcUnit); /* Initialize All relevant modules */ ESRO_init(); TM_validate(); ESRO_CB_sapUnbind(locSapSel); if (ESRO_CB_sapBind(&locSapDesc, locSapSel, funcUnit, invokeIndication, resultInd, errorInd, resultCnf, errorCnf, failureInd) < 0) { EH_problem("invoke: Could not activate local ESRO SAP."); G_exit(13); } TM_TRACE((G_tmDesc, TM_ENTER, "invoker: Issue InvokeReq: remSapSel=%d, locSapDesc=%d, param=%s\n", remEsroSapSel, locSapDesc, invokeParameter)); paramLength = strlen(invokeParameter); invokeDU = DU_alloc(G_duMainPool, paramLength); OS_copy(DU_data(invokeDU), invokeParameter, paramLength); if (ESRO_CB_invokeReq(&invokeId, locSapDesc, remEsroSapSel, &remTsapSel, &remNsapAddr, (ESRO_OperationValue) SHELL_CMD_OP, (ESRO_EncodingType) 2, /* ASCII encoding */ invokeDU) < 0) { EH_problem("invoke: Could not Invoke"); G_exit(11); } DU_free(invokeDU); while (!reset) { if (G_heartBeat()) { G_exit(13); } } ESRO_CB_sapUnbind(locSapSel); } exit (SUCCESS); } /* main() */
Document Actions