performer.c.txt
/*+
*
* File: performer.c
*
* Description: Performer (ESROS), function call API.
*
-*/
#ifdef OS_MALLOC_DEBUG
#include "os.h"
#undef FAIL
#endif
#include "estd.h"
#include "getopt.h"
#include "eh.h"
#include "tm.h"
#include "pf.h"
#include "esro.h"
#include "extfuncs.h"
RC_DEBUG_ENABLE;
char *__applicationName = "ops_xmpl performer";
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 */
#define G_tmHere() TM_trace(G_tmDesc, TM_ENTER, "\n")
ESRO_SapSel locSapSel = 15;
ESRO_SapDesc locSapDesc;
ESRO_InvokeId invokeId;
ESRO_EncodingType encodingType;
ESRO_OperationValue operationValue;
#define SHELL_CMD_OP 2
struct ESRO_Event event;
/* Static functions */
static Int perform(void);
/*<
* Function: main()
*
* Description: main function of performer.
*
* 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:s:")) != EOF) {
switch (c) {
case `T':
TM_setUp(optarg);
break;
case `l': /* Local ESRO Sap Selector */
{
Int gotVal;
if ( PF_getInt(optarg, &gotVal, 13, 0, 63) ) {
EH_problem("main (performer): ");
badUsage = TRUE;
} else {
locSapSel = gotVal;
}
}
break;
case `s':
if (strlen(optarg) != 0)
strcpy(pubQuName, optarg);
break;
case `u':
case `?':
default:
badUsage = TRUE;
break;
}
}
if (badUsage) {
G_usage();
G_exit(1);
}
G_init();
/* Do here what needs to be done */
{
ESRO_init();
TM_validate();
perform();
}
exit (0);
} /* 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);
}
/*<
* 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 = "";
String usage2 = "";
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)
{
signal(SIGINT, G_sigIntr);
G_exit(22);
}
static void resultReq(String result);
/*
static void errorReq(String result);
*/
/*<
* Function: perform()
*
* Description: Perform an operation.
*
* Arguments: None.
*
* Returns: None.
*
>*/
static Int
perform(void)
{
ESRO_RetVal gotVal;
ESRO_sapUnbind(locSapSel);
if ((gotVal = ESRO_sapBind(&locSapDesc, locSapSel, ESRO_3Way)) < 0) {
EH_fatal("perform: Could not activate local ESRO SAP.");
}
while ( TRUE ) {
while ((gotVal = ESRO_getEvent(locSapDesc, &event, 1)) < 0) { /*????*/
EH_problem("perform: ESRO_getEvent failed");
return (FAIL);
}
if (gotVal < 0) {
EH_problem("perform: Bad Event");
}
processEvent(&event);
}
}
/*<
* 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_INVOKEIND:
*(p_event->un.invokeInd.data + p_event->un.invokeInd.len) = `\0';
TM_TRACE((G_tmDesc, TM_ENTER,
"Got ESRO-Invoke.Indcation invokeId=%d, operationValue=%d, paramter=%s\n",
p_event->un.invokeInd.invokeId,
p_event->un.invokeInd.operationValue,
p_event->un.invokeInd.data));
/* Here is where you perform what you should do
* and then call resultReq or errorReq.
*/
invokeId = p_event->un.invokeInd.invokeId;
{
time_t idate;
idate = time(&idate);
resultReq(ctime(&idate));
}
break;
case ESRO_RESULTCNF:
TM_TRACE((G_tmDesc, TM_ENTER,
"Got ESRO-Result.Confirm invokeid=%d\n",
p_event->un.resultCnf.invokeId));
printf("------------------------------------------------------\n");
printf("Performer: Got Result Confirmation. invokeId=%d\n",
p_event->un.resultCnf.invokeId);
printf("------------------------------------------------------\n");
G_exit(0);
case ESRO_ERRORCNF:
G_tmHere();
break;
case ESRO_FAILUREIND:
G_tmHere();
break;
default:
G_tmHere();
EH_problem("processEvent: invalid event type");
break;
}
return (SUCCESS);
}
/*<
* Function: resultReq
*
* Description: Result request.
*
* Arguments: Result.
*
* Returns: None.
*
>*/
static void
resultReq(String result)
{
ESRO_RetVal gotVal;
TM_TRACE((G_tmDesc, TM_ENTER, "Issuing ESRO-Result.Request parameter=%s\n",
result));
gotVal = ESRO_resultReq(invokeId, (ESRO_EncodingType) 2,
strlen(result), result);
if (gotVal < 0) {
EH_problem("resultReq: Could not Invoke");
}
}
/*<
* Function: errorReq
*
* Description: Error request.
*
* Arguments: Error.
*
* Returns: None.
*
>*/
/*
static void
errorReq(String result)
{
ESRO_RetVal gotVal;
gotVal = ESRO_errorReq(invokeId, (ESRO_EncodingType) 2,
strlen(result), result);
if (gotVal < 0) {
EH_problem("errorReq: Could not Invoke");
}
}
*/