Hedgehog  3.1.0
A library to generate hybrid pipeline workflow systems
Loading...
Searching...
No Matches
default_notifier.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
20
21#ifndef HEDGEHOG_DEFAULT_NOTIFIER_H
22#define HEDGEHOG_DEFAULT_NOTIFIER_H
23
24#include <mutex>
25
26#include "../implementor/implementor_notifier.h"
27#include "../implementor/implementor_slot.h"
28#include "../../abstractions/base/input_output/slot_abstraction.h"
30namespace hh {
32namespace core {
34namespace implementor {
35
38 private:
39 std::unique_ptr<std::set<abstraction::SlotAbstraction *>> const
40 slots_ = nullptr;
41
42 public:
44 explicit DefaultNotifier() : slots_(std::make_unique<std::set<abstraction::SlotAbstraction *>>()){}
45
47 ~DefaultNotifier() override = default;
48
51 void addSlot(abstraction::SlotAbstraction *const slot) override { slots_->insert(slot); }
52
55 void removeSlot(abstraction::SlotAbstraction *const slot) override { slots_->erase(slot); }
56
59 [[nodiscard]] std::set<abstraction::SlotAbstraction *> const &connectedSlots() const override { return *slots_; }
60
62 void notify() override {
63 for (const auto &slot : *slots_) { slot->wakeUp(); }
64 }
65
67 void notifyAllTerminated() override {
68 for (auto notifier : *(this->abstractNotifiers_)) {
69 for (abstraction::SlotAbstraction *slot : *slots_) { slot->removeNotifier(notifier); }
70 }
71 for (abstraction::SlotAbstraction *slot : *slots_) { slot->wakeUp(); }
72 while (!slots_->empty()) { slots_->erase(slots_->begin()); }
73 }
74
75};
76}
77}
78}
79#endif //HEDGEHOG_DEFAULT_NOTIFIER_H
Hedgehog main namespace.
Core's abstraction to receive a signal.
Default concrete implementation of notifier interface.
void addSlot(abstraction::SlotAbstraction *const slot) override
Add a slot to transmit messages to.
std::unique_ptr< std::set< abstraction::SlotAbstraction * > > const slots_
Slot getting the message.
void removeSlot(abstraction::SlotAbstraction *const slot) override
Remove a slot to transmit messages to.
std::set< abstraction::SlotAbstraction * > const & connectedSlots() const override
Accessor to the connected slots.
~DefaultNotifier() override=default
Default destructor.
void notify() override
Notify method, calls wakeUp on all connected slots.
void notifyAllTerminated() override
Remove the notifier connection from all connected slots, and calls wakeUp on all.
Implementor for the NotifierAbstraction.
std::unique_ptr< std::set< abstraction::NotifierAbstraction * > > abstractNotifiers_
Set of linked NotifierAbstraction.