Skip to content

Commit d8acf7d

Browse files
committed
fix issue #3
1 parent 1032adb commit d8acf7d

File tree

4 files changed

+43
-8
lines changed

4 files changed

+43
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
*.lai
1212
*.la
1313
*.a
14+
*.user

src/gitlfrontcontroller.cpp

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

1010
SINGLETON_PATTERN_IMPLIMENT(GitlFrontController)
1111

12-
GitlFrontController::GitlFrontController()
12+
GitlFrontController::GitlFrontController() :
13+
m_cCmdExeMutex(QMutex::Recursive)
1314
{
1415
m_iMaxEvtInQue = 1000;
1516
subscribeToEvtByName(GITL_EXE_COMMAND_REQUEST_EVENT, MAKE_CALLBACK(GitlFrontController::detonate));
@@ -50,13 +51,13 @@ bool GitlFrontController::detonate( GitlEvent& rcEvt)
5051
{
5152
/// pending for worker thread execution
5253
m_cEvtQueMutex.lock();
53-
if( m_pcEvtQue.size() >= m_iMaxEvtInQue )
54+
if( m_pcWorkerThreadEvtQue.size() >= m_iMaxEvtInQue )
5455
{
5556
std::cerr << "Too Many Events Pending...Waiting..." << std::endl;
5657
m_cEvtQueNotFull.wait(&m_cEvtQueMutex);
5758
std::cerr << "Event Queue Not Full...Moving on..." << std::endl;
5859
}
59-
m_pcEvtQue.push_back(rcEvt.clone());
60+
m_pcWorkerThreadEvtQue.push_back(rcEvt.clone());
6061
m_cEvtQueMutex.unlock();
6162
m_cEvtQueNotEmpty.wakeAll();
6263
}
@@ -146,12 +147,12 @@ void GitlFrontController::run()
146147

147148
/// get one event from the waiting queue
148149
m_cEvtQueMutex.lock();
149-
if( m_pcEvtQue.empty() )
150+
if( m_pcWorkerThreadEvtQue.empty() )
150151
{
151152
m_cEvtQueNotEmpty.wait(&m_cEvtQueMutex);
152153
}
153-
GitlEvent* pcEvt = m_pcEvtQue.front();
154-
m_pcEvtQue.pop_front();
154+
GitlEvent* pcEvt = m_pcWorkerThreadEvtQue.front();
155+
m_pcWorkerThreadEvtQue.pop_front();
155156
m_cEvtQueMutex.unlock();
156157
m_cEvtQueNotFull.wakeAll();
157158

src/gitlfrontcontroller.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ class GitlFrontController : public GitlModual, public QThread
6767

6868
SINGLETON_PATTERN_DECLARE(GitlFrontController)
6969

70-
71-
ADD_CLASS_FIELD_PRIVATE(QList<GitlEvent*>, pcEvtQue)
70+
ADD_CLASS_FIELD_PRIVATE(QList<GitlEvent*>, pcMainThreadEvtQue)
71+
ADD_CLASS_FIELD_PRIVATE(QList<GitlEvent*>, pcWorkerThreadEvtQue)
7272
ADD_CLASS_FIELD_PRIVATE(QMutex, cEvtQueMutex)
7373
ADD_CLASS_FIELD_PRIVATE(QWaitCondition, cEvtQueNotEmpty)
7474
ADD_CLASS_FIELD_PRIVATE(QWaitCondition, cEvtQueNotFull)

test/testcase.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,24 @@ class SecParamCommand : public GitlAbstractCommand
8989

9090
};
9191

92+
class NestedCommand : public GitlAbstractCommand
93+
{
94+
Q_OBJECT
95+
public:
96+
/// Q_INVOKABLE is necessary for constructor
97+
Q_INVOKABLE explicit NestedCommand(QObject *parent = 0):GitlAbstractCommand(parent) {setInWorkerThread(false);}
98+
bool execute(GitlCommandParameter &rcInputArg, GitlCommandParameter &rcOutputArg)
99+
{
100+
GitlIvkCmdEvt cFirstNestedEvt("fir_param_command");
101+
cFirstNestedEvt.dispatch();
102+
103+
GitlIvkCmdEvt cSecondNestedEvt("sec_param_command");
104+
cSecondNestedEvt.dispatch();
105+
return true;
106+
}
107+
108+
};
109+
92110
class MultiParamCommand : public GitlAbstractCommand
93111
{
94112
Q_OBJECT
@@ -118,6 +136,7 @@ private slots:
118136
pcFC->registerCommand("fir_param_command", &FirParamCommand::staticMetaObject);
119137
pcFC->registerCommand("sec_param_command", &SecParamCommand::staticMetaObject);
120138
pcFC->registerCommand("multi_param_command", &MultiParamCommand::staticMetaObject);
139+
pcFC->registerCommand("nested_command", &NestedCommand::staticMetaObject);
121140

122141
}
123142

@@ -165,6 +184,20 @@ private slots:
165184

166185
}
167186

187+
void nestedCommandTest()
188+
{
189+
/// view
190+
TestView cView;
191+
192+
/// event (in real case, this event should be dispatch from user interface, i.e. the views)
193+
GitlIvkCmdEvt cRequestEvt("nested_command");
194+
cRequestEvt.dispatch();
195+
196+
/// verify
197+
QVERIFY(cView.getFirString()=="Hello GitlMVC");
198+
QVERIFY(cView.getSecString()=="this is the second param");
199+
}
200+
168201
};
169202

170203

0 commit comments

Comments
 (0)