AGXDynamics  2.31.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
agxNet::WebSocket Class Reference

A socket that connects to a client. More...

#include <WebSocket.h>

+ Inheritance diagram for agxNet::WebSocket:

Public Types

enum  ContentType { CONTENT_BINARY, CONTENT_TEXT }
 
typedef agx::observer_ptr
< const ControlChannel > 
ControlChannelConstObserver
 
typedef agx::ref_ptr< const
ControlChannel > 
ControlChannelConstRef
 
typedef agx::observer_ptr
< ControlChannel > 
ControlChannelObserver
 
typedef agx::ref_ptr
< ControlChannel > 
ControlChannelRef
 
typedef agx::Callback3
< ControlChannel
*, agxNet::WebSocket
*, agxNet::StructuredMessage * > 
MessageHandler
 
typedef agx::observer_ptr
< const Packet > 
PacketConstObserver
 
typedef agx::ref_ptr< const
Packet > 
PacketConstRef
 
typedef agx::observer_ptr< Packet > PacketObserver
 
typedef agx::ref_ptr< Packet > PacketRef
 
typedef agx::Callback3
< WebSocket *, agx::UInt8
*, size_t > 
ReceiveCallback
 A callback function that is run when a message is received from the socket. More...
 
typedef agx::Event2
< ControlChannel
*, agxNet::WebSocket * > 
SocketEvent
 

Public Member Functions

 AGX_DECLARE_VECTOR_TYPES (Packet)
 
template<typename T >
T * as ()
 Subclass casting. More...
 
template<typename T >
const T * as () const
 
template<typename T >
T * asSafe ()
 Safe subclass casting, return nullptr if template type does not match. More...
 
template<typename T >
const T * asSafe () const
 
 ControlChannel (agx::UInt16 port, const agx::String &token="")
 
 ControlChannel (agxNet::PortRange *portRange, const agx::String &token="")
 
agxNet::WebSocket * createConnection (const agx::String &address, agx::UInt16 port, bool useSSL=false, const agx::String &path="/", const agx::String &protocol="agx_stream", bool isAnonymous=false)
 
ContentType getContentType () const
 
int getLibwebsocketsWriteProtocol () const
 
agx::UInt8 * getPayload ()
 Returns a pointer to the data this Packet contains. More...
 
agx::UInt16 getPort () const
 
int getReferenceCount () const
 
size_t getSize () const
 
template<typename T >
bool is () const
 Subclass test. More...
 
bool isAnonymous () const
 
bool isAuthenticated () const
 
void messageReceived (void *message, size_t size)
 
 Packet (size_t size, ContentType type)
 
 Packet (const agx::String &message)
 
 Packet (const agxJson::Value &message)
 
 Packet (const agxData::Frame *frame)
 
void reference (void *ptr=nullptr) const
 Explicitly increment the reference count by one, indicating that this object has another pointer which is referencing it. More...
 
void registerMessageHandler (const agx::String &uri, MessageHandler callback)
 
void send (const agx::String &message)
 Send the content of the given packet to the client. More...
 
void send (Packet *packet)
 
void send (const StructuredMessage *message)
 
void send (const StructuredMessage *message)
 
bool service (agx::Real timeoutMs=0)
 
void setAnonymous (bool flag)
 
void setAuthenticated (bool flag)
 
void setReceiveCallback (ReceiveCallback callback)
 Set the callback function that should be called when new messages are received. More...
 
void unreference (void *ptr=nullptr) const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
void unreference_nodelete () const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 

Static Public Member Functions

template<typename T >
static bool ValidateCast (const Referenced *object)
 

Public Attributes

SocketEvent socketConnectEvent
 
SocketEvent socketDisconnectEvent
 

Protected Member Functions

virtual ~ControlChannel ()
 
virtual ~Packet ()
 
virtual ~WebSocket ()
 
void allocateObserverVector () const
 
void deleteUsingDeleteHandler () const
 

Static Protected Member Functions

static DeleteHandler * getDeleteHandler ()
 
static void setDeleteHandler (DeleteHandler *handler)
 Internal: Set a DeleteHandler to which deletion of all referenced counted objects will be delegated to. More...
 

Protected Attributes

Mutex m_mutex
 
ObserverContainer m_observers
 
AtomicValue m_refCount
 

Detailed Description

A socket that connects to a client.

ControlChannel.

WebSocket::Packet.

Instances of this class is created by the Socket server when a new client connects.

Definition at line 54 of file WebSocket.h.

Member Typedef Documentation

Definition at line 58 of file WebSocket.h.

Definition at line 58 of file WebSocket.h.

Definition at line 58 of file WebSocket.h.

A callback function that is run when a message is received from the socket.

The first argument is the WebSocket that received them message, the second is a pointer pointing to the received message and the third argument is the size of the message in bytes.

Definition at line 70 of file WebSocket.h.

Member Enumeration Documentation

Enumerator
CONTENT_BINARY 
CONTENT_TEXT 

Definition at line 136 of file WebSocket.h.

Constructor & Destructor Documentation

virtual agxNet::WebSocket::~WebSocket ( )
protectedvirtual
virtual agxNet::WebSocket::~Packet ( )
protectedvirtual
virtual agxNet::WebSocket::~ControlChannel ( )
protectedvirtual

Member Function Documentation

