]> git.saurik.com Git - wxWidgets.git/blame - src/common/socketiohandler.cpp
Add component-level filtering to wxLog.
[wxWidgets.git] / src / common / socketiohandler.cpp
CommitLineData
30c45bdd 1///////////////////////////////////////////////////////////////////////////////
86c5b12b 2// Name: src/common/socketiohandler.cpp
51fe4b60 3// Purpose: implementation of wxFDIOHandler for wxSocket
30c45bdd 4// Author: Angel Vidal, Lukasz Michalski
30c45bdd
VZ
5// Created: 08.24.06
6// RCS-ID: $Id$
7// Copyright: (c) 2006 Angel vidal
2804f77d 8// (c) 2007 Vadim Zeitlin <vadim@wxwidgets.org>
30c45bdd
VZ
9// License: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20// for compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
b4715d08
VZ
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
a1873279 27#if wxUSE_SOCKETS && wxUSE_SELECT_DISPATCHER
30c45bdd 28
2804f77d 29#include "wx/apptrait.h"
a9d859df 30#include "wx/private/socket.h"
54e757fc 31#include "wx/link.h"
30c45bdd
VZ
32
33// ============================================================================
34// implementation
35// ============================================================================
36
51fe4b60 37// ----------------------------------------------------------------------------
39b61b05 38// wxSocketFDIOManager: socket manager using wxFDIODispatcher
51fe4b60
VZ
39// ----------------------------------------------------------------------------
40
39b61b05 41class wxSocketFDIOManager : public wxSocketFDBasedManager
51fe4b60
VZ
42{
43public:
51fe4b60
VZ
44 virtual void Install_Callback(wxSocketImpl *socket, wxSocketNotify event);
45 virtual void Uninstall_Callback(wxSocketImpl *socket, wxSocketNotify event);
2804f77d 46};
30c45bdd 47
39b61b05 48void wxSocketFDIOManager::Install_Callback(wxSocketImpl *socket_,
51fe4b60 49 wxSocketNotify event)
30c45bdd 50{
acd523a9 51 wxSocketImplUnix * const socket = static_cast<wxSocketImplUnix *>(socket_);
51fe4b60 52
2804f77d 53 const int fd = socket->m_fd;
30c45bdd 54
2804f77d
VZ
55 if ( fd == -1 )
56 return;
30c45bdd 57
2804f77d 58 const SocketDir d = GetDirForEvent(socket, event);
30c45bdd 59
2804f77d
VZ
60 wxFDIODispatcher * const dispatcher = wxFDIODispatcher::Get();
61 if ( !dispatcher )
62 return;
30c45bdd 63
a9d859df 64 FD(socket, d) = fd;
30c45bdd 65
a9d859df
VZ
66 // register it when it's used for the first time, update it if it had been
67 // previously registered
acd523a9 68 const bool alreadyRegistered = socket->HasAnyEnabledCallbacks();
30c45bdd 69
acd523a9 70 socket->EnableCallback(d == FD_INPUT ? wxFDIO_INPUT : wxFDIO_OUTPUT);
30c45bdd 71
acd523a9
VZ
72 if ( alreadyRegistered )
73 dispatcher->ModifyFD(fd, socket, socket->GetEnabledCallbacks());
2804f77d 74 else
acd523a9 75 dispatcher->RegisterFD(fd, socket, socket->GetEnabledCallbacks());
30c45bdd
VZ
76}
77
39b61b05 78void wxSocketFDIOManager::Uninstall_Callback(wxSocketImpl *socket_,
51fe4b60 79 wxSocketNotify event)
30c45bdd 80{
acd523a9 81 wxSocketImplUnix * const socket = static_cast<wxSocketImplUnix *>(socket_);
51fe4b60 82
2804f77d 83 const SocketDir d = GetDirForEvent(socket, event);
30c45bdd 84
2804f77d
VZ
85 const int fd = FD(socket, d);
86 if ( fd == -1 )
87 return;
30c45bdd 88
2804f77d 89 FD(socket, d) = -1;
30c45bdd 90
2804f77d
VZ
91 const wxFDIODispatcherEntryFlags
92 flag = d == FD_INPUT ? wxFDIO_INPUT : wxFDIO_OUTPUT;
30c45bdd 93
2804f77d
VZ
94 wxFDIODispatcher * const dispatcher = wxFDIODispatcher::Get();
95 if ( !dispatcher )
96 return;
30c45bdd 97
acd523a9 98 socket->DisableCallback(flag);
a9d859df 99
acd523a9 100 if ( !socket->HasAnyEnabledCallbacks() )
a9d859df 101 dispatcher->UnregisterFD(fd);
2804f77d 102 else
acd523a9 103 dispatcher->ModifyFD(fd, socket, socket->GetEnabledCallbacks());
30c45bdd
VZ
104}
105
86c5b12b
VZ
106// set the wxBase variable to point to our wxSocketManager implementation
107//
108// see comments in wx/apptrait.h for the explanation of why do we do it
109// like this
110static struct ManagerSetter
30c45bdd 111{
86c5b12b
VZ
112 ManagerSetter()
113 {
39b61b05 114 static wxSocketFDIOManager s_manager;
86c5b12b
VZ
115 wxAppTraits::SetDefaultSocketManager(&s_manager);
116 }
117} gs_managerSetter;
30c45bdd 118
54e757fc
FM
119
120// see the relative linker macro in socket.cpp
121wxFORCE_LINK_THIS_MODULE( socketiohandler );
122
30c45bdd 123#endif // wxUSE_SOCKETS