ZeroEQ  0.7.0
ZeroEQ - Zero Event Queue
server.h
1 
2 /* Copyright (c) 2016, Human Brain Project
3  * Stefan.Eilemann@epfl.ch
4  */
5 
6 #ifndef ZEROEQ_HTTP_SERVER_H
7 #define ZEROEQ_HTTP_SERVER_H
8 
9 #include <zeroeq/http/api.h>
10 #include <zeroeq/receiver.h> // base class
11 #include <zeroeq/log.h>
12 
13 namespace zeroeq
14 {
16 namespace http
17 {
32 class Server : public zeroeq::Receiver
33 {
34 public:
49  ZEROEQHTTP_API Server( const URI& uri, Receiver& shared );
50  ZEROEQHTTP_API explicit Server( const URI& uri );
51  ZEROEQHTTP_API explicit Server( Receiver& shared );
52  ZEROEQHTTP_API Server();
53  ZEROEQHTTP_API explicit Server( Server& shared )
54  : Server( static_cast< Receiver& >( shared )) {}
55  ZEROEQHTTP_API ~Server();
56 
66  ZEROEQHTTP_API
67  static std::unique_ptr< Server > parse( int argc, const char* const* argv);
68  ZEROEQHTTP_API
69  static std::unique_ptr< Server > parse( int argc, const char* const* argv,
70  Receiver& shared );
79  ZEROEQHTTP_API const URI& getURI() const;
80 
91  ZEROEQHTTP_API SocketDescriptor getSocketDescriptor() const;
93 
97  bool handle( servus::Serializable& object )
98  { return handlePUT( object ) && handleGET( object );}
99 
101  ZEROEQHTTP_API bool remove( const servus::Serializable& object );
102 
104  ZEROEQHTTP_API bool remove( const std::string& event );
105 
119  ZEROEQHTTP_API bool handlePUT( servus::Serializable& object );
120 
131  ZEROEQHTTP_API
132  bool handlePUT( const std::string& event, const PUTFunc& func );
133 
140  ZEROEQHTTP_API bool handlePUT( const std::string& event,
141  const std::string& schema, const PUTFunc& func );
142 
152  ZEROEQHTTP_API bool handlePUT( const std::string& event,
153  const PUTPayloadFunc& func );
154 
161  ZEROEQHTTP_API bool handlePUT( const std::string& event,
162  const std::string& schema,
163  const PUTPayloadFunc& func );
176  ZEROEQHTTP_API bool handleGET( servus::Serializable& object );
177 
188  ZEROEQHTTP_API
189  bool handleGET( const std::string& event, const GETFunc& func );
190 
197  ZEROEQHTTP_API
198  bool handleGET( const std::string& event, const std::string& schema,
199  const GETFunc& func );
200 
205  ZEROEQHTTP_API
206  std::string getSchema( const servus::Serializable& object) const;
207 
209  ZEROEQHTTP_API std::string getSchema( const std::string& event ) const;
211 
212 private:
213  class Impl;
214  std::unique_ptr< Impl > _impl;
215 
216  // Receiver API
217  void addSockets( std::vector< detail::Socket >& entries ) final;
218  void process( detail::Socket& socket, uint32_t timeout ) final;
219  void addConnection( const std::string& ) final { ZEROEQDONTCALL; } // LCOV_EXCL_LINE
220 };
221 }
222 }
223 
224 #endif
Enhances servus::URI to guarantee the existance of a schema and to allow construction of [host][:port...
Definition: uri.h:20
ZEROEQHTTP_API bool handlePUT(servus::Serializable &object)
Subscribe a serializable object to receive updates from HTTP PUT requests.
ZEROEQHTTP_API const URI & getURI() const
Get the publisher URI.
ZEROEQHTTP_API bool handleGET(servus::Serializable &object)
Subscribe a serializable object to serve HTTP GET requests.
std::function< bool() > PUTFunc
HTTP PUT callback w/o payload, return reply success.
Definition: types.h:52
ZEROEQHTTP_API std::string getSchema(const servus::Serializable &object) const
bool handle(servus::Serializable &object)
Handle PUT and GET for the given object.
Definition: server.h:97
std::function< std::string() > GETFunc
HTTP GET callback to return JSON reply.
Definition: types.h:58
Serves HTTP GET and PUT requests for servus::Serializable objects.
Definition: server.h:32
std::function< bool(const std::string &) > PUTPayloadFunc
HTTP PUT callback w/ JSON payload, return reply success.
Definition: types.h:55
Base class for entities receiving data.
Definition: receiver.h:33
Publish-subscribe classes for typed events.
Definition: broker.h:12
Defines export visibility macros for library ZeroEQHTTP.
ZEROEQHTTP_API SocketDescriptor getSocketDescriptor() const
Get the underlying socket descriptor.
static ZEROEQHTTP_API std::unique_ptr< Server > parse(int argc, const char *const *argv)
Create a new Server when requested.