ZeroEQ  0.9.0
ZeroEQ - Zero Event Queue
server.h
1 
2 /* Copyright (c) 2017, Human Brain Project
3  * Stefan.Eilemann@epfl.ch
4  */
5 
6 #pragma once
7 
8 #include <zeroeq/api.h>
9 #include <zeroeq/receiver.h> // base class
10 #include <zeroeq/sender.h> // base class
11 #include <zeroeq/types.h>
12 
13 namespace zeroeq
14 {
23 class Server : public Receiver, public Sender
24 {
25 public:
38  ZEROEQ_API Server();
39 
52  ZEROEQ_API explicit Server(const std::string& session);
53 
66  ZEROEQ_API explicit Server(const URI& uri);
67 
81  ZEROEQ_API Server(const URI& uri, const std::string& session);
82 
96  ZEROEQ_API explicit Server(Receiver& shared);
97 
111  ZEROEQ_API Server(const std::string& session, Receiver& shared);
112 
126  ZEROEQ_API Server(const URI& uri, Receiver& shared);
127 
142  ZEROEQ_API Server(const URI& uri, const std::string& session,
143  Receiver& shared);
144 
146  ZEROEQ_API ~Server();
147 
148  ZEROEQ_API Server(Server&&);
149  ZEROEQ_API Server& operator=(Server&&);
150 
161  ZEROEQ_API bool handle(const uint128_t& request, const HandleFunc& func);
162 
168  ZEROEQ_API bool remove(const uint128_t& request);
169 
178  ZEROEQ_API const URI& getURI() const;
179 
181  ZEROEQ_API const std::string& getSession() const;
182 
183 private:
184  class Impl;
185  std::unique_ptr<Impl> _impl;
186 
187  Server(const Server&) = delete;
188  Server& operator=(const Server&) = delete;
189 
190  // Receiver API
191  void addSockets(std::vector<detail::Socket>& entries) final;
192  bool process(detail::Socket& socket) final;
193  void addConnection(const std::string& uri) final;
194 
195  // Sender API
196  ZEROEQ_API zmq::SocketPtr getSocket() final;
197 };
198 }
Enhances servus::URI to guarantee the existance of a schema and to allow construction of [host][:port...
Definition: uri.h:19
Defines export visibility macros for library ZeroEQ.
Server()
Create a default server.
Serves request from one or more Client(s).
Definition: server.h:23
const std::string & getSession() const
std::function< ReplyData(const void *, size_t)> HandleFunc
Callback for serving a Client::request() in Server::handle().
Definition: types.h:68
~Server()
Destroy this server.
Base class for entities receiving data.
Definition: receiver.h:38
Publish-subscribe and request-reply.
Definition: client.h:10
Interface for entities sending data.
Definition: sender.h:13
const URI & getURI() const
Get the server URI.
bool handle(const uint128_t &request, const HandleFunc &func)
Register a request handler.