initial import
[bbkeys.git] / Timer.hh
blob2a6e90f13a15327e55fc8d0c5bafe0ae287630f8
1 // Timer.hh for Blackbox - An X11 Window Manager
2 // Copyright (c) 1997 - 1999 Brad Hughes (bhughes@tcac.net)
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
22 #ifndef __Timer_hh
23 #define __Timer_hh
25 #ifdef TIME_WITH_SYS_TIME
26 # include <sys/time.h>
27 # include <time.h>
28 #else // !TIME_WITH_SYS_TIME
29 # ifdef HAVE_SYS_TIME_H
30 # include <sys/time.h>
31 # else // !HAVE_SYS_TIME_H
32 # include <time.h>
33 # endif // HAVE_SYS_TIME_H
34 #endif // TIME_WITH_SYS_TIME
36 // forward declaration
37 class BTimer;
38 class TimeoutHandler;
40 #include "BaseDisplay.hh"
43 class TimeoutHandler {
44 public:
45 virtual void timeout(void) = 0;
49 class BTimer {
50 friend BaseDisplay;
51 private:
52 BaseDisplay *display;
53 TimeoutHandler *handler;
54 int timing, once;
56 timeval _start, _timeout;
59 protected:
60 void fireTimeout(void);
63 public:
64 BTimer(BaseDisplay *, TimeoutHandler *);
65 virtual ~BTimer(void);
67 inline int &isTiming(void) { return timing; }
68 inline int &doOnce(void) { return once; }
70 inline const timeval &getTimeout(void) const { return _timeout; }
71 inline const timeval &getStartTime(void) const { return _start; }
73 inline void fireOnce(int o) { once = o; }
75 void setTimeout(long);
76 void setTimeout(timeval);
77 void start(void);
78 void stop(void);
79 void reset(void);
83 #endif // __Timer_hh