blob: bb66e340c091b901c69f4c3707110e39d39c68db [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// -=- EventManager.h
20
21// Win32 event manager. Caller supplies event & handler pairs and
22// then uses getMessage() in place of ::GetMessage() in the main
23// loop. EventManager calls the event handler whenever the event
24// is set.
25// Ownership of events remains with the caller.
26// It is the responsibility of handlers to reset events.
27
28#ifndef __RFB_WIN32_EVENT_MGR_H__
29#define __RFB_WIN32_EVENT_MGR_H__
30
31#include <rfb_win32/Win32Util.h>
32
33namespace rfb {
34 namespace win32 {
35
36 class EventHandler {
37 public:
38 virtual ~EventHandler() {}
39 virtual void processEvent(HANDLE event) = 0;
40 };
41
42 class EventManager {
43 public:
44 EventManager();
45 virtual ~EventManager();
46
47 // Add a Win32 event & handler for it
48 // NB: The handler must call ResetEvent on the event.
49 // NB: The caller retains ownership of the event.
50 virtual bool addEvent(HANDLE event, EventHandler* ecb);
51
52 // Remove a Win32 event
53 virtual void removeEvent(HANDLE event);
54
55 // getMessage
56 // Waits for a message to become available on the thread's message queue,
57 // and returns it. If any registered events become set while waiting then
58 // their handlers are called before returning.
59 // Returns zero if the message is WM_QUIT, -1 in case of error, >0 otherwise.
60 virtual BOOL getMessage(MSG* msg, HWND hwnd, UINT minMsg, UINT maxMsg);
61
62 protected:
63 // checkTimeouts
64 // Derived classes should override this to perform any extra processing,
65 // returning the maximum number of milliseconds after which the callback
66 // should be called again.
67 virtual int checkTimeouts();
68
69 HANDLE events[MAXIMUM_WAIT_OBJECTS];
70 EventHandler* handlers[MAXIMUM_WAIT_OBJECTS-1];
71 int eventCount;
72 };
73
74 };
75};
76
77#endif