ReactOS  0.4.15-dev-3303-g1ade494
fxtimer.hpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxTimer.hpp
8 
9 Abstract:
10 
11  This module implements a frameworks managed TIMER that
12  can synchrononize with driver frameworks object locks.
13 
14 Author:
15 
16 
17 
18 
19 Environment:
20 
21  Both kernel and user mode
22 
23 Revision History:
24 
25 
26 --*/
27 
28 #ifndef _FXTIMER_H_
29 #define _FXTIMER_H_
30 
31 //
32 // Driver Frameworks TIMER Design:
33 //
34 // The driver frameworks provides an optional TIMER wrapper object that allows
35 // a reference counted TIMER object to be created that can synchronize
36 // automatically with certain frameworks objects.
37 //
38 // This provides automatic synchronization between the TIMER's execution, and the
39 // frameworks objects event callbacks into the device driver.
40 //
41 
42 class FxTimer : public FxNonPagedObject {
43 
44 private:
45 
46  //
47  // Kernel Timer Object
48  //
50 
51  //
52  // This is the Framework object who is associated with the TIMER
53  // if supplied
54  //
56 
57  //
58  // This is the supplied Period to WdfTimerCreate
59  //
61 
62  //
63  // Optional tolerance for the timer in milliseconds
64  //
66 
67  //
68  // This indicates whether a high resolution attribute is set
69  // for the timer
70  //
72 
73  //
74  // This is the callback lock for the object this TIMER will
75  // synchronize with
76  //
78 
79  //
80  // This is the object whose reference count actually controls
81  // the lifetime of the m_CallbackLock
82  //
84 
85  //
86  // This is the user supplied callback function
87  //
89 
90  //
91  // This workitem object will be used to queue workitem from the timer
92  // dpc callback if the caller requests passive callback.
93  //
95 
96  //
97  // This is a pointer to thread object that invoked our dpc callback
98  // callback. This value will be used to avoid deadlock when we try
99  // to stop or delete the timer.
100  //
102 
103  //
104  // This is a pointer to the Stop thread object when driver invokes the
105  // timer's WdfTimerStop function.
106  //
108 
109  //
110  // TRUE if the timer was restarted while stopping.
111  //
113 
114  //
115  // TRUE if a start operation was aborted b/c stop was in progress.
116  //
118 
119  //
120  // Ensures only one of either Delete or Cleanup runsdown the object
121  //
123 
124 public:
125  static
127  NTSTATUS
128  _Create(
129  __in PFX_DRIVER_GLOBALS FxDriverGlobals,
132  __in FxObject* ParentObject,
133  __out WDFTIMER* Timer
134  );
135 
136  FxTimer(
137  __in PFX_DRIVER_GLOBALS FxDriverGlobals
138  );
139 
140  virtual
141  ~FxTimer(
142  VOID
143  );
144 
146  NTSTATUS
147  Initialize(
150  __in FxObject* ParentObject,
151  __out WDFTIMER* Timer
152  );
153 
154  virtual
155  BOOLEAN
156  Dispose(
157  VOID
158  );
159 
160  BOOLEAN
161  Start(
163  );
164 
165  BOOLEAN
166  Stop(
168  );
169 
170  VOID
171  TimerHandler(
172  VOID
173  );
174 
175  WDFOBJECT
177  VOID
178  )
179  {
180  if( m_Object != NULL ) {
181  return m_Object->GetObjectHandle();
182  }
183  else {
184  return NULL;
185  }
186  }
187 
188  WDFTIMER
190  VOID
191  )
192  {
193  return (WDFTIMER) GetObjectHandle();
194  }
195 
196 private:
197 
198  //
199  // Called from Dispose, or cleanup list to perform final flushing of any
200  // outstanding DPC's and dereferencing of objects.
201  //
202  VOID
204  VOID
205  );
206 
207  static
210 
211  static
214 
215  static
218 };
219 
220 #endif // _FXTIMER_H
221 
MxTimer m_Timer
Definition: fxtimer.hpp:49
ULONG m_Period
Definition: fxtimer.hpp:60
static _Must_inspect_result_ NTSTATUS _Create(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_TIMER_CONFIG Config, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in FxObject *ParentObject, __out WDFTIMER *Timer)
Definition: fxtimer.cpp:87
FxSystemWorkItem * m_SystemWorkItem
Definition: fxtimer.hpp:94
FxCallbackLock * m_CallbackLock
Definition: fxtimer.hpp:77
_In_ WDFDPC _In_ BOOLEAN Wait
Definition: wdfdpc.h:167
PFN_WDF_TIMER m_Callback
Definition: fxtimer.hpp:88
BOOLEAN m_UseHighResolutionTimer
Definition: fxtimer.hpp:71
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN Stop(__in BOOLEAN Wait)
Definition: fxtimer.cpp:633
FxTimer(__in PFX_DRIVER_GLOBALS FxDriverGlobals)
Definition: fxtimer.cpp:40
_Must_inspect_result_ NTSTATUS Initialize(__in PWDF_OBJECT_ATTRIBUTES Attributes, __in PWDF_TIMER_CONFIG Config, __in FxObject *ParentObject, __out WDFTIMER *Timer)
Definition: fxtimer.cpp:120
virtual BOOLEAN Dispose(VOID)
Definition: fxtimer.cpp:458
EXT_CALLBACK MdExtCallbackType
Definition: mxkm.h:36
static FN_WDF_SYSTEMWORKITEM _FxTimerWorkItemCallback
Definition: fxtimer.hpp:209
EVT_WDF_TIMER * PFN_WDF_TIMER
Definition: wdftimer.h:67
virtual ~FxTimer(VOID)
Definition: fxtimer.cpp:67
BOOLEAN Start(__in LARGE_INTEGER DueTime)
Definition: fxtimer.cpp:537
PVOID __inline GetObjectHandle(VOID)
Definition: fxobject.hpp:603
#define __out
Definition: dbghelp.h:62
unsigned char BOOLEAN
EVT_SYSTEMWORKITEM FN_WDF_SYSTEMWORKITEM
#define POINTER_ALIGNMENT
MxThread m_StopThread
Definition: fxtimer.hpp:107
WDFTIMER GetHandle(VOID)
Definition: fxtimer.hpp:189
VOID TimerHandler(VOID)
Definition: fxtimer.cpp:300
VOID FlushAndRundown(VOID)
Definition: fxtimer.cpp:481
WDFOBJECT GetObject(VOID)
Definition: fxtimer.hpp:176
BOOLEAN m_StartAborted
Definition: fxtimer.hpp:117
#define _Must_inspect_result_
Definition: ms_sal.h:558
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_CHILD_LIST_CONFIG Config
Definition: wdfchildlist.h:474
KDEFERRED_ROUTINE MdDeferredRoutineType
Definition: mxkm.h:35
static MdExtCallbackType _FxTimerExtCallbackThunk
Definition: fxtimer.hpp:217
BOOLEAN m_RunningDown
Definition: fxtimer.hpp:122
#define NULL
Definition: types.h:112
_In_ WDFTIMER _In_ LONGLONG DueTime
Definition: wdftimer.h:187
volatile POINTER_ALIGNMENT MxThread m_CallbackThread
Definition: fxtimer.hpp:101
unsigned int ULONG
Definition: retypes.h:1
BOOLEAN m_StopAgain
Definition: fxtimer.hpp:112
static MdDeferredRoutineType _FxTimerDpcThunk
Definition: fxtimer.hpp:213
#define __in
Definition: dbghelp.h:35
FxObject * m_CallbackLockObject
Definition: fxtimer.hpp:83
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
ULONG m_TolerableDelay
Definition: fxtimer.hpp:65
FxObject * m_Object
Definition: fxtimer.hpp:55