Skip to content
Snippets Groups Projects
Unverified Commit f602a0ab authored by Jens Georg's avatar Jens Georg Committed by GitHub
Browse files

Merge pull request #149 from ChimeraTK/wip-phako-144

Remove DeviceModule::writeOnOpen
parents 73948f83 07d059e4
No related branches found
No related tags found
No related merge requests found
......@@ -257,10 +257,6 @@ namespace ChimeraTK {
* The function is running an endless loop inside its own thread (moduleThread). */
void handleException();
/** List of TransferElements to be written after the device has been opened. This is used to write constant feeders
* to the device. */
std::list<boost::shared_ptr<TransferElement>> writeAfterOpen;
/** List of TransferElements to be written after the device has been recovered.
* See function addRecoveryAccessor() for details.*/
std::list<boost::shared_ptr<TransferElement>> writeRecoveryOpen;
......
......@@ -1006,8 +1006,13 @@ void Application::typedMakeConnection(VariableNetwork& network) {
impl->write();
}
else if(consumer.getType() == NodeType::Device) {
auto impl = createDeviceVariable<UserType>(consumer.getDeviceAlias(), consumer.getRegisterName(),
{VariableDirection::consuming, false}, consumer.getMode(), consumer.getNumberOfElements());
// we register the required accessor as a recovery accessor. This is just a bare RegisterAccessor without any decorations directly from the backend.
if(deviceMap.count(consumer.getDeviceAlias()) == 0) {
deviceMap[consumer.getDeviceAlias()] =
ChimeraTK::BackendFactory::getInstance().createBackend(consumer.getDeviceAlias());
}
auto impl = deviceMap[consumer.getDeviceAlias()]->getRegisterAccessor<UserType>(
consumer.getRegisterName(), consumer.getNumberOfElements(), 0, {});
impl->accessChannel(0) = feedingImpl->accessChannel(0);
// find the right DeviceModule for this alias name
DeviceModule* devmod = nullptr;
......@@ -1018,8 +1023,8 @@ void Application::typedMakeConnection(VariableNetwork& network) {
}
}
assert(devmod != nullptr);
// register feeder to be written after the device has been opened
devmod->writeAfterOpen.push_back(impl);
devmod->addRecoveryAccessor(impl);
}
else if(consumer.getType() == NodeType::TriggerReceiver) {
throw ChimeraTK::logic_error("Using constants as triggers is not supported!");
......
......@@ -294,13 +294,16 @@ namespace ChimeraTK {
}
}
}
// The device was successfully opened, try to initialise it
try {
for(auto& initHandler : initialisationHandlers) {
initHandler(this);
}
for(auto& te : writeAfterOpen) {
te->write();
for(auto& te : writeRecoveryOpen) {
if(te->getVersionNumber() != VersionNumber{nullptr}) {
te->write();
}
}
}
catch(ChimeraTK::runtime_error& e) {
......@@ -377,7 +380,9 @@ namespace ChimeraTK {
{ // scope for the lock guard
boost::unique_lock<boost::shared_mutex> uniqueLock(recoverySharedMutex);
for(auto& te : writeRecoveryOpen) {
te->write();
if(te->getVersionNumber() != VersionNumber{nullptr}) {
te->write();
}
}
} // end of scope for the lock guard
}
......
......@@ -52,9 +52,6 @@ namespace ChimeraTK {
// If the application has not yet fully started, we cannot wait for the device to open. Instead register
// the variable in the DeviceMoule, so the transfer will be performed after the device is opened.
assert(_recoveryAccessor != nullptr); // should always be true for writeable registers with this decorator
// Note: it's ok to use the recoveryAccessor here as well, since device opening and recovery happens in the
// same thread in the DeviceModule.
deviceModule.writeAfterOpen.push_back(this->_recoveryAccessor);
return false;
}
// We artificially increase the testabel mode counter so the test does not slip out of testable mode here in case
......
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