blob: ddfae4934a95e2a3024277c1850007345ba469b9 [file] [log] [blame]
Constantin Kaplinsky729598c2006-05-25 05:12:25 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19// -=- IntervalTimer.h
20//
21// Simple wrapper for standard Win32 timers
22
23#ifndef __RFB_WIN32_INTERVAL_TIMER_H__
24#define __RFB_WIN32_INTERVAL_TIMER_H__
25
26namespace rfb {
27
28 namespace win32 {
29
30 struct IntervalTimer {
31 IntervalTimer(HWND hwnd_, int id_)
32 : active(false), hwnd(hwnd_), id(id_) {
33 }
34 IntervalTimer() : active(false), hwnd(0), id(0) {
35 }
36 ~IntervalTimer() {
37 stop();
38 }
39
40 void start(int interval_) {
41 if (!active || interval_ != interval) {
42 interval = interval_;
43 if (!SetTimer(hwnd, id, interval, 0))
44 throw rdr::SystemException("SetTimer", GetLastError());
45 active = true;
46 }
47 }
48 void stop() {
49 if (active)
50 KillTimer(hwnd, id);
51 active = false;
52 }
53
54 void setHWND(HWND hwnd_) {hwnd=hwnd_;}
55 void setId(int id_) {id = id_;}
56 int getId() const {return id;}
57 bool isActive() const {return active;}
58
59 private:
60 HWND hwnd;
61 int id;
62 bool active;
63 int interval;
64 };
65
66 }; // win32
67
68}; // rfb
69
70#endif // __RFB_WIN32_INTERVAL_TIMER_H__