From e8b65c04d2a7cfa38f4c03aed05085c09c36afc1 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Mon, 22 Feb 2016 09:41:09 -0500 Subject: [PATCH] Update the dispatcher class to return a pointer to the newly created DProcess object so that the requestor can connect to various process signals as needed. --- src/server/Dispatcher.cpp | 27 +++++++++++++++------------ src/server/Dispatcher.h | 12 ++++++------ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/server/Dispatcher.cpp b/src/server/Dispatcher.cpp index 98b1ae3..74e72e9 100644 --- a/src/server/Dispatcher.cpp +++ b/src/server/Dispatcher.cpp @@ -109,27 +109,29 @@ void Dispatcher::stop(){ } //Overloaded Main Calling Functions (single command, or multiple in-order commands) -void Dispatcher::queueProcess(QString ID, QString cmd){ - queueProcess(NO_QUEUE, ID, QStringList() << cmd); +DProcess* Dispatcher::queueProcess(QString ID, QString cmd){ + return queueProcess(NO_QUEUE, ID, QStringList() << cmd); } -void Dispatcher::queueProcess(QString ID, QStringList cmds){ - queueProcess(NO_QUEUE, ID, cmds); +DProcess* Dispatcher::queueProcess(QString ID, QStringList cmds){ + return queueProcess(NO_QUEUE, ID, cmds); } -void Dispatcher::queueProcess(Dispatcher::PROC_QUEUE queue, QString ID, QString cmd){ - queueProcess(queue, ID, QStringList() << cmd); +DProcess* Dispatcher::queueProcess(Dispatcher::PROC_QUEUE queue, QString ID, QString cmd){ + return queueProcess(queue, ID, QStringList() << cmd); } -void Dispatcher::queueProcess(Dispatcher::PROC_QUEUE queue, QString ID, QStringList cmds){ +DProcess* Dispatcher::queueProcess(Dispatcher::PROC_QUEUE queue, QString ID, QStringList cmds){ //This is the primary queueProcess() function - all the overloads end up here to do the actual work //For multi-threading, need to emit a signal/slot for this action (object creations need to be in same thread as parent) qDebug() << "Queue Process:" << queue << ID << cmds; - emit mkProcs(queue, ID, cmds); + DProcess *P = createProcess(ID, cmds); + emit mkProcs(queue, P); + return P; } // === PRIVATE === //Simplification routine for setting up a process DProcess* Dispatcher::createProcess(QString ID, QStringList cmds){ - DProcess* P = new DProcess(); - P->moveToThread(this->thread()); + DProcess *P = new DProcess(); + //P->moveToThread(this->thread()); P->cmds = cmds; P->ID = ID; connect(P, SIGNAL(ProcFinished(QString)), this, SLOT(ProcFinished(QString)) ); @@ -137,9 +139,10 @@ DProcess* Dispatcher::createProcess(QString ID, QStringList cmds){ } // === PRIVATE SLOTS === -void Dispatcher::mkProcs(Dispatcher::PROC_QUEUE queue, QString ID, QStringList cmds){ +void Dispatcher::mkProcs(Dispatcher::PROC_QUEUE queue, DProcess *P){ //qDebug() << " - Create Process:" << queue << ID << cmds; - DProcess *P = createProcess(ID, cmds); + //DProcess *P = createProcess(ID, cmds); + P->moveToThread(this->thread()); QList list; if(!HASH.contains(queue)){ HASH.insert(queue, list); } //insert an empty list HASH[queue] << P; //add this proc to the end of the list diff --git a/src/server/Dispatcher.h b/src/server/Dispatcher.h index 78748e2..e20a7d1 100644 --- a/src/server/Dispatcher.h +++ b/src/server/Dispatcher.h @@ -61,10 +61,10 @@ public slots: void stop(); //save any currently-unrun processes for next time //Main Calling Functions (single command, or multiple in-order commands) - void queueProcess(QString ID, QString cmd); //uses NO_QUEUE - void queueProcess(QString ID, QStringList cmds); //uses NO_QUEUE - void queueProcess(Dispatcher::PROC_QUEUE, QString ID, QString cmd); - void queueProcess(Dispatcher::PROC_QUEUE, QString ID, QStringList cmds); + DProcess* queueProcess(QString ID, QString cmd); //uses NO_QUEUE + DProcess* queueProcess(QString ID, QStringList cmds); //uses NO_QUEUE + DProcess* queueProcess(Dispatcher::PROC_QUEUE, QString ID, QString cmd); + DProcess* queueProcess(Dispatcher::PROC_QUEUE, QString ID, QStringList cmds); private: // Queue file @@ -77,7 +77,7 @@ private: DProcess* createProcess(QString ID, QStringList cmds); private slots: - void mkProcs(Dispatcher::PROC_QUEUE, QString ID, QStringList cmds); + void mkProcs(Dispatcher::PROC_QUEUE, DProcess *P); void ProcFinished(QString ID); void CheckQueues(); @@ -87,7 +87,7 @@ signals: void DispatchStarting(QString ID); //Signals for private usage - void mkprocs(Dispatcher::PROC_QUEUE, QString ID, QStringList cmds); + void mkprocs(Dispatcher::PROC_QUEUE, DProcess*); };