Previous Menu Next
Example Code: Sending Events

The following code listing provides a trivial example of sending events to an engine.

In order to keep the example small, safety checks such as examining API call return values are not performed.

#include <stdio.h>
#include <stdlib.h>
#ifdef _WIN32
#include <WINSOCK.H>
#endif
#include <signal.h>
#include <EIO/EIO.h>

#define MAX_PDU_LEN 1000 /* max size of event buffer */


/* 	When SIGNET or SIGTERM is called, reset event
	I/O connection and the stack
*/
void
signal_handler( int sig )
{
	EIO_stackReset();
	ESOK_stackReset();
	exit(0);
}


int
main( int argc, char *argv[] )
{
	ESOK_Remote remote;
	ESOK_ConnectionId cid= 0;
	EIO_ConnectionId eid = 0;
	int32 create_time = 0;
	int32 streamId = 0;
	char* syntax = NULL;

	/*event encoding_type mdl for 8-bit text */
	char* encoding_type = "mdl";

	char  pdu [MAX_PDU_LEN];
	int32 pdu_length = 0;
	int instance = 1;

	extern char* optarg;
	
	signal (SIGTERM, signal_handler);
	signal (SIGINT, signal_handler);

  
	ESOK_stackInit ();		/*manpage*/
  
	EIO_stackInit ();		/*manpage*/
  
	ESOK_buildRemote(instance, &remote); /*manpage*/
  
	ESOK_open( &remote, &cid );	/*manpage*/
  
	EIO_open (cid, 0, &eid);	/*manpage*/

	while (gets(pdu))
	{
		pdu_length = strlen(pdu);
  
		EIO_sendEvent(	/*manpage*/

			      eid, pdu, pdu_length,
			      create_time,
			      encoding_type,
			      syntax );


  
		ESOK_process(0);	/*manpage*/
	}

	/* ensure socket stack has totally
	   processed event */
	while (!ESOK_stackEmpty());	/*manpage*/
	{
		ESOK_process(0);
	}
  
	EIO_close( eid );		/*manpage*/
  
	EIO_stackReset();		/*manpage*/
  
	ESOK_close( cid );		/*manpage*/
  
	ESOK_stackReset();		/*manpage*/

	exit (0);
}