1 /*
2  * wmslib/src/but/timer.h, part of wmslib (Library functions)
3  * Copyright (C) 1995 William Shubert.
4  * See "configure.h.in" for more copyright information.
5  *
6  * Includes for timer.c
7  */
8 
9 #ifndef  _BUT_TIMER_H_
10 #define  _BUT_TIMER_H_  1
11 
12 /**********************************************************************
13  * Constants
14  **********************************************************************/
15 #define  BUTTIMER_HIST  4
16 #define  BUTTIMER_MAXFREQ  400  /* Hz...the most we'll ever allow. */
17 #define  BUTTIMER_STDFREQ  100  /* Hz...the "standard" value. */
18 
19 /**********************************************************************
20  * Data types
21  **********************************************************************/
22 typedef enum  {
23   butTimer_on, butTimer_off, butTimer_dead
24 } ButTimerState;
25 
26 /* Private. */
27 struct  ButTimer_struct  {
28   void  *packet;
29   int  eventNum;
30   struct timeval  nextFiring, period;
31   bool  winOnly;  /* False=shut off when iconified. */
32   ButTimerState  state;
33   struct ButWin_struct  *win;
34   But  *but;
35   ButOut  (*timerFunc)(struct ButTimer_struct *timer);
36   struct ButTimer_struct  *next;
37   int  ticksPerPeriod;
38   bool  freqCounter;
39   int  lastRes[BUTTIMER_HIST];
40   int  resnum, ticksLeft;
41   MAGIC_STRUCT
42 };
43 
44 /**********************************************************************
45  * Functions
46  **********************************************************************/
47 /* Public. */
48 extern ButTimer  *butTimer_create(void *packet, But *but,
49 				  struct timeval delay,
50 				  struct timeval period,
51 				  bool  win_only,
52 				  ButOut (*timerfunc)(struct ButTimer_struct
53 						      *timer));
54 extern ButTimer  *butTimer_fCreate(void *packet, But *but,
55 				   struct timeval delay, int frequency,
56 				   bool win_only,
57 				   ButOut (*timerfunc)(struct ButTimer_struct
58 						       *timer));
59 extern void  butTimer_destroy(ButTimer *timer);
60 extern void  butTimer_reset(ButTimer *timer);
61 #define  butTimer_ticks(bt)        ((bt)->eventNum)
62 #define  butTimer_setTicks(bt, v)  ((bt)->eventNum = (v))
63 #define  butTimer_packet(bt)  ((bt)->packet)
64 
65 /* Private. */
66 extern struct timeval  but_timerAdd(struct timeval t1, struct timeval t2);
67 extern struct timeval  but_timerSub(struct timeval t1, struct timeval t2);
68 extern int  but_timerDiv(struct timeval t1, struct timeval t2,
69 			 struct timeval *remainder);
70 extern int  butEnv_checkTimers(ButEnv *env, struct timeval *timeout);
71 
72 #endif  /* _BUT_TIMER_H_ */
73