mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2024-11-17 21:26:04 +00:00
46 lines
1.5 KiB
C++
46 lines
1.5 KiB
C++
#include "logviewermanager.h"
|
|
|
|
LogViewerManager::LogViewerManager(std::shared_ptr<std::iostream> logStream_,
|
|
QPlainTextEdit* logTextEdit_,
|
|
QObject *parent) :
|
|
QObject(parent),
|
|
logStream(logStream_),
|
|
logTextEdit(logTextEdit_),
|
|
controllerForBgThread(nullptr)
|
|
{
|
|
assert(logTextEdit!=nullptr);
|
|
controllerForBgThread=new i2pd::qt::logviewer::Controller(*this);
|
|
}
|
|
|
|
namespace i2pd {
|
|
namespace qt {
|
|
namespace logviewer {
|
|
|
|
QString Worker::pollAndShootATimerForInfiniteRetries() {
|
|
std::shared_ptr<std::iostream> logStream=logViewerManager.getLogStream();
|
|
assert(logStream!=nullptr);
|
|
std::streamsize MAX_SZ=64*1024;
|
|
char*buf=(char*)malloc(MAX_SZ*sizeof(char));
|
|
if(buf==nullptr)return "";
|
|
std::streamsize read=logStream->readsome(buf, MAX_SZ);
|
|
if(read<0)read=0;
|
|
QString ret=QString::fromUtf8(buf, read);
|
|
free(buf);
|
|
return ret;
|
|
}
|
|
|
|
Controller::Controller(LogViewerManager ¶meter1):logViewerManager(parameter1) {
|
|
Worker *worker = new Worker(parameter1);
|
|
worker->moveToThread(&workerThread);
|
|
connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater);
|
|
connect(this, &Controller::operate1, worker, &Worker::doWork1);
|
|
connect(worker, &Worker::resultReady,
|
|
¶meter1, &LogViewerManager::appendPlainText_atGuiThread);
|
|
workerThread.start();
|
|
timerId=startTimer(100/*millis*/);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|