add hook to ParallelContainerBase to customize state propagation

This commit is contained in:
v4hn 2021-08-18 22:43:55 +02:00
parent 79869b856c
commit f32e747645
2 changed files with 14 additions and 7 deletions

View File

@ -227,10 +227,13 @@ public:
protected: protected:
void validateInterfaces(const StagePrivate& child, InterfaceFlags& external, bool first = false) const; void validateInterfaces(const StagePrivate& child, InterfaceFlags& external, bool first = false) const;
private:
/// callback for new externally received states /// callback for new externally received states
template <typename Interface::Direction> template <typename Interface::Direction>
void onNewExternalState(Interface::iterator external, bool updated); void propagateStateToChildren(Interface::iterator external, bool updated);
private:
// override for custom behavior on received interface states
virtual void initializeExternalInterfaces(InterfaceFlags expected);
}; };
PIMPL_FUNCTIONS(ParallelContainerBase) PIMPL_FUNCTIONS(ParallelContainerBase)

View File

@ -678,17 +678,21 @@ void ParallelContainerBasePrivate::resolveInterface(InterfaceFlags expected) {
if (exceptions) if (exceptions)
throw exceptions; throw exceptions;
initializeExternalInterfaces(expected);
required_interface_ = expected;
}
void ParallelContainerBasePrivate::initializeExternalInterfaces(InterfaceFlags expected) {
// States received by the container need to be copied to all children's pull interfaces. // States received by the container need to be copied to all children's pull interfaces.
if (expected & READS_START) if (expected & READS_START)
starts().reset(new Interface([this](Interface::iterator external, bool updated) { starts().reset(new Interface([this](Interface::iterator external, bool updated) {
this->onNewExternalState<Interface::FORWARD>(external, updated); this->propagateStateToChildren<Interface::FORWARD>(external, updated);
})); }));
if (expected & READS_END) if (expected & READS_END)
ends().reset(new Interface([this](Interface::iterator external, bool updated) { ends().reset(new Interface([this](Interface::iterator external, bool updated) {
this->onNewExternalState<Interface::BACKWARD>(external, updated); this->propagateStateToChildren<Interface::BACKWARD>(external, updated);
})); }));
required_interface_ = expected;
} }
void ParallelContainerBasePrivate::validateInterfaces(const StagePrivate& child, InterfaceFlags& external, void ParallelContainerBasePrivate::validateInterfaces(const StagePrivate& child, InterfaceFlags& external,
@ -723,7 +727,7 @@ void ParallelContainerBasePrivate::validateConnectivity() const {
} }
template <Interface::Direction dir> template <Interface::Direction dir>
void ParallelContainerBasePrivate::onNewExternalState(Interface::iterator external, bool updated) { void ParallelContainerBasePrivate::propagateStateToChildren(Interface::iterator external, bool updated) {
for (const Stage::pointer& stage : children()) for (const Stage::pointer& stage : children())
copyState<dir>(external, stage->pimpl()->pullInterface(dir), updated); copyState<dir>(external, stage->pimpl()->pullInterface(dir), updated);
} }