Hemera::AsyncInitObject Class Referenceabstract

An asynchronous object performing a late initialization. More...

Inheritance diagram for Hemera::AsyncInitObject:

Public Slots

Hemera::Operationinit ()


void ready ()

Protected Slots

virtual void initImpl ()=0
void setReady ()
void setInitError (const QString &errorName, const QString &message=QString())
void setOnePartIsReady ()

Protected Member Functions

void setParts (uint parts)

Detailed Description

An asynchronous object performing a late initialization.

AsyncInitObject is the backbone of Hemera Qt5 SDK. Its initialization paradigm recurs in almost any class exported by the SDK, and allows for a truly asynchronous and transparent workflow in your SDK usage.

An AsyncInitObject has in most cases an empty constructor, and the whole creation logic is handled during its initialization phase, represented as an Operation. The initialization procedure can as well fail, and in that case the object will be unusable.

Even though AsyncInitObject is heavily used inside Hemera, it is also meant to be exploited in client applications needing specific asynchronous logic.

See also

Member Function Documentation

Hemera::Operation * Hemera::AsyncInitObject::init ( )

Initializes the object.

This function returns a meaningful value only upon its first call. The returned Operation tracks the progress of the init procedure, and notifies when the initialization has completed, and of any possible errors occurred.

An operation representing the initialization procedure, or a null pointer in case the request was unsatisfiable.
void Hemera::AsyncInitObject::setParts ( uint  parts)

Sets the number of parts of this object.

When implementing an AsyncInitObject, one can choose whether to have a sequential procedure, or maybe a parallel one. In case your object initializes throughout a sum of parallel procedures, AsyncInitObject can be used with a partial completion mechanism.

When setParts is called, setOnePartIsReady should be used instead of setReady. The object will be set ready as soon as setOnePartIsReady is called as many times as the object's parts. If setFinishedWithError is called at any time before completion, the initialization procedure will be considered failed, no matter how many parts have been completed.

parts The number of parts this object is composed of

Upon calling setParts, setReady won't be working anymore.
virtual void Hemera::AsyncInitObject::initImpl ( )
protectedpure virtualslot

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.

Implemented in Hemera::USBGadgetManager, Hemera::SoftwareManagement::ProgressReporter, Hemera::ServiceManager, Hyperspace::CapabilityWatcher, Hyperspace::Stream::FileReceiverGate, Hyperspace::REST::Gate, Hyperspace::Stream::FilePublisherGate, and Hyperspace::Stream::FullDuplexGate.

void Hemera::AsyncInitObject::setReady ( )

Completes the initialization of the object

Once setReady is called, the object's initialization will be declared successfully completed.

If your object has parts, this method will do nothing
void Hemera::AsyncInitObject::setInitError ( const QString &  errorName,
const QString &  message = QString() 

Triggers a fatal failure in the object's initialization.

Once this function is called, the object is to be considered garbage.
void Hemera::AsyncInitObject::setOnePartIsReady ( )

Completes the initialization of a part of the object.

This method tracks the reference counting of the object's parts. When called as many times as the object's parts, its behavior is equivalent to setReady.

If your object has no parts, this method will do nothing
void Hemera::AsyncInitObject::ready ( )

Emitted when the object has initialized successfully.

Object state can be monitored either from this signal or from the init operation.