[comp.windows.x.motif] Timer Interrupt

yu@unisql.UUCP (Yeong-Ho Yu) (01/24/91)

 I am trying to make a main event handler which will run for at least
the given time, and returns the control back to the program.
That is, it should be a temparary XtAppMainLoop.

 I made up the following function:

void TempEventH(XtAppContext app, unsigned int time)
{
  XEvent event;

  XtAppAddTimeOut(app, time, NULL, NULL);  /* put up a timer event */
  while(!(XtAppPending(app) & XtIMTimer)){ /* until it arrives */
    XtAppNextEvent(app, &event);           /* do the event  processing */
    XtDispatchEvent(&event);
  }
}  

 Of course, it does not work.  But, I don't know why.
Any suggestions?  Many thanks in advance.



-- 
Yeong-Ho Yu

  Internet: execu!sequoia!unisql!yu@cs.utexas.edu
      UUCP: {uunet, cs.utexas.edu!execu}!sequoia!unisql!yu

lynnes@ALEX.CSS.GOV (Christopher Lynnes) (01/24/91)

> I am trying to make a main event handler which will run for at least
>the given time, and returns the control back to the program.
>That is, it should be a temparary XtAppMainLoop.
>
> I made up the following function:
>
>void TempEventH(XtAppContext app, unsigned int time)
>{
>  XEvent event;
>
>  XtAppAddTimeOut(app, time, NULL, NULL);  /* put up a timer event */
>  while(!(XtAppPending(app) & XtIMTimer)){ /* until it arrives */
>    XtAppNextEvent(app, &event);           /* do the event  processing */
>    XtDispatchEvent(&event);
>  }
>}  
>
> Of course, it does not work.  But, I don't know why.
>Any suggestions?  Many thanks in advance.

	My guess is that XtAppPending() returns the input mask for all
of the events in the queue which INCLUDES the timer that you add before
the loop. The result is that the routine returns immediately. (Is this
so?)
	Instead, try using XtAppPeekEvent, which returns True if the
next event in the queue is a window event, and False if it's a timer
or input event. What's more, if it is a timer, it will dispatch the
event automatically, so you should be able to use

>void TempEventH(XtAppContext app, unsigned int time)
>{
>  XEvent event;
>
>  XtAppAddTimeOut(app, time, NULL, NULL);  /* put up a timer event */

   while (XtAppPeekEvent(app, &event)) /* Peeking leaves event on queue */
   {
       XtAppNextEvent(app, &event); /* This gets the event from the queue */
       XtDispatchEvent(&event);
   }
}

I tried this (without application contexts) and it seems to work.


Chris Lynnes                                ===== : = :::::
Teledyne Geotech                           ===== :: == :::::
Alexandria, Virginia                            ::: ===
(703) 739-7316                                  ::   ==
lynnes@seismo.CSS.GOV                           :     =

tjhorton@vis.toronto.edu ("Timothy J. Horton") (01/27/91)

>>I am trying to make a main event handler which will run for at least
>>the given time, and returns the control back to the program.
>>That is, it should be a temparary XtAppMainLoop.
>>I made up the following function:
>>
>>void TempEventH(XtAppContext app, unsigned int time)
>>{
>>  XEvent event;
>>  XtAppAddTimeOut(app, time, NULL, NULL);  /* put up a timer event */
>>  while(!(XtAppPending(app) & XtIMTimer)){ /* until it arrives */
>>    XtAppNextEvent(app, &event);           /* do the event  processing */
>>    XtDispatchEvent(&event);
>>  }
>>}  

I might speak from ignorance, but I have the distinct impression (for
many convoluted reasons) that timeouts are not handled how you may think.

First, they are not an X event type (there is no "timeout" event down
in real X, to my knowledget).  I think rather that they must be dealt with
by the mainloop, involving timeouts on selects and dispatching and so forth.
My guess is that it is implimentation dependant, too.

(It can't be unix alarm timeouts, either.  For instance, System V unix
doesn't handle timer subdivisions less than 1 second, whereas BSD unix does,
so how would you get the subsecond accuracy in an X application on system V
unless you user a special device driver or something -- which would be nearly
ridiculous and I almost know they don't do it).

I'd be interested in getting the real dope on how XtAppAddTimeOut type
timeouts are (usually) implimentated.  Please, anyone know?