Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

EventManager.h 2.6KB

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