1 | /* $Id: os2timer.h,v 1.8 1999-12-29 08:36:10 phaller Exp $ */
|
---|
2 |
|
---|
3 | #ifndef __OS2TIMER_H__
|
---|
4 | #define __OS2TIMER_H__
|
---|
5 | /*
|
---|
6 | * OS/2 Timer class
|
---|
7 | *
|
---|
8 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
9 | * Copyright 1999 Patrick Haller (phaller@gmx.net)
|
---|
10 | *
|
---|
11 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
12 | *
|
---|
13 | */
|
---|
14 |
|
---|
15 | #ifdef _OS2WIN_H
|
---|
16 | #define HEV int
|
---|
17 | #define HTIMER int
|
---|
18 | #endif
|
---|
19 |
|
---|
20 |
|
---|
21 | /****************************************************************************
|
---|
22 | * Definitions *
|
---|
23 | ****************************************************************************/
|
---|
24 |
|
---|
25 | #define OS2TIMER_RESOLUTION_MINIMUM 32
|
---|
26 | #define OS2TIMER_RESOLUTION_MAXIMUM 0x7ffffffe
|
---|
27 |
|
---|
28 |
|
---|
29 | /****************************************************************************
|
---|
30 | * Structures *
|
---|
31 | ****************************************************************************/
|
---|
32 |
|
---|
33 | #if 0
|
---|
34 | typedef struct _MMTIMEREVENT
|
---|
35 | {
|
---|
36 | struct _MMTIMEREVENT* prev;
|
---|
37 | struct _MMTIMEREVENT* next;
|
---|
38 |
|
---|
39 | DWORD id; // event id
|
---|
40 | DWORD timeScheduled; // system time to fire event
|
---|
41 | DWORD timePeriod; // period if periodic event
|
---|
42 | TID tidCaller; // thread ID of caller thread
|
---|
43 | DWORD dwUser; // user supplied value
|
---|
44 | LPTIMERCALLBACK lpCallback; // address to call
|
---|
45 | DWORD dwFlags; // event flags
|
---|
46 | } MMTIMEREVENT, *PMMTIMEREVENT, *LPTIMEREVENT;
|
---|
47 | #endif
|
---|
48 |
|
---|
49 | /*
|
---|
50 | addEvent
|
---|
51 | removeEvent
|
---|
52 | rescheduleEvent
|
---|
53 | callbackCaller
|
---|
54 | */
|
---|
55 |
|
---|
56 |
|
---|
57 | /****************************************************************************
|
---|
58 | * Class: OS2TimerResolution *
|
---|
59 | ****************************************************************************/
|
---|
60 |
|
---|
61 | class OS2TimerResolution
|
---|
62 | {
|
---|
63 | public:
|
---|
64 | // public entries
|
---|
65 | static BOOL enterResolutionScope(int dwPeriod); // request timer resolution
|
---|
66 | static BOOL leaveResolutionScope(int dwPeriod); // release resolution request
|
---|
67 | static int queryCurrentResolution(); // query maximum resolution
|
---|
68 |
|
---|
69 | // public variables
|
---|
70 | int dwPeriod;
|
---|
71 |
|
---|
72 | protected:
|
---|
73 | // constructors and destructors
|
---|
74 | OS2TimerResolution(void);
|
---|
75 | OS2TimerResolution(int dwPeriod);
|
---|
76 | ~OS2TimerResolution();
|
---|
77 |
|
---|
78 | // simple linked list
|
---|
79 | static OS2TimerResolution* sTimerResolutions; // list of resolution scoped
|
---|
80 | OS2TimerResolution* next; // link to next entry
|
---|
81 | };
|
---|
82 |
|
---|
83 |
|
---|
84 | /****************************************************************************
|
---|
85 | * Class: OS2Timer *
|
---|
86 | ****************************************************************************/
|
---|
87 |
|
---|
88 | class OS2Timer
|
---|
89 | {
|
---|
90 | public:
|
---|
91 | OS2Timer();
|
---|
92 | ~OS2Timer();
|
---|
93 |
|
---|
94 | void TimerHandler();
|
---|
95 | BOOL StartTimer(int period, int resolution, LPTIMECALLBACK lptc,
|
---|
96 | int dwUser, int fuEvent);
|
---|
97 | void StopTimer();
|
---|
98 | void KillTimer();
|
---|
99 |
|
---|
100 | protected:
|
---|
101 |
|
---|
102 | private:
|
---|
103 | HEV TimerSem;
|
---|
104 | HTIMER TimerHandle;
|
---|
105 | HANDLE hTimerThread;
|
---|
106 | DWORD TimerThreadID;
|
---|
107 | LPTIMECALLBACK clientCallback;
|
---|
108 | DWORD userData;
|
---|
109 |
|
---|
110 | BOOL fFatal;
|
---|
111 | int TimerStatus;
|
---|
112 | enum {
|
---|
113 | InActive = 0,
|
---|
114 | Running,
|
---|
115 | Stopped
|
---|
116 | };
|
---|
117 | static int timerPeriod;
|
---|
118 |
|
---|
119 | // Linked list management
|
---|
120 | OS2Timer* next; // Next Timer
|
---|
121 | static OS2Timer* timers; // List of Timer
|
---|
122 |
|
---|
123 | };
|
---|
124 |
|
---|
125 | #endif
|
---|