]>
git.saurik.com Git - wxWidgets.git/blob - src/common/fdiodispatcher.cpp
607519b365e4833cf35971cb52eb988134924ad1
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
= new wxSelectDispatcher();
58 #endif // wxUSE_SELECT_DISPATCHER
61 wxASSERT_MSG( gs_dispatcher
, "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
;
86 wxMappedFDIODispatcher::RegisterFD(int fd
, wxFDIOHandler
*handler
, int flags
)
88 wxCHECK_MSG( handler
, false, "handler can't be NULL" );
90 // notice that it's not an error to register a handler for the same fd
91 // twice as it can be done with different flags -- but it is an error to
92 // register different handlers
93 wxFDIOHandlerMap::iterator i
= m_handlers
.find(fd
);
94 if ( i
!= m_handlers
.end() )
96 wxASSERT_MSG( i
->second
.handler
== handler
,
97 "registering different handler for the same fd?" );
98 wxASSERT_MSG( i
->second
.flags
!= flags
,
99 "reregistering with the same flags?" );
102 m_handlers
[fd
] = wxFDIOHandlerEntry(handler
, flags
);
108 wxMappedFDIODispatcher::ModifyFD(int fd
, wxFDIOHandler
*handler
, int flags
)
110 wxCHECK_MSG( handler
, false, "handler can't be NULL" );
112 wxFDIOHandlerMap::iterator i
= m_handlers
.find(fd
);
113 wxCHECK_MSG( i
!= m_handlers
.end(), false,
114 "modifying unregistered handler?" );
116 i
->second
= wxFDIOHandlerEntry(handler
, flags
);
121 bool wxMappedFDIODispatcher::UnregisterFD(int fd
)
123 wxFDIOHandlerMap::iterator i
= m_handlers
.find(fd
);
124 if ( i
== m_handlers
.end() )
132 // ----------------------------------------------------------------------------
133 // wxSelectDispatcherModule
134 // ----------------------------------------------------------------------------
136 class wxFDIODispatcherModule
: public wxModule
139 virtual bool OnInit() { return true; }
140 virtual void OnExit() { wxDELETE(gs_dispatcher
); }
143 DECLARE_DYNAMIC_CLASS(wxFDIODispatcherModule
)
146 IMPLEMENT_DYNAMIC_CLASS(wxFDIODispatcherModule
, wxModule
)