ofxHTTP
A collection of tools for HTTP.
ofx::HTTP::SSERoute Class Reference

A route for handling WebSockets. More...

#include <SSERoute.h>

Inheritance diagram for ofx::HTTP::SSERoute:
ofx::HTTP::BaseRoute_< SSERouteSettings > ofx::HTTP::AbstractRoute ofx::HTTP::AbstractHTTPRequestHandler ofx::HTTP::AbstractHTTPRequestHandlerFactory ofx::HTTP::AbstractServerEventRequestHandler

Public Types

typedef SSERouteSettings Settings
 A typedef for the SSERouteSettings.
 

Public Member Functions

 SSERoute (const Settings &settings)
 Create a SSERoute with the given Settings. More...
 
virtual ~SSERoute ()
 Destroy the SSERoute.
 
virtual bool canHandleRequest (const Poco::Net::HTTPServerRequest &request, bool isSecurePort) const override
 Determine if this route can handle the given request. More...
 
virtual Poco::Net::HTTPRequestHandler * createRequestHandler (const Poco::Net::HTTPServerRequest &request) override
 Creates a new HTTPRequestHandler for the given request. More...
 
virtual void stop () override
 Stop any pending activity and close this route. More...
 
void send (const std::string &data, bool cache=false)
 Send a SSEFrame to all connections. More...
 
void send (const std::string &event, const std::string &data, bool cache=false)
 Send a SSEFrame to all connections. More...
 
void send (const SSEFrame &frame, bool cache=false)
 Send a SSEFrame to all connected connections. More...
 
std::size_t numConnections () const
 
std::size_t frameCacheSize () const
 
void clearFrameCache ()
 Clears the frame cache.
 
template<class ListenerClass >
void registerEventListeners (ListenerClass *listener, int priority=OF_EVENT_ORDER_AFTER_APP)
 Register event listeners for this route. More...
 
template<class ListenerClass >
void unregisterEventListeners (ListenerClass *listener, int priority=OF_EVENT_ORDER_AFTER_APP)
 Unregister event listeners for this route. More...
 
- Public Member Functions inherited from ofx::HTTP::BaseRoute_< SSERouteSettings >
 BaseRoute_ (const SSERouteSettings &settings=SSERouteSettings())
 Create a BaseRoute. More...
 
virtual ~BaseRoute_ ()
 Destroy a BaseRoute.
 
virtual void setup (const SSERouteSettings &settings)
 Setup the route with settings. More...
 
virtual std::string routePathPattern () const override
 Get the route's regex path pattern. More...
 
void handleRequest (Poco::Net::HTTPServerRequest &request, Poco::Net::HTTPServerResponse &response) override
 
virtual void handleRequest (ServerEventArgs &evt) override
 Handle the ServerEventArgs. More...
 
const SSERouteSettingssettings () const
 
AbstractServergetServer () override
 
void setServer (AbstractServer *server) override
 Set the server that owns this route. More...
 
- Public Member Functions inherited from ofx::HTTP::AbstractRoute
virtual ~AbstractRoute ()
 Destroy the AbstractRoute instance.
 
- Public Member Functions inherited from ofx::HTTP::AbstractHTTPRequestHandler
virtual ~AbstractHTTPRequestHandler ()
 Destroy the AbstractHTTPRequestHandler.
 
- Public Member Functions inherited from ofx::HTTP::AbstractServerEventRequestHandler
virtual ~AbstractServerEventRequestHandler ()
 Destroy the AbstractServerEventRequestHandler.
 
- Public Member Functions inherited from ofx::HTTP::AbstractHTTPRequestHandlerFactory
virtual ~AbstractHTTPRequestHandlerFactory ()
 Destroy the AbstractHTTPRequestHandlerFactory.
 

Public Attributes

SSEEvents events
 SSEEvents for SSE callbacks.
 

Friends

class SSEConnection
 

Additional Inherited Members

