| /*------------------------------------------------------*/
/* Simple Event Broker Client Program */
/* Artur Stefanowicz, NSIS Poland */
/* (based on standard simpcl example) */
/* */
/* Description: This demo program acts as a */
/* client initiating TOUPPER service which in */
/* turn posts an event that will be caught by */
/* simp_evt program. */
/* */
/* Usage: (1) boot application */
/* (2) start simp_evt */
/* (3) invoke simpcl with some string */
/* */
/*------------------------------------------------------*/
#include <stdio.h>
#include "atmi.h"
#if defined(__STDC__) || defined(__cplusplus)
main(int argc, char *argv[])
#else
main(argc, argv)
int argc;
char *argv[];
#endif
{
char *sendbuf, *rcvbuf;
long sendlen, rcvlen;
int ret;
TPINIT *initbuff;
if(argc != 2)
{
printf("Usage: simpcl string\n");
exit(1);
}
initbuff = (TPINIT *)tpalloc("TPINIT",NULL,0);
if(initbuff == NULL)
{
printf("Error allocating INIT buffer\n");
exit(1);
}
/* Attach to System/T as a Client Process */
if (tpinit(initbuff) == -1)
{
printf("Tpinit failed with error: %s\n",tpstrerror(tperrno));
exit(1);
}
sendlen = strlen(argv[2]);
/* Allocate STRING buffers for the request and the reply */
if((sendbuf = (char *)tpalloc("STRING", NULL, sendlen+1)) == NULL)
{
printf("Error allocating send buffer\n");
tpterm();
exit(1);
}
if((rcvbuf = (char *) tpalloc("STRING", NULL, sendlen+1)) == NULL)
{
printf("Error allocating receive buffer\n");
tpfree(sendbuf);
tpterm();
exit(1);
}
strcpy(sendbuf, argv[2]);
/* Request the service TOUPPER, waiting for a reply */
ret = tpcall("TOUPPER", sendbuf, 0, &rcvbuf, &rcvlen, (long)0);
if(ret == -1)
{
printf("Error calling service TOUPPER:%s\n",
tpstrerror(tperrno));
tpfree(sendbuf);
tpfree(rcvbuf);
tpterm();
exit(1);
}
printf("Returned string is: %s\n", rcvbuf);
/* Free Buffers & Detach from System/T */
tpfree(sendbuf);
tpfree(rcvbuf);
tpterm();
}
|
| /*------------------------------------------------------*/
/* Simple Event Broker Client Program */
/* Artur Stefanowicz, NSIS Poland */
/* (based on standard simpcl example) */
/* */
/* Description: This demo program acts as a */
/* client for Event Broker messages, using one */
/* of EB reactions on events: message, service */
/* call or enqueuing request. */
/* By default, it catches events with names */
/* starting with S, one of them being event */
/* posted by TOUPPER service wnen it is called */
/* */
/* Usage: (1) boot application */
/* (2) start simp_evt */
/* (3) invoke simpcl with some string */
/* */
/*------------------------------------------------------*/
#include <stdio.h>
#include "atmi.h"
#include "fml32.h"
/* this is unsolicited messages handler...*/
void unsol_handler(char *str, long len, long flag)
{
char type[20];
char subtype[20];
FBFR32 *fbr32;
/* first check what type of buffer arrived... */
/* in this demo, we just handle STRING & FML32 buffers */
tptypes(str, type, subtype);
/* if this is STRING then...*/
if(!strcmp(type, "STRING"))
printf("\nUnsolicited message of type STRING: %s", str);
else
if(!strcmp(type, "FML32"))
{
printf("\nUnsolicited message of type FML32");
fbr32 = (FBFR32 *)str;
Fprint32(fbr32);
}
else
printf("\nUnhandled type: %s", type);
}
/* this pointer to a function is later used at tpsetunsol()... */
void (*unsol_handler_ptr)() = unsol_handler;
#if defined(__STDC__) || defined(__cplusplus)
main(int argc, char *argv[])
#else
main(argc, argv)
int argc;
char *argv[];
#endif
{
char *rcvbuf;
long rcvlen;
int ret;
int cnt;
TPINIT *initbuff;
if(argc != 1)
{
printf("\nUsage: [> simp_evt], no params allowed");
exit(1);
}
initbuff = (TPINIT *)tpalloc("TPINIT",NULL,0);
if(initbuff == NULL)
{
printf("\nError allocating INIT buffer");
exit(1);
}
/* we use SIGNAL notification mode...*/
initbuff->flags = TPU_SIG;
/* Attach to System/T as a Client Process */
if (tpinit(initbuff) == -1)
{
fprintf(stderr, "Tpinit failed\n");
exit(1);
}
/* I had very strict compiler...sorry for that animal...*/
(*(void (*)())tpsetunsol)((void (*)())unsol_handler_ptr);
/* Now, we want to place some subscriptions, for example */
/* for all events startinng with S */
/* Look in documentation for specific rules */
if(tpsubscribe("S.*", NULL, NULL, 0) < 0)
{
printf("Error on subscribe %s", tpstrerror(tperrno));
exit(1);
}
/* now enter loop waiting for events */
/* anytime you press a key, we additionaly */
/* check for unsolicited messages - this is */
/* in case notification mode would be changed to DIPIN */
/* Loop stops on pressing 'q' */
ch = 'a';
while(ch != 'q')
{
cnt = tpchkunsol();
printf("\nUnsol msg cnt = %d", cnt);
ch = getchar();
}
tpterm();
}
|
| /*------------------------------------------------------*/
/* Simple Server Program with Event Broker */
/* functionality */
/* Artur Stefanowicz, NSIS Poland */
/* (based on standard simpcl example) */
/* */
/* Description: This demo program acts as a */
/* server for Event Broker example. When TOUPPER */
/* service is called, it posts SIMPSRV_CALLED */
/* event */
/* */
/* Usage: (1) boot application */
/* (2) start simp_evt */
/* (3) invoke simpcl with some string */
/* */
/*------------------------------------------------------*/
#include <stdio.h>
#include <ctype.h>
#include <atmi.h>
#include <userlog.h>
/*
tpsvrinit is executed when a server is booted, before it begins
processing requests. It is not necessary to have this function.
Also available is tpsvrdone (not used in this example), which is
called at server shutdown time.
*/
#if defined(__STDC__) || defined(__cplusplus)
tpsvrinit(int argc, char *argv[])
#else
tpsvrinit(argc, argv)
int argc;
char **argv;
#endif
{
/* Some compilers warn if argc and argv aren't used. */
argc = argc;
argv = argv;
/* userlog writes to the central TUXEDO message log */
userlog("Welcome to the simple server");
return(0);
}
/*
This function performs the actual service requested by the client.
Its argument is a structure containing among other things a pointer
to the data buffer, and the length of the data buffer.
*/
#ifdef __cplusplus
extern "C"
#endif
void
#if defined(__STDC__) || defined(__cplusplus)
TOUPPER(TPSVCINFO *rqst)
#else
TOUPPER(rqst)
TPSVCINFO *rqst;
#endif
{
int i;
for(i = 0; i < rqst->len-1; i++)
rqst->data[i] = toupper(rqst->data[i]);
/* now post an event 'SIMPSRV_CALLED'...*/
if(tppost("SIMPSRV_CALLED", rqst->data, rqst->len, TPNOREPLY) < 0)
userlog("tppost failed: %s", tpstrerror(tperrno));
/* Return the transformed buffer to the requestor. */
tpreturn(TPSUCCESS, 0, rqst->data, 0L, 0);
}
|