evtloopsrc.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/evtloopsrc.h
  3. // Purpose: declaration of wxEventLoopSource class
  4. // Author: Vadim Zeitlin
  5. // Created: 2009-10-21
  6. // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
  7. // Licence: wxWindows licence
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_EVTLOOPSRC_H_
  10. #define _WX_EVTLOOPSRC_H_
  11. // Include the header to get wxUSE_EVENTLOOP_SOURCE definition from it.
  12. #include "wx/evtloop.h"
  13. // ----------------------------------------------------------------------------
  14. // wxEventLoopSource: a source of events which may be added to wxEventLoop
  15. // ----------------------------------------------------------------------------
  16. // TODO: refactor wxSocket under Unix to reuse wxEventLoopSource instead of
  17. // duplicating much of its logic
  18. //
  19. // TODO: freeze the API and document it
  20. #if wxUSE_EVENTLOOP_SOURCE
  21. #define wxTRACE_EVT_SOURCE "EventSource"
  22. // handler used to process events on event loop sources
  23. class wxEventLoopSourceHandler
  24. {
  25. public:
  26. // called when descriptor is available for non-blocking read
  27. virtual void OnReadWaiting() = 0;
  28. // called when descriptor is available for non-blocking write
  29. virtual void OnWriteWaiting() = 0;
  30. // called when there is exception on descriptor
  31. virtual void OnExceptionWaiting() = 0;
  32. // virtual dtor for the base class
  33. virtual ~wxEventLoopSourceHandler() { }
  34. };
  35. // flags describing which kind of IO events we're interested in
  36. enum
  37. {
  38. wxEVENT_SOURCE_INPUT = 0x01,
  39. wxEVENT_SOURCE_OUTPUT = 0x02,
  40. wxEVENT_SOURCE_EXCEPTION = 0x04,
  41. wxEVENT_SOURCE_ALL = wxEVENT_SOURCE_INPUT |
  42. wxEVENT_SOURCE_OUTPUT |
  43. wxEVENT_SOURCE_EXCEPTION
  44. };
  45. // wxEventLoopSource itself is an ABC and can't be created directly, currently
  46. // the only way to create it is by using wxEventLoop::AddSourceForFD().
  47. class wxEventLoopSource
  48. {
  49. public:
  50. // dtor is pure virtual because it must be overridden to remove the source
  51. // from the event loop monitoring it
  52. virtual ~wxEventLoopSource() = 0;
  53. void SetHandler(wxEventLoopSourceHandler* handler) { m_handler = handler; }
  54. wxEventLoopSourceHandler* GetHandler() const { return m_handler; }
  55. void SetFlags(int flags) { m_flags = flags; }
  56. int GetFlags() const { return m_flags; }
  57. protected:
  58. // ctor is only used by the derived classes
  59. wxEventLoopSource(wxEventLoopSourceHandler *handler, int flags)
  60. : m_handler(handler),
  61. m_flags(flags)
  62. {
  63. }
  64. wxEventLoopSourceHandler* m_handler;
  65. int m_flags;
  66. wxDECLARE_NO_COPY_CLASS(wxEventLoopSource);
  67. };
  68. inline wxEventLoopSource::~wxEventLoopSource() { }
  69. #if defined(__UNIX__)
  70. #include "wx/unix/evtloopsrc.h"
  71. #endif // __UNIX__
  72. #if defined(__WXGTK20__)
  73. #include "wx/gtk/evtloopsrc.h"
  74. #endif
  75. #if defined(__DARWIN__)
  76. #include "wx/osx/evtloopsrc.h"
  77. #endif
  78. #endif // wxUSE_EVENTLOOP_SOURCE
  79. #endif // _WX_EVTLOOPSRC_H_