Skip to content

Commit d1ab2c1

Browse files
committed
Plugin: modify CBackendThread
1 parent 29777c6 commit d1ab2c1

10 files changed

Lines changed: 60 additions & 44 deletions

Plugins/Player/OperatePlayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ int COperatePlayer::InitialMenu()
121121
QAction* pStart = m_Menu.addAction(
122122
QIcon::fromTheme("media-playback-start"), tr("Start"));
123123
pStart->setCheckable(true);
124-
check = connect(this, &CConnecterPlayer::sigRunning,
124+
check = connect(this, &COperatePlayer::sigRunning,
125125
pStart, &QAction::toggle);
126126
Q_ASSERT(check);
127127
check = connect(pStart, &QAction::toggled,

Plugins/Template/Base/BackendTemplateBase.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ CBackend::OnInitReturnValue CBackendTemplateBase::OnInit()
3636
OnInitReturnValue ret = OnInitReturnValue::NotUseOnProcess;
3737
// TODO: Modify Initialization
3838

39+
// When ready
3940
emit sigRunning();
41+
4042
return ret;
4143
}
4244

@@ -45,6 +47,7 @@ int CBackendTemplateBase::OnClean()
4547
int nRet = 0;
4648
// TODO: Modify clean
4749

50+
// When finished
4851
emit sigFinished();
4952
return nRet;
5053
}
@@ -68,5 +71,7 @@ int CBackendTemplateBase::OnProcess()
6871
{
6972
// TODO: add event dispatch (non-Qt event loop)
7073

74+
// TODO: When an error occurs. emit sigStop();
75+
7176
return 0;
7277
}

Plugins/Template/Base/OperateTemplateBase.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,11 @@ int COperateTemplateBase::Start()
5151
{
5252
int nRet = 0;
5353
// TODO: If backend threads are not needed, modifications are required.
54-
m_pThread = new CBackendThread(this, false);
54+
m_pThread = new CBackendThread(this, false, false);
5555
if(!m_pThread) {
5656
qCritical(log) << "new CBackendThread fail";
5757
return -1;
5858
}
59-
6059
m_pThread->start();
6160
return nRet;
6261
}

Plugins/Template/Desktop/BackendTemplateDesktop.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ CBackend::OnInitReturnValue CBackendTemplateDesktop::OnInit()
3636
OnInitReturnValue ret = OnInitReturnValue::NotUseOnProcess;
3737
// TODO: Modify Initialization
3838

39+
// When ready
3940
emit sigRunning();
41+
4042
return ret;
4143
}
4244

@@ -45,7 +47,6 @@ int CBackendTemplateDesktop::OnClean()
4547
int nRet = 0;
4648
// TODO: Modify clean
4749

48-
emit sigFinished();
4950
return nRet;
5051
}
5152

@@ -67,7 +68,9 @@ int CBackendTemplateDesktop::OnClean()
6768
int CBackendTemplateDesktop::OnProcess()
6869
{
6970
// TODO: add event dispatch (non-Qt event loop)
70-
71+
72+
// TODO: When an error occurs. emit sigStop();
73+
7174
return 0;
7275
}
7376

Plugins/Template/Server/BackendTemplateServer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ int CBackendTemplateServer::OnClean()
6767
int CBackendTemplateServer::OnProcess()
6868
{
6969
// TODO: add event dispatch (non-Qt event loop)
70-
70+
71+
// TODO: When an error occurs. emit sigStop();
72+
7173
return 0;
7274
}
7375

Src/BackendThread.cpp

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

88
static Q_LOGGING_CATEGORY(log, "BackendThread")
99

10-
CBackendThread::CBackendThread(COperate *pOperate, bool bFinishedSignal)
10+
CBackendThread::CBackendThread(COperate *pOperate, bool bRunningSignal, 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_bRunningSignal(bRunningSignal)
1819
, m_bFinishedSignal(bFinishedSignal)
1920
{
2021
qDebug(log) << Q_FUNC_INFO;
@@ -94,6 +95,9 @@ void CBackendThread::run()
9495
emit m_pOperate->sigStop();
9596
emit m_pOperate->sigFinished();
9697
return;
98+
} else {
99+
if(m_bRunningSignal)
100+
emit m_pOperate->sigRunning();
97101
}
98102
}
99103

