Newer
Older
Martin Christoph Hierholzer
committed
/*
* ApplicationModule.cc
*
* Created on: Jun 17, 2016
* Author: Martin Hierholzer
*/
#include "ApplicationModule.h"
Martin Christoph Hierholzer
committed
#include "Application.h"
Martin Christoph Hierholzer
committed
namespace ChimeraTK {
void ApplicationModule::run() {
Martin Christoph Hierholzer
committed
// start the module thread
assert(!moduleThread.joinable());
Martin Christoph Hierholzer
committed
moduleThread = boost::thread(&ApplicationModule::mainLoopWrapper, this);
Martin Christoph Hierholzer
committed
}
Martin Christoph Hierholzer
committed
/*********************************************************************************************************************/
Martin Christoph Hierholzer
committed
void ApplicationModule::terminate() {
if(moduleThread.joinable()) {
moduleThread.interrupt();
moduleThread.join();
}
assert(!moduleThread.joinable());
}
Martin Christoph Hierholzer
committed
/*********************************************************************************************************************/
Martin Christoph Hierholzer
committed
ApplicationModule::~ApplicationModule() {
assert(!moduleThread.joinable());
Martin Christoph Hierholzer
committed
}
Martin Christoph Hierholzer
committed
/*********************************************************************************************************************/
Martin Christoph Hierholzer
committed
void ApplicationModule::mainLoopWrapper() {
Application::registerThread("ApplicatioModule "+getName());
Application::testableModeLock("start");
Martin Christoph Hierholzer
committed
// enter the main loop
mainLoop();
Application::testableModeUnlock("terminate");
Martin Christoph Hierholzer
committed
}
Martin Christoph Hierholzer
committed
Martin Christoph Hierholzer
committed
/*********************************************************************************************************************/
Martin Christoph Hierholzer
committed
VariableNetworkNode ApplicationModule::operator()(const std::string& variableName) const {
Martin Christoph Hierholzer
committed
for(auto variable : getAccessorList()) {
Martin Christoph Hierholzer
committed
if(variable.getName() == variableName) return VariableNetworkNode(variable);
Martin Christoph Hierholzer
committed
}
throw std::logic_error("Variable '"+variableName+"' is not part of the module '"+_name+"'.");
}
/*********************************************************************************************************************/
Martin Christoph Hierholzer
committed
Module& ApplicationModule::operator[](const std::string& moduleName) const {
Martin Christoph Hierholzer
committed
for(auto submodule : getSubmoduleList()) {
if(submodule->getName() == moduleName) return *submodule;
}
throw std::logic_error("Sub-module '"+moduleName+"' is not part of the module '"+_name+"'.");
}
Martin Christoph Hierholzer
committed
} /* namespace ChimeraTK */