| 1 | /* $Id: os2timer.h,v 1.12 2003-03-05 14:48:45 sandervl 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 | /* 2001-09-16 PH | 
|---|
| 26 | with the new OS2KRNL's dating 2001-09-14 and later, there is | 
|---|
| 27 | a special CLOCKSCALE feature added which allows for much finer | 
|---|
| 28 | granularity of the OS/2 system timers up to a maximum resolution | 
|---|
| 29 | of 2ms. This is supposed to be enough for most timing issues here. | 
|---|
| 30 |  | 
|---|
| 31 | Note: | 
|---|
| 32 | we need to add support for dynamic detection of this feature. | 
|---|
| 33 | */ | 
|---|
| 34 | #define OS2TIMER_RESOLUTION_MINIMUM 1 | 
|---|
| 35 | #define OS2TIMER_RESOLUTION_MAXIMUM 0x7ffffffe | 
|---|
| 36 |  | 
|---|
| 37 |  | 
|---|
| 38 | /**************************************************************************** | 
|---|
| 39 | * Structures                                                               * | 
|---|
| 40 | ****************************************************************************/ | 
|---|
| 41 |  | 
|---|
| 42 | #if 0 | 
|---|
| 43 | typedef struct _MMTIMEREVENT | 
|---|
| 44 | { | 
|---|
| 45 | struct _MMTIMEREVENT* prev; | 
|---|
| 46 | struct _MMTIMEREVENT* next; | 
|---|
| 47 |  | 
|---|
| 48 | DWORD           id;                    // event id | 
|---|
| 49 | DWORD           timeScheduled;         // system time to fire event | 
|---|
| 50 | DWORD           timePeriod;            // period if periodic event | 
|---|
| 51 | TID             tidCaller;             // thread ID of caller thread | 
|---|
| 52 | DWORD           dwUser;                // user supplied value | 
|---|
| 53 | LPTIMERCALLBACK lpCallback;            // address to call | 
|---|
| 54 | DWORD           dwFlags;               // event flags | 
|---|
| 55 | } MMTIMEREVENT, *PMMTIMEREVENT, *LPTIMEREVENT; | 
|---|
| 56 | #endif | 
|---|
| 57 |  | 
|---|
| 58 | /* | 
|---|
| 59 | addEvent | 
|---|
| 60 | removeEvent | 
|---|
| 61 | rescheduleEvent | 
|---|
| 62 | callbackCaller | 
|---|
| 63 | */ | 
|---|
| 64 |  | 
|---|
| 65 |  | 
|---|
| 66 | /**************************************************************************** | 
|---|
| 67 | * Class: OS2TimerResolution                                                * | 
|---|
| 68 | ****************************************************************************/ | 
|---|
| 69 |  | 
|---|
| 70 | class OS2TimerResolution | 
|---|
| 71 | { | 
|---|
| 72 | public: | 
|---|
| 73 | // public entries | 
|---|
| 74 | static BOOL enterResolutionScope(int dwPeriod); // request timer resolution | 
|---|
| 75 | static BOOL leaveResolutionScope(int dwPeriod); // release resolution request | 
|---|
| 76 | static int  queryCurrentResolution();           // query maximum resolution | 
|---|
| 77 |  | 
|---|
| 78 | // public variables | 
|---|
| 79 | int dwPeriod; | 
|---|
| 80 |  | 
|---|
| 81 | protected: | 
|---|
| 82 | // constructors and destructors | 
|---|
| 83 | OS2TimerResolution(void); | 
|---|
| 84 | OS2TimerResolution(int dwPeriod); | 
|---|
| 85 | ~OS2TimerResolution(); | 
|---|
| 86 |  | 
|---|
| 87 | // simple linked list | 
|---|
| 88 | static OS2TimerResolution* sTimerResolutions; // list of resolution scoped | 
|---|
| 89 | OS2TimerResolution* next;              // link to next entry | 
|---|
| 90 | }; | 
|---|
| 91 |  | 
|---|
| 92 |  | 
|---|
| 93 | /**************************************************************************** | 
|---|
| 94 | * Class: OS2Timer                                                          * | 
|---|
| 95 | ****************************************************************************/ | 
|---|
| 96 |  | 
|---|
| 97 | class OS2Timer | 
|---|
| 98 | { | 
|---|
| 99 | public: | 
|---|
| 100 | OS2Timer(); | 
|---|
| 101 | ~OS2Timer(); | 
|---|
| 102 |  | 
|---|
| 103 | void          TimerHandler(); | 
|---|
| 104 | BOOL          StartTimer(int period, int resolution, LPTIMECALLBACK lptc, | 
|---|
| 105 | int dwUser, int fuEvent); | 
|---|
| 106 | void          StopTimer(); | 
|---|
| 107 | void          KillTimer(); | 
|---|
| 108 |  | 
|---|
| 109 |  | 
|---|
| 110 | DWORD         getTimerID()         { return timerID; }; | 
|---|
| 111 | void          setTimerID(DWORD id) { timerID = id; }; | 
|---|
| 112 |  | 
|---|
| 113 | protected: | 
|---|
| 114 |  | 
|---|
| 115 | private: | 
|---|
| 116 | HEV            TimerSem; | 
|---|
| 117 | HTIMER         TimerHandle; | 
|---|
| 118 | HANDLE         hTimerThread; | 
|---|
| 119 | DWORD          TimerThreadID; | 
|---|
| 120 | LPTIMECALLBACK clientCallback; | 
|---|
| 121 | DWORD          userData; | 
|---|
| 122 | DWORD          dwFlags; // corresponds with fuEvent | 
|---|
| 123 |  | 
|---|
| 124 | BOOL           fFatal; | 
|---|
| 125 | int            TimerStatus; | 
|---|
| 126 | DWORD          timerID; | 
|---|
| 127 | enum { | 
|---|
| 128 | InActive = 0, | 
|---|
| 129 | Running, | 
|---|
| 130 | Stopped | 
|---|
| 131 | }; | 
|---|
| 132 | static  int    timerPeriod; | 
|---|
| 133 |  | 
|---|
| 134 | // Linked list management | 
|---|
| 135 | OS2Timer*        next;                   // Next Timer | 
|---|
| 136 | static    OS2Timer*        timers;                 // List of Timer | 
|---|
| 137 |  | 
|---|
| 138 | }; | 
|---|
| 139 |  | 
|---|
| 140 | #endif | 
|---|