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 <memory>
21 :
22 : #include "base/macros.h"
23 : #include "base/win/scoped_handle.h"
24 : #include "syzygy/kasko/waitable_timer.h"
25 :
26 m : namespace base {
27 m : class TimeDelta;
28 m : } // namespace base
29 :
30 m : namespace kasko {
31 :
32 : // Implements WaitableTimer using a fixed timer interval.
33 m : class WaitableTimerImpl : public WaitableTimer {
34 m : public:
35 : // Creates an instance with a fixed timer interval. Each time the timer is
36 : // started, it will become signaled after the given interval elapses.
37 : // @param interval The fixed timer interval.
38 : // @returns a WaitableTimer instance, or NULL in case of an error.
39 m : static std::unique_ptr<WaitableTimer> Create(const base::TimeDelta& interval);
40 :
41 m : ~WaitableTimerImpl() override;
42 :
43 : // WaitableTimer implementation.
44 m : void Start() override;
45 m : HANDLE GetHANDLE() override;
46 :
47 m : private:
48 : // Instantiates an instance using the pre-created waitable timer handle and a
49 : // fixed interval.
50 : // @param handle A waitable timer HANDLE.
51 : // @param interval The fixed timer interval.
52 m : explicit WaitableTimerImpl(base::win::ScopedHandle handle,
53 m : const base::TimeDelta& interval);
54 :
55 : // A waitable timer HANDLE.
56 m : base::win::ScopedHandle handle_;
57 : // The fixed timer interval, in a format suitable for SetWaitableTimer.
58 m : LARGE_INTEGER interval_;
59 :
60 m : DISALLOW_COPY_AND_ASSIGN(WaitableTimerImpl);
61 m : };
62 :
63 m : } // namespace kasko
64 :
65 : #endif // SYZYGY_KASKO_WAITABLE_TIMER_IMPL_H_
|