]> git.saurik.com Git - wxWidgets.git/blame - src/common/fdiodispatcher.cpp
compilation fix for PCH-less compilation after the last change
[wxWidgets.git] / src / common / fdiodispatcher.cpp
CommitLineData
b46b1d59
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: src/common/fdiodispatcher.cpp
3// Purpose: Implementation of common wxFDIODispatcher methods
4// Author: Vadim Zeitlin
5// Created: 2007-05-13
6// RCS-ID: $Id$
7// Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
8// Licence: wxWindows licence
9///////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
19// for compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
26#ifndef WX_PRECOMP
5e1eac14 27 #include "wx/module.h"
b46b1d59
VZ
28#endif //WX_PRECOMP
29
30#include "wx/private/fdiodispatcher.h"
31
5e1eac14
VZ
32#include "wx/private/selectdispatcher.h"
33#ifdef __UNIX__
34 #include "wx/unix/private/epolldispatcher.h"
35#endif
36
37wxFDIODispatcher *gs_dispatcher = NULL;
38
b46b1d59
VZ
39// ============================================================================
40// implementation
41// ============================================================================
42
5e1eac14
VZ
43// ----------------------------------------------------------------------------
44// wxFDIODispatcher
45// ----------------------------------------------------------------------------
46
47/* static */
48wxFDIODispatcher *wxFDIODispatcher::Get()
49{
50 if ( !gs_dispatcher )
51 {
0a6c4c2e 52#if wxUSE_EPOLL_DISPATCHER
5e1eac14
VZ
53 gs_dispatcher = wxEpollDispatcher::Create();
54 if ( !gs_dispatcher )
55#endif // wxUSE_EPOLL_DISPATCHER
56#if wxUSE_SELECT_DISPATCHER
fdf7ff73 57 gs_dispatcher = new wxSelectDispatcher();
2804f77d 58#endif // wxUSE_SELECT_DISPATCHER
5e1eac14
VZ
59 }
60
61 wxASSERT_MSG( gs_dispatcher, _T("failed to create any IO dispatchers") );
62
63 return gs_dispatcher;
64}
65
66/* static */
67void wxFDIODispatcher::DispatchPending()
68{
69 if ( gs_dispatcher )
70 gs_dispatcher->Dispatch(0);
71}
72
73// ----------------------------------------------------------------------------
74// wxMappedFDIODispatcher
75// ----------------------------------------------------------------------------
76
ad8d42f8 77wxFDIOHandler *wxMappedFDIODispatcher::FindHandler(int fd) const
b46b1d59
VZ
78{
79 const wxFDIOHandlerMap::const_iterator it = m_handlers.find(fd);
80
81 return it == m_handlers.end() ? NULL : it->second.handler;
82}
83
84
ad8d42f8 85bool wxMappedFDIODispatcher::RegisterFD(int fd, wxFDIOHandler *handler, int flags)
b46b1d59
VZ
86{
87 wxUnusedVar(flags);
88
89 wxCHECK_MSG( handler, false, _T("handler can't be NULL") );
90
91 // notice that it's not an error to register a handler for the same fd
92 // twice as it can be done with different flags -- but it is an error to
93 // register different handlers
94 wxFDIOHandlerMap::iterator i = m_handlers.find(fd);
95 if ( i != m_handlers.end() )
96 {
97 wxASSERT_MSG( i->second.handler == handler,
98 _T("registering different handler for the same fd?") );
99 wxASSERT_MSG( i->second.flags != flags,
100 _T("reregistering with the same flags?") );
101 }
102
103 m_handlers[fd] = wxFDIOHandlerEntry(handler, flags);
104
105 return true;
106}
107
ad8d42f8 108bool wxMappedFDIODispatcher::ModifyFD(int fd, wxFDIOHandler *handler, int flags)
b46b1d59
VZ
109{
110 wxUnusedVar(flags);
111
112 wxCHECK_MSG( handler, false, _T("handler can't be NULL") );
113
114 wxFDIOHandlerMap::iterator i = m_handlers.find(fd);
115 wxCHECK_MSG( i != m_handlers.end(), false,
116 _T("modifying unregistered handler?") );
117
118 i->second = wxFDIOHandlerEntry(handler, flags);
119
120 return true;
121}
122
af57c51a 123bool wxMappedFDIODispatcher::UnregisterFD(int fd)
b46b1d59
VZ
124{
125 wxFDIOHandlerMap::iterator i = m_handlers.find(fd);
af57c51a 126 if ( i == m_handlers.end() )
ad8d42f8 127 return false;
b46b1d59 128
af57c51a 129 m_handlers.erase(i);
b46b1d59 130
ad8d42f8 131 return true;
b46b1d59
VZ
132}
133
5e1eac14
VZ
134// ----------------------------------------------------------------------------
135// wxSelectDispatcherModule
136// ----------------------------------------------------------------------------
137
138class wxFDIODispatcherModule : public wxModule
139{
140public:
141 virtual bool OnInit() { return true; }
142 virtual void OnExit() { wxDELETE(gs_dispatcher); }
143
144private:
145 DECLARE_DYNAMIC_CLASS(wxFDIODispatcherModule)
146};
147
148IMPLEMENT_DYNAMIC_CLASS(wxFDIODispatcherModule, wxModule)