]>
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"
29 #include "wx/private/fdiodispatcher.h"
31 // ============================================================================
33 // ============================================================================
35 wxFDIOHandler
*wxMappedFDIODispatcher::FindHandler(int fd
) const
37 const wxFDIOHandlerMap::const_iterator it
= m_handlers
.find(fd
);
39 return it
== m_handlers
.end() ? NULL
: it
->second
.handler
;
43 bool wxMappedFDIODispatcher::RegisterFD(int fd
, wxFDIOHandler
*handler
, int flags
)
47 wxCHECK_MSG( handler
, false, _T("handler can't be NULL") );
49 // notice that it's not an error to register a handler for the same fd
50 // twice as it can be done with different flags -- but it is an error to
51 // register different handlers
52 wxFDIOHandlerMap::iterator i
= m_handlers
.find(fd
);
53 if ( i
!= m_handlers
.end() )
55 wxASSERT_MSG( i
->second
.handler
== handler
,
56 _T("registering different handler for the same fd?") );
57 wxASSERT_MSG( i
->second
.flags
!= flags
,
58 _T("reregistering with the same flags?") );
61 m_handlers
[fd
] = wxFDIOHandlerEntry(handler
, flags
);
66 bool wxMappedFDIODispatcher::ModifyFD(int fd
, wxFDIOHandler
*handler
, int flags
)
70 wxCHECK_MSG( handler
, false, _T("handler can't be NULL") );
72 wxFDIOHandlerMap::iterator i
= m_handlers
.find(fd
);
73 wxCHECK_MSG( i
!= m_handlers
.end(), false,
74 _T("modifying unregistered handler?") );
76 i
->second
= wxFDIOHandlerEntry(handler
, flags
);
81 bool wxMappedFDIODispatcher::UnregisterFD(int fd
, int flags
)
83 wxFDIOHandlerMap::iterator i
= m_handlers
.find(fd
);
84 if( i
== m_handlers
.end())
87 i
->second
.flags
&= ~flags
;
88 if ( !i
->second
.flags
)
90 // this handler is not registered for anything any more, get rid of it