ZeroEQ  0.7.0
ZeroEQ - Zero Event Queue
subscriber.h
1 
2 /* Copyright (c) 2014-2016, 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 
12 #include <vector>
13 
14 namespace zeroeq
15 {
33 class Subscriber : public Receiver
34 {
35 public:
45  ZEROEQ_API Subscriber();
46 
58  ZEROEQ_API explicit Subscriber( const std::string& session );
59 
70  ZEROEQ_API explicit Subscriber( const URI& uri );
71 
89  ZEROEQ_API Subscriber( const URI& uri, const std::string& session );
90 
97  ZEROEQ_API Subscriber( Receiver& shared );
98 
108  ZEROEQ_API Subscriber( const std::string& session, Receiver& shared );
109 
119  ZEROEQ_API Subscriber( const URI& uri, Receiver& shared );
120 
130  ZEROEQ_API Subscriber( const URI& uri, const std::string& session,
131  Receiver& shared );
132 
134  ZEROEQ_API ~Subscriber();
135 
149  ZEROEQ_API bool subscribe( servus::Serializable& serializable );
150 
160  ZEROEQ_API bool subscribe( const uint128_t& event, const EventFunc& func );
161 
171  ZEROEQ_API bool subscribe( const uint128_t& event,
172  const EventPayloadFunc& func );
173 
181  ZEROEQ_API bool unsubscribe( const servus::Serializable& serializable );
182 
183  ZEROEQ_API bool unsubscribe( const uint128_t& event );
184 
186  ZEROEQ_API const std::string& getSession() const;
187 
188 private:
189  class Impl;
190  std::unique_ptr< Impl > _impl;
191 
192  // Receiver API
193  void addSockets( std::vector< detail::Socket >& entries ) final;
194  void process( detail::Socket& socket, uint32_t timeout ) final;
195  void update() final;
196  void addConnection( const std::string& uri ) final;
197 };
198 
199 }
200 
201 #endif
Enhances servus::URI to guarantee the existance of a schema and to allow construction of [host][:port...
Definition: uri.h:20
Subscribes to Publisher to receive events.
Definition: subscriber.h:33
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 w/o payload.
Definition: types.h:43
Base class for entities receiving data.
Definition: receiver.h:33
std::function< void(const void *, size_t) > EventPayloadFunc
Callback for receival of subscribed event w/ payload.
Definition: types.h:49
Publish-subscribe classes for typed events.
Definition: broker.h:12