10#include <ChimeraTK/Device.h>
12#include <boost/thread/latch.hpp>
207 template<
typename UserType>
218 return "RecoveryStage::NO_ERROR";
220 return "RecoveryStage::DETECTION";
222 return "RecoveryStage::OPEN";
224 return "RecoveryStage::INIT_HANDLERS";
226 return "RecoveryStage::RECOVERY_ACCESSORS";
228 return "RecoveryStage::CLEAR_ERROR";
230 throw ChimeraTK::logic_error(
"Unknown recovery stage, cannot convert to string.");
Implements access to a ChimeraTK::Device.
uint64_t writeOrder()
Each call to this function gives a unique number.
std::atomic< int64_t > _synchronousTransferCounter
void decrementDataFaultCounter() override
Decrement the fault counter and set the data validity flag to ok if the counter has reached 0.
bool _deviceHasError
The error flag whether the device is functional.
size_t getCircularNetworkHash() const override
Get the ID of the circular dependency network (0 if none).
boost::latch _initialValueLatch
std::atomic< uint64_t > _writeOrderCounter
std::list< RegisterPath > _readRegisterPaths
std::vector< VariableNetworkNode > getNodesList() const
Create and return list of VariableNetworkNodes for all device registers.
void waitForInitialValues()
Wait for initial values coming from the device.
bool _isHoldingInitialValueLatch
Latch to halt accessors until initial values can be received.
const std::string & getDeviceAliasOrURI() const
Return associated device alias resp.
Device & getDevice()
Return the underlying ChimeraTK::Device object.
VersionNumber getExceptionVersionNumber()
Use this function to read the exception version number.
VersionNumber _exceptionVersionNumber
Version number of the last exception.
DataValidity getDataValidity() const override
Return the data validity flag.
void terminate() override
Terminate the module.
void addInitialisationHandler(std::function< void(ChimeraTK::Device &)> initialisationHandler)
Add initialisation handlers to the device.
std::list< RegisterPath > _writeRegisterPaths
boost::shared_mutex _errorMutex
Mutex to protect deviceHasError.
boost::shared_lock< boost::shared_mutex > getRecoverySharedLock()
Returns a shared lock for the DeviceModule::recoveryMutex.
DeviceManager(DeviceManager &&other)=delete
VoidOutput deviceBecameFunctional
A trigger that indicated that the device just became available again an error (in contrast to the err...
void reportException(const std::string &errMsg)
Use this function to report an exception.
std::shared_ptr< RecoveryGroup > _recoveryGroup
cppext::future_queue< std::string > _errorQueue
Queue used for communication between reportException() and the moduleThread.
void mainLoopImpl()
This functions tries to open the device and set the deviceError.
void addRecoveryAccessor(boost::shared_ptr< RecoveryHelper > recoveryAccessor)
Add a TransferElement to the list DeviceModule::writeRecoveryOpen.
std::list< std::function< void(ChimeraTK::Device &)> > _initialisationHandlers
DeviceManager & operator=(DeviceManager &&other)=delete
std::list< EntityOwner * > getInputModulesRecursively(std::list< EntityOwner * > startList) override
Use pointer to the module as unique identifier.
void prepare() override
Prepare the execution of the module.
boost::shared_mutex _recoveryMutex
Mutex for writing the DeviceModule::writeRecoveryOpen.
void mainLoop() override
Wrapper around the actual main loop implementation to add unsubscribing from the barrier to allow a c...
std::string _deviceAliasOrCDD
void incrementDataFaultCounter() override
Set the data validity flag to fault and increment the fault counter.
friend struct detail::CircularDependencyDetector
std::list< boost::shared_ptr< RecoveryHelper > > _recoveryHelpers
List of TransferElements to be written after the device has been recovered.
StatusWithMessage _deviceError
A VariableGroup for exception status and message.
std::string stageToString(RecoveryGroup::RecoveryStage stage)
Helper function for better error messages.
Decorator of the NDRegisterAccessor which facilitates tests of the application.
InvalidityTracer application module.
The shared state of a group of DeviceManagers which are recovering together.
static std::mutex globalDeviceOpenMutex
Protect the device open actions for all DeviceManagers and groups.
Application * app
Pointer to the application to access the recovery lock.
std::set< DeviceBackend::BackendID > recoveryBackendIDs
All backend ID in this recovery group.
static constexpr const char * stageToString(RecoveryStage stage)
bool waitForRecoveryStage(RecoveryStage stage)
std::atomic< bool > shutdown
Indicate that all DeviceManagers in the group should terminate their main loop.
std::mutex _initHandlerOpenCloseMutex
Protect closing and re-opening the device of any DeviceManager in a recovery group against each other...
void setErrorAtStage(RecoveryStage stage)
std::atomic< RecoveryStage > errorAtStage
Indicator whether recovery has to be repeated, and from which barrier.
std::barrier recoveryBarrier
A barrier is used to ensure that each stage of the recovery process is completed by all DeviceManager...
A VariableGroup for error status and message reporting.
Convenience class for output void (always UpdateMode::push)