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"
27 #include "wx/private/fdiodispatcher.h"
28 #include "wx/unix/private/fdiounix.h"
30 // ============================================================================
31 // wxFDIOManagerUnix implementation
32 // ============================================================================
34 int wxFDIOManagerUnix::AddInput(wxFDIOHandler
*handler
, int fd
, Direction d
)
36 wxFDIODispatcher
* const dispatcher
= wxFDIODispatcher::Get();
37 wxCHECK_MSG( dispatcher
, -1, "can't monitor FDs without FD IO dispatcher" );
39 // translate our direction to dispatcher flags
40 const int flag
= d
== INPUT
? wxFDIO_INPUT
: wxFDIO_OUTPUT
;
42 // we need to either register this FD with the dispatcher or update an
43 // existing registration depending on whether it had been previously
44 // registered for anything or not
46 const int regmask
= handler
->GetRegisteredEvents();
49 ok
= dispatcher
->RegisterFD(fd
, handler
, flag
);
53 ok
= dispatcher
->ModifyFD(fd
, handler
, regmask
| flag
);
59 // update the stored mask of registered events
60 handler
->SetRegisteredEvent(flag
);
65 void wxFDIOManagerUnix::RemoveInput(wxFDIOHandler
*handler
, int fd
, Direction d
)
67 wxFDIODispatcher
* const dispatcher
= wxFDIODispatcher::Get();
71 const int flag
= d
== INPUT
? wxFDIO_INPUT
: wxFDIO_OUTPUT
;
73 // just as in AddInput() above we may need to either just modify the FD or
74 // remove it completely if we don't need to monitor it any more
76 const int regmask
= handler
->GetRegisteredEvents();
77 if ( regmask
== flag
)
79 ok
= dispatcher
->UnregisterFD(fd
);
83 ok
= dispatcher
->ModifyFD(fd
, handler
, regmask
& ~flag
);
88 wxLogDebug("Failed to unregister %d in direction %d", fd
, d
);
91 // do this even after a failure to unregister it, we still tried...
92 handler
->ClearRegisteredEvent(flag
);
95 wxFDIOManager
*wxAppTraits::GetFDIOManager()
97 static wxFDIOManagerUnix s_manager
;