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

ran code formatter on changed from last commit

parent 9468db94
No related branches found
No related tags found
No related merge requests found
...@@ -7,131 +7,130 @@ constexpr useconds_t DeviceOpenTimeout = 500; ...@@ -7,131 +7,130 @@ 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 invalidateOnFailure) { bool ExceptionHandlingDecorator<UserType>::genericTransfer(
std::function<void() > invalidateData{}; std::function<bool(void)> callable, bool invalidateOnFailure) {
if (invalidateOnFailure) { std::function<void()> invalidateData{};
invalidateData = [ = ](){setDataValidity(DataValidity::faulty);}; if(invalidateOnFailure) {
} else { invalidateData = [=]() { setDataValidity(DataValidity::faulty); };
invalidateData = []() {
}; // do nothing if user does
// not want to invalidate data.
}
while (true) {
try {
if (!dm.device.isOpened()) {
invalidateData();
Application::getInstance().testableModeUnlock("waitForDeviceOpen");
boost::this_thread::sleep(boost::posix_time::millisec(DeviceOpenTimeout));
Application::getInstance().testableModeLock("waitForDeviceOpen");
continue;
}
auto retval = callable();
setDataValidity(DataValidity::ok);
return retval;
} catch (ChimeraTK::runtime_error& e) {
invalidateData();
dm.reportException(e.what());
}
}
}
template<typename UserType>
bool ExceptionHandlingDecorator<UserType>::doWriteTransfer(ChimeraTK::VersionNumber versionNumber) {
return genericTransfer([this, versionNumber]() {
return ChimeraTK::NDRegisterAccessorDecorator<UserType>::doWriteTransfer(versionNumber);
}, false);
}
template<typename UserType>
bool ExceptionHandlingDecorator<UserType>::doWriteTransferDestructively(ChimeraTK::VersionNumber versionNumber) {
return genericTransfer([this, versionNumber]() {
return ChimeraTK::NDRegisterAccessorDecorator<UserType>::doWriteTransferDestructively(versionNumber);
}, false);
}
template<typename UserType>
void ExceptionHandlingDecorator<UserType>::doReadTransfer() {
genericTransfer([this]() {
return ChimeraTK::NDRegisterAccessorDecorator<UserType>::doReadTransfer(), true; });
}
template<typename UserType>
bool ExceptionHandlingDecorator<UserType>::doReadTransferNonBlocking() {
return genericTransfer(
[this]() {
return ChimeraTK::NDRegisterAccessorDecorator<UserType>::doReadTransferNonBlocking(); });
}
template<typename UserType>
bool ExceptionHandlingDecorator<UserType>::doReadTransferLatest() {
return genericTransfer(
[this]() {
return ChimeraTK::NDRegisterAccessorDecorator<UserType>::doReadTransferLatest(); });
}
template<typename UserType>
TransferFuture ExceptionHandlingDecorator<UserType>::doReadTransferAsync() {
TransferFuture future;
genericTransfer([this, &future]() {
future = ChimeraTK::NDRegisterAccessorDecorator<UserType>::doReadTransferAsync();
return true;
});
return future;
} }
else {
template<typename UserType> invalidateData = []() {}; // do nothing if user does
void ExceptionHandlingDecorator<UserType>::doPreRead() { // not want to invalidate data.
genericTransfer([this]() {
return ChimeraTK::NDRegisterAccessorDecorator<UserType>::doPreRead(), true; });
} }
while(true) {
template<typename UserType> try {
void ExceptionHandlingDecorator<UserType>::doPostRead() { if(!dm.device.isOpened()) {
genericTransfer([this]() { invalidateData();
return ChimeraTK::NDRegisterAccessorDecorator<UserType>::doPostRead(), true; }); Application::getInstance().testableModeUnlock("waitForDeviceOpen");
boost::this_thread::sleep(boost::posix_time::millisec(DeviceOpenTimeout));
Application::getInstance().testableModeLock("waitForDeviceOpen");
continue;
}
auto retval = callable();
setDataValidity(DataValidity::ok);
return retval;
}
catch(ChimeraTK::runtime_error& e) {
invalidateData();
dm.reportException(e.what());
}
} }
}
template<typename UserType>
void ExceptionHandlingDecorator<UserType>::doPreWrite() { template<typename UserType>
genericTransfer([this]() { bool ExceptionHandlingDecorator<UserType>::doWriteTransfer(ChimeraTK::VersionNumber versionNumber) {
return ChimeraTK::NDRegisterAccessorDecorator<UserType>::doPreWrite(), true; }, false); return genericTransfer(
[this, versionNumber]() {
return ChimeraTK::NDRegisterAccessorDecorator<UserType>::doWriteTransfer(versionNumber);
},
false);
}
template<typename UserType>
bool ExceptionHandlingDecorator<UserType>::doWriteTransferDestructively(ChimeraTK::VersionNumber versionNumber) {
return genericTransfer(
[this, versionNumber]() {
return ChimeraTK::NDRegisterAccessorDecorator<UserType>::doWriteTransferDestructively(versionNumber);
},
false);
}
template<typename UserType>
void ExceptionHandlingDecorator<UserType>::doReadTransfer() {
genericTransfer([this]() { return ChimeraTK::NDRegisterAccessorDecorator<UserType>::doReadTransfer(), true; });
}
template<typename UserType>
bool ExceptionHandlingDecorator<UserType>::doReadTransferNonBlocking() {
return genericTransfer(
[this]() { return ChimeraTK::NDRegisterAccessorDecorator<UserType>::doReadTransferNonBlocking(); });
}
template<typename UserType>
bool ExceptionHandlingDecorator<UserType>::doReadTransferLatest() {
return genericTransfer(
[this]() { return ChimeraTK::NDRegisterAccessorDecorator<UserType>::doReadTransferLatest(); });
}
template<typename UserType>
TransferFuture ExceptionHandlingDecorator<UserType>::doReadTransferAsync() {
TransferFuture future;
genericTransfer([this, &future]() {
future = ChimeraTK::NDRegisterAccessorDecorator<UserType>::doReadTransferAsync();
return true;
});
return future;
}
template<typename UserType>
void ExceptionHandlingDecorator<UserType>::doPreRead() {
genericTransfer([this]() { return ChimeraTK::NDRegisterAccessorDecorator<UserType>::doPreRead(), true; });
}
template<typename UserType>
void ExceptionHandlingDecorator<UserType>::doPostRead() {
genericTransfer([this]() { return ChimeraTK::NDRegisterAccessorDecorator<UserType>::doPostRead(), true; });
}
template<typename UserType>
void ExceptionHandlingDecorator<UserType>::doPreWrite() {
genericTransfer([this]() { return ChimeraTK::NDRegisterAccessorDecorator<UserType>::doPreWrite(), true; }, false);
}
template<typename UserType>
void ExceptionHandlingDecorator<UserType>::doPostWrite() {
genericTransfer([this]() { return ChimeraTK::NDRegisterAccessorDecorator<UserType>::doPostWrite(), true; }, false);
}
template<typename UserType>
DataValidity ExceptionHandlingDecorator<UserType>::dataValidity() const {
// faulty Validity from the decorated class takes precedence over our own
auto delegatedValidity = ChimeraTK::NDRegisterAccessorDecorator<UserType>::dataValidity();
if(delegatedValidity == DataValidity::faulty) {
return delegatedValidity;
} }
template<typename UserType> return validity;
void ExceptionHandlingDecorator<UserType>::doPostWrite() { }
genericTransfer([this]() {
return ChimeraTK::NDRegisterAccessorDecorator<UserType>::doPostWrite(), true; }, false);
}
template<typename UserType> template<typename UserType>
DataValidity ExceptionHandlingDecorator<UserType>::dataValidity() const { void ExceptionHandlingDecorator<UserType>::setDataValidity(DataValidity newValidity) {
// faulty Validity from the decorated class takes precedence over our own // Remember ourselves, but also pass down the line
auto delegatedValidity = ChimeraTK::NDRegisterAccessorDecorator<UserType>::dataValidity(); if(newValidity != validity) {
if (delegatedValidity == DataValidity::faulty) { validity = newValidity;
return delegatedValidity; ChimeraTK::NDRegisterAccessorDecorator<UserType>::setDataValidity(validity);
}
return validity;
}
template<typename UserType>
void ExceptionHandlingDecorator<UserType>::setDataValidity(DataValidity newValidity) {
// Remember ourselves, but also pass down the line
if (newValidity != validity) {
validity = newValidity;
ChimeraTK::NDRegisterAccessorDecorator<UserType>::setDataValidity(validity);
}
} }
}
template<typename UserType> template<typename UserType>
void ExceptionHandlingDecorator<UserType>::interrupt() { void ExceptionHandlingDecorator<UserType>::interrupt() {
// notify the condition variable waiting in reportException of the genericTransfer // notify the condition variable waiting in reportException of the genericTransfer
dm.notify(); dm.notify();
ChimeraTK::NDRegisterAccessorDecorator<UserType>::interrupt(); ChimeraTK::NDRegisterAccessorDecorator<UserType>::interrupt();
} }
INSTANTIATE_TEMPLATE_FOR_CHIMERATK_USER_TYPES(ExceptionHandlingDecorator); INSTANTIATE_TEMPLATE_FOR_CHIMERATK_USER_TYPES(ExceptionHandlingDecorator);
} /* namespace ChimeraTK */ } /* namespace ChimeraTK */
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