static char timertest_id[] = "$Header: timertest.cc,v 1.2 96/07/22 10:42:36 oreilly Exp $";


/*
$Log:	timertest.cc,v $
Revision 1.2  96/07/22  10:42:36  10:42:36  oreilly (Thomas C. O'Reilly)
First external release

*/
#include <stdio.h>
#include <Xm/Xm.h>
#include <Xm/RowColumn.h>
#include <Xm/PushB.h>
#include <unistd.h>
#include <time.h>
 
/* Function prototypes */
void slowHandler(XtPointer clientData, XtIntervalId *id);
void fastHandler(XtPointer clientData, XtIntervalId *id);
void startTimers(Widget w, XtPointer clientData, XtPointer callData);


const int slowDelay = 5000;
const int fastDelay = 1000;

void main(int argc, char **argv)
{
  XtAppContext appContext;
  
  Widget topLevel = XtVaAppInitialize(&appContext,
				     "timertest",
				      NULL, 0, &argc, argv, NULL, NULL);
  
  Widget rowColumn = 
    XtVaCreateManagedWidget("rowColumn", xmRowColumnWidgetClass,
			    topLevel, NULL);
  
  Widget start = XtVaCreateManagedWidget("start",
					 xmPushButtonWidgetClass,
					 rowColumn, NULL);
  
  XtAddCallback(start, XmNactivateCallback, startTimers, 0);
  
					     
  XtRealizeWidget(topLevel);
  
  XtAppMainLoop(appContext);
}


void slowHandler(XtPointer clientData, XtIntervalId *id)
{
  const unsigned int secs = 3;
  const long loops = 1000000;
  
  fprintf(stderr, "slowHandler()\n");

  time_t startTime = time(NULL);
  time_t now = startTime;
  const time_t timeOut = 10;
  fprintf(stderr, "Start looping... ");  
  while (now - startTime < timeOut)
  {
    now = time(NULL);
  }

  fprintf(stderr, "done\n");
  XtAppAddTimeOut(XtWidgetToApplicationContext((Widget )clientData),
		  slowDelay, slowHandler, clientData);
}


void fastHandler(XtPointer clientData, XtIntervalId *id)
{
  fprintf(stderr, "fastHandler()\n");
  XtAppAddTimeOut(XtWidgetToApplicationContext((Widget )clientData),
		  fastDelay, fastHandler, clientData);
}


void startTimers(Widget w, XtPointer clientData, XtPointer callData)
{
  fprintf(stderr, "startTimers()\n");
  
  XtIntervalId slowTimer = 
    XtAppAddTimeOut(XtWidgetToApplicationContext(w), 
		    slowDelay, slowHandler, (XtPointer )w);
  
  XtIntervalId fastTimer = 
    XtAppAddTimeOut(XtWidgetToApplicationContext(w), 
		    fastDelay, fastHandler, (XtPointer )w);

}