Src/BackendThread.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,19 @@
1414
class PLUGIN_EXPORT CBackendThread : public QThread
1515
{
1616
Q_OBJECT
17-
17+
1818
public:
1919
/*!
2020
* \brief CBackendThread
2121
* \param pOperate
22+
* \param bRunningSignal
23+
* - true: when the thread is running, emit COperate::sigRunning signal
24+
* - false: not emit signal
2225
* \param bFinishedSignal
23-
* - true: When the thread is quit, emit a `COperate::sigFinished()` signal
26+
* - true: when the thread is quit, emit COperate::sigFinished signal
2427
* - false: not emit signal
2528
*/
26-
explicit CBackendThread(COperate *pOperate = nullptr, bool bFinishedSignal = true);
29+
explicit CBackendThread(COperate *pOperate, bool bRunningSignal, bool bFinishedSignal);
2730
virtual ~CBackendThread() override;
2831
/*!
2932
* \brief Quit
@@ -35,7 +38,7 @@ class PLUGIN_EXPORT CBackendThread : public QThread
3538
virtual void run() override;
3639
COperate* m_pOperate;
3740
CBackend* m_pBackend;
38-
39-
//! When the thread is quit, emit a `COperate::sigFinished()` signal
41+
42+
bool m_bRunningSignal;
4043
bool m_bFinishedSignal;
4144
};

Src/FrmViewer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ CFrmViewer::CFrmViewer(QWidget *parent)
4343
setFocusPolicy(Qt::WheelFocus);
4444
setFocus();
4545

46-
// When the connecter is not connected, don't accept keyboard and mouse event
47-
// When the CConnecter::sigConnected() set true. accept keyboard and mouse event
48-
// \see CConnecter::sigConnected()
46+
// When the operate is not run, don't accept keyboard and mouse event
47+
// When the COperate::sigRunning() set true. accept keyboard and mouse event
48+
// \see COperate::sigRunning()
4949
setEnabled(false);
5050

5151
bool check = connect(&m_TimerRecordVideo, SIGNAL(timeout()),

Src/OperateDesktop.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,11 @@ int COperateDesktop::InitialMenu()
368368
Q_ASSERT(check);
369369
m_Menu.addAction(m_pRecordPause);
370370
#endif
371-
371+
372372
m_Menu.addSeparator();
373373
if(m_pActionSettings)
374374
m_Menu.addAction(m_pActionSettings);
375-
375+
376376
return nRet;
377377
}
378378

@@ -385,15 +385,15 @@ int COperateDesktop::Start()
385385
{
386386
qDebug(log) << Q_FUNC_INFO;
387387
int nRet = 0;
388-
389-
m_pThread = new CBackendThread(this);
388+
// When the operate is not running, the viewer does not accept keyboard and mouse events.
389+
// Therefore, when the backend is ready, the sigRunning signal is emitted by the backend.
390+
// See: CFrmViewer::CFrmViewer(), CFrmViewer::slotRunning()
391+
m_pThread = new CBackendThread(this, false, true);
390392
if(!m_pThread) {
391393
qCritical(log) << "new CBackendThread fail";
392394
return -1;
393395
}
394-
395396
m_pThread->start();
396-
397397
return nRet;
398398
}
399399

Src/OperateServer.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,6 @@ QWidget *COperateServer::GetViewer()
2626
return m_pViewer;
2727
}
2828

29-
int COperateServer::Start()
30-
{
31-
qDebug(log) << Q_FUNC_INFO;
32-
emit sigRunning();
33-
return 0;
34-
}
35-
36-
int COperateServer::Stop()
37-
{
38-
qDebug(log) << Q_FUNC_INFO;
39-
int nRet = 0;
40-
if(m_pActionStart && m_pActionStart->isChecked()) {
41-
bool check = connect(m_pThread, SIGNAL(finished()),
42-
this, SIGNAL(sigFinished()));
43-
Q_ASSERT(check);
44-
m_pActionStart->setChecked(false);
45-
} else
46-
emit sigFinished();
47-
48-
return nRet;
49-
}
50-
5129
int COperateServer::Initial()
5230
{
5331
int nRet = 0;
@@ -85,6 +63,28 @@ int COperateServer::Clean()
8563
return nRet;
8664
}
8765

66+
int COperateServer::Start()
67+
{
68+
qDebug(log) << Q_FUNC_INFO;
69+
emit sigRunning();
70+
return 0;
71+
}
72+
73+
int COperateServer::Stop()
74+
{
75+
qDebug(log) << Q_FUNC_INFO;
76+
int nRet = 0;
77+
if(m_pActionStart && m_pActionStart->isChecked()) {
78+
bool check = connect(m_pThread, SIGNAL(finished()),
79+
this, SIGNAL(sigFinished()));
80+
Q_ASSERT(check);
81+
m_pActionStart->setChecked(false);
82+
} else
83+
emit sigFinished();
84+
85+
return nRet;
86+
}
87+
8888
void COperateServer::slotStart(bool checked)
8989
{
9090
qDebug(log) << Q_FUNC_INFO << m_pActionStart->isChecked();
@@ -107,7 +107,7 @@ void COperateServer::slotStart(bool checked)
107107
m_pActionStart->setToolTip(m_pActionStart->text());
108108
m_pActionStart->setIcon(QIcon::fromTheme("media-playback-stop"));
109109
Q_ASSERT(!m_pThread);
110-
m_pThread = new CBackendThread(this, false);
110+
m_pThread = new CBackendThread(this, false, false);
111111
if(!m_pThread) {
112112
qCritical(log) << "new CBackendThread fail";
113113
return;

0 commit comments

Comments
 (0)