agxNet::WebSocket::AGX_DECLARE_VECTOR_TYPES ( Packet  )
void agx::Referenced::allocateObserverVector ( ) const
protectedinherited
template<typename T >
T* agx::Referenced::as ( )
inherited

Subclass casting.

Template type must match actual type, dynamic_cast assertion will fail otherwise.

Referenced by agx::InternalData::get(), agxVehicle::Track::getNode(), and agx::InternalData::getOrCreate().

template<typename T >
const T* agx::Referenced::as ( ) const
inherited
template<typename T >
T* agx::Referenced::asSafe ( )
inherited

Safe subclass casting, return nullptr if template type does not match.

Referenced by agxUtil::CollectBodiesAndWiresVisitor::visit().

template<typename T >
const T* agx::Referenced::asSafe ( ) const
inherited
agxNet::WebSocket::ControlChannel ( agx::UInt16  port,
const agx::String &  token = "" 
)
agxNet::WebSocket::ControlChannel ( agxNet::PortRange *  portRange,
const agx::String &  token = "" 
)
agxNet::WebSocket* agxNet::WebSocket::createConnection ( const agx::String &  address,
agx::UInt16  port,
bool  useSSL = false,
const agx::String &  path = "/",
const agx::String &  protocol = "agx_stream",
bool  isAnonymous = false 
)
void agx::Referenced::deleteUsingDeleteHandler ( ) const
protectedinherited
ContentType agxNet::WebSocket::getContentType ( ) const
static DeleteHandler* agx::Referenced::getDeleteHandler ( )
staticprotectedinherited
Returns
a DeleteHandler.
int agxNet::WebSocket::getLibwebsocketsWriteProtocol ( ) const
agx::UInt8* agxNet::WebSocket::getPayload ( )

Returns a pointer to the data this Packet contains.

Senders should write their message to this memory area.

agx::UInt16 agxNet::WebSocket::getPort ( ) const
int agx::Referenced::getReferenceCount ( ) const
inherited
Returns
the number pointers currently referencing this object.
size_t agxNet::WebSocket::getSize ( ) const
template<typename T >
bool agx::Referenced::is ( ) const
inherited
bool agxNet::WebSocket::isAnonymous ( ) const
bool agxNet::WebSocket::isAuthenticated ( ) const
void agxNet::WebSocket::messageReceived ( void *  message,
size_t  size 
)
agxNet::WebSocket::Packet ( size_t  size,
ContentType  type 
)
agxNet::WebSocket::Packet ( const agx::String &  message)
agxNet::WebSocket::Packet ( const agxJson::Value &  message)
agxNet::WebSocket::Packet ( const agxData::Frame *  frame)
void agx::Referenced::reference ( void *  ptr = nullptr) const
inherited

Explicitly increment the reference count by one, indicating that this object has another pointer which is referencing it.

This method should be used with care, always balanced with the same number of calls to unreference.

Referenced by agxData::Val< UInt >::Val().

void agxNet::WebSocket::registerMessageHandler ( const agx::String &  uri,
MessageHandler  callback 
)
void agxNet::WebSocket::send ( const agx::String &  message)

Send the content of the given packet to the client.

void agxNet::WebSocket::send ( Packet *  packet)
void agxNet::WebSocket::send ( const StructuredMessage *  message)
void agxNet::WebSocket::send ( const StructuredMessage *  message)
bool agxNet::WebSocket::service ( agx::Real  timeoutMs = 0)
void agxNet::WebSocket::setAnonymous ( bool  flag)
void agxNet::WebSocket::setAuthenticated ( bool  flag)
static void agx::Referenced::setDeleteHandler ( DeleteHandler *  handler)
staticprotectedinherited

Internal: Set a DeleteHandler to which deletion of all referenced counted objects will be delegated to.

void agxNet::WebSocket::setReceiveCallback ( ReceiveCallback  callback)

Set the callback function that should be called when new messages are received.

void agx::Referenced::unreference ( void *  ptr = nullptr) const
inherited

Decrement the reference count by one, indicating that a pointer to this object is referencing it.

If the reference count goes to zero, it is assumed that this object is no longer referenced and is automatically deleted.

This method should be used with care, always balanced with the same number of calls to reference.

void agx::Referenced::unreference_nodelete ( ) const
inherited

Decrement the reference count by one, indicating that a pointer to this object is referencing it.

However, do not delete it, even if ref count goes to 0. Warning, unref_nodelete() should only be called if the user knows exactly who will be responsible for, one should prefer unref() over unref_nodelete() as the later can lead to memory leaks.

template<typename T >
static bool agx::Referenced::ValidateCast ( const Referenced *  object)
staticinherited

Member Data Documentation

Mutex agx::Referenced::m_mutex
mutableprotectedinherited

Definition at line 240 of file Referenced.h.

ObserverContainer agx::Referenced::m_observers
mutableprotectedinherited

Definition at line 239 of file Referenced.h.

AtomicValue agx::Referenced::m_refCount
mutableprotectedinherited

Definition at line 241 of file Referenced.h.

SocketEvent agxNet::WebSocket::socketConnectEvent

Definition at line 283 of file WebSocket.h.

SocketEvent agxNet::WebSocket::socketDisconnectEvent

Definition at line 284 of file WebSocket.h.


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