NAP
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
WebSocketInterface Class Reference

#include <websocketinterface.h>

Public Member Functions

 WebSocketInterface (WebSocketService &service)
 
virtual ~WebSocketInterface ()
 
virtual bool init (utility::ErrorState &errorState) override
 
template<typename T >
T & as ()
 
template<typename T >
const T & as () const
 
- Public Member Functions inherited from Resource
 Resource ()
 
- Public Member Functions inherited from Object
 Object ()
 
virtual ~Object ()
 
virtual void onDestroy ()
 
 Object (Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object &&)=delete
 
Objectoperator= (Object &&)=delete
 

Protected Member Functions

void addEvent (WebSocketEventPtr newEvent)
 

Protected Attributes

std::queue< WebSocketEventPtrmEvents
 
std::mutex mEventMutex
 
WebSocketServicemService = nullptr
 

Additional Inherited Members

- Static Public Member Functions inherited from Object
static bool isIDProperty (rtti::Instance &object, const rtti::Property &property)
 
- Public Attributes inherited from Object
std::string mID
 Property: 'mID' unique name of the object. Used as an identifier by the system. More...
 

Description

Base class of all web-socket clients and servers. Don't derive from this directly but from nap::IWebSocketClient and nap::IWebSocketServer instead. Every web-socket interface is registered with the nap::WebSocketService. This allows a client or server to receive web-socket messages and connection updates on a different thread than the application thread. By itself this object does not interface with an endpoint. Use the nap::WebSocketClient and nap::WebSocketServer instead.

Inheritance diagram for WebSocketInterface:
[legend]
Collaboration diagram for WebSocketInterface:
[legend]

Constructor & Destructor Documentation

◆ WebSocketInterface()

Constructor

Parameters
servicethe web-socket service that forwards events to the application.

◆ ~WebSocketInterface()

virtual ~WebSocketInterface ( )
virtual

Member Function Documentation

◆ addEvent()

void addEvent ( WebSocketEventPtr  newEvent)
protected

Called when the end point receives a new event. Adds the event to the list of events to be processed on the application thread.

Parameters
newEventthe web-socket event.

◆ as() [1/2]

T & as

Returns the interface as an interface of type T. The interface is either a server or client, for example: this->as<nap::WebSocketServer>(); Asserts if the interface isn't of type T.

Returns
The web-socket interface as T.

◆ as() [2/2]

const T & as

Returns the interface as an interface of type T. The interface is either a server or client, for example: this->as<nap::WebSocketServer>(); Asserts if the interface isn't of type T.

Returns
The web-socket interface as T.

◆ init()

virtual bool init ( utility::ErrorState errorState)
overridevirtual

Initialize this object after de-serialization

Parameters
errorStatecontains the error message when initialization fails

Reimplemented from Object.

Reimplemented in IWebSocketClient, IWebSocketServer, and PortalWebSocketServer.

Member Data Documentation

◆ mEventMutex

std::mutex mEventMutex
protected

◆ mEvents

std::queue<WebSocketEventPtr> mEvents
protected

◆ mService

WebSocketService* mService = nullptr
protected