BasicEndpoint.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <swarmio/Endpoint.h>
4 #include <swarmio/Mailbox.h>
5 #include <mutex>
6 #include <set>
7 #include <atomic>
8 
10 {
15  class SWARMIO_API BasicEndpoint : public Endpoint
16  {
17  private:
18 
23  bool _isRunning;
24 
28  std::set<Mailbox*> _mailboxes;
29 
34  std::recursive_mutex _mutex;
35 
40  std::atomic<uint64_t> _counter;
41 
49  void ReplyWithError(const Node* sender, const data::Message* message, data::Error error);
50 
51  protected:
52 
57  BasicEndpoint() : _counter(1), _isRunning(false) { }
58 
68  virtual void Send(const void* data, size_t size, const Node* node) = 0;
69 
77  virtual bool ReceiveMessage(const Node* sender, const data::Message* message) noexcept;
78 
87  virtual bool ReceiveMessage(const Node* sender, const void* data, size_t size) noexcept;
88 
94  virtual void NodeWasDiscovered(const Node* node) noexcept;
95 
101  virtual void NodeDidJoin(const Node* node) noexcept;
102 
108  virtual void NodeWillLeave(const Node* node) noexcept;
109 
118  virtual void RegisterMailbox(Mailbox* mailbox) override;
119 
128  virtual void UnregisterMailbox(Mailbox* mailbox) override;
129 
137  virtual void ReplaceMailbox(Mailbox* oldMailbox, Mailbox* newMailbox) override;
138 
139  public:
140 
146  virtual void Start() override;
147 
155  virtual void Stop() override;
156 
162  bool IsRunning()
163  {
164  return _isRunning;
165  }
166 
177  virtual void Send(data::Message* message, const Node* node) override;
178 
186  virtual void Tag(data::Message* message) override;
187  };
188 }
std::set< Mailbox * > _mailboxes
Container for registered mailboxes.
Definition: BasicEndpoint.h:28
BasicEndpoint()
Protected constructor.
Definition: BasicEndpoint.h:57
std::recursive_mutex _mutex
Mutex used to synchronize access to the list of mailboxes.
Definition: BasicEndpoint.h:34
bool IsRunning()
Checks whether the endpoint has been started.
std::atomic< uint64_t > _counter
Atomic counter for message identifiers.
Definition: BasicEndpoint.h:40
Abstract base class for Endpoint implementations.
Definition: Endpoint.h:25
bool _isRunning
True if the Mailbox has been started.
Definition: BasicEndpoint.h:23
An helper class for Endpoint implementations which implements some common basic functionality.
Definition: BasicEndpoint.h:15
Represents a Node the Endpoint knows about and can send messages to.
Abstract base class for Mailbox implementations.
Definition: Mailbox.h:13


swarmros
Author(s):
autogenerated on Fri Apr 3 2020 03:42:47