Skip to content

Commit

Permalink
fix issue #3
Browse files Browse the repository at this point in the history
  • Loading branch information
lheric committed Mar 18, 2015
1 parent 1032adb commit d8acf7d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
*.lai
*.la
*.a
*.user
13 changes: 7 additions & 6 deletions src/gitlfrontcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

SINGLETON_PATTERN_IMPLIMENT(GitlFrontController)

GitlFrontController::GitlFrontController()
GitlFrontController::GitlFrontController() :
m_cCmdExeMutex(QMutex::Recursive)
{
m_iMaxEvtInQue = 1000;
subscribeToEvtByName(GITL_EXE_COMMAND_REQUEST_EVENT, MAKE_CALLBACK(GitlFrontController::detonate));
Expand Down Expand Up @@ -50,13 +51,13 @@ bool GitlFrontController::detonate( GitlEvent& rcEvt)
{
/// pending for worker thread execution
m_cEvtQueMutex.lock();
if( m_pcEvtQue.size() >= m_iMaxEvtInQue )
if( m_pcWorkerThreadEvtQue.size() >= m_iMaxEvtInQue )
{
std::cerr << "Too Many Events Pending...Waiting..." << std::endl;
m_cEvtQueNotFull.wait(&m_cEvtQueMutex);
std::cerr << "Event Queue Not Full...Moving on..." << std::endl;
}
m_pcEvtQue.push_back(rcEvt.clone());
m_pcWorkerThreadEvtQue.push_back(rcEvt.clone());
m_cEvtQueMutex.unlock();
m_cEvtQueNotEmpty.wakeAll();
}
Expand Down Expand Up @@ -146,12 +147,12 @@ void GitlFrontController::run()

/// get one event from the waiting queue
m_cEvtQueMutex.lock();
if( m_pcEvtQue.empty() )
if( m_pcWorkerThreadEvtQue.empty() )
{
m_cEvtQueNotEmpty.wait(&m_cEvtQueMutex);
}
GitlEvent* pcEvt = m_pcEvtQue.front();
m_pcEvtQue.pop_front();
GitlEvent* pcEvt = m_pcWorkerThreadEvtQue.front();
m_pcWorkerThreadEvtQue.pop_front();
m_cEvtQueMutex.unlock();
m_cEvtQueNotFull.wakeAll();

Expand Down
4 changes: 2 additions & 2 deletions src/gitlfrontcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ class GitlFrontController : public GitlModual, public QThread

SINGLETON_PATTERN_DECLARE(GitlFrontController)


ADD_CLASS_FIELD_PRIVATE(QList<GitlEvent*>, pcEvtQue)
ADD_CLASS_FIELD_PRIVATE(QList<GitlEvent*>, pcMainThreadEvtQue)
ADD_CLASS_FIELD_PRIVATE(QList<GitlEvent*>, pcWorkerThreadEvtQue)
ADD_CLASS_FIELD_PRIVATE(QMutex, cEvtQueMutex)
ADD_CLASS_FIELD_PRIVATE(QWaitCondition, cEvtQueNotEmpty)
ADD_CLASS_FIELD_PRIVATE(QWaitCondition, cEvtQueNotFull)
Expand Down
33 changes: 33 additions & 0 deletions test/testcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,24 @@ class SecParamCommand : public GitlAbstractCommand

};

class NestedCommand : public GitlAbstractCommand
{
Q_OBJECT
public:
/// Q_INVOKABLE is necessary for constructor
Q_INVOKABLE explicit NestedCommand(QObject *parent = 0):GitlAbstractCommand(parent) {setInWorkerThread(false);}
bool execute(GitlCommandParameter &rcInputArg, GitlCommandParameter &rcOutputArg)
{
GitlIvkCmdEvt cFirstNestedEvt("fir_param_command");
cFirstNestedEvt.dispatch();

GitlIvkCmdEvt cSecondNestedEvt("sec_param_command");
cSecondNestedEvt.dispatch();
return true;
}

};

class MultiParamCommand : public GitlAbstractCommand
{
Q_OBJECT
Expand Down Expand Up @@ -118,6 +136,7 @@ private slots:
pcFC->registerCommand("fir_param_command", &FirParamCommand::staticMetaObject);
pcFC->registerCommand("sec_param_command", &SecParamCommand::staticMetaObject);
pcFC->registerCommand("multi_param_command", &MultiParamCommand::staticMetaObject);
pcFC->registerCommand("nested_command", &NestedCommand::staticMetaObject);

}

Expand Down Expand Up @@ -165,6 +184,20 @@ private slots:

}

void nestedCommandTest()
{
/// view
TestView cView;

/// event (in real case, this event should be dispatch from user interface, i.e. the views)
GitlIvkCmdEvt cRequestEvt("nested_command");
cRequestEvt.dispatch();

/// verify
QVERIFY(cView.getFirString()=="Hello GitlMVC");
QVERIFY(cView.getSecString()=="this is the second param");
}

};


Expand Down

0 comments on commit d8acf7d

Please sign in to comment.