]>
Commit | Line | Data |
---|---|---|
b46b1d59 VZ |
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 | ||
ad8d42f8 | 35 | wxFDIOHandler *wxMappedFDIODispatcher::FindHandler(int fd) const |
b46b1d59 VZ |
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 | ||
ad8d42f8 | 43 | bool wxMappedFDIODispatcher::RegisterFD(int fd, wxFDIOHandler *handler, int flags) |
b46b1d59 VZ |
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 | ||
ad8d42f8 | 66 | bool wxMappedFDIODispatcher::ModifyFD(int fd, wxFDIOHandler *handler, int flags) |
b46b1d59 VZ |
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 | ||
af57c51a | 81 | bool wxMappedFDIODispatcher::UnregisterFD(int fd) |
b46b1d59 VZ |
82 | { |
83 | wxFDIOHandlerMap::iterator i = m_handlers.find(fd); | |
af57c51a | 84 | if ( i == m_handlers.end() ) |
ad8d42f8 | 85 | return false; |
b46b1d59 | 86 | |
af57c51a | 87 | m_handlers.erase(i); |
b46b1d59 | 88 | |
ad8d42f8 | 89 | return true; |
b46b1d59 VZ |
90 | } |
91 |