Skip to content

Commit e7efbf0

Browse files
committed
Plugins::FtpServer: add process error
1 parent 69651a5 commit e7efbf0

File tree

6 files changed

+48
-15
lines changed

6 files changed

+48
-15
lines changed

Plugins/FtpServer/BackendFtpServer.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,13 @@ CBackend::OnInitReturnValue CBackendFtpServer::OnInit()
5555
}
5656
}
5757
if(bListen) {
58-
qInfo(log) << "The ftp server listen in" << m_Para->GetPort();
58+
QString szMsg = tr("Ftp server listen in %1").arg(m_Para->GetPort());
59+
qInfo(log) << szMsg;
60+
emit sigInformation(szMsg);
5961
} else {
60-
QString szErr = tr("The ftp server is not listening in %1").arg(m_Para->GetPort());
62+
QString szErr = tr("Ftp server is not listening in %1").arg(m_Para->GetPort());
6163
emit sigError(-1, szErr);
64+
return OnInitReturnValue::Fail;
6265
}
6366
return OnInitReturnValue::NotUseOnProcess;
6467
}

Plugins/FtpServer/OperateFtpServer.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ QSharedPointer<CParameterFtpServer> COperateFtpServer::GetParameter()
141141
void COperateFtpServer::slotStart(bool checked)
142142
{
143143
qDebug(log) << Q_FUNC_INFO << m_pStart->isChecked();
144+
bool check = false;
144145
if(!checked) {
145146
m_pStart->setText(tr("Start server"));
146147
m_pStart->setToolTip(m_pStart->text());
@@ -163,6 +164,10 @@ void COperateFtpServer::slotStart(bool checked)
163164
qCritical(log) << "new CBackendThread fail";
164165
return;
165166
}
166-
167+
check = connect(this, &COperateFtpServer::sigError,
168+
this, [this](const int nError, const QString &szError){
169+
m_pStart->setChecked(false);
170+
});
171+
Q_ASSERT(check);
167172
m_pThread->start();
168173
}

Src/Backend.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
static Q_LOGGING_CATEGORY(log, "Operate")
99

10-
CBackend::CBackend(COperate *pOperate)
10+
CBackend::CBackend(COperate *pOperate, bool bStopSignal)
1111
: QObject() // Because it's in a different thread with pOperate
12+
, m_bStopSignal(bStopSignal)
1213
{
1314
qDebug(log) << Q_FUNC_INFO;
1415
SetConnect(pOperate);
@@ -127,9 +128,11 @@ void CBackend::slotTimeOut()
127128
qCritical(log) << "Process fail";
128129
emit sigError(-3, "Process fail");
129130
}
130-
131-
// Error or stop, must notify user disconnect it
132-
emit sigStop();
131+
132+
if(m_bStopSignal) {
133+
// Error or stop, must notify user disconnect it
134+
emit sigStop();
135+
}
133136
}
134137

135138
int CBackend::OnProcess()

Src/Backend.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,15 @@ class PLUGIN_EXPORT CBackend : public QObject
4242
{
4343
Q_OBJECT
4444
public:
45-
explicit CBackend(COperate *pOperate = nullptr);
45+
/*!
46+
* \brief CBackend
47+
* \param pOperate
48+
* \param bStopSignal
49+
* - true: When an error occurs, emit a `COperate::sigStop()` signal
50+
* - false: not emit signal
51+
*
52+
*/
53+
explicit CBackend(COperate *pOperate = nullptr, bool bStopSignal = true);
4654
virtual ~CBackend();
4755

4856
public:
@@ -264,4 +272,7 @@ protected Q_SLOTS:
264272

265273
private:
266274
int SetConnect(COperate* pOperate);
275+
276+
//! When an error occurs, emit a `COperate::sigStop()` signal
277+
bool m_bStopSignal;
267278
};

Src/BackendThread.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
static Q_LOGGING_CATEGORY(log, "BackendThread")
99

10-
CBackendThread::CBackendThread(COperate *pOperate, bool bSingle)
10+
CBackendThread::CBackendThread(COperate *pOperate, bool bFinishedSignal)
1111
// Note that the parent object pointer cannot be set here.
1212
// If set the parent, the object is also deleted
1313
// when the parent object (CConnecterThread) is destroyed.
1414
// Because it is deleted when it is finished.
1515
: QThread()
1616
, m_pOperate(pOperate)
1717
, m_pBackend(nullptr)
18-
, m_bSignal(bSingle)
18+
, m_bFinishedSignal(bFinishedSignal)
1919
{
2020
qDebug(log) << Q_FUNC_INFO;
2121
bool check = false;
@@ -79,7 +79,7 @@ void CBackendThread::run()
7979
if(!m_pBackend || !bRet)
8080
{
8181
qCritical(log) << "InstanceBackend fail";
82-
if(m_bSignal) {
82+
if(m_bFinishedSignal) {
8383
emit m_pOperate->sigStop();
8484
emit m_pOperate->sigFinished();
8585
}
@@ -93,7 +93,7 @@ void CBackendThread::run()
9393
m_pBackend->Stop();
9494
m_pBackend->deleteLater();
9595
m_pBackend = nullptr;
96-
if(m_bSignal) {
96+
if(m_bFinishedSignal) {
9797
emit m_pOperate->sigStop();
9898
emit m_pOperate->sigFinished();
9999
}
@@ -108,7 +108,7 @@ void CBackendThread::run()
108108
m_pBackend->deleteLater();
109109
}
110110

111-
if(m_bSignal)
111+
if(m_bFinishedSignal)
112112
emit m_pOperate->sigFinished();
113113

114114
qDebug(log) << Q_FUNC_INFO << "end";

Src/BackendThread.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,28 @@
1414
class PLUGIN_EXPORT CBackendThread : public QThread
1515
{
1616
Q_OBJECT
17+
1718
public:
18-
explicit CBackendThread(COperate *pOperate = nullptr, bool bSignal = true);
19+
/*!
20+
* \brief CBackendThread
21+
* \param pOperate
22+
* \param bFinishedSignal
23+
* - true: When an error occurs, emit a `COperate::sigFinished()` signal
24+
* - false: not emit signal
25+
*/
26+
explicit CBackendThread(COperate *pOperate = nullptr, bool bFinishedSignal = true);
1927
virtual ~CBackendThread() override;
2028
/*!
2129
* \brief Quit
2230
* \note Use this replace QThread::quit, QThread::exit, QThread::terminate
2331
*/
2432
virtual void quit();
33+
2534
protected:
2635
virtual void run() override;
2736
COperate* m_pOperate;
2837
CBackend* m_pBackend;
29-
bool m_bSignal;
38+
39+
//! When an error occurs, emit a `COperate::sigFinished()` signal
40+
bool m_bFinishedSignal;
3041
};

0 commit comments

Comments
 (0)