Cleanly separate GUI socket-related code from net library.
This fixes linking problems under Unix introduced by recent changes which
fixed previous problems which were due to files not being linked in at all.
In order to provide a clean separation between base, net and core libraries we
now use the same wxSocketManager (wxSocketFDBasedManager), defined in net
library for both console and GUI Unix applications and just use different FD
IO manager for them: the latter can be defined in base and core libraries as
it doesn't involve wxSocketImpl at all, only its base wxFDIOHandler class.
At more detailed level, these changes required:
1. Adding the new wxFDIOManager class.
2. Refactoring the old (and now removed) wxSocketFDIOManager to use the same
code as wxSocketFDIOManager. This involved:
a) Adding handler and direction parameter to RemoveInput().
b) Storing the mask of registered events in wxFDIOHandler itself.
c) Defining wxFDIOManagerUnix which works with wxFDIODispatcher.
3. Changing the traits classes in Unix ports to define GetFDIOManager()
instead of GetSocketManager().
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61688 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
100
src/unix/fdiounix.cpp
Normal file
100
src/unix/fdiounix.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/unix/fdiounix.cpp
|
||||
// Purpose: wxFDIOManager implementation for console Unix applications
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2009-08-17
|
||||
// RCS-ID: $Id: wxhead.cpp,v 1.10 2009-06-29 10:23:04 zeitlin Exp $
|
||||
// Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// for compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/apptrait.h"
|
||||
#include "wx/private/fdiodispatcher.h"
|
||||
#include "wx/unix/private/fdiounix.h"
|
||||
|
||||
// ============================================================================
|
||||
// wxFDIOManagerUnix implementation
|
||||
// ============================================================================
|
||||
|
||||
int wxFDIOManagerUnix::AddInput(wxFDIOHandler *handler, int fd, Direction d)
|
||||
{
|
||||
wxFDIODispatcher * const dispatcher = wxFDIODispatcher::Get();
|
||||
wxCHECK_MSG( dispatcher, -1, "can't monitor FDs without FD IO dispatcher" );
|
||||
|
||||
// translate our direction to dispatcher flags
|
||||
const int flag = d == INPUT ? wxFDIO_INPUT : wxFDIO_OUTPUT;
|
||||
|
||||
// we need to either register this FD with the dispatcher or update an
|
||||
// existing registration depending on whether it had been previously
|
||||
// registered for anything or not
|
||||
bool ok;
|
||||
const int regmask = handler->GetRegisteredEvents();
|
||||
if ( !regmask )
|
||||
{
|
||||
ok = dispatcher->RegisterFD(fd, handler, flag);
|
||||
}
|
||||
else
|
||||
{
|
||||
ok = dispatcher->ModifyFD(fd, handler, regmask | flag);
|
||||
}
|
||||
|
||||
if ( !ok )
|
||||
return -1;
|
||||
|
||||
// update the stored mask of registered events
|
||||
handler->SetRegisteredEvent(flag);
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
void wxFDIOManagerUnix::RemoveInput(wxFDIOHandler *handler, int fd, Direction d)
|
||||
{
|
||||
wxFDIODispatcher * const dispatcher = wxFDIODispatcher::Get();
|
||||
if ( !dispatcher )
|
||||
return;
|
||||
|
||||
const int flag = d == INPUT ? wxFDIO_INPUT : wxFDIO_OUTPUT;
|
||||
|
||||
// just as in AddInput() above we may need to either just modify the FD or
|
||||
// remove it completely if we don't need to monitor it any more
|
||||
bool ok;
|
||||
const int regmask = handler->GetRegisteredEvents();
|
||||
if ( regmask == flag )
|
||||
{
|
||||
ok = dispatcher->UnregisterFD(fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
ok = dispatcher->ModifyFD(fd, handler, regmask & ~flag);
|
||||
}
|
||||
|
||||
if ( !ok )
|
||||
{
|
||||
wxLogDebug("Failed to unregister %d in direction %d", fd, d);
|
||||
}
|
||||
|
||||
// do this even after a failure to unregister it, we still tried...
|
||||
handler->ClearRegisteredEvent(flag);
|
||||
}
|
||||
|
||||
wxFDIOManager *wxAppTraits::GetFDIOManager()
|
||||
{
|
||||
static wxFDIOManagerUnix s_manager;
|
||||
return &s_manager;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user