1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/unix/fdiounix.cpp
3 // Purpose: wxFDIOManager implementation for console Unix applications
4 // Author: Vadim Zeitlin
6 // RCS-ID: $Id: wxhead.cpp,v 1.10 2009-06-29 10:23:04 zeitlin Exp $
7 // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
26 #include "wx/apptrait.h"
28 #include "wx/private/fdiodispatcher.h"
29 #include "wx/unix/private/fdiounix.h"
31 // ============================================================================
32 // wxFDIOManagerUnix implementation
33 // ============================================================================
35 int wxFDIOManagerUnix::AddInput(wxFDIOHandler
*handler
, int fd
, Direction d
)
37 wxFDIODispatcher
* const dispatcher
= wxFDIODispatcher::Get();
38 wxCHECK_MSG( dispatcher
, -1, "can't monitor FDs without FD IO dispatcher" );
40 // translate our direction to dispatcher flags
41 const int flag
= d
== INPUT
? wxFDIO_INPUT
: wxFDIO_OUTPUT
;
43 // we need to either register this FD with the dispatcher or update an
44 // existing registration depending on whether it had been previously
45 // registered for anything or not
47 const int regmask
= handler
->GetRegisteredEvents();
50 ok
= dispatcher
->RegisterFD(fd
, handler
, flag
);
54 ok
= dispatcher
->ModifyFD(fd
, handler
, regmask
| flag
);
60 // update the stored mask of registered events
61 handler
->SetRegisteredEvent(flag
);
66 void wxFDIOManagerUnix::RemoveInput(wxFDIOHandler
*handler
, int fd
, Direction d
)
68 wxFDIODispatcher
* const dispatcher
= wxFDIODispatcher::Get();
72 const int flag
= d
== INPUT
? wxFDIO_INPUT
: wxFDIO_OUTPUT
;
74 // just as in AddInput() above we may need to either just modify the FD or
75 // remove it completely if we don't need to monitor it any more
77 const int regmask
= handler
->GetRegisteredEvents();
78 if ( regmask
== flag
)
80 ok
= dispatcher
->UnregisterFD(fd
);
84 ok
= dispatcher
->ModifyFD(fd
, handler
, regmask
& ~flag
);
89 wxLogDebug("Failed to unregister %d in direction %d", fd
, d
);
92 // do this even after a failure to unregister it, we still tried...
93 handler
->ClearRegisteredEvent(flag
);
96 wxFDIOManager
*wxAppTraits::GetFDIOManager()
98 static wxFDIOManagerUnix s_manager
;