-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
592 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
#ifndef EXTENDEDFILEBUFFER_H | ||
#define EXTENDEDFILEBUFFER_H | ||
|
||
#include "ExtendedStdBuffer.h" | ||
#include <src/Logging.h> | ||
|
||
#include <QProcess> | ||
#include <iostream> | ||
|
||
|
||
class ExtendedProcFileBuffer : public QObject, public std::basic_streambuf<char> { | ||
Q_OBJECT | ||
public: | ||
|
||
ExtendedProcFileBuffer(QProcess* pProcess, QProcess::ProcessChannel eChannel) | ||
{ | ||
|
||
this->m_pParentProcess = new sParentProcess(); | ||
this->m_pParentProcess->pProcess = pProcess; | ||
this->m_pParentProcess->eChannel = eChannel; | ||
|
||
switch (eChannel) | ||
{ | ||
default: | ||
|
||
case QProcess::ProcessChannel::StandardOutput: | ||
|
||
QObject::connect( pProcess, &QProcess::readyReadStandardOutput, this, &ExtendedProcFileBuffer::receiveProcData ); | ||
|
||
|
||
break; | ||
case QProcess::ProcessChannel::StandardError : | ||
|
||
QObject::connect( pProcess, &QProcess::readyReadStandardError, this, &ExtendedProcFileBuffer::receiveProcData ); | ||
|
||
break; | ||
|
||
} | ||
|
||
} | ||
|
||
~ExtendedProcFileBuffer() | ||
{ | ||
|
||
if (this->m_pParentProcess != NULL) | ||
{ | ||
delete m_pParentProcess; | ||
} | ||
|
||
} | ||
|
||
public slots: | ||
|
||
virtual void receiveProcData() | ||
{ | ||
|
||
if (this->m_pParentProcess == NULL) | ||
{ | ||
LOGERROR("No parent process given!") | ||
return; | ||
} | ||
|
||
|
||
QByteArray oArray; | ||
|
||
switch (this->m_pParentProcess->eChannel) | ||
{ | ||
default: | ||
|
||
case QProcess::StandardOutput: | ||
|
||
oArray = this->m_pParentProcess->pProcess->readAllStandardOutput(); | ||
break; | ||
|
||
case QProcess::StandardError: | ||
|
||
oArray = this->m_pParentProcess->pProcess->readAllStandardError(); | ||
break; | ||
} | ||
|
||
|
||
QString sString = QString(oArray); | ||
|
||
emit sendText(sString); | ||
} | ||
|
||
public slots: | ||
void transferText(QString sString) | ||
{ | ||
emit sendText(sString); | ||
} | ||
|
||
signals: | ||
void sendText(QString sString); | ||
|
||
protected: | ||
virtual int_type overflow(int_type v) | ||
{ | ||
if (v == '\n') | ||
{ | ||
} | ||
return v; | ||
} | ||
|
||
virtual std::streamsize xsputn(const char *p, std::streamsize n) | ||
{ | ||
|
||
std::string sStdText(p, n); | ||
|
||
if ((p[n] == 4) || (p[n] == 0)) | ||
{ | ||
sStdText.append("\n"); | ||
} | ||
|
||
QString sText(sStdText.c_str()); | ||
|
||
this->transferText(sText); | ||
|
||
return n; | ||
} | ||
|
||
|
||
protected: | ||
|
||
struct sParentProcess | ||
{ | ||
QProcess* pProcess; | ||
QProcess::ProcessChannel eChannel; | ||
}; | ||
|
||
|
||
|
||
|
||
sParentProcess* m_pParentProcess = NULL; | ||
|
||
}; | ||
|
||
|
||
#endif // EXTENDEDFILEBUFFER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
#ifndef EXTENDEDTHREADFILEBUFFER_H | ||
#define EXTENDEDTHREADFILEBUFFER_H | ||
|
||
#include "ExecuteThread.h" | ||
#include "ExtendedStdBuffer.h" | ||
#include <src/Logging.h> | ||
|
||
#include <QProcess> | ||
#include <iostream> | ||
|
||
|
||
class ExtendedThreadFileBuffer : public QObject, public std::basic_streambuf<char> { | ||
Q_OBJECT | ||
public: | ||
|
||
ExtendedThreadFileBuffer(ExecuteThread* pThread, QProcess::ProcessChannel eChannel) | ||
{ | ||
|
||
this->m_pParentThread = new sParentThread(); | ||
this->m_pParentThread->pThread = pThread; | ||
this->m_pParentThread->eChannel = eChannel; | ||
|
||
switch (eChannel) | ||
{ | ||
default: | ||
|
||
case QProcess::ProcessChannel::StandardOutput: | ||
|
||
QObject::connect( pThread, &ExecuteThread::readyReadStandardOutput, this, &ExtendedThreadFileBuffer::receiveProcData ); | ||
|
||
|
||
break; | ||
case QProcess::ProcessChannel::StandardError : | ||
|
||
QObject::connect( pThread, &ExecuteThread::readyReadStandardError, this, &ExtendedThreadFileBuffer::receiveProcData ); | ||
|
||
break; | ||
|
||
} | ||
} | ||
|
||
~ExtendedThreadFileBuffer() | ||
{ | ||
|
||
if (this->m_pParentThread != NULL) | ||
{ | ||
delete m_pParentThread; | ||
m_pParentThread = NULL; | ||
} | ||
|
||
} | ||
virtual void stopTransmissions() | ||
{ | ||
m_bTransmissionAllowed = false; | ||
} | ||
|
||
public slots: | ||
|
||
virtual void receiveProcData() | ||
{ | ||
|
||
if (this->m_pParentThread == NULL) | ||
{ | ||
LOGERROR("No parent process given!") | ||
return; | ||
} | ||
|
||
|
||
QByteArray oArray; | ||
|
||
switch (this->m_pParentThread->eChannel) | ||
{ | ||
default: | ||
|
||
case QProcess::StandardOutput: | ||
|
||
oArray = this->m_pParentThread->pThread->readAllStandardOutput(); | ||
break; | ||
|
||
case QProcess::StandardError: | ||
|
||
oArray = this->m_pParentThread->pThread->readAllStandardError(); | ||
break; | ||
} | ||
|
||
|
||
QString sString = QString(oArray); | ||
|
||
|
||
if (m_bTransmissionAllowed) | ||
{ | ||
emit sendText(sString); | ||
} | ||
|
||
} | ||
|
||
public slots: | ||
void transferText(QString sString) | ||
{ | ||
emit sendText(sString); | ||
} | ||
|
||
signals: | ||
void sendText(QString sString); | ||
|
||
protected: | ||
virtual int_type overflow(int_type v) | ||
{ | ||
if (v == '\n') | ||
{ | ||
} | ||
return v; | ||
} | ||
|
||
virtual std::streamsize xsputn(const char *p, std::streamsize n) | ||
{ | ||
|
||
std::string sStdText(p, n); | ||
|
||
if ((p[n] == 4) || (p[n] == 0)) | ||
{ | ||
sStdText.append("\n"); | ||
} | ||
|
||
QString sText(sStdText.c_str()); | ||
|
||
this->transferText(sText); | ||
|
||
return n; | ||
} | ||
|
||
|
||
|
||
protected: | ||
|
||
struct sParentThread | ||
{ | ||
ExecuteThread* pThread; | ||
QProcess::ProcessChannel eChannel; | ||
}; | ||
|
||
|
||
bool m_bTransmissionAllowed = true; | ||
|
||
sParentThread* m_pParentThread = NULL; | ||
|
||
}; | ||
|
||
|
||
#endif // EXTENDEDTHREADFILEBUFFER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.