Hedgehog  3.1.0
A library to generate hybrid pipeline workflow systems
Loading...
Searching...
No Matches
notifier_abstraction.h
Go to the documentation of this file.
1// NIST-developed software is provided by NIST as a public service. You may use, copy and distribute copies of the
2// software in any medium, provided that you keep intact this entire notice. You may improve, modify and create
3// derivative works of the software or any portion of the software, and you may copy and distribute such modifications
4// or works. Modified works should carry a notice stating that you changed the software and should note the date and
5// nature of any such change. Please explicitly acknowledge the National Institute of Standards and Technology as the
6// source of the software. NIST-developed software is expressly provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND,
7// EXPRESS, IMPLIED, IN FACT OR ARISING BY OPERATION OF LAW, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
8// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT AND DATA ACCURACY. NIST NEITHER REPRESENTS NOR
9// WARRANTS THAT THE OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ANY DEFECTS WILL BE
10// CORRECTED. NIST DOES NOT WARRANT OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF THE SOFTWARE OR THE RESULTS
11// THEREOF, INCLUDING BUT NOT LIMITED TO THE CORRECTNESS, ACCURACY, RELIABILITY, OR USEFULNESS OF THE SOFTWARE. You
12// are solely responsible for determining the appropriateness of using and distributing the software and you assume
13// all risks associated with its use, including but not limited to the risks and costs of program errors, compliance
14// with applicable laws, damage to or loss of data, programs or equipment, and the unavailability or interruption of
15// operation. This software is not intended to be used in any situation where a failure could cause risk of injury or
16// damage to property. The software developed by NIST employees is not subject to copyright protection within the
17// United States.
18
19#ifndef HEDGEHOG_NOTIFIER_ABSTRACTION_H
20#define HEDGEHOG_NOTIFIER_ABSTRACTION_H
21#pragma once
22
23#include <utility>
24#include <ostream>
25
26#include "slot_abstraction.h"
27#include "../../../implementors/implementor/implementor_notifier.h"
28#include "../clonable_abstraction.h"
29
31namespace hh {
33namespace core {
34
35#ifndef DOXYGEN_SHOULD_SKIP_THIS
37namespace implementor {
39class ImplementorNotifier;
40}
41#endif //DOXYGEN_SHOULD_SKIP_THIS
42
44namespace abstraction {
45
48 private:
49 std::shared_ptr<implementor::ImplementorNotifier>
51 public:
54 explicit NotifierAbstraction(std::shared_ptr<implementor::ImplementorNotifier> notifier)
55 : concreteNotifier_(std::move(notifier)) {
56 concreteNotifier_->initialize(this);
57 }
58
60 virtual ~NotifierAbstraction() = default;
61
66 [[nodiscard]] std::set<NotifierAbstraction *> const &notifiers() const { return concreteNotifier_->notifiers(); }
67
72 [[nodiscard]] std::set<NotifierAbstraction *> &notifiers() { return concreteNotifier_->notifiers(); }
73
76 void addSlot(SlotAbstraction *const slot) { concreteNotifier_->addSlot(slot); }
77
80 void removeSlot(SlotAbstraction *const slot) { concreteNotifier_->removeSlot(slot); }
81
84 [[nodiscard]] std::set<SlotAbstraction *> const &connectedSlots() const {
85 return concreteNotifier_->connectedSlots();
86 }
87
89 void notify() { concreteNotifier_->notify(); }
90
92 void notifyAllTerminated() { concreteNotifier_->notifyAllTerminated(); }
93
94 protected:
100 std::map<abstraction::NodeAbstraction *, std::shared_ptr<NodeAbstraction>> &mapping) {
101 std::shared_ptr<NodeAbstraction> duplicateSlot;
102 auto notifierAsNode = dynamic_cast<abstraction::NodeAbstraction *>(this);
103 if (!mapping.contains(notifierAsNode)) {
104 throw std::runtime_error("A node that we are trying to connect is not mapped yet.");
105 }
106 auto mappedNotifier = std::dynamic_pointer_cast<abstraction::NotifierAbstraction>(mapping.at(notifierAsNode));
107 if (mappedNotifier == nullptr) {
108 throw std::runtime_error("The mapped type of a node is not of the right type: abstraction::NodeAbstraction.");
109 }
110
111 for (auto &notifier : this->notifiers()) {
112 for (auto &slot : notifier->connectedSlots()) {
113 for (auto &s : slot->slots()) {
114 if (auto slotAsNode = dynamic_cast<abstraction::NodeAbstraction *>(s)) {
115 if (mapping.contains(slotAsNode)) {
116 auto mappedSlot = std::dynamic_pointer_cast<abstraction::SlotAbstraction>(mapping.at(slotAsNode));
117 if (mappedSlot == nullptr) {
118 throw std::runtime_error("The mapped type of a node is not of the right type: SlotAbstraction.");
119 }
120
121 for(auto mmapedS : mappedSlot->slots()) {
122 for (auto mmapedN : mappedNotifier->notifiers()) {
123 mmapedN->addSlot(mmapedS);
124 mmapedS->addNotifier(mmapedN);
125 }
126 }
127
128 }
129 } else {
130 throw std::runtime_error("A slot is not a node when duplicating edges.");
131 }
132 }
133 }
134 }
135 }
136};
137}
138}
139}
140#endif //HEDGEHOG_NOTIFIER_ABSTRACTION_H
Hedgehog main namespace.
Core abstraction to notify slots.
void notifyAllTerminated()
Notifier all slots that this node is terminated.
void addSlot(SlotAbstraction *const slot)
Add a SlotAbstraction to this notifier.
std::shared_ptr< implementor::ImplementorNotifier > concreteNotifier_
Concrete implementation of the notifier used in the node.
std::set< NotifierAbstraction * > & notifiers()
Accessor to notifiers.
void removeSlot(SlotAbstraction *const slot)
Remove SlotAbstraction from this notifier.
virtual ~NotifierAbstraction()=default
Default destructor.
void duplicateEdgeNotifier(std::map< abstraction::NodeAbstraction *, std::shared_ptr< NodeAbstraction > > &mapping)
Duplicate edges of the current notifier to slots to clone in map.
void notify()
Notify a slot to wake up.
NotifierAbstraction(std::shared_ptr< implementor::ImplementorNotifier > notifier)
Constructor utilising a concrete implementation.
std::set< NotifierAbstraction * > const & notifiers() const
Const accessor to notifiers.
std::set< SlotAbstraction * > const & connectedSlots() const
Accessor to the slots attached to this notifier.
Core's abstraction to receive a signal.