Skip to content
Snippets Groups Projects
Commit dc33baaa authored by Martin Killenberg's avatar Martin Killenberg
Browse files

changed updater to run in its own thread. Tests still using doocs update,...

changed updater to run in its own thread. Tests still using doocs update, which is just doing an insanely long sleep of 1 second.
parent 8cba27de
No related branches found
No related tags found
No related merge requests found
...@@ -30,7 +30,8 @@ class CSAdapterEqFct : public EqFct , boost::noncopyable { ...@@ -30,7 +30,8 @@ class CSAdapterEqFct : public EqFct , boost::noncopyable {
boost::shared_ptr<ControlSystemPVManager> const & controlSystemPVManager, boost::shared_ptr<ControlSystemPVManager> const & controlSystemPVManager,
boost::shared_ptr<DoocsUpdater> const & updater, boost::shared_ptr<DoocsUpdater> const & updater,
std::string fctName = std::string()); std::string fctName = std::string());
~CSAdapterEqFct();
void init(); void init();
void update(); void update();
int fct_code(); int fct_code();
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <unordered_map> #include <unordered_map>
#include <map> #include <map>
#include <mtca4u/TransferElement.h> #include <mtca4u/TransferElement.h>
#include <boost/noncopyable.hpp>
namespace ChimeraTK{ namespace ChimeraTK{
/** A class to synchronise DeviceToControlSystem variable to Doocs. /** A class to synchronise DeviceToControlSystem variable to Doocs.
...@@ -12,13 +13,16 @@ namespace ChimeraTK{ ...@@ -12,13 +13,16 @@ namespace ChimeraTK{
* when the thread is started, and (FIXME can be stopped by the stop() function which * when the thread is started, and (FIXME can be stopped by the stop() function which
* returns after the thread has been joined). This happens latest in the destructor. * returns after the thread has been joined). This happens latest in the destructor.
*/ */
class DoocsUpdater{ class DoocsUpdater: public boost::noncopyable{
public: public:
~DoocsUpdater(){}; ~DoocsUpdater();
void update(); // Update all variables once. This is the intermediate solution void update(); // Update all variables once. This is the intermediate solution
// before we have implemented the thread, and for testing // before we have implemented the thread, and for testing
void run(){};
void stop(){}; void updateLoop(); // Endless loop with interruption point around the update function.
// Intermediate solution until we have a working/testable version of readAny()
void run();
void stop();
void addVariable( mtca4u::TransferElement & variable, std::function<void ()> updaterFunction); void addVariable( mtca4u::TransferElement & variable, std::function<void ()> updaterFunction);
protected: protected:
......
...@@ -22,6 +22,11 @@ namespace ChimeraTK{ ...@@ -22,6 +22,11 @@ namespace ChimeraTK{
registerProcessVariablesInDoocs(); registerProcessVariablesInDoocs();
} }
CSAdapterEqFct::~CSAdapterEqFct(){
//stop the updater thread before any of the process variables go out of scope
updater_->stop();
}
void CSAdapterEqFct::init(){ void CSAdapterEqFct::init(){
std::cout << "this is eqfct init of " << fct_name() << std::endl; std::cout << "this is eqfct init of " << fct_name() << std::endl;
} }
...@@ -33,9 +38,10 @@ namespace ChimeraTK{ ...@@ -33,9 +38,10 @@ namespace ChimeraTK{
// dirty hack until this is moved to a thread: unlock this EqFct. The updater does the locking // dirty hack until this is moved to a thread: unlock this EqFct. The updater does the locking
// and the locks are not re-entrant // and the locks are not re-entrant
unlock(); //unlock();
updater_->update(); //updater_->update();
lock(); //lock();
sleep(1);
} }
int CSAdapterEqFct::fct_code(){ int CSAdapterEqFct::fct_code(){
......
...@@ -20,4 +20,26 @@ namespace ChimeraTK{ ...@@ -20,4 +20,26 @@ namespace ChimeraTK{
} }
} }
void DoocsUpdater::updateLoop(){
while(true){
update();
// FIXME: This is brainstorming. Use testable sleep here
boost::this_thread::sleep_for(boost::chrono::milliseconds(10));
}
}
void DoocsUpdater::run(){
_syncThread = boost::thread( boost::bind( &DoocsUpdater::updateLoop, this) );
}
void DoocsUpdater::stop(){
_syncThread.interrupt();
_syncThread.join();
}
DoocsUpdater::~DoocsUpdater(){
stop();
}
}//namespace ChimeraTK }//namespace ChimeraTK
...@@ -48,4 +48,5 @@ EqFct* eq_create (int eq_code, void *) { ...@@ -48,4 +48,5 @@ EqFct* eq_create (int eq_code, void *) {
* the config file. We start the application here. It will be launched in a separate thread. */ * the config file. We start the application here. It will be launched in a separate thread. */
void post_init_epilog() { void post_init_epilog() {
ChimeraTK::ApplicationBase::getInstance().run(); ChimeraTK::ApplicationBase::getInstance().run();
doocsAdapter.updater->run();
} }
...@@ -21,9 +21,10 @@ using namespace ChimeraTK; ...@@ -21,9 +21,10 @@ using namespace ChimeraTK;
class TestableCSAdapterEqFct: public CSAdapterEqFct{ class TestableCSAdapterEqFct: public CSAdapterEqFct{
public: public:
TestableCSAdapterEqFct(int fctCode, TestableCSAdapterEqFct(int fctCode,
boost::shared_ptr<ControlSystemPVManager> controlSystemPVManager, boost::shared_ptr<ControlSystemPVManager> controlSystemPVManager,
std::string fctName): boost::shared_ptr<DoocsUpdater> const & updater,
CSAdapterEqFct(fctCode, controlSystemPVManager, boost::make_shared<DoocsUpdater>(), fctName){ std::string fctName):
CSAdapterEqFct(fctCode, controlSystemPVManager, updater, fctName){
} }
std::vector< boost::shared_ptr<D_fct> > & getDoocsProperties(){ std::vector< boost::shared_ptr<D_fct> > & getDoocsProperties(){
return doocsProperties_; return doocsProperties_;
...@@ -50,7 +51,8 @@ BOOST_AUTO_TEST_CASE( testCSAdapterEqFct ) { ...@@ -50,7 +51,8 @@ BOOST_AUTO_TEST_CASE( testCSAdapterEqFct ) {
auto csManager = doocsAdapter.getControlSystemPVManager(); auto csManager = doocsAdapter.getControlSystemPVManager();
VariableMapper::getInstance().directImport( getAllVariableNames(csManager ) ); VariableMapper::getInstance().directImport( getAllVariableNames(csManager ) );
// after that create the EqFct // after that create the EqFct
TestableCSAdapterEqFct eqFct(42, csManager, "test"); auto updater = boost::make_shared<DoocsUpdater>();
TestableCSAdapterEqFct eqFct(42, csManager, updater, "test");
// Test that the right number of properties is created. // Test that the right number of properties is created.
// Currently the vector is still empty. // Currently the vector is still empty.
...@@ -86,12 +88,12 @@ BOOST_AUTO_TEST_CASE( testCSAdapterEqFct ) { ...@@ -86,12 +88,12 @@ BOOST_AUTO_TEST_CASE( testCSAdapterEqFct ) {
// and the other direction // and the other direction
businessLogic.fromDeviceInt->accessData(0) = 12; businessLogic.fromDeviceInt->accessData(0) = 12;
businessLogic.fromDeviceInt->write(); businessLogic.fromDeviceInt->write();
eqFct.update(); updater->update();
BOOST_CHECK_EQUAL( doocsProperties["FROM_DEVICE.INT "]->value(), 12); BOOST_CHECK_EQUAL( doocsProperties["FROM_DEVICE.INT "]->value(), 12);
businessLogic.fromDeviceInt->accessData(0) = 15; businessLogic.fromDeviceInt->accessData(0) = 15;
businessLogic.fromDeviceInt->write(); businessLogic.fromDeviceInt->write();
eqFct.update(); updater->update();
BOOST_CHECK_EQUAL( doocsProperties["FROM_DEVICE.INT "]->value(), 15); BOOST_CHECK_EQUAL( doocsProperties["FROM_DEVICE.INT "]->value(), 15);
} }
...@@ -110,9 +112,10 @@ BOOST_AUTO_TEST_CASE( testWithMapping ) { ...@@ -110,9 +112,10 @@ BOOST_AUTO_TEST_CASE( testWithMapping ) {
VariableMapper::getInstance().prepareOutput( "EqFctTest.xml", getAllVariableNames(csManager ) ); VariableMapper::getInstance().prepareOutput( "EqFctTest.xml", getAllVariableNames(csManager ) );
// in the mapping two locations are created // in the mapping two locations are created
TestableCSAdapterEqFct toDeviceEqFct(42, csManager, "test.TO_DEVICE"); auto updater = boost::make_shared<DoocsUpdater>();
TestableCSAdapterEqFct fromDeviceEqFct(42, csManager, "test.FROM_DEVICE"); TestableCSAdapterEqFct toDeviceEqFct(42, csManager, updater, "test.TO_DEVICE");
TestableCSAdapterEqFct fromDeviceEqFct(42, csManager, updater, "test.FROM_DEVICE");
BOOST_REQUIRE( toDeviceEqFct.getDoocsProperties().size() == 1 ); BOOST_REQUIRE( toDeviceEqFct.getDoocsProperties().size() == 1 );
BOOST_REQUIRE( fromDeviceEqFct.getDoocsProperties().size() == 1 ); BOOST_REQUIRE( fromDeviceEqFct.getDoocsProperties().size() == 1 );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment