Hyperspace::Stream::FilePublisherGate Class Reference

An implementation of Hyperspace::Stream::Gate for file downloads. More...

#include <HyperspaceStream/FilePublisherGate>

Inheritance diagram for Hyperspace::Stream::FilePublisherGate:

Public Member Functions

 FilePublisherGate (const QString &filename, const QList< QByteArray > &capabilities, const QByteArray &baseTarget="/", QObject *parent=nullptr)
 Creates a new Gate and exposes a file. More...
 
 FilePublisherGate (qintptr fd, const QList< QByteArray > &capabilities, const QByteArray &baseTarget="/", QObject *parent=nullptr)
 Creates a new Gate and exposes a file descriptor. More...
 
virtual ~FilePublisherGate ()
 Default destructor. More...
 
- Public Member Functions inherited from Hyperspace::Stream::Gate
virtual ~Gate ()
 default destructor More...
 

Protected Member Functions

virtual void incomingConnection (const QByteArray &id, 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 ()
 
- Signals inherited from Hemera::AsyncInitObject
void ready ()
 
- 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 file downloads.

FilePublisherGate offers a high-performance, non-blocking way of exposing files from Applications to Hyperspace. It is capable of exposing either a filesystem (or resource) path or an existing open file descriptor.

On the receiving end, the handshake will carry an additional attribute, Hyperspace-Stream-File-Size, with the size of the file in bytes. The stream pipe will automatically be truncated on download completion.

To expose a file, simply create a Gate and initialize it.

See also
Hyperspace::Stream::Gate

Constructor & Destructor Documentation

Hyperspace::Stream::FilePublisherGate::FilePublisherGate ( const QString &  filename,
const QList< QByteArray > &  capabilities,
const QByteArray &  baseTarget = "/",
QObject *  parent = nullptr 
)
explicit

Creates a new Gate and exposes a file.

filename can be either a full filesystem path (in this case, you need to make sure the application can access it) or a "resource://" URL. If the file does not exist, initialization will fail.

filename The file to be exposed over the Gate capabilities The capabilities of the Gate. baseTarget The target of the Gate. parent QObject parent, if any.

Hyperspace::Stream::FilePublisherGate::FilePublisherGate ( qintptr  fd,
const QList< QByteArray > &  capabilities,
const QByteArray &  baseTarget = "/",
QObject *  parent = nullptr 
)
explicit

Creates a new Gate and exposes a file descriptor.

filename has to be a file descriptor to a file. If the fd is not usable, not readable, not a file or not open, initialization will fail.

filename The file descriptor to be exposed over the Gate capabilities The capabilities of the Gate. baseTarget The target of the Gate. parent QObject parent, if any.

Hyperspace::Stream::FilePublisherGate::~FilePublisherGate ( )
virtual

Default destructor.

Member Function Documentation

void Hyperspace::Stream::FilePublisherGate::incomingConnection ( const QByteArray &  id,
Protocol::StreamSocketType  type,
qintptr  fd 
)
finaloverrideprotectedvirtual

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::FilePublisherGate::severConnectionImpl ( const QByteArray &  id)
finaloverrideprotectedvirtual

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::FilePublisherGate::initImpl ( )
overrideprotectedvirtual

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.