ZeroEQ
0.7.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 | handle (servus::Serializable &object) |
Handle PUT and GET for the given object. More... | |
ZEROEQHTTP_API bool | remove (const servus::Serializable &object) |
Remove PUT and GET handling for given object. More... | |
ZEROEQHTTP_API bool | remove (const std::string &event) |
Remove PUT and GET handling for given event. More... | |
ZEROEQHTTP_API bool | handlePUT (servus::Serializable &object) |
Subscribe a serializable object to receive updates from HTTP PUT requests. More... | |
ZEROEQHTTP_API bool | handlePUT (const std::string &event, const PUTFunc &func) |
Subscribe an event to receive HTTP PUT requests. More... | |
ZEROEQHTTP_API bool | handlePUT (const std::string &event, const std::string &schema, const PUTFunc &func) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
ZEROEQHTTP_API bool | handlePUT (const std::string &event, const PUTPayloadFunc &func) |
Subscribe an event to receive HTTP PUT requests with payload. More... | |
ZEROEQHTTP_API bool | handlePUT (const std::string &event, const std::string &schema, const PUTPayloadFunc &func) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
ZEROEQHTTP_API bool | handleGET (servus::Serializable &object) |
Subscribe a serializable object to serve HTTP GET requests. More... | |
ZEROEQHTTP_API bool | handleGET (const std::string &event, const GETFunc &func) |
Subscribe an event to serve HTTP GET requests. More... | |
ZEROEQHTTP_API bool | handleGET (const std::string &event, const std::string &schema, const GETFunc &func) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
ZEROEQHTTP_API std::string | getSchema (const servus::Serializable &object) const |
ZEROEQHTTP_API std::string | getSchema (const std::string &event) const |
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 | |
ZEROEQHTTP_API | Server (const URI &uri, Receiver &shared) |
Construct a new HTTP server. More... | |
ZEROEQHTTP_API | Server (const URI &uri) |
ZEROEQHTTP_API | Server (Receiver &shared) |
ZEROEQHTTP_API | Server () |
ZEROEQHTTP_API | Server (Server &shared) |
ZEROEQHTTP_API | ~Server () |
ZEROEQHTTP_API const URI & | getURI () const |
Get the publisher URI. More... | |
ZEROEQHTTP_API SocketDescriptor | getSocketDescriptor () const |
Get the underlying socket descriptor. More... | |
static ZEROEQHTTP_API std::unique_ptr< Server > | parse (int argc, const char *const *argv) |
Create a new Server when requested. More... | |
static ZEROEQHTTP_API 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. |
ZEROEQHTTP_API std::string zeroeq::http::Server::getSchema | ( | const servus::Serializable & | object | ) | const |
Referenced by handle().
ZEROEQHTTP_API std::string zeroeq::http::Server::getSchema | ( | const std::string & | event | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
ZEROEQHTTP_API 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. Due to implementation details, the socket notifies on write, not on read.
std::runtime_error | if the descriptor could not be obtained. |
ZEROEQHTTP_API const URI& zeroeq::http::Server::getURI | ( | ) | const |
|
inline |
Handle PUT and GET for the given object.
Definition at line 97 of file server.h.
References getSchema(), handleGET(), and handlePUT().
ZEROEQHTTP_API bool zeroeq::http::Server::handleGET | ( | 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 removeGET().
object | the object to serve during receive() |
Referenced by handle().
ZEROEQHTTP_API bool zeroeq::http::Server::handleGET | ( | 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 |
ZEROEQHTTP_API bool zeroeq::http::Server::handleGET | ( | const std::string & | event, |
const std::string & | schema, | ||
const GETFunc & | func | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
event | the event name to serve during receive() |
schema | describes data layout of event |
func | the callback function for serving the GET request |
ZEROEQHTTP_API bool zeroeq::http::Server::handlePUT | ( | 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 removePUT().
object | the object to update on receive() |
Referenced by handle().
ZEROEQHTTP_API bool zeroeq::http::Server::handlePUT | ( | 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 |
ZEROEQHTTP_API bool zeroeq::http::Server::handlePUT | ( | const std::string & | event, |
const std::string & | schema, | ||
const PUTFunc & | func | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
event | the event name to receive PUT requests for during receive() |
schema | describes data layout of event |
func | the callback function for serving the PUT request |
ZEROEQHTTP_API bool zeroeq::http::Server::handlePUT | ( | 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 |
ZEROEQHTTP_API bool zeroeq::http::Server::handlePUT | ( | const std::string & | event, |
const std::string & | schema, | ||
const PUTPayloadFunc & | func | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
event | the event name to receive PUT requests for during receive() |
schema | describes data layout of event |
func | the callback function for serving the PUT request |
|
static |
Create a new Server when requested.
The creation and parameters depend on the following command line parameters:
ZEROEQHTTP_API bool zeroeq::http::Server::remove | ( | const servus::Serializable & | object | ) |
Remove PUT and GET handling for given object.
ZEROEQHTTP_API bool zeroeq::http::Server::remove | ( | const std::string & | event | ) |
Remove PUT and GET handling for given event.