]> git.saurik.com Git - wxWidgets.git/blob - include/wx/evtloopsrc.h
Comment-only update
[wxWidgets.git] / include / wx / evtloopsrc.h
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
10 #ifndef _WX_EVTLOOPSRC_H_
11 #define _WX_EVTLOOPSRC_H_
12
13 // Include the header to get wxUSE_EVENTLOOP_SOURCE definition from it.
14 #include "wx/evtloop.h"
15
16 // ----------------------------------------------------------------------------
17 // wxEventLoopSource: a source of events which may be added to wxEventLoop
18 // ----------------------------------------------------------------------------
19
20 // TODO: refactor wxSocket under Unix to reuse wxEventLoopSource instead of
21 // duplicating much of its logic
22 //
23 // TODO: freeze the API and document it
24
25 #if wxUSE_EVENTLOOP_SOURCE
26
27 #define wxTRACE_EVT_SOURCE "EventSource"
28
29 // handler used to process events on event loop sources
30 class wxEventLoopSourceHandler
31 {
32 public:
33 // called when descriptor is available for non-blocking read
34 virtual void OnReadWaiting() = 0;
35
36 // called when descriptor is available for non-blocking write
37 virtual void OnWriteWaiting() = 0;
38
39 // called when there is exception on descriptor
40 virtual void OnExceptionWaiting() = 0;
41
42 // virtual dtor for the base class
43 virtual ~wxEventLoopSourceHandler() { }
44 };
45
46 // flags describing which kind of IO events we're interested in
47 enum
48 {
49 wxEVENT_SOURCE_INPUT = 0x01,
50 wxEVENT_SOURCE_OUTPUT = 0x02,
51 wxEVENT_SOURCE_EXCEPTION = 0x04,
52 wxEVENT_SOURCE_ALL = wxEVENT_SOURCE_INPUT |
53 wxEVENT_SOURCE_OUTPUT |
54 wxEVENT_SOURCE_EXCEPTION
55 };
56
57 // wxEventLoopSource itself is an ABC and can't be created directly, currently
58 // the only way to create it is by using wxEventLoop::AddSourceForFD().
59 class wxEventLoopSource
60 {
61 public:
62 // dtor is pure virtual because it must be overridden to remove the source
63 // from the event loop monitoring it
64 virtual ~wxEventLoopSource() = 0;
65
66 void SetHandler(wxEventLoopSourceHandler* handler) { m_handler = handler; }
67 wxEventLoopSourceHandler* GetHandler() const { return m_handler; }
68
69 void SetFlags(int flags) { m_flags = flags; }
70 int GetFlags() const { return m_flags; }
71
72 protected:
73 // ctor is only used by the derived classes
74 wxEventLoopSource(wxEventLoopSourceHandler *handler, int flags)
75 : m_handler(handler),
76 m_flags(flags)
77 {
78 }
79
80 wxEventLoopSourceHandler* m_handler;
81 int m_flags;
82
83 wxDECLARE_NO_COPY_CLASS(wxEventLoopSource);
84 };
85
86 inline wxEventLoopSource::~wxEventLoopSource() { }
87
88 #if defined(__UNIX__)
89 #include "wx/unix/evtloopsrc.h"
90 #endif // __UNIX__
91
92 #if defined(__WXGTK20__)
93 #include "wx/gtk/evtloopsrc.h"
94 #endif
95
96 #if defined(__DARWIN__)
97 #include "wx/osx/evtloopsrc.h"
98 #endif
99
100 #endif // wxUSE_EVENTLOOP_SOURCE
101
102 #endif // _WX_EVTLOOPSRC_H_
103