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