An implementation of Hyperspace::Gate for Stream endpoints. More...

#include <HyperspaceStream/Gate>

Inheritance diagram for Hyperspace::Stream::Gate:

Public Slots

void severAllConnections ()
 Truncates all existing connections. More...
 
void severConnection (const QByteArray &id)
 Truncates a connection to a specific client. More...
 
- Public Slots inherited from Hemera::AsyncInitObject
Hemera::Operationinit ()
 

Public Member Functions

virtual ~Gate ()
 default destructor More...
 

Protected Member Functions

QHash< QByteArray, qintptr > availableConnections () const
 
virtual Rebound validateWave (const Hyperspace::Wave &wave)
 
virtual void incomingConnection (const QByteArray &id, Hyperspace::Protocol::StreamSocketType type, qintptr fd)=0
 
virtual void severConnectionImpl (const QByteArray &id)=0
 
- Protected Member Functions inherited from Hyperspace::Gate
void assignWaveTarget (AbstractWaveTarget *target)
 Assigns an AbstractWaveTarget to this gate. More...
 
- Protected Member Functions inherited from Hemera::AsyncInitObject
void setParts (uint parts)
 

Additional Inherited Members

- Signals inherited from Hemera::AsyncInitObject
void ready ()
 
- Protected Slots inherited from Hemera::AsyncInitObject
virtual void initImpl ()=0
 
void setReady ()
 
void setInitError (const QString &errorName, const QString &message=QString())
 
void setOnePartIsReady ()
 

Detailed Description

An implementation of Hyperspace::Gate for Stream endpoints.

Gate offers a low level interface to Hyperspace Stream pipes, and serves as the base for all Stream implementation. Gate is purely virtual, and should be subclassed by developers only if you're looking into performing specific operations on the file descriptor of the pipe. Otherwise, you're probably better off with Hyperspace::Stream::FullDuplexGate or equivalent.

Stream pipes are implemented via a handshake mechanism which is performed via Hyperspace, with a STREAMREQUEST Wave. Gate internally manages such handshake and takes care of opening the pipe. Stream pipes are accessible through a Unix file descriptor, which abstracts Hyperspace's communication layer with the transport. Various implementations of Gate are optimized for best usage of the pipe for various use cases - in case you need your own implementation, you can assume the fd behaves like a Unix socket.

A Gate exposes one single endpoint, unless specified differently. This endpoint is capable of managing STREAMREQUEST Waves only - any GET, PUT, POST or DELETE will result in a NotImplemented Rebound. To bring up a gate, simply initialize it via init().

See also
Hyperspace::Stream::FullDuplexGate
Hyperspace::Stream::FileReceiverGate
Hyperspace::Stream::FilePublisherGate

Constructor & Destructor Documentation

Hyperspace::Stream::Gate::~Gate ( )
virtual

default destructor

Member Function Documentation

void Hyperspace::Stream::Gate::severAllConnections ( )
slot

Truncates all existing connections.

void Hyperspace::Stream::Gate::severConnection ( const QByteArray &  id)
slot

Truncates a connection to a specific client.

id The client's id.

QHash< QByteArray, qintptr > Hyperspace::Stream::Gate::availableConnections ( ) const
protected
Returns
Available and online clients, identified by their id and their associated pipe.
Rebound Hyperspace::Stream::Gate::validateWave ( const Hyperspace::Wave wave)
protectedvirtual
Returns
Validates a handshake.

This method can be reimplemented by a Gate to provide an additional hook for the Hyperspace handshake. By default, no requirements are enforced on the STREAMREQUEST Wave, but specific implementations of a Gate might require some attributes to be set (such as Hyperspace::Stream::FileReceiverGate) or to set additional attributes in the Rebound (such as Hyperspace::Stream::FilePublisherGate).

Reimplement this method to provide manually the Rebound to the handshake. Please note that when accepting the handshake, you should use Accepted as Response, and not OK.

Note
You can reimplement this method in any Gate overload, as it is supposed to be implemented by the user.

wave The handshake Wave. It is always a STREAMREQUEST Wave.

Returns
A Rebound for the handshake. It has to be Accepted for the handshake to be completed.
virtual void Hyperspace::Stream::Gate::incomingConnection ( const QByteArray &  id,
Hyperspace::Protocol::StreamSocketType  type,
qintptr  fd 
)
protectedpure virtual

Reimplement this method in your Gate to handle new connections. It will be called every time a stream has been initiated successfully. You can assume fd is already open and ready to stream and receive data without further action.

id The id of the client. type The type of the pipe. fd The file descriptor of the pipe.

Implemented in Hyperspace::Stream::FileReceiverGate, Hyperspace::Stream::FilePublisherGate, and Hyperspace::Stream::FullDuplexGate.

virtual void Hyperspace::Stream::Gate::severConnectionImpl ( const QByteArray &  id)
protectedpure virtual

Reimplement this method in your gate to sever a connection. Usually, you just need to close() the file descriptor, unless you have been performing some other operations or are using wrappers. Nevertheless, you need to make sure that after calling this method the file descriptor will be closed within this process, and the associated pipe closed.

id The id of the client.

Implemented in Hyperspace::Stream::FileReceiverGate, Hyperspace::Stream::FilePublisherGate, and Hyperspace::Stream::FullDuplexGate.