Hedgehog  0.0.0
A library to generate hybrid pipeline workflow systems
core_graph_sink.h
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 
20 #ifndef HEDGEHOG_CORE_GRAPH_SINK_H
21 #define HEDGEHOG_CORE_GRAPH_SINK_H
22 
23 #include "../../queue/receiver/core_queue_multi_receivers.h"
24 
26 namespace hh::core {
27 
30 template<class GraphOutput>
31 class CoreGraphSink : public CoreQueueMultiReceivers<GraphOutput> {
32  public:
34  CoreGraphSink() : CoreNode("Sink", NodeType::Sink, 1),
35  CoreSlot("Sink", NodeType::Sink, 1),
36  CoreReceiver<GraphOutput>("Sink", NodeType::Sink, 1),
37  CoreQueueMultiReceivers<GraphOutput>("Sink", NodeType::Sink, 1) {
38  HLOG_SELF(0, "Creating CoreGraphSink")
39  }
40 
42  ~CoreGraphSink() override {HLOG_SELF(0, "Destructing CoreGraphSink")}
43 
46  void visit(AbstractPrinter *printer) override {
47  HLOG_SELF(1, "Visit")
48  if (printer->hasNotBeenVisited(this)) {
49  printer->printNodeInformation(this);
50  }
51  }
52 
56  [[noreturn]] behavior::Node *node() override {
57  std::ostringstream oss;
58  oss << "Internal error, should not be called, sink does not have a node: " << __FUNCTION__;
59  HLOG_SELF(0, oss.str())
60  throw (std::runtime_error(oss.str()));
61  }
62 
66  [[noreturn]] std::shared_ptr<CoreNode> clone() override {
67  std::ostringstream oss;
68  oss
69  << "Internal error, should not be called, graph's sink can't be clone, as an outer graph can't be cloned : "
70  << __FUNCTION__;
71  HLOG_SELF(0, oss.str())
72  throw (std::runtime_error(oss.str()));
73  }
74 
77  bool waitForNotification() override {
78  std::unique_lock<std::mutex> lock(*(this->slotMutex()));
79 
80  HLOG_SELF(2, "Wait for the notification")
81 
82  this->notifyConditionVariable()->wait(lock,
83  [this]() {
84  return !this->receiversEmpty() || this->numberInputNodes() == 0;
85  });
86  HLOG_SELF(2, "Notification received")
87 
88  return true;
89  }
90 
95  [[noreturn]] void duplicateEdge([[maybe_unused]]CoreNode *duplicateNode,
96  [[maybe_unused]]std::map<CoreNode *,
97  std::shared_ptr<CoreNode>> &correspondenceMap) override {
98  std::ostringstream oss;
99  oss << "Internal error, should not be called, sink does not have edges to connect in an execution pipeline: "
100  << __FUNCTION__;
101  HLOG_SELF(0, oss.str())
102  throw (std::runtime_error(oss.str()));
103  }
104 };
105 
106 }
107 #endif //HEDGEHOG_CORE_GRAPH_SINK_H
Receiver Interface, receive one data type from CoreSender.
Definition: core_receiver.h:44
CoreGraphSink()
Default sink constructor.
bool waitForNotification() override
Wait for notification from the output nodes and return the state of the sink.
~CoreGraphSink() override
Default sink destructor.
std::shared_ptr< std::mutex > const & slotMutex() const
Mutex accessor.
void duplicateEdge([[maybe_unused]]CoreNode *duplicateNode, [[maybe_unused]]std::map< CoreNode *, std::shared_ptr< CoreNode >> &correspondenceMap) override
Duplicate edge for a sink, throw an error in every case.
Printer interface.
Node Behavior definition.
Definition: node.h:39
Slot interface, receive notification from CoreNotifier.
Definition: core_slot.h:34
bool hasNotBeenVisited(core::CoreNode const *node)
Accessor to check if a node has been visited by the printer.
Part of the outer graph that gathers data from the output nodes and makes them available as the graph...
NodeType
Hedgehog node&#39;s type.
Definition: core_node.h:40
size_t numberInputNodes() const final
Number of CoreNotifier linked accessor.
void visit(AbstractPrinter *printer) override
Special visit method for graph&#39;s sink.
Main Hedgehog core abstraction.
Definition: core_node.h:48
Multi receivers for nodes possessing a queue of data.
std::shared_ptr< std::condition_variable > const & notifyConditionVariable() const
Condition variable accessor.
Hedgehog core namespace.
Definition: core_execute.h:25
behavior::Node * node() override
Get a node from the graph&#39;s sink, that does not exist, throw an error in every case.
bool receiversEmpty() final
Test emptiness of all receivers.
virtual void printNodeInformation(core::CoreNode *node)=0
Print node information.
std::shared_ptr< CoreNode > clone() override
Get a clone of the graph&#39;s sink, that does not exist, throw an error in every case.