1818
1919#include < string>
2020
21+ #include " dtlmod/ActorRegistry.hpp"
2122#include " dtlmod/Transport.hpp"
2223#include " dtlmod/Variable.hpp"
2324
@@ -45,66 +46,52 @@ class Engine {
4546
4647 friend class Stream ;
4748
48- protected:
4949 std::string name_;
5050 Type type_ = Type::Undefined;
5151 std::shared_ptr<Transport> transport_ = nullptr ;
5252 std::weak_ptr<Stream> stream_;
5353
54- sg4::MutexPtr pub_mutex_ = sg4::Mutex::create();
55- std::set<sg4::ActorPtr> publishers_;
54+ ActorRegistry publishers_;
55+ ActorRegistry subscribers_;
56+ std::string metadata_file_;
57+
58+ protected:
5659 sg4::ActivitySet pub_transaction_;
5760 sg4::ConditionVariablePtr pub_transaction_completed_ = sg4::ConditionVariable::create();
58- sg4::BarrierPtr pub_barrier_ = nullptr ;
5961 unsigned int current_pub_transaction_id_ = 0 ;
6062 unsigned int completed_pub_transaction_id_ = 0 ;
6163 bool pub_transaction_in_progress_ = false ;
62- virtual void begin_pub_transaction () = 0;
63- virtual void end_pub_transaction () = 0;
64- virtual void pub_close () = 0;
6564
66- sg4::MutexPtr sub_mutex_ = sg4::Mutex::create();
67- std::set<sg4::ActorPtr> subscribers_;
6865 sg4::ActivitySet sub_transaction_;
69-
70- sg4::BarrierPtr sub_barrier_ = nullptr ;
7166 unsigned int current_sub_transaction_id_ = 0 ;
7267 bool sub_transaction_in_progress_ = false ;
73- virtual void begin_sub_transaction () = 0;
74- virtual void end_sub_transaction () = 0;
75- virtual void sub_close () = 0;
76-
77- std::string metadata_file_;
78- void export_metadata_to_file () const ;
7968
80- // / \cond EXCLUDE_FROM_DOCUMENTATION
8169 void close_stream () const ;
8270
8371 virtual void create_transport (const Transport::Method& transport_method) = 0;
84-
8572 void set_transport (std::shared_ptr<Transport> transport) noexcept { transport_ = transport; }
8673 [[nodiscard]] std::shared_ptr<Transport> get_transport () const noexcept { return transport_; }
8774
8875 void add_publisher (sg4::ActorPtr actor);
89- void rm_publisher (sg4::ActorPtr actor) noexcept { publishers_.erase (actor); }
90- [[nodiscard]] bool is_publisher (sg4::ActorPtr actor) const noexcept
91- {
92- return publishers_.find (actor) != publishers_.end ();
93- }
76+ void rm_publisher (sg4::ActorPtr actor) noexcept { publishers_.remove (actor); }
77+ [[nodiscard]] bool is_publisher (sg4::ActorPtr actor) const noexcept { return publishers_.contains (actor); }
9478 // Synchronize publishers on engine closing
95- [[nodiscard]] int is_last_publisher () const { return (pub_barrier_ && pub_barrier_->wait ()); }
79+ [[nodiscard]] bool is_last_publisher () { return publishers_.is_last_at_barrier (); }
80+ virtual void begin_pub_transaction () = 0;
81+ virtual void end_pub_transaction () = 0;
82+ virtual void pub_close () = 0;
9683
9784 void add_subscriber (sg4::ActorPtr actor);
98- void rm_subscriber (sg4::ActorPtr actor) noexcept { subscribers_.erase (actor); }
99- [[nodiscard]] bool is_subscriber (sg4::ActorPtr actor) const noexcept
100- {
101- return subscribers_.find (actor) != subscribers_.end ();
102- }
85+ void rm_subscriber (sg4::ActorPtr actor) noexcept { subscribers_.remove (actor); }
86+ [[nodiscard]] bool is_subscriber (sg4::ActorPtr actor) const noexcept { return subscribers_.contains (actor); }
10387 // Synchronize subscribers on engine closing
104- [[nodiscard]] int is_last_subscriber () const noexcept { return subscribers_.empty (); }
88+ [[nodiscard]] bool is_last_subscriber () const noexcept { return subscribers_.is_empty (); }
89+ virtual void begin_sub_transaction () = 0;
90+ virtual void end_sub_transaction () = 0;
91+ virtual void sub_close () = 0;
10592
10693 void set_metadata_file_name ();
107- // / \endcond
94+ void export_metadata_to_file () const ;
10895
10996public:
11097 // / \cond EXCLUDE_FROM_DOCUMENTATION
@@ -118,9 +105,9 @@ class Engine {
118105 [[nodiscard]] sg4::ActivitySet& get_pub_transaction () noexcept { return pub_transaction_; }
119106 [[nodiscard]] const sg4::ActivitySet& get_sub_transaction () const noexcept { return sub_transaction_; }
120107 [[nodiscard]] sg4::ActivitySet& get_sub_transaction () noexcept { return sub_transaction_; }
121- [[nodiscard]] const std::set<sg4::ActorPtr>& get_publishers () const noexcept { return publishers_; }
122- [[nodiscard]] size_t get_num_publishers () const noexcept { return publishers_.size (); }
123- [[nodiscard]] size_t get_num_subscribers () const noexcept { return subscribers_.size (); }
108+ [[nodiscard]] const std::set<sg4::ActorPtr>& get_publishers () const noexcept { return publishers_. get_all () ; }
109+ [[nodiscard]] size_t get_num_publishers () const noexcept { return publishers_.count (); }
110+ [[nodiscard]] size_t get_num_subscribers () const noexcept { return subscribers_.count (); }
124111 // / \endcond
125112
126113 // / @brief Helper function to print out the name of the Engine.
0 commit comments