Пример #1
0
void SendStatusRequest( void )
{
	char message[16];
	MSG_LOGO rlogo;
	long     rlen;

	/* Flush all old messages in the ring
	 *    **********************************/
	logo.type   = TypeStatus;
	logo.mod    = 0;
	logo.instid = InstId;
	while( tport_getmsg( &region, &logo, 1,
				&rlogo, &rlen, message, (long)16 ) != GET_NONE );

	/* Build status request message
	 *    ****************************/
	sprintf(message,"%d\n", MyModId );

	/* Set logo values of message
	 *    **************************/
	logo.type   = TypeReqStatus;
	logo.mod    = MyModId;
	logo.instid = InstId;

	/* Send status message to transport ring
	 *    **************************************/
	if ( tport_putmsg( &region, &logo, strlen(message), message ) != PUT_OK )
		fprintf(stderr, "status: Error sending message to transport region.\n" );

	return;
}
Пример #2
0
/******************************************************************************
 * orb2eworm_status() builds a heartbeat or error message & puts it into       *
 *                   shared memory.  Writes errors to log file & screen.      *
 ******************************************************************************/
void 
orb2eworm_status( unsigned char type, short ierr, char *note )
{
	MSG_LOGO logo;
	char	msg[256];
	long	size;
	long	t;

	/*
	 * Build the message 
	 */
	logo.instid = InstId;
	logo.mod = MyModId;
	logo.type = type;

	time( &t );

	if ( type == TypeHeartBeat ) 
	{
		sprintf( msg, "%ld\n\0", t );
	} 
	else if ( type == TypeError ) 
	{
		sprintf( msg, "%ld %hd %s\n\0", t, ierr, note );
		logit( "et", "orb2eworm: %s\n", note );
	}
	size = strlen( msg );	/* don't include the null byte in the message */

	/*
	 * Write the message to shared memory 
	 */
	if ( tport_putmsg( &Region, &logo, size, msg ) != PUT_OK ) 
	{
		if ( type == TypeHeartBeat ) 
		{
			logit( "et", "orb2eworm:  Error sending heartbeat.\n" );
		} 
		else if ( type == TypeError ) 
		{
			logit( "et",
			 "orb2eworm:  Error sending error:%d.\n", ierr );
		}
	}
	return;
}
Пример #3
0
/******************************************************************
 *                             Heartbeat                          *
 *          Send a heartbeat to the transport ring buffer         *
 ******************************************************************/
void *Heartbeat( void *dummy )
{
        char     msg[20];
        unsigned short length;
        time_t   now;
        MSG_LOGO logo;
 
        logo.instid = InstId;
        logo.mod   = MyModId;
        logo.type  = TypeHeartBeat;
        for(;;)
        {
                sleep_ew( HeartBeatInterval*1000 );
                time( &now );
                sprintf( msg, "%d\n\0", (int) now );
                length = strlen( msg );
                if ( tport_putmsg( &Region, &logo, length, msg ) != PUT_OK )
                        logit("t", "orb2eworm: Error sending heartbeat\n");
        }
}
Пример #4
0
void SendRestartRequest( char*  modPid ) /* pid of module as ascii string*/
{
	MSG_LOGO logo;
	char message[512];

	/* Build message
	 *    *************/
	strcpy (message,modPid);
	strcat( message, "\n\0" );

	/* Set logo values of pager message
	 *    ********************************/
	logo.type   = TypeRestart;
	logo.mod    = MyModId;
	logo.instid = InstId;

	/* Send restart message to transport ring
	 *    **************************************/
	if ( tport_putmsg( &region, &logo, strlen(message), message ) != PUT_OK )
		fprintf(stderr, "restart: Error sending message to transport region.\n" );

	return;

}
Пример #5
0
main( int argc, char **argv )
{
	thread_t tidHeartbeat;
	int	nbytes_orb;	
	int	nbytes_tp;
	MSG_LOGO putlogo;	/* logo of message     */
	int	res;
	TracePacket tp;
	int     pktid;
	char    srcname[STRSZ];
	double  mytime;
	char    *rawpkt = NULL;
	struct Packet *Pkt = NULL;
	struct PktChannel *pktchan = NULL;
	int	ichan;
	int     bufsize = 0;
	char	*sitedb;
	int	rc;	

	if ( argc != 2 ) 
	{
		fprintf( stderr, "Usage: orb2eworm <configfile>\n" );
		exit( 0 );
	}

	chdir_ewparams( "orb2eworm" );

	elog_init( argc, argv );

	orb2eworm_config( argv[1] );

	logit_init( "orb2eworm", (short) MyModId, MAX_LOGMSG_SIZE, LogSwitch );
	logit( "", "%s: Read command file <%s>\n", argv[0], argv[1] );

	orb2eworm_lookup( );

	if( ( sitedb = getenv( "SITE_DB" ) ) == NULL )
	{
		fprintf(stderr, "Environment variable SITE_DB not defined; ");
		fprintf(stderr, "orb2eworm exiting.\n");
		exit( -1 );
	}

	read_site_db( sitedb );

	OrbFd = orbopen( OrbName, "r&" );
	if( OrbFd < 0 ) 
	{
		logit( "e", "Failed to connect to orb %s--Bye\n", OrbName );
		exit( -1 );
	}
	else 
	{
		logit( "", "Connected to orb %s\n", OrbName );
	}

	if( ! STREQ( ChannelSelect, "" ) )
	{
		orbselect( OrbFd, ChannelSelect );
	}

	if( ! STREQ( ChannelReject, "" ) )
	{
		orbreject( OrbFd, ChannelReject );
	}

	tport_attach( &Region, RingKey );
	logit( "", "orb2eworm: Attached to public memory region %s: %d\n",
	      RingName, RingKey );

	StartThread( Heartbeat, 0, &tidHeartbeat );

	putlogo.instid = InstId;
	putlogo.mod = MyModId;
	putlogo.type = TypeTracebuf;

	for( ;; ) 
	{
		terminate_if_requested();

		/* Accept that heartbeats will be delayed for 
		   now while orbreap blocks */

		rc = orbreap( OrbFd, &pktid, srcname, &mytime,
			&rawpkt, (int *)&nbytes_orb, &bufsize );
		if( rc < 0 )
		{
			elog_clear_register( 1 );
			continue;
		}

		rc = unstuffPkt( srcname, mytime, rawpkt, nbytes_orb, &Pkt );
		if( rc == 0 )
		{
			logit( "et", "Unstuff failure in orb2eworm for %s\n", srcname );
			elog_clear_register( 1 );
			continue;
		}

		for( ichan = 0; ichan < Pkt->nchannels; ichan++ )
		{
			pktchan = gettbl( Pkt->channels, ichan );

			if( pktchan_to_tracebuf( pktchan, &tp,
						 mytime, &nbytes_tp  ) )
					continue;

			res = tport_putmsg( &Region, &putlogo,
					    nbytes_tp, tp.msg );
		}
	}

}