NAP
Public Types | Public Member Functions | List of all members
PortalEvent Class Reference

#include </opt/build/repo/nap/system_modules/napportal/src/portalevent.h>

Public Types

using APIEventList = std::vector< APIEventPtr >
 
using APIEventConstIterator = utility::UniquePtrConstVectorWrapper< APIEventList, APIEvent * >
 

Public Member Functions

 PortalEvent (const PortalEventHeader &header)
 
 PortalEvent (const PortalEventHeader &header, const WebSocketConnection &connection)
 
const std::string & getID () const
 
const std::string & getPortalID () const
 
const EPortalEventTypegetType () const
 
bool hasConnection () const
 
const WebSocketConnectiongetConnection () const
 
bool toAPIMessageJSON (std::string &outJSON, utility::ErrorState &error)
 
void addAPIEvent (APIEventPtr apiEvent)
 
int getCount () const
 
const APIEventConstIterator getAPIEvents () const
 
const APIEventgetAPIEvent (int index) const
 
APIEventgetAPIEvent (int index)
 
APIEventoperator[] (std::size_t idx)
 
const APIEventoperator[] (std::size_t idx) const
 
- Public Member Functions inherited from Event
virtual ~Event ()=default
 
 Event ()=default
 
 Event (const Event &)=delete
 
Eventoperator= (const Event &)=delete
 

Description

Used for communication between the client and server side of NAP portals. Contains all the information for the app to decide where to route the event and how to handle it. EPortalEventType::Request events are sent by clients to request a full description of the portal. EPortalEventType::Response events are then sent by the server as a response to request events. EPortalEventType::Update events can be sent both ways and indicate that portal items should be updated.

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

Member Typedef Documentation

◆ APIEventConstIterator

◆ APIEventList

using APIEventList = std::vector<APIEventPtr>

Constructor & Destructor Documentation

◆ PortalEvent() [1/2]

PortalEvent ( const PortalEventHeader header)

Default constructor

Parameters
headerthe portal event header containing information about the objective of the event

◆ PortalEvent() [2/2]

PortalEvent ( const PortalEventHeader header,
const WebSocketConnection connection 
)

Construct portal event with websocket connection

Parameters
headerthe portal event header containing information about the objective of the event
connectionthe WebSocket connection used for sending the event

Member Function Documentation

◆ addAPIEvent()

void addAPIEvent ( APIEventPtr  apiEvent)

Adds an API event to the portal event, relating to a portal item

Parameters
apiEventthe API event to add to the portal event

◆ getAPIEvent() [1/2]

APIEvent* getAPIEvent ( int  index)
Parameters
indexthe index of the API event
Returns
an API event based on the given index, throws an exception when out of bounds

◆ getAPIEvent() [2/2]

const APIEvent* getAPIEvent ( int  index) const
Parameters
indexthe index of the API event
Returns
an API event based on the given index, throws an exception when out of bounds

◆ getAPIEvents()

const APIEventConstIterator getAPIEvents ( ) const
Returns
the API events of this portal event

◆ getConnection()

const WebSocketConnection& getConnection ( ) const
Returns
retrieves the WebSocket connection used for sending the event

◆ getCount()

int getCount ( ) const
Returns
the number of API events inside this portal event

◆ getID()

const std::string& getID ( ) const
Returns
unique ID of the portal event

◆ getPortalID()

const std::string& getPortalID ( ) const
Returns
unique ID of the sending / receiving portal

◆ getType()

const EPortalEventType& getType ( ) const
Returns
type of the portal event, determines the effect

◆ hasConnection()

bool hasConnection ( ) const
Returns
whether the portal event contains a WebSocket connection

◆ operator[]() [1/2]

APIEvent& operator[] ( std::size_t  idx)

Array [] subscript operator

Returns
the API event at index

◆ operator[]() [2/2]

const APIEvent& operator[] ( std::size_t  idx) const

Array [] subscript operator

Returns
the API event at index

◆ toAPIMessageJSON()

bool toAPIMessageJSON ( std::string &  outJSON,
utility::ErrorState error 
)

Converts the portal event to a JSON string of API messages used for sending over the WebSocket server.

Parameters
outJSONthe string that will contain the JSON after converting
errorshould hold the error message when conversion fails
Returns
whether the conversion was successful