/******************************************************************************
 * This file is part of a software distribution, which is furnished under the *
 * terms of a license.  Use of this software  by any means is subject to this *
 * license  and  signifies  the  acceptance of  the  licensing  terms  stated *
 * therein. Please see  the file LICENSE in the  top-level directory  of this *
 * software  distribution  for detailed copyright  disclaimers  and licensing *
 * terms.                                                                     *
 ******************************************************************************
 * Copryight (c) by Andreas S. Wetzel - All rights reserved.                  *
 ******************************************************************************/

/* $Id: heartbeat.c,v 1.2 2001/03/19 14:54:01 mickey Exp $ */

#include <vchat.h>
#include <proto_common.h>

/*** Globals ***/

VTIMER vtimer = {0,0,0};

/*** Externals ***/

extern VP vp;

extern u_char is_handler;
extern VCONN sconn;

/*
 * void heartbeat(void);
 *
 * This function is called every second by SIGALRM to fulfill several
 * timer triggered tasks, such as updating the clock and online clock
 * counter or triggering the videosnake due to inactivity timer expiration.
 */

void heartbeat(void)
{
#if HELP_DISPLAY
	static u_long	helpflg	= 0;
#endif
	static u_char	sync	= 0;
	time_t		now;

	is_handler = 1;

	if(sync)
	{
		++vtimer.clocksrc;
	}
	else
	{
		time(&now);
		sync = vtimer.clocksrc = (now % 60);
	}

	if(vp.vclock_pbc_enable)
	{
		switch(vtimer.pbc_timer)
		{
			case 0:		break;
			case 1:		vtimer.pbc_timer = 0;
					put_back_cursor();
					break;
			default:	--vtimer.pbc_timer;
					break;	
		}
	}

	/*
	 * Update clock if necessary
	 */

	if(!(vtimer.clocksrc % 60))
		update_clock();

	/*
	 * Update online time if necessary
	 */

	if((vtimer.clocksrc % 60) == sync)
		update_onlinetime((vtimer.clocksrc) - sync);

#if HELP_DISPLAY

	/*
	 * Flip vserver to help display
	 */

	if(!helpflg && !(vtimer.clocksrc % HELP_DISPLAY_CYCLE))
	{
		helpflg = vtimer.clocksrc + HELP_DISPLAY_DURATION;

		alter_status(STAT_SERVER, "<Type `.h' for help> ");
		update_status(0);
	}

	if(helpflg && vtimer.clocksrc > helpflg)
	{
		helpflg = 0;
		alter_status(STAT_SERVER, "%s ", sconn.host);
		update_status(0);
	}

#endif
	/*
	 * Lookout for snake-timer expiration
	 */

	if(vp.vclock_snake_enable)
	{
		switch(vtimer.snake_timer)
		{
			case 0:		break;
			case 1:		vtimer.snake_timer = 0;
					display_snake();
					line_update();
					break;
			default:	--vtimer.snake_timer;
					break;
		}
	}

	is_handler = 0;
}


syntax highlighted by Code2HTML, v. 0.9.1