X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ad8d42f83cdf7a4f26969957e94ed166a1a5710e..51146826fc0a0a949d88f23fb9d83fc1f1ada14e:/src/common/fdiodispatcher.cpp diff --git a/src/common/fdiodispatcher.cpp b/src/common/fdiodispatcher.cpp index f2e54e3036..f526487130 100644 --- a/src/common/fdiodispatcher.cpp +++ b/src/common/fdiodispatcher.cpp @@ -24,14 +24,56 @@ #endif #ifndef WX_PRECOMP + #include "wx/module.h" #endif //WX_PRECOMP #include "wx/private/fdiodispatcher.h" +#include "wx/private/selectdispatcher.h" +#ifdef __UNIX__ + #include "wx/unix/private/epolldispatcher.h" +#endif + +wxFDIODispatcher *gs_dispatcher = NULL; + // ============================================================================ // implementation // ============================================================================ +// ---------------------------------------------------------------------------- +// wxFDIODispatcher +// ---------------------------------------------------------------------------- + +/* static */ +wxFDIODispatcher *wxFDIODispatcher::Get() +{ + if ( !gs_dispatcher ) + { +#if wxUSE_EPOLL_DISPATCHER + gs_dispatcher = wxEpollDispatcher::Create(); + if ( !gs_dispatcher ) +#endif // wxUSE_EPOLL_DISPATCHER +#if wxUSE_SELECT_DISPATCHER + gs_dispatcher = wxSelectDispatcher::Create(); +#endif // wxUSE_WCHAR_T + } + + wxASSERT_MSG( gs_dispatcher, _T("failed to create any IO dispatchers") ); + + return gs_dispatcher; +} + +/* static */ +void wxFDIODispatcher::DispatchPending() +{ + if ( gs_dispatcher ) + gs_dispatcher->Dispatch(0); +} + +// ---------------------------------------------------------------------------- +// wxMappedFDIODispatcher +// ---------------------------------------------------------------------------- + wxFDIOHandler *wxMappedFDIODispatcher::FindHandler(int fd) const { const wxFDIOHandlerMap::const_iterator it = m_handlers.find(fd); @@ -78,19 +120,29 @@ bool wxMappedFDIODispatcher::ModifyFD(int fd, wxFDIOHandler *handler, int flags) return true; } -bool wxMappedFDIODispatcher::UnregisterFD(int fd, int flags) +bool wxMappedFDIODispatcher::UnregisterFD(int fd) { wxFDIOHandlerMap::iterator i = m_handlers.find(fd); - if( i == m_handlers.end()) + if ( i == m_handlers.end() ) return false; - i->second.flags &= ~flags; - if ( !i->second.flags ) - { - // this handler is not registered for anything any more, get rid of it - m_handlers.erase(i); - } + m_handlers.erase(i); return true; } +// ---------------------------------------------------------------------------- +// wxSelectDispatcherModule +// ---------------------------------------------------------------------------- + +class wxFDIODispatcherModule : public wxModule +{ +public: + virtual bool OnInit() { return true; } + virtual void OnExit() { wxDELETE(gs_dispatcher); } + +private: + DECLARE_DYNAMIC_CLASS(wxFDIODispatcherModule) +}; + +IMPLEMENT_DYNAMIC_CLASS(wxFDIODispatcherModule, wxModule)