]> git.saurik.com Git - wxWidgets.git/blob - src/common/socketiohandler.cpp
remove confusing wxDialog::ButtonSizerFlags and extract button styles properly in...
[wxWidgets.git] / src / common / socketiohandler.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/socketiohandler.cpp
3 // Purpose: implementation of wxFDIOHandler for wxSocket
4 // Author: Angel Vidal, Lukasz Michalski
5 // Created: 08.24.06
6 // RCS-ID: $Id$
7 // Copyright: (c) 2006 Angel vidal
8 // (c) 2007 Vadim Zeitlin <vadim@wxwidgets.org>
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
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_SOCKETS && wxUSE_SELECT_DISPATCHER
28
29 #include "wx/apptrait.h"
30 #include "wx/private/socket.h"
31 #include "wx/link.h"
32
33 // ============================================================================
34 // implementation
35 // ============================================================================
36
37 // ----------------------------------------------------------------------------
38 // wxSocketFDIOManager: socket manager using wxFDIODispatcher
39 // ----------------------------------------------------------------------------
40
41 class wxSocketFDIOManager : public wxSocketFDBasedManager
42 {
43 public:
44 virtual void Install_Callback(wxSocketImpl *socket, wxSocketNotify event);
45 virtual void Uninstall_Callback(wxSocketImpl *socket, wxSocketNotify event);
46 };
47
48 void wxSocketFDIOManager::Install_Callback(wxSocketImpl *socket_,
49 wxSocketNotify event)
50 {
51 wxSocketImplUnix * const socket = static_cast<wxSocketImplUnix *>(socket_);
52
53 const int fd = socket->m_fd;
54
55 if ( fd == -1 )
56 return;
57
58 const SocketDir d = GetDirForEvent(socket, event);
59
60 wxFDIODispatcher * const dispatcher = wxFDIODispatcher::Get();
61 if ( !dispatcher )
62 return;
63
64 FD(socket, d) = fd;
65
66 // register it when it's used for the first time, update it if it had been
67 // previously registered
68 const bool alreadyRegistered = socket->HasAnyEnabledCallbacks();
69
70 socket->EnableCallback(d == FD_INPUT ? wxFDIO_INPUT : wxFDIO_OUTPUT);
71
72 if ( alreadyRegistered )
73 dispatcher->ModifyFD(fd, socket, socket->GetEnabledCallbacks());
74 else
75 dispatcher->RegisterFD(fd, socket, socket->GetEnabledCallbacks());
76 }
77
78 void wxSocketFDIOManager::Uninstall_Callback(wxSocketImpl *socket_,
79 wxSocketNotify event)
80 {
81 wxSocketImplUnix * const socket = static_cast<wxSocketImplUnix *>(socket_);
82
83 const SocketDir d = GetDirForEvent(socket, event);
84
85 const int fd = FD(socket, d);
86 if ( fd == -1 )
87 return;
88
89 FD(socket, d) = -1;
90
91 const wxFDIODispatcherEntryFlags
92 flag = d == FD_INPUT ? wxFDIO_INPUT : wxFDIO_OUTPUT;
93
94 wxFDIODispatcher * const dispatcher = wxFDIODispatcher::Get();
95 if ( !dispatcher )
96 return;
97
98 socket->DisableCallback(flag);
99
100 if ( !socket->HasAnyEnabledCallbacks() )
101 dispatcher->UnregisterFD(fd);
102 else
103 dispatcher->ModifyFD(fd, socket, socket->GetEnabledCallbacks());
104 }
105
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
110 static struct ManagerSetter
111 {
112 ManagerSetter()
113 {
114 static wxSocketFDIOManager s_manager;
115 wxAppTraits::SetDefaultSocketManager(&s_manager);
116 }
117 } gs_managerSetter;
118
119
120 // see the relative linker macro in socket.cpp
121 wxFORCE_LINK_THIS_MODULE( socketiohandler );
122
123 #endif // wxUSE_SOCKETS