Skip to content
Snippets Groups Projects
Commit 8e820037 authored by vargheseg's avatar vargheseg
Browse files

genericTransfer: disable data invalidation

- New flag parameter for ExceptionHandlingDecorator::genericTransfer.
  Method does not invalidate data if flag invalidateOnFailure is set to
  false.
- Write related methods in ExceptionHandlingDecorator set
  invalidateOnFailure flag to false

Changes resolve ticket #57.
parent 436458a4
No related branches found
No related tags found
No related merge requests found
...@@ -50,7 +50,7 @@ namespace ChimeraTK { ...@@ -50,7 +50,7 @@ namespace ChimeraTK {
protected: protected:
DeviceModule& dm; DeviceModule& dm;
DataValidity validity{DataValidity::ok}; DataValidity validity{DataValidity::ok};
bool genericTransfer(std::function<bool(void)> callable); bool genericTransfer(std::function<bool(void)> callable, bool invalidateOnFailure = true);
}; };
DECLARE_TEMPLATE_FOR_CHIMERATK_USER_TYPES(ExceptionHandlingDecorator); DECLARE_TEMPLATE_FOR_CHIMERATK_USER_TYPES(ExceptionHandlingDecorator);
......
...@@ -8,11 +8,18 @@ constexpr useconds_t DeviceOpenTimeout = 500; ...@@ -8,11 +8,18 @@ constexpr useconds_t DeviceOpenTimeout = 500;
namespace ChimeraTK { namespace ChimeraTK {
template<typename UserType> template<typename UserType>
bool ExceptionHandlingDecorator<UserType>::genericTransfer(std::function<bool(void)> callable) { bool ExceptionHandlingDecorator<UserType>::genericTransfer(std::function<bool(void)> callable, bool invalidateOnFailure) {
std::function<void()> invalidateData{};
if (invalidateOnFailure) {
invalidateData = [=]() { setDataValidity(DataValidity::faulty); };
} else {
invalidateData = []() {}; // do nothing if user does
// not want to invalidate data.
}
while(true) { while(true) {
try { try {
if(!dm.device.isOpened()) { if(!dm.device.isOpened()) {
setDataValidity(DataValidity::faulty); invalidateData();
Application::getInstance().testableModeUnlock("waitForDeviceOpen"); Application::getInstance().testableModeUnlock("waitForDeviceOpen");
boost::this_thread::sleep(boost::posix_time::millisec(DeviceOpenTimeout)); boost::this_thread::sleep(boost::posix_time::millisec(DeviceOpenTimeout));
Application::getInstance().testableModeLock("waitForDeviceOpen"); Application::getInstance().testableModeLock("waitForDeviceOpen");
...@@ -21,9 +28,9 @@ namespace ChimeraTK { ...@@ -21,9 +28,9 @@ namespace ChimeraTK {
auto retval = callable(); auto retval = callable();
setDataValidity(DataValidity::ok); setDataValidity(DataValidity::ok);
return retval; return retval;
} }
catch(ChimeraTK::runtime_error& e) { } catch (ChimeraTK::runtime_error& e) {
setDataValidity(DataValidity::faulty); invalidateData();
dm.reportException(e.what()); dm.reportException(e.what());
} }
} }
...@@ -33,14 +40,14 @@ namespace ChimeraTK { ...@@ -33,14 +40,14 @@ namespace ChimeraTK {
bool ExceptionHandlingDecorator<UserType>::doWriteTransfer(ChimeraTK::VersionNumber versionNumber) { bool ExceptionHandlingDecorator<UserType>::doWriteTransfer(ChimeraTK::VersionNumber versionNumber) {
return genericTransfer([this, versionNumber]() { return genericTransfer([this, versionNumber]() {
return ChimeraTK::NDRegisterAccessorDecorator<UserType>::doWriteTransfer(versionNumber); return ChimeraTK::NDRegisterAccessorDecorator<UserType>::doWriteTransfer(versionNumber);
}); }, false);
} }
template<typename UserType> template<typename UserType>
bool ExceptionHandlingDecorator<UserType>::doWriteTransferDestructively(ChimeraTK::VersionNumber versionNumber) { bool ExceptionHandlingDecorator<UserType>::doWriteTransferDestructively(ChimeraTK::VersionNumber versionNumber) {
return genericTransfer([this, versionNumber]() { return genericTransfer([this, versionNumber]() {
return ChimeraTK::NDRegisterAccessorDecorator<UserType>::doWriteTransferDestructively(versionNumber); return ChimeraTK::NDRegisterAccessorDecorator<UserType>::doWriteTransferDestructively(versionNumber);
}); }, false);
} }
template<typename UserType> template<typename UserType>
...@@ -83,12 +90,12 @@ namespace ChimeraTK { ...@@ -83,12 +90,12 @@ namespace ChimeraTK {
template<typename UserType> template<typename UserType>
void ExceptionHandlingDecorator<UserType>::doPreWrite() { void ExceptionHandlingDecorator<UserType>::doPreWrite() {
genericTransfer([this]() { return ChimeraTK::NDRegisterAccessorDecorator<UserType>::doPreWrite(), true; }); genericTransfer([this]() { return ChimeraTK::NDRegisterAccessorDecorator<UserType>::doPreWrite(), true; }, false);
} }
template<typename UserType> template<typename UserType>
void ExceptionHandlingDecorator<UserType>::doPostWrite() { void ExceptionHandlingDecorator<UserType>::doPostWrite() {
genericTransfer([this]() { return ChimeraTK::NDRegisterAccessorDecorator<UserType>::doPostWrite(), true; }); genericTransfer([this]() { return ChimeraTK::NDRegisterAccessorDecorator<UserType>::doPostWrite(), true; }, false);
} }
template<typename UserType> template<typename UserType>
......
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