]> git.saurik.com Git - wxWidgets.git/blame - src/common/fdiodispatcher.cpp
remove apparently unused file (src/osx/core/gsocket.cpp seems to have replaced it)
[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
5e1eac14 27 #include "wx/module.h"
b46b1d59
VZ
28#endif //WX_PRECOMP
29
30#include "wx/private/fdiodispatcher.h"
31
5e1eac14
VZ
32#include "wx/private/selectdispatcher.h"
33#ifdef __UNIX__
34 #include "wx/unix/private/epolldispatcher.h"
35#endif
36
37wxFDIODispatcher *gs_dispatcher = NULL;
38
b46b1d59
VZ
39// ============================================================================
40// implementation
41// ============================================================================
42
5e1eac14
VZ
43// ----------------------------------------------------------------------------
44// wxFDIODispatcher
45// ----------------------------------------------------------------------------
46
47/* static */
48wxFDIODispatcher *wxFDIODispatcher::Get()
49{
50 if ( !gs_dispatcher )
51 {
0a6c4c2e 52#if wxUSE_EPOLL_DISPATCHER
5e1eac14
VZ
53 gs_dispatcher = wxEpollDispatcher::Create();
54 if ( !gs_dispatcher )
55#endif // wxUSE_EPOLL_DISPATCHER
56#if wxUSE_SELECT_DISPATCHER
fdf7ff73 57 gs_dispatcher = new wxSelectDispatcher();
2804f77d 58#endif // wxUSE_SELECT_DISPATCHER
5e1eac14
VZ
59 }
60
c139dda1 61 wxASSERT_MSG( gs_dispatcher, "failed to create any IO dispatchers" );
5e1eac14
VZ
62
63 return gs_dispatcher;
64}
65
66/* static */
67void wxFDIODispatcher::DispatchPending()
68{
69 if ( gs_dispatcher )
70 gs_dispatcher->Dispatch(0);
71}
72
73// ----------------------------------------------------------------------------
74// wxMappedFDIODispatcher
75// ----------------------------------------------------------------------------
76
ad8d42f8 77wxFDIOHandler *wxMappedFDIODispatcher::FindHandler(int fd) const
b46b1d59
VZ
78{
79 const wxFDIOHandlerMap::const_iterator it = m_handlers.find(fd);
80
81 return it == m_handlers.end() ? NULL : it->second.handler;
82}
83
84
c139dda1
VZ
85bool
86wxMappedFDIODispatcher::RegisterFD(int fd, wxFDIOHandler *handler, int flags)
b46b1d59 87{
c139dda1 88 wxCHECK_MSG( handler, false, "handler can't be NULL" );
b46b1d59
VZ
89
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() )
95 {
96 wxASSERT_MSG( i->second.handler == handler,
c139dda1 97 "registering different handler for the same fd?" );
b46b1d59 98 wxASSERT_MSG( i->second.flags != flags,
c139dda1 99 "reregistering with the same flags?" );
b46b1d59
VZ
100 }
101
102 m_handlers[fd] = wxFDIOHandlerEntry(handler, flags);
103
104 return true;
105}
106
c139dda1
VZ
107bool
108wxMappedFDIODispatcher::ModifyFD(int fd, wxFDIOHandler *handler, int flags)
b46b1d59 109{
c139dda1 110 wxCHECK_MSG( handler, false, "handler can't be NULL" );
b46b1d59
VZ
111
112 wxFDIOHandlerMap::iterator i = m_handlers.find(fd);
113 wxCHECK_MSG( i != m_handlers.end(), false,
c139dda1 114 "modifying unregistered handler?" );
b46b1d59
VZ
115
116 i->second = wxFDIOHandlerEntry(handler, flags);
117
118 return true;
119}
120
af57c51a 121bool wxMappedFDIODispatcher::UnregisterFD(int fd)
b46b1d59
VZ
122{
123 wxFDIOHandlerMap::iterator i = m_handlers.find(fd);
af57c51a 124 if ( i == m_handlers.end() )
ad8d42f8 125 return false;
b46b1d59 126
af57c51a 127 m_handlers.erase(i);
b46b1d59 128
ad8d42f8 129 return true;
b46b1d59
VZ
130}
131
5e1eac14
VZ
132// ----------------------------------------------------------------------------
133// wxSelectDispatcherModule
134// ----------------------------------------------------------------------------
135
136class wxFDIODispatcherModule : public wxModule
137{
138public:
139 virtual bool OnInit() { return true; }
140 virtual void OnExit() { wxDELETE(gs_dispatcher); }
141
142private:
143 DECLARE_DYNAMIC_CLASS(wxFDIODispatcherModule)
144};
145
146IMPLEMENT_DYNAMIC_CLASS(wxFDIODispatcherModule, wxModule)