- Protected Attributes inherited from ofx::HTTP::BaseRoute_< SSERouteSettings >
SSERouteSettings _settings
 The settings.
 
AbstractServer_server
 A pointer to the server.
 

Detailed Description

A route for handling WebSockets.

Constructor & Destructor Documentation

◆ SSERoute()

ofx::HTTP::SSERoute::SSERoute ( const Settings settings)

Create a SSERoute with the given Settings.

Parameters
settingsThe WebSocketRoute settings.

Member Function Documentation

◆ canHandleRequest()

bool ofx::HTTP::SSERoute::canHandleRequest ( const Poco::Net::HTTPServerRequest &  request,
bool  isSecurePort 
) const
overridevirtual

Determine if this route can handle the given request.

Parameters
requestThe incoming Poco::Net::HTTPServerRequest to be tested.
isSecurePorttrue iff the connection is SSL encrypted. Some implmenetations of this interface may choose to only handle requests on secure ports.
Returns
true iff the route can handle the given request.

Reimplemented from ofx::HTTP::BaseRoute_< SSERouteSettings >.

◆ createRequestHandler()

Poco::Net::HTTPRequestHandler * ofx::HTTP::SSERoute::createRequestHandler ( const Poco::Net::HTTPServerRequest &  request)
overridevirtual

Creates a new HTTPRequestHandler for the given request.

Before this is called, it is expected that the calling server has confirmed that this route is capable of handling the request by calling canHandleRequest().

Parameters
requestThe HTTPServerRequest to be passed to the handler.
Returns
An HTTPRequestHandler that will handle the request.
Note
Redeclared here for documentation puposes.

Reimplemented from ofx::HTTP::BaseRoute_< SSERouteSettings >.

◆ frameCacheSize()

std::size_t ofx::HTTP::SSERoute::frameCacheSize ( ) const
Returns
the size of the frame cache.

◆ numConnections()

std::size_t ofx::HTTP::SSERoute::numConnections ( ) const
Returns
The number of active SSEConnections.

◆ registerEventListeners()

template<class ListenerClass >
void ofx::HTTP::SSERoute::registerEventListeners ( ListenerClass *  listener,
int  priority = OF_EVENT_ORDER_AFTER_APP 
)

Register event listeners for this route.

The listener class must implement the following callbacks:

onSSEOpenEvent(...), onSSECloseEvent(...), onSSEFrameSentEvent(...).

Template Parameters
ListenerClassThe lister class to register.
Parameters
listenerA pointer to the listener class.
priorityThe listener priority.

◆ send() [1/3]

void ofx::HTTP::SSERoute::send ( const std::string &  data,
bool  cache = false 
)

Send a SSEFrame to all connections.

Parameters
dataThe frame to send.
cacheTrue if the frame should be indexed and cached.

◆ send() [2/3]

void ofx::HTTP::SSERoute::send ( const std::string &  event,
const std::string &  data,
bool  cache = false 
)

Send a SSEFrame to all connections.

Parameters
eventThe event name to send.
dataThe frame to send.
cacheTrue if the frame should be indexed and cached.

◆ send() [3/3]

void ofx::HTTP::SSERoute::send ( const SSEFrame frame,
bool  cache = false 
)

Send a SSEFrame to all connected connections.

Parameters
frameThe frame to send.
cacheTrue if the frame should be indexed and cached.

◆ stop()

void ofx::HTTP::SSERoute::stop ( )
overridevirtual

Stop any pending activity and close this route.

This method may block until the route is fully stopped.

Reimplemented from ofx::HTTP::BaseRoute_< SSERouteSettings >.

◆ unregisterEventListeners()

template<class ListenerClass >
void ofx::HTTP::SSERoute::unregisterEventListeners ( ListenerClass *  listener,
int  priority = OF_EVENT_ORDER_AFTER_APP 
)

Unregister event listeners for this route.

Template Parameters
ListenerClassThe lister class to uregister.
Parameters
listenerA pointer to the listener class.
priorityThe listener priority.

The documentation for this class was generated from the following files: