[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference tpsys::tuxedo

Title:Welcome to TUXEDO
Moderator:MICROW::HERRLICH
Created:Wed Dec 07 1994
Last Modified:Wed May 21 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:153
Total number of notes:421

147.0. "EventBroker example for NT (Tux v6.2 only) " by JACEK::STEFANOWICZ () Thu Apr 03 1997 05:27

    One of the nice feature that appears in v6.2 on NT is Event Broker
    service. The following examples form simple demo acting as follows:
    
    
    	simp_evt <-------- TMUSREVT <-------  simpserv
                                                 |
    			simpcl -------->----------
    
    simpcl invokes TOUPPER service, which posts SIMPSERV_CALLED event.
    simp_evt, when registering, subscribes all events which names
    starts with 'S'. So, when an event is posted, TMUSREVT (server
    dealing with subscriptions) passes it to simp_evt.
    
    This is just one of the possibilities of reacting on event. Two
    other options include:
    - invoking specified service
    - enqueuing request
    
    1.Building examples:
    buildclient -o simp_evt.exe -f simp_evt.c
    buildclient -o simpcl.exe -f simpcl.c
    buildserver -o simpserv.exe -f simpserv.c -s TOUPPER
    
    2.Remember about changing ubbsimple parameters
    3.Remember abiut environment variables (TUXDIR,APPDIR,TUXCONFIG)
    
    have fun,
    Artur  
T.RTitleUserPersonal
Name
DateLines
147.1SIMPCL.C - regular clientJACEK::STEFANOWICZThu Apr 03 1997 05:2884
/*------------------------------------------------------*/
/*	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();
}
147.2SIMP_EVT.C - Event clientJACEK::STEFANOWICZThu Apr 03 1997 05:29116
/*------------------------------------------------------*/
/*	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();
}
147.3SIMPSERV.C - Server posting eventJACEK::STEFANOWICZThu Apr 03 1997 05:2970
/*------------------------------------------------------*/
/*	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);
}
147.4UBBSIMPLEJACEK::STEFANOWICZThu Apr 03 1997 05:3033
#Replace the <bracketed> items with the appropriate values.

*RESOURCES
IPCKEY		<123456>
MASTER		simple
MAXACCESSERS	10
MAXSERVERS	10
MAXSERVICES	50
MODEL		MP
LDBAL		N
NOTIFY      SIGNAL

*MACHINES
DEFAULT:		
	APPDIR=<"c:\users\artur\kurs_tuxedo_development\testy">
	TUXCONFIG=<"c:\users\artur\kurs_tuxedo_development\testy\tuxconfig">
	TUXDIR=<"c:\tux62">

"SKRZYNKA"	LMID=simple

*GROUPS
AppGroup    LMID=simple	GRPNO=1	OPENINFO=NONE
SysEvtGroup LMID=simple GRPNO=2 OPENINFO=NONE
UsrEvtGroup LMID=simple GRPNO=3 OPENINFO=NONE

*SERVERS
DEFAULT:		CLOPT="-A"
simpserv	SRVGRP=AppGroup SRVID=1 MAXGEN=5
TMUSREVT SRVGRP=UsrEvtGroup SRVID=50 RESTART=Y MAXGEN=5
TMSYSEVT SRVGRP=SysEvtGroup SRVID=60 RESTART=Y MAXGEN=5

*SERVICES
TOUPPER SRVGRP=AppGroup