]>
git.saurik.com Git - wxWidgets.git/blob - src/common/fdiodispatcher.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/fdiodispatcher.cpp
3 // Purpose: Implementation of common wxFDIODispatcher methods
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
27 #include "wx/module.h"
30 #include "wx/private/fdiodispatcher.h"
32 #include "wx/private/selectdispatcher.h"
34 #include "wx/unix/private/epolldispatcher.h"
37 wxFDIODispatcher
*gs_dispatcher
= NULL
;
39 // ============================================================================
41 // ============================================================================
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
48 wxFDIODispatcher
*wxFDIODispatcher::Get()
52 #if wxUSE_EPOLL_DISPATCHER
53 gs_dispatcher
= wxEpollDispatcher::Create();
55 #endif // wxUSE_EPOLL_DISPATCHER
56 #if wxUSE_SELECT_DISPATCHER
57 gs_dispatcher
= wxSelectDispatcher::Create();
58 #endif // wxUSE_SELECT_DISPATCHER
61 wxASSERT_MSG( gs_dispatcher
, _T("failed to create any IO dispatchers") );
67 void wxFDIODispatcher::DispatchPending()
70 gs_dispatcher
->Dispatch(0);
73 // ----------------------------------------------------------------------------
74 // wxMappedFDIODispatcher
75 // ----------------------------------------------------------------------------
77 wxFDIOHandler
*wxMappedFDIODispatcher::FindHandler(int fd
) const
79 const wxFDIOHandlerMap::const_iterator it
= m_handlers
.find(fd
);
81 return it
== m_handlers
.end() ? NULL
: it
->second
.handler
;
85 bool wxMappedFDIODispatcher::RegisterFD(int fd
, wxFDIOHandler
*handler
, int flags
)
89 wxCHECK_MSG( handler
, false, _T("handler can't be NULL") );
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() )
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?") );
103 m_handlers
[fd
] = wxFDIOHandlerEntry(handler
, flags
);
108 bool wxMappedFDIODispatcher::ModifyFD(int fd
, wxFDIOHandler
*handler
, int flags
)
112 wxCHECK_MSG( handler
, false, _T("handler can't be NULL") );
114 wxFDIOHandlerMap::iterator i
= m_handlers
.find(fd
);
115 wxCHECK_MSG( i
!= m_handlers
.end(), false,
116 _T("modifying unregistered handler?") );
118 i
->second
= wxFDIOHandlerEntry(handler
, flags
);
123 bool wxMappedFDIODispatcher::UnregisterFD(int fd
)
125 wxFDIOHandlerMap::iterator i
= m_handlers
.find(fd
);
126 if ( i
== m_handlers
.end() )
134 // ----------------------------------------------------------------------------
135 // wxSelectDispatcherModule
136 // ----------------------------------------------------------------------------
138 class wxFDIODispatcherModule
: public wxModule
141 virtual bool OnInit() { return true; }
142 virtual void OnExit() { wxDELETE(gs_dispatcher
); }
145 DECLARE_DYNAMIC_CLASS(wxFDIODispatcherModule
)
148 IMPLEMENT_DYNAMIC_CLASS(wxFDIODispatcherModule
, wxModule
)