Hedgehog  0.0.0
A library to generate hybrid pipeline workflow systems
core_queue_notifier.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_QUEUE_NOTIFIER_H
21 #define HEDGEHOG_CORE_QUEUE_NOTIFIER_H
22 
23 #include "../../base/sender/core_notifier.h"
24 
26 namespace hh::core {
27 
29 class CoreQueueNotifier : public virtual CoreNotifier {
30  private:
31  std::shared_ptr<std::set<CoreSlot *>> slots_ = nullptr;
32 
33  public:
38  CoreQueueNotifier(std::string_view const &name, NodeType const type, size_t const numberThreads) :
39  CoreNotifier(name, type, numberThreads) {
40  HLOG_SELF(0, "Creating CoreQueueNotifier with type: " << (int) type << " and name: " << name)
41  slots_ = std::make_shared<std::set<CoreSlot *>>();
42  }
43 
45  ~CoreQueueNotifier() override {HLOG_SELF(0, "Destructing CoreQueueNotifier")}
46 
49  [[nodiscard]] std::shared_ptr<std::set<CoreSlot *>> const &slots() const { return slots_; }
50 
53  void addSlot(CoreSlot *slot) override {
54  HLOG_SELF(0, "Add Slot " << slot->name() << "(" << slot->id() << ")")
55  this->slots()->insert(slot);
56  }
57 
60  void removeSlot(CoreSlot *slot) override {
61  HLOG_SELF(0, "Remove Slot " << slot->name() << "(" << slot->id() << ")")
62  this->slots_->erase(slot);
63  }
64 
66  void notifyAllTerminated() override {
67  HLOG_SELF(2, "Notify all terminated")
68  std::for_each(this->slots()->begin(), this->slots()->end(), [this](CoreSlot *s) { s->removeNotifier(this); });
69  std::for_each(this->slots()->begin(), this->slots()->end(), [](CoreSlot *s) { s->wakeUp(); });
70  }
71 
75  HLOG_SELF(0, "Copy Cluster CoreQueueNotifier information from " << rhs->name() << "(" << rhs->id() << ")")
76  for (CoreSlot *slot : *(rhs->slots_)) { slot->addNotifier(this); }
77  this->slots_ = rhs->slots_;
78  }
79 };
80 
81 }
82 #endif //HEDGEHOG_CORE_QUEUE_NOTIFIER_H
NodeType type() const
Node type accessor.
Definition: core_node.h:132
~CoreQueueNotifier() override
CoreQueueNotifier destructor.
Core Notifier interface, emit notification to CoreSlot.
Definition: core_notifier.h:34
void copyInnerStructure(CoreQueueNotifier *rhs)
Copy the inner structure of the notifier (set of slots and connections)
virtual void wakeUp()=0
Interface to define what the node do when it receive a signal.
std::shared_ptr< std::set< CoreSlot * > > slots_
Set of connected slots.
void notifyAllTerminated() override
Notify all slots that the node is terminated.
std::shared_ptr< std::set< CoreSlot * > > const & slots() const
Connected slots accessor.
Slot interface, receive notification from CoreNotifier.
Definition: core_slot.h:34
void addSlot(CoreSlot *slot) override
Add a slot to the set of connected slots.
virtual void removeNotifier(CoreNotifier *notifier)=0
Interface to remove a CoreNotifier from this slot.
CoreQueueNotifier(std::string_view const &name, NodeType const type, size_t const numberThreads)
CoreQueueNotifier constructor.
NodeType
Hedgehog node&#39;s type.
Definition: core_node.h:40
void removeSlot(CoreSlot *slot) override
Remove a slot from the set of connected slots.
Notifier of CoreQueueSlot.
Hedgehog core namespace.
Definition: core_execute.h:25
std::string_view const & name() const
Node name accessor.
Definition: core_node.h:128
size_t numberThreads() const
Number of threads associated accessor.
Definition: core_node.h:152
virtual std::string id() const
Unique Id accessor.
Definition: core_node.h:114