Skip to content
Snippets Groups Projects
Commit 71180027 authored by Tomasz Kozak's avatar Tomasz Kozak
Browse files

Continue with issue #80:

- remove "void ExceptionHandlingDecorator::setDataValidity(DataValidity newValidity)"
- add "void ExceptionHandlingDecorator::setOwner(EntityOwner* owner)" and remove owner setting in constructor
parent 6fa95cd7
No related branches found
No related tags found
No related merge requests found
...@@ -19,8 +19,8 @@ namespace ChimeraTK { ...@@ -19,8 +19,8 @@ namespace ChimeraTK {
class ExceptionHandlingDecorator : public ChimeraTK::NDRegisterAccessorDecorator<UserType> { class ExceptionHandlingDecorator : public ChimeraTK::NDRegisterAccessorDecorator<UserType> {
public: public:
ExceptionHandlingDecorator( ExceptionHandlingDecorator(
boost::shared_ptr<ChimeraTK::NDRegisterAccessor<UserType>> accessor, DeviceModule& devMod, EntityOwner* owner) boost::shared_ptr<ChimeraTK::NDRegisterAccessor<UserType>> accessor, DeviceModule& devMod)
: ChimeraTK::NDRegisterAccessorDecorator<UserType>(accessor), deviceModule(devMod), _owner(owner) {} : ChimeraTK::NDRegisterAccessorDecorator<UserType>(accessor), deviceModule(devMod) {}
bool doWriteTransfer(ChimeraTK::VersionNumber versionNumber = {}) override; bool doWriteTransfer(ChimeraTK::VersionNumber versionNumber = {}) override;
...@@ -43,16 +43,16 @@ namespace ChimeraTK { ...@@ -43,16 +43,16 @@ namespace ChimeraTK {
DataValidity dataValidity() const override; DataValidity dataValidity() const override;
void setDataValidity(DataValidity validity = DataValidity::ok) override;
void interrupt() override; void interrupt() override;
void setOwner(EntityOwner* owner);
protected: protected:
DeviceModule& deviceModule; DeviceModule& deviceModule;
DataValidity validity{DataValidity::ok}; DataValidity validity{DataValidity::ok};
bool genericTransfer(std::function<bool(void)> callable, bool invalidateOnFailure = true); bool genericTransfer(std::function<bool(void)> callable, bool invalidateOnFailure = true);
void setOwnerValidity(DataValidity newValidity); void setOwnerValidity(DataValidity newValidity);
EntityOwner* _owner; EntityOwner* _owner = {nullptr};
}; };
DECLARE_TEMPLATE_FOR_CHIMERATK_USER_TYPES(ExceptionHandlingDecorator); DECLARE_TEMPLATE_FOR_CHIMERATK_USER_TYPES(ExceptionHandlingDecorator);
......
...@@ -358,7 +358,7 @@ boost::shared_ptr<ChimeraTK::NDRegisterAccessor<UserType>> Application::createDe ...@@ -358,7 +358,7 @@ boost::shared_ptr<ChimeraTK::NDRegisterAccessor<UserType>> Application::createDe
assert(devmod != nullptr); assert(devmod != nullptr);
// decorate the accessor with a ExceptionHandlingDecorator and return it // decorate the accessor with a ExceptionHandlingDecorator and return it
return boost::make_shared<ExceptionHandlingDecorator<UserType>>(accessor, *devmod, nullptr); return boost::make_shared<ExceptionHandlingDecorator<UserType>>(accessor, *devmod);
} }
/*********************************************************************************************************************/ /*********************************************************************************************************************/
......
...@@ -7,20 +7,19 @@ constexpr useconds_t DeviceOpenTimeout = 500; ...@@ -7,20 +7,19 @@ constexpr useconds_t DeviceOpenTimeout = 500;
namespace ChimeraTK { namespace ChimeraTK {
template<typename UserType> template<typename UserType>
void ExceptionHandlingDecorator<UserType>::setOwnerValidity(DataValidity newValidity) { void ExceptionHandlingDecorator<UserType>::setOwnerValidity(DataValidity newValidity) {
if (newValidity != validity) { if (newValidity != validity) {
validity = newValidity; validity = newValidity;
if (!_owner) return; // hack to deal with null ptr until it filled correctly if (!_owner) return;
if (newValidity == DataValidity::faulty) { if (newValidity == DataValidity::faulty) {
_owner->incrementDataFaultCounter(); _owner->incrementDataFaultCounter();
} else { } else {
_owner->decrementDataFaultCounter(); _owner->decrementDataFaultCounter();
} }
}
} }
}
template<typename UserType> template<typename UserType>
bool ExceptionHandlingDecorator<UserType>::genericTransfer( bool ExceptionHandlingDecorator<UserType>::genericTransfer(
std::function<bool(void)> callable, bool updateOwnerValidityFlag) { std::function<bool(void)> callable, bool updateOwnerValidityFlag) {
...@@ -30,9 +29,9 @@ namespace ChimeraTK { ...@@ -30,9 +29,9 @@ namespace ChimeraTK {
setOwnerValidityFunction = std::bind(&ExceptionHandlingDecorator<UserType>::setOwnerValidity, this, std::placeholders::_1); setOwnerValidityFunction = std::bind(&ExceptionHandlingDecorator<UserType>::setOwnerValidity, this, std::placeholders::_1);
} }
else { else {
setOwnerValidityFunction = [](DataValidity) {}; // do nothing if user does setOwnerValidityFunction = [](DataValidity) {}; // do nothing if user does // not want to invalidate data.
// not want to invalidate data.
} }
while(true) { while(true) {
try { try {
if(!deviceModule.device.isOpened()) { if(!deviceModule.device.isOpened()) {
...@@ -131,22 +130,18 @@ namespace ChimeraTK { ...@@ -131,22 +130,18 @@ namespace ChimeraTK {
return 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
deviceModule.notify(); deviceModule.notify();
ChimeraTK::NDRegisterAccessorDecorator<UserType>::interrupt(); ChimeraTK::NDRegisterAccessorDecorator<UserType>::interrupt();
} }
template<typename UserType>
void ExceptionHandlingDecorator<UserType>::setOwner(EntityOwner* owner) {
_owner = owner;
}
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