]>
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
6 // Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 // ============================================================================
12 // ============================================================================
14 // ----------------------------------------------------------------------------
16 // ----------------------------------------------------------------------------
18 // for compilers that support precompilation, includes "wx.h".
19 #include "wx/wxprec.h"
26 #include "wx/module.h"
29 #include "wx/private/fdiodispatcher.h"
31 #include "wx/private/selectdispatcher.h"
33 #include "wx/unix/private/epolldispatcher.h"
36 wxFDIODispatcher
*gs_dispatcher
= NULL
;
38 // ============================================================================
40 // ============================================================================
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
47 wxFDIODispatcher
*wxFDIODispatcher::Get()
51 #if wxUSE_EPOLL_DISPATCHER
52 gs_dispatcher
= wxEpollDispatcher::Create();
54 #endif // wxUSE_EPOLL_DISPATCHER
55 #if wxUSE_SELECT_DISPATCHER
56 gs_dispatcher
= new wxSelectDispatcher();
57 #endif // wxUSE_SELECT_DISPATCHER
60 wxASSERT_MSG( gs_dispatcher
, "failed to create any IO dispatchers" );
66 void wxFDIODispatcher::DispatchPending()
69 gs_dispatcher
->Dispatch(0);
72 // ----------------------------------------------------------------------------
73 // wxMappedFDIODispatcher
74 // ----------------------------------------------------------------------------
76 wxFDIOHandler
*wxMappedFDIODispatcher::FindHandler(int fd
) const
78 const wxFDIOHandlerMap::const_iterator it
= m_handlers
.find(fd
);
80 return it
== m_handlers
.end() ? NULL
: it
->second
.handler
;
85 wxMappedFDIODispatcher::RegisterFD(int fd
, wxFDIOHandler
*handler
, int flags
)
87 wxCHECK_MSG( handler
, false, "handler can't be NULL" );
89 // notice that it's not an error to register a handler for the same fd
90 // twice as it can be done with different flags -- but it is an error to
91 // register different handlers
92 wxFDIOHandlerMap::iterator i
= m_handlers
.find(fd
);
93 if ( i
!= m_handlers
.end() )
95 wxASSERT_MSG( i
->second
.handler
== handler
,
96 "registering different handler for the same fd?" );
97 wxASSERT_MSG( i
->second
.flags
!= flags
,
98 "reregistering with the same flags?" );
101 m_handlers
[fd
] = wxFDIOHandlerEntry(handler
, flags
);
107 wxMappedFDIODispatcher::ModifyFD(int fd
, wxFDIOHandler
*handler
, int flags
)
109 wxCHECK_MSG( handler
, false, "handler can't be NULL" );
111 wxFDIOHandlerMap::iterator i
= m_handlers
.find(fd
);
112 wxCHECK_MSG( i
!= m_handlers
.end(), false,
113 "modifying unregistered handler?" );
115 i
->second
= wxFDIOHandlerEntry(handler
, flags
);
120 bool wxMappedFDIODispatcher::UnregisterFD(int fd
)
122 wxFDIOHandlerMap::iterator i
= m_handlers
.find(fd
);
123 if ( i
== m_handlers
.end() )
131 // ----------------------------------------------------------------------------
132 // wxSelectDispatcherModule
133 // ----------------------------------------------------------------------------
135 class wxFDIODispatcherModule
: public wxModule
138 virtual bool OnInit() { return true; }
139 virtual void OnExit() { wxDELETE(gs_dispatcher
); }
142 DECLARE_DYNAMIC_CLASS(wxFDIODispatcherModule
)
145 IMPLEMENT_DYNAMIC_CLASS(wxFDIODispatcherModule
, wxModule
)