]> git.saurik.com Git - wxWidgets.git/blob - src/common/fdiodispatcher.cpp
PCH-less compilation fix
[wxWidgets.git] / src / common / fdiodispatcher.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/fdiodispatcher.cpp
3 // Purpose: Implementation of common wxFDIODispatcher methods
4 // Author: Vadim Zeitlin
5 // Created: 2007-05-13
6 // RCS-ID: $Id$
7 // Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #ifndef WX_PRECOMP
27 #endif //WX_PRECOMP
28
29 #include "wx/private/fdiodispatcher.h"
30
31 // ============================================================================
32 // implementation
33 // ============================================================================
34
35 wxFDIOHandler *wxMappedFDIODispatcher::FindHandler(int fd) const
36 {
37 const wxFDIOHandlerMap::const_iterator it = m_handlers.find(fd);
38
39 return it == m_handlers.end() ? NULL : it->second.handler;
40 }
41
42
43 bool wxMappedFDIODispatcher::RegisterFD(int fd, wxFDIOHandler *handler, int flags)
44 {
45 wxUnusedVar(flags);
46
47 wxCHECK_MSG( handler, false, _T("handler can't be NULL") );
48
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() )
54 {
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?") );
59 }
60
61 m_handlers[fd] = wxFDIOHandlerEntry(handler, flags);
62
63 return true;
64 }
65
66 bool wxMappedFDIODispatcher::ModifyFD(int fd, wxFDIOHandler *handler, int flags)
67 {
68 wxUnusedVar(flags);
69
70 wxCHECK_MSG( handler, false, _T("handler can't be NULL") );
71
72 wxFDIOHandlerMap::iterator i = m_handlers.find(fd);
73 wxCHECK_MSG( i != m_handlers.end(), false,
74 _T("modifying unregistered handler?") );
75
76 i->second = wxFDIOHandlerEntry(handler, flags);
77
78 return true;
79 }
80
81 bool wxMappedFDIODispatcher::UnregisterFD(int fd, int flags)
82 {
83 wxFDIOHandlerMap::iterator i = m_handlers.find(fd);
84 if( i == m_handlers.end())
85 return false;
86
87 i->second.flags &= ~flags;
88 if ( !i->second.flags )
89 {
90 // this handler is not registered for anything any more, get rid of it
91 m_handlers.erase(i);
92 }
93
94 return true;
95 }
96