invoker.c.txt
/*+
* File: invoker.c
*
* Description: Invoker, function call API
*
-*/
#ifdef OS_MALLOC_DEBUG
#include "os.h"
#undef FAIL
#endif
#include "estd.h"
#include "pf.h"
#include "eh.h"
#include "getopt.h"
#include "tm.h"
#include "addr.h"
#include "inetaddr.h"
#include "esro.h"
#include "extfuncs.h"
RC_DEBUG_ENABLE;
char *__applicationName = "ops_xmpl invoker";
extern char pubQuName[];
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);
ESRO_SapSel locSapSel = 14;
ESRO_SapDesc locSapDesc;
ESRO_InvokeId invokeId;
ESRO_EncodingType encodingType;
ESRO_OperationValue operationValue;
#define SHELL_CMD_OP 2
ESRO_SapSel remEsroSapSel = 15;
T_SapSel remTsapSel = {2, {0x22, 0x22} }; /* UDP Port Number */
N_SapAddr remNsapAddr = {4, {198, 62, 92, 10} }; /* Remote IP Address */
struct ESRO_Event event;
/*<
* Function: main()
*
* Description: main function of invoker.
*
* 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:s: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 `s':
if (strlen(optarg) != 0)
strcpy(pubQuName, optarg);
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();
/* Application Specific Code Goes Here */
{
static void invoke(void);
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]);
invoke();
}
exit (SUCCESS);
} /* main() */
/*<
* 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);
ESRO_init();
TM_validate();
}
/*<
* 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);
************/
signal(SIGINT, G_sigIntr);
G_exit(22);
}
/*<
* Function: invoke()
*
* Description: Invoke an operation.
*
* Arguments: None.
*
* Returns: None.
*
>*/
static void
invoke(void)
{
ESRO_RetVal gotVal;
String invokeParameter = "date";
ESRO_sapUnbind(locSapSel);
if ((gotVal = ESRO_sapBind(&locSapDesc, locSapSel, ESRO_3Way)) < 0) {
EH_problem("invoke: Could not activate local ESRO SAP.");
G_exit(13);
}
TM_TRACE((G_tmDesc, TM_ENTER,
"invoker: Issue InvokeReq: remEsroSapSel=%d, parameter=%s\n",
remEsroSapSel, invokeParameter));
gotVal = ESRO_invokeReq(&invokeId, locSapDesc, remEsroSapSel,
&remTsapSel, &remNsapAddr,
(ESRO_OperationValue) SHELL_CMD_OP,
(ESRO_EncodingType) 2, /* ASCII encoding */
4, invokeParameter);
if (gotVal < 0) {
EH_problem("invoke: Could not Invoke");
}
while ( TRUE ) {
while ((gotVal = ESRO_getEvent(locSapDesc, &event, TRUE)) < 0) {
EH_problem("invoke: ESRO_getEvent failed");
G_exit(1);
}
if (gotVal < 0) {
EH_problem("invoke: ESRO_getEvent failed");
}
processEvent(&event);
G_exit(0);
}
}
/*<
* Function: processEvent
*
* Description: Process event.
*
* Arguments: Event.
*
* Returns: 0 on successful completion, -1 on unsuccessful completion.
*
>*/
SuccFail
processEvent(struct ESRO_Event *p_event)
{
switch (p_event->type) {
case ESRO_RESULTIND:
*(p_event->un.resultInd.data + p_event->un.resultInd.len) = `\0';
TM_TRACE((G_tmDesc, TM_ENTER,
"processEvent(Invoker): resultInd invokeId=%d, paramter=%s\n",
p_event->un.resultInd.invokeId,
p_event->un.resultInd.data));
printf("-------------------------------------------------------------------\n");
printf("Invoker: Got Result Indication: invokeId=%d, paramter=%s\n",
p_event->un.resultInd.invokeId,
p_event->un.resultInd.data);
printf("-------------------------------------------------------------------\n");
break;
case ESRO_ERRORIND:
TM_TRACE((G_tmDesc, TM_ENTER,
"processEvent: ErrorInd invokeId=%d, parameter=%s\n",
p_event->un.errorInd.invokeId,
p_event->un.errorInd.data));
printf("Invoker: Got Error Indication: invokeId=%d, parameter=%s\n",
p_event->un.errorInd.invokeId,
p_event->un.errorInd.data);
break;
case ESRO_FAILUREIND:
TM_TRACE((G_tmDesc, TM_ENTER, "processEvent: FailureInd Code=%d\n",
p_event->un.failureInd.failureValue));
printf("Invoker: Operation Failed: Failure Code %d\n",
p_event->un.failureInd.failureValue);
break;
default:
TM_TRACE((G_tmDesc, TM_ENTER, "processEvent: Invalid primitive\n"));
EH_problem("processEvent(Invoker): Invalid primitive");
printf("Invoker: Invalid primitive");
return (FAIL);
}
return (SUCCESS);
}