1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/unix/fdiounix.cpp
3 // Purpose: wxFDIOManager implementation for console Unix applications
4 // Author: Vadim Zeitlin
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"
28 #include "wx/apptrait.h"
30 #include "wx/private/fdiodispatcher.h"
31 #include "wx/unix/private/fdiounix.h"
33 // ============================================================================
34 // wxFDIOManagerUnix implementation
35 // ============================================================================
37 int wxFDIOManagerUnix::AddInput(wxFDIOHandler
*handler
, int fd
, Direction d
)
39 wxFDIODispatcher
* const dispatcher
= wxFDIODispatcher::Get();
40 wxCHECK_MSG( dispatcher
, -1, "can't monitor FDs without FD IO dispatcher" );
42 // translate our direction to dispatcher flags
43 const int flag
= d
== INPUT
? wxFDIO_INPUT
: wxFDIO_OUTPUT
;
45 // we need to either register this FD with the dispatcher or update an
46 // existing registration depending on whether it had been previously
47 // registered for anything or not
49 const int regmask
= handler
->GetRegisteredEvents();
52 ok
= dispatcher
->RegisterFD(fd
, handler
, flag
);
56 ok
= dispatcher
->ModifyFD(fd
, handler
, regmask
| flag
);
62 // update the stored mask of registered events
63 handler
->SetRegisteredEvent(flag
);
68 void wxFDIOManagerUnix::RemoveInput(wxFDIOHandler
*handler
, int fd
, Direction d
)
70 wxFDIODispatcher
* const dispatcher
= wxFDIODispatcher::Get();
74 const int flag
= d
== INPUT
? wxFDIO_INPUT
: wxFDIO_OUTPUT
;
76 // just as in AddInput() above we may need to either just modify the FD or
77 // remove it completely if we don't need to monitor it any more
79 const int regmask
= handler
->GetRegisteredEvents();
80 if ( regmask
== flag
)
82 ok
= dispatcher
->UnregisterFD(fd
);
86 ok
= dispatcher
->ModifyFD(fd
, handler
, regmask
& ~flag
);
91 wxLogDebug("Failed to unregister %d in direction %d", fd
, d
);
94 // do this even after a failure to unregister it, we still tried...
95 handler
->ClearRegisteredEvent(flag
);
98 wxFDIOManager
*wxAppTraits::GetFDIOManager()
100 static wxFDIOManagerUnix s_manager
;
104 #endif // wxUSE_SOCKETS