1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/unix/fdiounix.cpp
3 // Purpose: wxFDIOManager implementation for console Unix applications
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 // ============================================================================
12 // ============================================================================
14 // ----------------------------------------------------------------------------
16 // ----------------------------------------------------------------------------
18 // for compilers that support precompilation, includes "wx.h".
19 #include "wx/wxprec.h"
27 #include "wx/apptrait.h"
29 #include "wx/private/fdiodispatcher.h"
30 #include "wx/unix/private/fdiounix.h"
32 // ============================================================================
33 // wxFDIOManagerUnix implementation
34 // ============================================================================
36 int wxFDIOManagerUnix::AddInput(wxFDIOHandler
*handler
, int fd
, Direction d
)
38 wxFDIODispatcher
* const dispatcher
= wxFDIODispatcher::Get();
39 wxCHECK_MSG( dispatcher
, -1, "can't monitor FDs without FD IO dispatcher" );
41 // translate our direction to dispatcher flags
42 const int flag
= d
== INPUT
? wxFDIO_INPUT
: wxFDIO_OUTPUT
;
44 // we need to either register this FD with the dispatcher or update an
45 // existing registration depending on whether it had been previously
46 // registered for anything or not
48 const int regmask
= handler
->GetRegisteredEvents();
51 ok
= dispatcher
->RegisterFD(fd
, handler
, flag
);
55 ok
= dispatcher
->ModifyFD(fd
, handler
, regmask
| flag
);
61 // update the stored mask of registered events
62 handler
->SetRegisteredEvent(flag
);
67 void wxFDIOManagerUnix::RemoveInput(wxFDIOHandler
*handler
, int fd
, Direction d
)
69 wxFDIODispatcher
* const dispatcher
= wxFDIODispatcher::Get();
73 const int flag
= d
== INPUT
? wxFDIO_INPUT
: wxFDIO_OUTPUT
;
75 // just as in AddInput() above we may need to either just modify the FD or
76 // remove it completely if we don't need to monitor it any more
78 const int regmask
= handler
->GetRegisteredEvents();
79 if ( regmask
== flag
)
81 ok
= dispatcher
->UnregisterFD(fd
);
85 ok
= dispatcher
->ModifyFD(fd
, handler
, regmask
& ~flag
);
90 wxLogDebug("Failed to unregister %d in direction %d", fd
, d
);
93 // do this even after a failure to unregister it, we still tried...
94 handler
->ClearRegisteredEvent(flag
);
97 wxFDIOManager
*wxAppTraits::GetFDIOManager()
99 static wxFDIOManagerUnix s_manager
;
103 #endif // wxUSE_SOCKETS