X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/af57c51ab758ad9810ea5bbb3703341cd5f367b1..0bbe61b8c18a1795189f0cf73cc61c14a0fb846d:/src/common/fdiodispatcher.cpp?ds=sidebyside diff --git a/src/common/fdiodispatcher.cpp b/src/common/fdiodispatcher.cpp index 112f892dc2..83573829c1 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 = new wxSelectDispatcher(); +#endif // wxUSE_SELECT_DISPATCHER + } + + 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); @@ -89,3 +131,18 @@ bool wxMappedFDIODispatcher::UnregisterFD(int fd) 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)