Hyperspace::Stream::FullDuplexGate Class Reference

An implementation of Hyperspace::Stream::Gate for full duplex communication. More...

#include <HyperspaceStream/FullDuplexGate>

Inheritance diagram for Hyperspace::Stream::FullDuplexGate:


void newConnection (const QByteArray &id, QIODevice *device)
 Emitted whenever a new client connects. More...
- Signals inherited from Hemera::AsyncInitObject
void ready ()

Public Member Functions

 FullDuplexGate (const QList< QByteArray > &capabilities, const QByteArray &baseTarget="/", QObject *parent=nullptr)
 Creates a new Gate. More...
virtual ~FullDuplexGate ()
 Default destructor. More...
QHash< QByteArray, QIODevice * > connections () const
- Public Member Functions inherited from Hyperspace::Stream::Gate
virtual ~Gate ()
 default destructor More...

Protected Member Functions

virtual void incomingConnection (const QByteArray &id, Hyperspace::Protocol::StreamSocketType type, qintptr fd) overridefinal
virtual void severConnectionImpl (const QByteArray &id) overridefinal
virtual void initImpl () override
- Protected Member Functions inherited from Hyperspace::Stream::Gate
QHash< QByteArray, qintptr > availableConnections () const
virtual Rebound validateWave (const Hyperspace::Wave &wave)
- 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

- Public Slots inherited from Hyperspace::Stream::Gate
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 ()
- Protected Slots inherited from Hemera::AsyncInitObject
void setReady ()
void setInitError (const QString &errorName, const QString &message=QString())
void setOnePartIsReady ()

Detailed Description

An implementation of Hyperspace::Stream::Gate for full duplex communication.

FullDuplexGate is a convenience interface which exposes high level Qt objects for communicating with the other end. Instead of a file descriptor, it returns an initialized and ready to use QIODevice which already implements all the needed logic, and can be used as a network transparent mean of communication.

After creating the Gate and initializing it, listen to newConnection for new devices.

QIODevice's memory is managed by FullDuplexGate, and you should not delete it yourself. Also, once the connection drops, the device will be garbage collected as soon as possible.
See also

Constructor & Destructor Documentation

Hyperspace::Stream::FullDuplexGate::FullDuplexGate ( const QList< QByteArray > &  capabilities,
const QByteArray &  baseTarget = "/",
QObject *  parent = nullptr 

Creates a new Gate.

capabilities The capabilities of the Gate. baseTarget The target of the Gate. parent QObject parent, if any.

Hyperspace::Stream::FullDuplexGate::~FullDuplexGate ( )

Default destructor.

Member Function Documentation

QHash< QByteArray, QIODevice * > Hyperspace::Stream::FullDuplexGate::connections ( ) const
The list of active connections, identified by their id and with their associated QIODevice.
void Hyperspace::Stream::FullDuplexGate::incomingConnection ( const QByteArray &  id,
Hyperspace::Protocol::StreamSocketType  type,
qintptr  fd 

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.

Implements Hyperspace::Stream::Gate.

void Hyperspace::Stream::FullDuplexGate::severConnectionImpl ( const QByteArray &  id)

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.

Implements Hyperspace::Stream::Gate.

void Hyperspace::Stream::FullDuplexGate::initImpl ( )

Implements the object intialization

When implementing an AsyncInitObject, this method should hold your initialization logic. It is called by AsyncInitObject when needed, and the developer should just reimplement it without invoking it.

Once the initialization procedure is completed, either setReady, setOnePartIsReady or setInitError must be called.

Implements Hemera::AsyncInitObject.

void Hyperspace::Stream::FullDuplexGate::newConnection ( const QByteArray &  id,
QIODevice *  device 

Emitted whenever a new client connects.

Listen to this signal to handle incoming connections. The device is guaranteed to be open, writable and readable. You can start streaming data right away when the signal comes in.

id The client id. device The newly created device, which holds the stream pipe.