]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/evtloopsrc.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/evtloopsrc.h
3 // Purpose: declaration of wxEventLoopSource class
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_EVTLOOPSRC_H_
12 #define _WX_EVTLOOPSRC_H_
14 // Include the header to get wxUSE_EVENTLOOP_SOURCE definition from it.
15 #include "wx/evtloop.h"
17 // ----------------------------------------------------------------------------
18 // wxEventLoopSource: a source of events which may be added to wxEventLoop
19 // ----------------------------------------------------------------------------
21 // TODO: refactor wxSocket under Unix to reuse wxEventLoopSource instead of
22 // duplicating much of its logic
24 // TODO: freeze the API and document it
26 #if wxUSE_EVENTLOOP_SOURCE
28 #define wxTRACE_EVT_SOURCE "EventSource"
30 // handler used to process events on event loop sources
31 class wxEventLoopSourceHandler
34 // called when descriptor is available for non-blocking read
35 virtual void OnReadWaiting() = 0;
37 // called when descriptor is available for non-blocking write
38 virtual void OnWriteWaiting() = 0;
40 // called when there is exception on descriptor
41 virtual void OnExceptionWaiting() = 0;
43 // virtual dtor for the base class
44 virtual ~wxEventLoopSourceHandler() { }
47 // flags describing which kind of IO events we're interested in
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
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
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;
67 void SetHandler(wxEventLoopSourceHandler
* handler
) { m_handler
= handler
; }
68 wxEventLoopSourceHandler
* GetHandler() const { return m_handler
; }
70 void SetFlags(int flags
) { m_flags
= flags
; }
71 int GetFlags() const { return m_flags
; }
74 // ctor is only used by the derived classes
75 wxEventLoopSource(wxEventLoopSourceHandler
*handler
, int flags
)
81 wxEventLoopSourceHandler
* m_handler
;
84 wxDECLARE_NO_COPY_CLASS(wxEventLoopSource
);
87 inline wxEventLoopSource::~wxEventLoopSource() { }
90 #include "wx/unix/evtloopsrc.h"
93 #if defined(__WXGTK20__)
94 #include "wx/gtk/evtloopsrc.h"
97 #if defined(__DARWIN__)
98 #include "wx/osx/evtloopsrc.h"
101 #endif // wxUSE_EVENTLOOP_SOURCE
103 #endif // _WX_EVTLOOPSRC_H_