-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexternalinput.cpp
93 lines (72 loc) · 2.47 KB
/
externalinput.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "externalinput.h"
#include "ui_externalinput.h"
ExternalInput::ExternalInput(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::ExternalInput)
{
ui->setupUi(this);
connect(ui->enableBox,SIGNAL(stateChanged(int)),this,SLOT(enable(int)));
}
ExternalInput::~ExternalInput()
{
delete ui;
}
void ExternalInput::Init(Buffer* buf){
buffer = buf;
}
void ExternalInput::enable(int status){
if (status==2){
QString program = QString(ui->commandEdit->toPlainText()).arg(buffer->width).arg(buffer->height);
//arguments << "-style" << "fusion";
outNum = ui->inputBox->value();
output = (char*)buffer->Open(outNum);
data.clear();
myProcess = new QProcess();
QThread* workThread = new QThread(this);
//myProcess->moveToThread(workThread);
workThread->start();
// connect(myProcess,SIGNAL(readyRead()),this,SLOT(printOutput()));
// connect(myProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(fillBuffer()));
connect(buffer->clock,SIGNAL(timeout()),this,SLOT(fillBuffer()));
connect(myProcess,SIGNAL(readyReadStandardError()),this,SLOT(printOutput()));
connect(myProcess,SIGNAL(finished(int)),this,SLOT(processExit()));
qDebug() << program;
myProcess->start(program);
qDebug()<<"vykonalsom";
// connect(buffer->clock,SIGNAL(timeout()),this,SLOT(newFrame()));
} else {
myProcess->close();
}
}
void ExternalInput::printOutput(){
QString text = myProcess->readAllStandardError();
QString cut = ui->outputBox->toPlainText();
if (text.contains('\r')){
cut.truncate(cut.lastIndexOf('\n',cut.lastIndexOf('\n')-1));
ui->outputBox->clear();
ui->outputBox->appendPlainText(cut);
}
ui->outputBox->appendPlainText(text);
//qDebug() << myProcess->readAllStandardOutput();
}
void ExternalInput::fillBuffer(){
data.append(myProcess->readAllStandardOutput());
if (data.length() >= buffer->buf_len){
memcpy(output, data.data(), buffer->buf_len);
data.remove(0, buffer->buf_len);
buffer->newFrame(ui->inputBox->value());
}
// output
}
void ExternalInput::newFrame(){
if (myProcess->bytesToWrite()==0){
// myProcess->write(input,buffer->buf_len);
}
}
void ExternalInput::processExit(){
ui->enableBox->setChecked(false);
}
void ExternalInput::on_comboBox_currentTextChanged(const QString &arg1)
{
ui->commandEdit->setPlainText(arg1);
}