Skip to content
Snippets Groups Projects
Commit 88a89a2f authored by Nadeem Shehzad's avatar Nadeem Shehzad
Browse files

added: Variable group. Removed debug statements.

parent bd751e90
No related branches found
No related tags found
No related merge requests found
......@@ -14,7 +14,6 @@
#include "Module.h"
#include "VirtualModule.h"
#include "VariableGroup.h"
//#include "Application.h"
#include "ScalarAccessor.h"
namespace ChimeraTK {
......@@ -32,7 +31,11 @@ class DeviceModule : public Module {
/** Default constructor: create dysfunctional device module */
DeviceModule() {}
/** Destructor */
virtual ~DeviceModule();
/** Move operation with the move constructor */
DeviceModule(DeviceModule &&other) { operator=(std::move(other)); }
......@@ -42,6 +45,7 @@ class DeviceModule : public Module {
deviceAliasOrURI = std::move(other.deviceAliasOrURI);
registerNamePrefix = std::move(other.registerNamePrefix);
subModules = std::move(other.subModules);
deviceError = std::move(other.deviceError);
return *this;
}
......@@ -71,7 +75,14 @@ class DeviceModule : public Module {
void terminate() override;
VersionNumber getCurrentVersionNumber() const override { return currentVersionNumber; }
void setCurrentVersionNumber(VersionNumber versionNumber) override {
if(versionNumber > currentVersionNumber) currentVersionNumber = versionNumber;
}
/** Version number of last push-type read operation - will be passed on to any write operations */
VersionNumber currentVersionNumber;
protected:
// populate virtualisedModuleFromCatalog based on the information in the device's catalogue
VirtualModule& virtualiseFromCatalog() const;
......@@ -91,7 +102,7 @@ class DeviceModule : public Module {
ScalarOutput<int> status{this,"status","",""};
ScalarOutput<std::string> message{this,"errMsg","",""};
};
//DeviceError deviceError;
DeviceError deviceError{this, "deviceError", "Error"};
private:
/** The thread executing reportException() */
......
......@@ -35,10 +35,14 @@ namespace ChimeraTK {
deviceAliasOrURI(_deviceAliasOrURI),
registerNamePrefix(_registerNamePrefix)
{
std::cout<<"deviceModule"<<std::endl;
application->registerDeviceModule(this);
}
/*********************************************************************************************************************/
DeviceModule::~DeviceModule() {
assert(!moduleThread.joinable());
}
/*********************************************************************************************************************/
......@@ -51,8 +55,6 @@ namespace ChimeraTK {
/*********************************************************************************************************************/
Module& DeviceModule::operator[](const std::string& moduleName) const {
std::cout<<"DeviceModule:"<<moduleName<<std::endl;
if(subModules.count(moduleName) == 0) {
subModules[moduleName] = {deviceAliasOrURI, registerNamePrefix/moduleName};
}
......@@ -80,7 +82,6 @@ namespace ChimeraTK {
virtualisedModuleFromCatalog = VirtualModule(deviceAliasOrURI, "Device module", ModuleType::Device);
// obtain register catalogue
std::cout<<"DeviceModule::virtualiseFromCatalog"<<std::endl;
Device d;
d.open(deviceAliasOrURI); /// @todo: do not actually open the device (needs extension of DeviceAccess)!
auto catalog = d.getRegisterCatalogue();
......@@ -172,44 +173,49 @@ namespace ChimeraTK {
/*********************************************************************************************************************/
void DeviceModule::reportException(std::string errMsg ){
status = 1;
deviceError.status = 1;
deviceError.message = errMsg;
deviceError.writeAll();
std::unique_lock<std::mutex> lk(errorMutex);
errorQueue.push(errMsg);
errorCondVar.wait(lk);
deviceError.status = 0;
deviceError.message = "";
deviceError.writeAll();
}
/*********************************************************************************************************************/
void DeviceModule::handleException(){
Application::registerThread("DM_"+getName());
std::string error;
while(true)
{
try{
errorQueue.pop_wait(error);
//if (error == "none")
//break;
Device d;
while(true)
{
d.open(deviceAliasOrURI);
if (d.isOpened())
try{
d.open(deviceAliasOrURI);
if (d.isOpened())
{
break;
}
usleep(5000);
}
catch(std::exception ex)
{
break;
//std::cout<<"caught exception:"<<ex.what()<<std::endl;
//deviceError.message = ex.what();
}
usleep(5000);
}
deviceError.status = 1;
deviceError.message = "";
//lk.unlock();
errorCondVar.notify_all();
}
catch(std::exception ex)
{
std::cout<<"caught exception:"<<ex.what()<<std::endl;
//deviceError.message = ex.what();
}
}
}
/*********************************************************************************************************************/
......@@ -217,7 +223,6 @@ namespace ChimeraTK {
void DeviceModule::run() {
// start the module thread
std::cout<<"start the module thread"<<std::endl;
assert(!moduleThread.joinable());
moduleThread = boost::thread(&DeviceModule::handleException, this);
}
......@@ -225,17 +230,19 @@ namespace ChimeraTK {
/*********************************************************************************************************************/
void DeviceModule::terminate() {
//reportException("none");
if(moduleThread.joinable()) {
moduleThread.interrupt();
// try joining the thread
while(!moduleThread.try_join_for(boost::chrono::milliseconds(10))) {
// if thread is not yet joined, send interrupt() to all variables.
for(auto &var : getAccessorListRecursive()) {
if(var.getDirection() == VariableDirection{VariableDirection::feeding,false}) continue;
var.getAppAccessorNoType().getHighLevelImplElement()->interrupt();
}
// it may not suffice to send interrupt() once, as the exception might get overwritten in the queue, thus we
// repeat this until the thread was joined.
}
}
assert(!moduleThread.joinable());
......
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