diff --git a/uhd_cpp/uhd_spectrum/main.cpp b/uhd_cpp/uhd_spectrum/main.cpp index 7593b40bac20b58b0559a981884ae96d7d345202..45388b494568945d68ced86ee54e639e0118be0a 100644 --- a/uhd_cpp/uhd_spectrum/main.cpp +++ b/uhd_cpp/uhd_spectrum/main.cpp @@ -1,4 +1,4 @@ -#include "specwidget.h" +#include "specwidget.h" #ifdef __GNUC__ #include #endif diff --git a/uhd_cpp/uhd_spectrum/specwidget.ui b/uhd_cpp/uhd_spectrum/specwidget.ui index 8b025b048cb5b86de2bd799eae7951543b49b2e6..e3fa71c20f0b51f04ac5d10557da7d422c762b47 100644 --- a/uhd_cpp/uhd_spectrum/specwidget.ui +++ b/uhd_cpp/uhd_spectrum/specwidget.ui @@ -23,10 +23,6 @@ Start - - - :/icons/icons/signal.svg:/icons/icons/signal.svg - @@ -225,8 +221,8 @@ 0 0 - 310 - 450 + 320 + 478 @@ -370,8 +366,8 @@ 0 0 - 310 - 165 + 320 + 478 @@ -534,8 +530,8 @@ 0 0 - 310 - 450 + 320 + 478 @@ -562,8 +558,8 @@ 0 0 - 310 - 450 + 320 + 478 diff --git a/uhd_cpp/uhd_spectrum/stdout_watcher.cpp b/uhd_cpp/uhd_spectrum/stdout_watcher.cpp index 924692c55688079a018cf84fb50a48458bc077d2..3276df93c3d33ce51c14a5d48390e0dba7dc5a27 100644 --- a/uhd_cpp/uhd_spectrum/stdout_watcher.cpp +++ b/uhd_cpp/uhd_spectrum/stdout_watcher.cpp @@ -1,4 +1,4 @@ -#include "stdout_watcher.h" +#include "stdout_watcher.h" #include #include #ifdef __GNUC__ @@ -7,6 +7,11 @@ #include #include #endif +#ifdef _MSVC_LANG +#include +#include +#endif + stdout_watcher::stdout_watcher(QObject *parent) : QThread(parent), m_bStop(false) { @@ -15,8 +20,63 @@ stdout_watcher::stdout_watcher(QObject *parent) : QThread(parent), void stdout_watcher::stop_and_wait() { m_bStop = true; + fprintf (stdout,"Bye!\n"); + fprintf (stderr,"Bye!\n"); wait(); } + +#ifdef _MSVC_LANG +void stdout_watcher::run() +{ + return; + auto pt = [&](FILE * stda,bool stderrb)->void{ + + + HANDLE hOutputReadTmp = 0; + HANDLE hOutputWrite = 0; + + if (!CreatePipe(&hOutputReadTmp,&hOutputWrite,0,0)) + emit evt_stdata("[stdout watcher]:CreatePipe Error.",stderrb); + + int hCrt =_open_osfhandle( (long)hOutputWrite, _O_TEXT ); + FILE *hf = _fdopen( hCrt, "w" ); + *stda = *hf; + int i = setvbuf( stda, NULL, _IONBF, 0 ); + CHAR lpBuffer[1024]; + DWORD nBytesRead; + + while(!m_bStop) + { + if (!ReadFile(hOutputReadTmp, lpBuffer,sizeof(lpBuffer), + &nBytesRead,NULL) || !nBytesRead) + { + if (GetLastError() == ERROR_BROKEN_PIPE) + break; // pipe done - normal exit path. + else + emit evt_stdata("ReadFile",stderrb); + } + + if (nBytesRead >0 ) + { + emit evt_stdata(QByteArray(lpBuffer,nBytesRead),stderrb); + } + } + + fclose(hf); + _close(hCrt); + CloseHandle(hOutputReadTmp); + CloseHandle(hOutputWrite); + + }; + std::thread t1(pt, stderr,true); + std::thread t2(pt, stdout,false); + + t1.join(); + t2.join(); +} +#endif + + #ifdef __GNUC__ void stdout_watcher::run() diff --git a/uhd_cpp/uhd_spectrum/stdout_watcher.h b/uhd_cpp/uhd_spectrum/stdout_watcher.h index 484934b3db31f4dc7d264a252f01fac1e2514c46..cebcd344b12ce5a0dc796c013b2c132c10f97bc1 100644 --- a/uhd_cpp/uhd_spectrum/stdout_watcher.h +++ b/uhd_cpp/uhd_spectrum/stdout_watcher.h @@ -1,8 +1,11 @@ -#ifndef STDOUT_WATCHER_H +#ifndef STDOUT_WATCHER_H #define STDOUT_WATCHER_H #include #include +#ifdef _MSVC_LANG +#include +#endif class stdout_watcher : public QThread { Q_OBJECT @@ -14,6 +17,7 @@ signals: void evt_stdata(QByteArray,bool stderrb); public: std::atomic m_bStop; + }; #endif // STDOUT_WATCHER_H