1 : // Copyright 2014 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 :
15 : #ifndef SYZYGY_KASKO_WAITABLE_TIMER_IMPL_H_
16 : #define SYZYGY_KASKO_WAITABLE_TIMER_IMPL_H_
17 :
18 : #include <windows.h>
19 :
20 : #include "base/macros.h"
21 : #include "base/memory/scoped_ptr.h"
22 : #include "base/win/scoped_handle.h"
23 : #include "syzygy/kasko/waitable_timer.h"
24 :
25 m : namespace base {
26 m : class TimeDelta;
27 m : } // namespace base
28 :
29 m : namespace kasko {
30 :
31 : // Implements WaitableTimer using a fixed timer interval.
32 m : class WaitableTimerImpl : public WaitableTimer {
33 m : public:
34 : // Creates an instance with a fixed timer interval. Each time the timer is
35 : // started, it will become signaled after the given interval elapses.
36 : // @param interval The fixed timer interval.
37 : // @returns a WaitableTimer instance, or NULL in case of an error.
38 m : static scoped_ptr<WaitableTimer> Create(const base::TimeDelta& interval);
39 :
40 m : ~WaitableTimerImpl() override;
41 :
42 : // WaitableTimer implementation.
43 m : void Start() override;
44 m : HANDLE GetHANDLE() override;
45 :
46 m : private:
47 : // Instantiates an instance using the pre-created waitable timer handle and a
48 : // fixed interval.
49 : // @param handle A waitable timer HANDLE.
50 : // @param interval The fixed timer interval.
51 m : explicit WaitableTimerImpl(base::win::ScopedHandle handle,
52 m : const base::TimeDelta& interval);
53 :
54 : // A waitable timer HANDLE.
55 m : base::win::ScopedHandle handle_;
56 : // The fixed timer interval, in a format suitable for SetWaitableTimer.
57 m : LARGE_INTEGER interval_;
58 :
59 m : DISALLOW_COPY_AND_ASSIGN(WaitableTimerImpl);
60 m : };
61 :
62 m : } // namespace kasko
63 :
64 : #endif // SYZYGY_KASKO_WAITABLE_TIMER_IMPL_H_
|