ZeroEQ  0.9.0
ZeroEQ - Zero Event Queue
subscriber.h
1 
2 /* Copyright (c) 2014-2017, Human Brain Project
3  * Daniel Nachbaur <daniel.nachbaur@epfl.ch>
4  * Stefan.Eilemann@epfl.ch
5  */
6 
7 #ifndef ZEROEQ_SUBSCRIBER_H
8 #define ZEROEQ_SUBSCRIBER_H
9 
10 #include <zeroeq/receiver.h> // base class
11 #include <zeroeq/uri.h> // used inline
12 
13 #include <vector>
14 
15 namespace zeroeq
16 {
34 class Subscriber : public Receiver
35 {
36 public:
46  ZEROEQ_API Subscriber();
47 
59  ZEROEQ_API explicit Subscriber(const std::string& session);
60 
71  ZEROEQ_API explicit Subscriber(const URIs& uris);
72 
79  ZEROEQ_API explicit Subscriber(Receiver& shared);
80 
90  ZEROEQ_API Subscriber(const std::string& session, Receiver& shared);
91 
101  ZEROEQ_API Subscriber(const URIs& uris, Receiver& shared);
102 
104  ZEROEQ_API ~Subscriber();
105 
106  explicit Subscriber(const URI& uri)
107  : Subscriber(URIs{uri})
108  {
109  }
110  Subscriber(const URI& uri, Receiver& shared)
111  : Subscriber(URIs{uri}, shared)
112  {
113  }
114 
128  ZEROEQ_API bool subscribe(servus::Serializable& serializable);
129 
139  ZEROEQ_API bool subscribe(const uint128_t& event, const EventFunc& func);
140 
150  ZEROEQ_API bool subscribe(const uint128_t& event,
151  const EventPayloadFunc& func);
152 
160  ZEROEQ_API bool unsubscribe(const servus::Serializable& serializable);
161 
162  ZEROEQ_API bool unsubscribe(const uint128_t& event);
163 
165  ZEROEQ_API const std::string& getSession() const;
166 
167 private:
168  class Impl;
169  std::unique_ptr<Impl> _impl;
170 
171  // Receiver API
172  void addSockets(std::vector<detail::Socket>& entries) final;
173  bool process(detail::Socket& socket) final;
174  void update() final;
175  void addConnection(const std::string& uri) final;
176 };
177 }
178 
179 #endif
Enhances servus::URI to guarantee the existance of a schema and to allow construction of [host][:port...
Definition: uri.h:19
Subscribes to Publisher to receive events.
Definition: subscriber.h:34
bool unsubscribe(const servus::Serializable &serializable)
Unsubscribe a serializable object to stop applying updates from any connected publisher.
const std::string & getSession() const
Subscriber()
Create a default subscriber.
~Subscriber()
Destroy this subscriber and withdraw any subscriptions.
bool subscribe(servus::Serializable &serializable)
Subscribe a serializable object to receive updates from any connected publisher.
std::function< void()> EventFunc
Callback for receival of subscribed event without payload.
Definition: types.h:56
std::vector< URI > URIs
A vector of URIs.
Definition: types.h:53
std::function< void(const void *, size_t)> EventPayloadFunc
Callback for receival of subscribed event with payload.
Definition: types.h:59
Base class for entities receiving data.
Definition: receiver.h:38
Subscriber(const URI &uri, Receiver &shared)
Definition: subscriber.h:110
Publish-subscribe and request-reply.
Definition: client.h:10
Subscriber(const URI &uri)
Definition: subscriber.h:106