| 1 |
////////////////////////////////////////////////////////////////////////////// |
| 2 |
////////////////////////////////////////////////////////////////////////////// |
| 3 |
// |
| 4 |
// copyright : (C) 2009 by Eran Ifrah |
| 5 |
// file name : unixprocess_impl.h |
| 6 |
// |
| 7 |
// ------------------------------------------------------------------------- |
| 8 |
// A |
| 9 |
// _____ _ _ _ _ |
| 10 |
// / __ \ | | | | (_) | |
| 11 |
// | / \/ ___ __| | ___| | _| |_ ___ |
| 12 |
// | | / _ \ / _ |/ _ \ | | | __/ _ ) |
| 13 |
// | \__/\ (_) | (_| | __/ |___| | || __/ |
| 14 |
// \____/\___/ \__,_|\___\_____/_|\__\___| |
| 15 |
// |
| 16 |
// F i l e |
| 17 |
// |
| 18 |
// This program is free software; you can redistribute it and/or modify |
| 19 |
// it under the terms of the GNU General Public License as published by |
| 20 |
// the Free Software Foundation; either version 2 of the License, or |
| 21 |
// (at your option) any later version. |
| 22 |
// |
| 23 |
////////////////////////////////////////////////////////////////////////////// |
| 24 |
////////////////////////////////////////////////////////////////////////////// |
| 25 |
|
| 26 |
#ifndef __unixprocessimpl__ |
| 27 |
#define __unixprocessimpl__ |
| 28 |
|
| 29 |
#if defined(__WXMAC__) || defined(__WXGTK__) |
| 30 |
#include "codelite_exports.h" |
| 31 |
#include "processreaderthread.h" |
| 32 |
#include "asyncprocess.h" |
| 33 |
|
| 34 |
class wxTerminal; |
| 35 |
|
| 36 |
class WXDLLIMPEXP_CL UnixProcessImpl : public IProcess |
| 37 |
{ |
| 38 |
int m_readHandle; |
| 39 |
int m_stderrHandle = wxNOT_FOUND; |
| 40 |
int m_writeHandle; |
| 41 |
wxString m_tty; |
| 42 |
friend class wxTerminal; |
| 43 |
|
| 44 |
private: |
| 45 |
void StartReaderThread(); |
| 46 |
bool ReadFromFd(int fd, fd_set& rset, wxString& output); |
| 47 |
|
| 48 |
public: |
| 49 |
UnixProcessImpl(wxEvtHandler* parent); |
| 50 |
virtual ~UnixProcessImpl(); |
| 51 |
|
| 52 |
static IProcess* Execute(wxEvtHandler* parent, const wxArrayString& args, size_t flags, |
| 53 |
const wxString& workingDirectory = wxEmptyString, IProcessCallback* cb = NULL); |
| 54 |
|
| 55 |
static IProcess* Execute(wxEvtHandler* parent, const wxString& cmd, size_t flags, |
| 56 |
const wxString& workingDirectory = wxEmptyString, IProcessCallback* cb = NULL); |
| 57 |
|
| 58 |
void SetReadHandle(const int& readHandle) { this->m_readHandle = readHandle; } |
| 59 |
void SetWriteHandler(const int& writeHandler) { this->m_writeHandle = writeHandler; } |
| 60 |
int GetReadHandle() const { return m_readHandle; } |
| 61 |
int GetStderrHandle() const { return m_stderrHandle; } |
| 62 |
int GetWriteHandle() const { return m_writeHandle; } |
| 63 |
void SetStderrHandle(int stderrHandle) { this->m_stderrHandle = stderrHandle; } |
| 64 |
|
| 65 |
void SetTty(const wxString& tty) { this->m_tty = tty; } |
| 66 |
const wxString& GetTty() const { return m_tty; } |
| 67 |
|
| 68 |
public: |
| 69 |
virtual void Cleanup(); |
| 70 |
virtual bool IsAlive(); |
| 71 |
virtual bool Read(wxString& buff, wxString& buffErr); |
| 72 |
virtual bool Write(const wxString& buff); |
| 73 |
virtual bool Write(const std::string& buff); |
| 74 |
virtual bool WriteRaw(const wxString& buff); |
| 75 |
virtual bool WriteRaw(const std::string& buff); |
| 76 |
virtual void Terminate(); |
| 77 |
virtual bool WriteToConsole(const wxString& buff); |
| 78 |
virtual void Detach(); |
| 79 |
virtual void Signal(wxSignal sig); |
| 80 |
}; |
| 81 |
#endif //#if defined(__WXMAC )||defined(__WXGTK__) |
| 82 |
#endif // __unixprocessimpl__ |