1 #include "otsdaq/WorkLoopManager/WorkLoop.h"
2 #include "otsdaq/Macros/CoutMacros.h"
3 #include "otsdaq/MessageFacility/MessageFacility.h"
5 #include <toolbox/task/WorkLoopFactory.h>
13 #define __MF_SUBJECT__ "Workloop"
15 #define __COUT_HDR__ (std::string("Workloop-") + WorkLoop::workLoopName_ + "\t<>")
18 WorkLoop::WorkLoop(
const std::string& name)
19 : continueWorkLoop_(false)
21 , workLoopType_(
"waiting")
23 , job_(toolbox::task::bind(this, &
WorkLoop::workLoopThread, workLoopName_))
25 __COUT__ <<
"Constructed." << __E__;
29 WorkLoop::~WorkLoop(
void)
31 __COUT__ <<
"Destructor." << __E__;
33 toolbox::task::getWorkLoopFactory()->removeWorkLoop(workLoopName_, workLoopType_);
34 __COUT__ <<
"Destructed." << __E__;
38 void WorkLoop::startWorkLoop(
void)
40 __COUT__ <<
"Starting WorkLoop: " << workLoopName_ << __E__;
41 continueWorkLoop_ =
true;
44 workLoop_ = toolbox::task::getWorkLoopFactory()->getWorkLoop(workLoopName_, workLoopType_);
46 catch(xcept::Exception& e)
48 __COUT__ <<
"ERROR: Can't create WorkLoop job for " << workLoopName_ << __E__;
52 if(workLoop_->isActive())
58 workLoop_->submit(job_);
60 catch(xcept::Exception& e)
62 __COUT__ <<
"ERROR: Can't submit WorkLoop job for " << workLoopName_ << __E__;
68 workLoop_->activate();
70 catch(xcept::Exception& e)
72 __COUT__ <<
"ERROR: Can't activate WorkLoop job for " << workLoopName_ <<
" Very likely because the name " << workLoopName_ <<
" is not unique!"
79 bool WorkLoop::stopWorkLoop()
81 __COUT__ <<
"Stopping WorkLoop: " << workLoopName_ << __E__;
83 continueWorkLoop_ =
false;
86 __COUT__ <<
"MEASSAGE: WorkLoop " << workLoopName_ <<
" was not created at all! This message will be commented in the future" << __E__;
90 __COUT__ <<
"initially workLoop_->isActive() " << (workLoop_->isActive() ?
"yes" :
"no") << __E__;
97 catch(xcept::Exception& e)
99 __COUT__ <<
"WARNING: Can't cancel WorkLoop job for " << workLoopName_ <<
" because probably it has never been activated!" << __E__;
101 __COUT__ <<
"workLoop_->isActive() " << (workLoop_->isActive() ?
"yes" :
"no") << __E__;
107 workLoop_->remove(job_);
109 catch(xcept::Exception& e)
116 __COUT__ <<
"WARNING: Can't remove request WorkLoop: " << workLoopName_ << __E__;
117 __COUT__ <<
"workLoop_->isActive() " << (workLoop_->isActive() ?
"yes" :
"no") << __E__;
120 __COUT__ <<
"Stopped WorkLoop: " << workLoopName_ << __E__;
121 __COUT__ <<
"workLoop_->isActive() " << (workLoop_->isActive() ?
"yes" :
"no") << __E__;
126 bool WorkLoop::isActive(
void)
const {
return workLoop_->isActive() && continueWorkLoop_; }