Newer
Older
Martin Christoph Hierholzer
committed
/*
* ConsumingFanOut.h
*
* Created on: Jun 15, 2016
* Author: Martin Hierholzer
*/
#ifndef CHIMERATK_CONSUMING_FAN_OUT_H
#define CHIMERATK_CONSUMING_FAN_OUT_H
#include <ChimeraTK/NDRegisterAccessorDecorator.h>
Martin Christoph Hierholzer
committed
#include "FanOut.h"
namespace ChimeraTK {
/** FanOut implementation which acts as a read-only (i.e. consuming) NDRegisterAccessor. The values read through
* this accessor will be obtained from the given feeding implementation and distributed to any number of slaves. */
Martin Christoph Hierholzer
committed
template<typename UserType>
class ConsumingFanOut : public FanOut<UserType>, public ChimeraTK::NDRegisterAccessorDecorator<UserType> {
Martin Christoph Hierholzer
committed
public:
ConsumingFanOut(boost::shared_ptr<ChimeraTK::NDRegisterAccessor<UserType>> feedingImpl)
Martin Christoph Hierholzer
committed
: FanOut<UserType>(feedingImpl),
ChimeraTK::NDRegisterAccessorDecorator<UserType>(feedingImpl)
Martin Christoph Hierholzer
committed
{
Martin Christoph Hierholzer
committed
assert(feedingImpl->isReadable());
Martin Christoph Hierholzer
committed
}
void doPostRead() override {
ChimeraTK::NDRegisterAccessorDecorator<UserType>::doPostRead();
Martin Christoph Hierholzer
committed
for(auto &slave : FanOut<UserType>::slaves) { // send out copies to slaves
Martin Christoph Hierholzer
committed
// do not send copy if no data is expected (e.g. trigger)
if(slave->getNumberOfSamples() != 0) {
Martin Christoph Hierholzer
committed
slave->accessChannel(0) = buffer_2D[0];
Martin Christoph Hierholzer
committed
}
slave->write();
}
}
Martin Christoph Hierholzer
committed
protected:
using ChimeraTK::NDRegisterAccessor<UserType>::buffer_2D;
Martin Christoph Hierholzer
committed
};
} /* namespace ChimeraTK */
#endif /* CHIMERATK_CONSUMING_FAN_OUT_H */