]> git.saurik.com Git - wxWidgets.git/blame - include/wx/evtloopsrc.h
Don't define __STRICT_ANSI__, we should build both with and without it.
[wxWidgets.git] / include / wx / evtloopsrc.h
CommitLineData
5cd99866
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/evtloopsrc.h
3// Purpose: declaration of wxEventLoopSource class
4// Author: Vadim Zeitlin
5// Created: 2009-10-21
5cd99866
VZ
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
64b4a359
VZ
13// Include the header to get wxUSE_EVENTLOOP_SOURCE definition from it.
14#include "wx/evtloop.h"
15
5cd99866
VZ
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
30class wxEventLoopSourceHandler
31{
32public:
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
47enum
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 |
2f6b64a9 54 wxEVENT_SOURCE_EXCEPTION
5cd99866
VZ
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().
59class wxEventLoopSource
60{
61public:
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
72protected:
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
86inline 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"
da0ee16e
VZ
94#endif
95
96#if defined(__DARWIN__)
5cd99866 97 #include "wx/osx/evtloopsrc.h"
da0ee16e 98#endif
5cd99866
VZ
99
100#endif // wxUSE_EVENTLOOP_SOURCE
101
102#endif // _WX_EVTLOOPSRC_H_
103