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