-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogresswriterworker.cpp
More file actions
103 lines (85 loc) · 1.84 KB
/
progresswriterworker.cpp
File metadata and controls
103 lines (85 loc) · 1.84 KB
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
94
95
96
97
98
99
100
101
102
103
#include "progresswriterworker.h"
#include "general.h"
#include <QTimer>
#include <QThread>
#include <QCoreApplication>
ProgressWriterWorker::ProgressWriterWorker(QObject *parent)
: QObject{parent}
{
}
ProgressWriterWorker::~ProgressWriterWorker()
{
if (m_ptr_named_pipe != nullptr)
{
delete m_ptr_named_pipe;
}
}
void ProgressWriterWorker::setInputFileName(const QString file_name, bool named)
{
this->m_file_name = file_name;
this->m_named = named;
}
void ProgressWriterWorker::setHandler(progress_writer_handler handler)
{
m_handler = handler;
}
bool ProgressWriterWorker::isPipeExist()
{
if (this->m_ptr_named_pipe == nullptr)
{
return false;
}
return this->m_ptr_named_pipe->isExist();
}
bool ProgressWriterWorker::createPipe()
{
if (this->m_ptr_named_pipe != nullptr)
{
delete this->m_ptr_named_pipe;
}
this->m_ptr_named_pipe = Factory::createNamedPipeObject(this->m_file_name);
if (this->m_ptr_named_pipe != nullptr)
{
m_ptr_named_pipe->setName(m_file_name);
return true;
}
return false;
}
void ProgressWriterWorker::writePipe(const QString content)
{
if(!isPipeExist())
{
return;
}
m_ptr_named_pipe->pipeWrite(content);
}
void ProgressWriterWorker::nextStep()
{
if (m_handler == nullptr)
{
return;
}
m_handler(this);
}
void ProgressWriterWorker::startJob()
{
set_thread_name(m_file_name + " writer thread");
if(!createPipe())
{
qDebug()<<"error creation pipe adapter"<<endl;
endJob();
return;
}
nextStep();
}
bool ProgressWriterWorker::isFinishing()
{
return m_finishing;
}
void ProgressWriterWorker::endJob()
{
qDebug()<<"ending writer job"<<endl;
m_finishing = true;
QThread * current = QThread::currentThread();
current->quit();
}