]> git.saurik.com Git - wxWidgets.git/blame - src/common/fdiodispatcher.cpp
ANSI+Unicode compatibility fixes to wxArrayString
[wxWidgets.git] / src / common / fdiodispatcher.cpp
CommitLineData
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 35wxFDIOHandler *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 43bool 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 66bool 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
ad8d42f8 81bool wxMappedFDIODispatcher::UnregisterFD(int fd, int flags)
b46b1d59
VZ
82{
83 wxFDIOHandlerMap::iterator i = m_handlers.find(fd);
ad8d42f8
VZ
84 if( i == m_handlers.end())
85 return false;
b46b1d59 86
b46b1d59
VZ
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
ad8d42f8 94 return true;
b46b1d59
VZ
95}
96