ZeroEQ
0.6.0
ZeroEQ - Zero Event Queue
|
Serves HTTP GET and PUT requests for servus::Serializable objects. More...
#include <server.h>
Public Member Functions | |
Object registration for PUT and GET requests | |
bool | add (servus::Serializable &object) |
Subscribe and register the given object. More... | |
bool | remove (const servus::Serializable &object) |
Unsubscribe and unregister the given object. More... | |
bool | subscribe (servus::Serializable &object) |
Subscribe a serializable object to receive updates from HTTP PUT requests. More... | |
bool | subscribe (const std::string &event, const PUTFunc &func) |
Subscribe an event to receive HTTP PUT requests. More... | |
bool | subscribe (const std::string &event, const PUTPayloadFunc &func) |
Subscribe an event to receive HTTP PUT requests with payload. More... | |
bool | unsubscribe (const servus::Serializable &object) |
Unsubscribe the given object to stop applying updates. More... | |
bool | unsubscribe (const std::string &event) |
Unsubscribe the given event to stop receiving PUT requests. More... | |
bool | register_ (servus::Serializable &object) |
Subscribe a serializable object to serve HTTP GET requests. More... | |
bool | register_ (const std::string &event, const GETFunc &func) |
Subscribe an event to serve HTTP GET requests. More... | |
bool | unregister (const servus::Serializable &object) |
Unsubscribe the given object for GET requests. More... | |
bool | unregister (const std::string &event) |
Unsubscribe the given event name for GET requests. More... | |
Public Member Functions inherited from zeroeq::Receiver | |
Receiver () | |
Create a new standalone receiver. More... | |
Receiver (Receiver &shared) | |
Create a shared receiver. More... | |
virtual | ~Receiver () |
Destroy this receiver. More... | |
bool | receive (const uint32_t timeout=TIMEOUT_INDEFINITE) |
Receive at least one event from all shared receivers. More... | |
Setup | |
Server (const URI &uri, Receiver &shared) | |
Construct a new HTTP server. More... | |
Server (const URI &uri) | |
Server (Receiver &shared) | |
Server () | |
Server (Server &shared) | |
virtual | ~Server () |
const URI & | getURI () const |
Get the publisher URI. More... | |
SocketDescriptor | getSocketDescriptor () const |
Get the underlying socket descriptor. More... | |
static std::unique_ptr< Server > | parse (int argc, const char *const *argv) |
Create a new Server when requested. More... | |
static std::unique_ptr< Server > | parse (int argc, const char *const *argv, Receiver &shared) |
Additional Inherited Members | |
Protected Member Functions inherited from zeroeq::Receiver | |
virtual void | update () |
Update the internal connection list. More... | |
void * | getZMQContext () |
Serves HTTP GET and PUT requests for servus::Serializable objects.
Behaves semantically like a Publisher (for GET) and Subscriber (for PUT), except uses HTTP with JSON payload as the protocol. Requests are served synchronously (as per HTTP spec). Objects are available under their Serializable::getTypeName(), with '::' replaced by '/'. The REST API is case insensitive. For example, zerobuf::render::Camera is served at 'GET|PUT [uri]/zerobuf/render/camera'.
Not thread safe.
Example:
Construct a new HTTP server.
To process requests on the incoming port, call receive(). If no hostname is given, the server listens on all interfaces (INADDR_ANY). If no port is given, the server selects a random port. Use getURI() to retrieve the chosen parameters.
uri | The server address in the form "[tcp://][hostname][:port]" |
shared | a shared receiver, see Receiver constructor. |
std::runtime_error | on malformed URI or connection issues. |
|
inline |
Subscribe and register the given object.
Definition at line 95 of file server.h.
References register_(), and subscribe().
SocketDescriptor zeroeq::http::Server::getSocketDescriptor | ( | ) | const |
Get the underlying socket descriptor.
Can be used by client code to be notified when new data is available and subsequently call receive.
std::runtime_error | if the descriptor could not be obtained. |
const URI& zeroeq::http::Server::getURI | ( | ) | const |
|
static |
Create a new Server when requested.
The creation and parameters depend on the following command line parameters:
bool zeroeq::http::Server::register_ | ( | servus::Serializable & | object | ) |
Subscribe a serializable object to serve HTTP GET requests.
Every request will be directly handled during receive() by using toJSON(). To track updates on the object, the serializable's received function is called accordingly.
The subscribed object instance has to be valid until unregister().
object | the object to serve during receive() |
Referenced by add().
bool zeroeq::http::Server::register_ | ( | const std::string & | event, |
const GETFunc & | func | ||
) |
Subscribe an event to serve HTTP GET requests.
Every request will be directly handled during receive() by calling the registered GET function.
event | the event name to serve during receive() |
func | the callback function for serving the GET request |
|
inline |
Unsubscribe and unregister the given object.
Definition at line 99 of file server.h.
References unregister(), and unsubscribe().
bool zeroeq::http::Server::subscribe | ( | servus::Serializable & | object | ) |
Subscribe a serializable object to receive updates from HTTP PUT requests.
Every update will be directly applied on the object during receive() using fromJSON(). To track updates on the object, the serializable's updated function is called accordingly.
The subscribed object instance has to be valid until unsubscribe().
object | the object to update on receive() |
Referenced by add().
bool zeroeq::http::Server::subscribe | ( | const std::string & | event, |
const PUTFunc & | func | ||
) |
Subscribe an event to receive HTTP PUT requests.
Every receival of the event will call the registered callback function.
event | the event name to receive PUT requests for during receive() |
func | the callback function for serving the PUT request |
bool zeroeq::http::Server::subscribe | ( | const std::string & | event, |
const PUTPayloadFunc & | func | ||
) |
Subscribe an event to receive HTTP PUT requests with payload.
Every receival of the event will call the registered callback function.
event | the event name to receive PUT requests for during receive() |
func | the callback function for serving the PUT request |
bool zeroeq::http::Server::unregister | ( | const servus::Serializable & | object | ) |
Unsubscribe the given object for GET requests.
Referenced by remove().
bool zeroeq::http::Server::unregister | ( | const std::string & | event | ) |
Unsubscribe the given event name for GET requests.
bool zeroeq::http::Server::unsubscribe | ( | const servus::Serializable & | object | ) |
Unsubscribe the given object to stop applying updates.
Referenced by remove().
bool zeroeq::http::Server::unsubscribe | ( | const std::string & | event | ) |
Unsubscribe the given event to stop receiving PUT requests.