1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/unix/private/executeiohandler.h
3 // Purpose: IO handler class for the FD used by wxExecute() under Unix
4 // Author: Rob Bresalier, Vadim Zeitlin
7 // Copyright: (c) 2013 Rob Bresalier, Vadim Zeitlin
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_UNIX_PRIVATE_EXECUTEIOHANDLER_H_
12 #define _WX_UNIX_PRIVATE_EXECUTEIOHANDLER_H_
14 #include "wx/private/streamtempinput.h"
16 // This class handles IO events on the pipe FD connected to the child process
17 // stdout/stderr and is used by wxExecute().
19 // Currently it can derive from either wxEventLoopSourceHandler or
20 // wxFDIOHandler depending on the kind of dispatcher/event loop it is used
21 // with. In the future, when we get rid of wxFDIOHandler entirely, it will
22 // derive from wxEventLoopSourceHandler only.
24 class wxExecuteIOHandlerBase
: public T
27 wxExecuteIOHandlerBase(int fd
, wxStreamTempInputBuffer
& buf
)
31 m_callbackDisabled
= false;
34 // Called when the associated descriptor is available for reading.
35 virtual void OnReadWaiting()
37 // Sync process, process all data coming at us from the pipe so that
38 // the pipe does not get full and cause a deadlock situation.
45 // These methods are never called as we only monitor the associated FD for
46 // reading, but we still must implement them as they're pure virtual in the
48 virtual void OnWriteWaiting() { }
49 virtual void OnExceptionWaiting() { }
51 // Disable any future calls to our OnReadWaiting(), can be called when
52 // we're sure that no more input is forthcoming.
53 void DisableCallback()
55 if ( !m_callbackDisabled
)
57 m_callbackDisabled
= true;
67 virtual void DoDisable() = 0;
69 wxStreamTempInputBuffer
& m_buf
;
71 // If true, DisableCallback() had been already called.
72 bool m_callbackDisabled
;
74 wxDECLARE_NO_COPY_CLASS(wxExecuteIOHandlerBase
);
77 // This is the version used with wxFDIODispatcher, which must be passed to the
78 // ctor in order to register this handler with it.
79 class wxExecuteFDIOHandler
: public wxExecuteIOHandlerBase
<wxFDIOHandler
>
82 wxExecuteFDIOHandler(wxFDIODispatcher
& dispatcher
,
84 wxStreamTempInputBuffer
& buf
)
85 : wxExecuteIOHandlerBase
<wxFDIOHandler
>(fd
, buf
),
86 m_dispatcher(dispatcher
)
88 dispatcher
.RegisterFD(fd
, this, wxFDIO_INPUT
);
91 virtual ~wxExecuteFDIOHandler()
97 virtual void DoDisable()
99 m_dispatcher
.UnregisterFD(m_fd
);
102 wxFDIODispatcher
& m_dispatcher
;
104 wxDECLARE_NO_COPY_CLASS(wxExecuteFDIOHandler
);
107 // And this is the version used with an event loop. As AddSourceForFD() is
108 // static, we don't require passing the event loop to the ctor but an event
109 // loop must be running to handle our events.
110 class wxExecuteEventLoopSourceHandler
111 : public wxExecuteIOHandlerBase
<wxEventLoopSourceHandler
>
114 wxExecuteEventLoopSourceHandler(int fd
, wxStreamTempInputBuffer
& buf
)
115 : wxExecuteIOHandlerBase
<wxEventLoopSourceHandler
>(fd
, buf
)
117 m_source
= wxEventLoop::AddSourceForFD(fd
, this, wxEVENT_SOURCE_INPUT
);
120 virtual ~wxExecuteEventLoopSourceHandler()
126 virtual void DoDisable()
132 wxEventLoopSource
* m_source
;
134 wxDECLARE_NO_COPY_CLASS(wxExecuteEventLoopSourceHandler
);
137 #endif // _WX_UNIX_PRIVATE_EXECUTEIOHANDLER_H_