Carousel
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Properties Pages
Public Member Functions | Protected Slots | List of all members
ComponentManager Class Reference

The ComponentManager holds information about the components that can be used by the application. More...

#include <ComponentManager.h>

Inherits IComponentManager.

Public Member Functions

 ComponentManager (IServiceLocator *serviceLocator, QObject *parent=nullptr)
 
 ComponentManager (IServiceLocator *serviceLocator, IComponentDependencies *dependencies, QObject *parent=nullptr)
 
bool addComponent (IComponent *component)
 
DependenciesSolvingResult check ()
 
const ObservableList
< IComponent * > & 
components () const
 
const IComponentDependenciesdependencies () const
 
bool isChecked () const
 
QStringList missingComponents () const
 
QList< IComponent * > orphanComponents () const
 
IServiceLocatorserviceLocator () const
 
void shutdown ()
 
DependenciesSolvingResult shutdownAllComponents ()
 
DependenciesSolvingResult shutdownComponent (IComponent *component)
 
DependenciesSolvingResult shutdownComponents (const QList< IComponent * > &components)
 
QList< IComponent * > startedComponents () const
 
DependenciesSolvingResult startup ()
 
DependenciesSolvingResult startupAllComponents ()
 
DependenciesSolvingResult startupComponent (IComponent *component)
 
DependenciesSolvingResult startupComponents (QList< IComponent * > components)
 
QList< IComponent * > stoppedComponents () const
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
 QObject (QObject *parent, const char *name)
 
bool blockSignals (bool block)
 
QObjectchild (const char *objName, const char *inheritsClass, bool recursiveSearch) const
 
const QObjectList & children () const
 
const char * className () const
 
bool connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const QObject *receiver, const char *method)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method)
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QByteArraydynamicPropertyNames () const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name) const
 
QList< T > findChildren (const QRegExp &regExp) const
 
QList< T > findChildren (const QString &name) const
 
bool inherits (const char *className) const
 
void insertChild (QObject *object)
 
void installEventFilter (QObject *filterObj)
 
bool isA (const char *className) const
 
bool isWidgetType () const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
const char * name () const
 
const char * name (const char *defaultName) const
 
QString objectName () const
 
QObjectparent () const
 
QVariant property (const char *name) const
 
void removeChild (QObject *object)
 
void removeEventFilter (QObject *obj)
 
void setName (const char *name)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval)
 
QThreadthread () const
 

Protected Slots

virtual bool enableAndStartComponent (IComponent *component)
 
virtual void forceShutdownCheckedComponent (IComponent *component)
 
virtual void onAboutToShutDown ()
 
virtual void onComponentAboutToShutDown (IComponent *component)
 
virtual void onComponentShutDown (IComponent *component)
 
virtual void onComponentStarted (IComponent *component)
 
virtual void onStartedUp ()
 
virtual void shutdownCheckedComponent (IComponent *component)
 
virtual bool startCheckedComponent (IComponent *component)
 

Additional Inherited Members

- Signals inherited from IComponentManager
void aboutToShutDown ()
 
void componentAboutToShutDown (IComponent *component)
 
void componentShutDown (IComponent *component)
 
void componentStarted (IComponent *component)
 
void startedUp ()
 
- Static Public Member Functions inherited from QObject
bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
- Protected Member Functions inherited from QObject
bool checkConnectArgs (const char *signal, const QObject *object, const char *method)
 
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const char *signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const char *signal)
 
int receivers (const char *signal) const
 
QObjectsender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 
- Static Protected Member Functions inherited from QObject
QByteArray normalizeSignalSlot (const char *signalSlot)
 
- Properties inherited from IComponentManager
QList< IComponent * > orphanComponents
 
QList< IComponent * > startedComponents
 
QList< IComponent * > stoppedComponents
 
- Properties inherited from QObject
 objectName
 

Detailed Description

The ComponentManager holds information about the components that can be used by the application.

Each component (described in a IComponent and ComponentDefinition classes, stores the name, description and availability of the component) that was statically registered or dynamically discovered by providers will be added to the ComponentManager after boot loading sequence in CarouselBootloader::configureComponentManager() method. Components also can be added and started during run-time.

Then, after checking and resolving dependencies, all enabled components will be started with IServiceLocator reference as initialziation data. It enables components to get access to shared servces of your application.

Also manager uses IComponentDependencies for components sorting and finding components dependencies.

Note
it takes ownership for added components, and also takes for the IComponentDependencies.

Constructor & Destructor Documentation

ComponentManager::ComponentManager ( IServiceLocator serviceLocator,
QObject parent = nullptr 
)
explicit

Creates an instance of the ComponentManager class with default ComponentInitialiser and ComponentDependencies instances.

ComponentManager::ComponentManager ( IServiceLocator serviceLocator,
IComponentDependencies dependencies,
QObject parent = nullptr 
)
explicit

Creates an instance of the ComponentManager class with specified dependencies and default ComponentInitialiser instance.

Member Function Documentation

bool ComponentManager::addComponent ( IComponent component)
virtual

Adds a new component. Component with same name should not already exists in the manager.

A newly is appended to the stoppedComponents() list and to the dependencies(). This method sets isChecked() to false.

Parameters
componentIf manager already has component with same name as component - the last one will not be added to the manager. The same for the null pointer - it will be ignored.

Returns true if component was succesfully added. If it is a null point or already existed one - returns false. Note, that ComponentManager does not take ownership for component, which was not successfully added.

See Also
IComponentDependencies::addComponent()

Implements IComponentManager.

DependenciesSolvingResult ComponentManager::check ( )
virtual

Uses DependencySolver for checking of added components according to their dependencies.

Returns a dependencies solving result, that contains a list of distinct components and a list of components, those dependencies were not found.

It caches resulting value for prefomance, but addComponent() is resets it.

See Also
isChecked()

Implements IComponentManager.

const ObservableList<IComponent *>& ComponentManager::components ( ) const
virtual

Returns a list of all added components. It is a shortcut to the IComponentDependencies::components().

See Also
IComponentDependencies::dependencies().

Implements IComponentManager.

const IComponentDependencies& ComponentManager::dependencies ( ) const
virtual

Returns a component dependencies.

Implements IComponentManager.

bool ComponentManager::isChecked ( ) const
virtual

Uses DependencySolver for checking of added components according to their dependencies.

Returns a dependencies solving result, that contains a list of distinct components and a list of components, those dependencies were not found.

See Also
check()

Implements IComponentManager.

IServiceLocator* ComponentManager::serviceLocator ( ) const
virtual

Gets an initialization data that will be passed to the started components.

See Also
startupComponent()

Implements IComponentManager.

QStringList ComponentManager::missingComponents ( ) const
virtual

Returns a list of missing parent names those children were added to the manager.

This list is populated after check() or startup/shutdown components and resets after the addComponent() call.

See Also
orphanComponents()

Implements IComponentManager.

QList<IComponent *> ComponentManager::orphanComponents ( ) const
virtual

Returns a list of components those parents were not added to the manager while components were started.

This list is populated after check() or startup/shutdown components and resets after the addComponent() call.

See Also
missingComponents()

Implements IComponentManager.

QList<IComponent *> ComponentManager::stoppedComponents ( ) const
virtual

Returns a list of already stopped or non-started yet components.

Implements IComponentManager.

QList<IComponent *> ComponentManager::startedComponents ( ) const
virtual

Returns a list of started components.

Implements IComponentManager.

void ComponentManager::shutdown ( )
virtual

Shuts down all the components. Call this method when your application is going to quit

Implements IComponentManager.

DependenciesSolvingResult ComponentManager::shutdownComponent ( IComponent component)
virtual

Shuts down the specified component and all its implicit children, obtained by IComponentDependencies::completeListWithParent() in such order, that children will be shut down first.

Shut component is moved from the startedComponents() to the stoppedComponents() list.

Ignores null pointer or unexisting component.

Returns a DependenciesSolvingResult with components that were realy shut down. Components that already were shut down will not appear to the result list.

Implements IComponentManager.

DependenciesSolvingResult ComponentManager::shutdownAllComponents ( )
virtual

This method is added for convinient. It is a shortkey to the shutdownComponents(components()).

Returns a DependenciesSolvingResult with components that were realy shut down. Components that already were shut down will not appear to the result list.

See Also
shutdownComponents()

Implements IComponentManager.

DependenciesSolvingResult ComponentManager::shutdownComponents ( const QList< IComponent * > &  components)
virtual

Shuts down specified components in such order, that children will be shut down before their parents.

Shut components are moved from the startedComponents() to the stoppedComponents() list.

Returns a DependenciesSolvingResult with components that were realy shut down. Components that already were shut down will not appear to the result list.

Implements IComponentManager.

DependenciesSolvingResult ComponentManager::startup ( )
virtual

Begins working and starts components which were added on the start of application. Starts only enabled components.

Components with disabled parent components will not be started.

Initialization data will be passed to the started components (if any).

See Also
shutdown()

Implements IComponentManager.

DependenciesSolvingResult ComponentManager::startupComponent ( IComponent component)
virtual

Implicitly calls check() and starts (if resolving) up the specified components and all its parents, obtained by IComponentDependencies::completeListWithChild() in such order, that parents will be started first. All started components became enabled.

Components will not start if parent component could not start.

Initialization data will be passed to the started components (if any). Returns a dependencies solving result, that contains a list of distinct components and a list of components, those dependencies were not found.

All started components will be moved from the stoppedComponents() to the startedComponents() list.

Returns a DependenciesSolvingResult with components that were realy started. Components that already were started will not appear to the result list.

Note
component should be added to the manager before starting.
See Also
addComponent(), check()

Implements IComponentManager.

DependenciesSolvingResult ComponentManager::startupAllComponents ( )
virtual

This method is added for convinient. It is a shortkey to the startupComponents(components()).

Initialization data will be passed to the started components (if any).

Returns a DependenciesSolvingResult with components that were realy started. Components that already were started will not appear to the result list.

See Also
addComponent(), check(), startupComponents()

Implements IComponentManager.

DependenciesSolvingResult ComponentManager::startupComponents ( QList< IComponent * >  components)
virtual

Implicitly calls check() and starts (if resolving) up the specified components and all its parents, obtained by IComponentDependencies::completeListWithChild() in such order, that parents will be started first. All started components became enabled.

Components will not start if parent component could not start.

Initialization data will be passed to the started components (if any). Returns a dependencies solving result, that contains a list of distinct components and a list of components, those dependencies were not found.

Components, those parents were not added to manager, will be appended to the orphanComponents() list and names of their missing parents will be appended to the missingComponents() list. All started components will be moved from the stoppedComponents() to the startedComponents() list.

Returns a DependenciesSolvingResult with components that were realy started. Components that already were started will not appear to the result list.

Note
components should be added to the manager before starting.
See Also
addComponent(), check(), startupAllComponents()

Implements IComponentManager.

virtual void ComponentManager::onStartedUp ( )
protectedvirtualslot

This method is invoked after manager started up.

virtual void ComponentManager::onAboutToShutDown ( )
protectedvirtualslot

This method is invoked before manager will be shut down.

virtual void ComponentManager::onComponentStarted ( IComponent component)
protectedvirtualslot

This method is invoked when component is started up by the ComponentManager. It emits componentStarted() signal and moves component from the stopped to started list.

virtual void ComponentManager::onComponentAboutToShutDown ( IComponent component)
protectedvirtualslot

This method is invoked before component will be shut down by the ComponentManager. It emits componentAboutToShutDown().

virtual void ComponentManager::onComponentShutDown ( IComponent component)
protectedvirtualslot

This method is invoked when component is shut down by the ComponentManager. It emits componentShutDown() signal and moves component from the started to stopped list.

virtual bool ComponentManager::startCheckedComponent ( IComponent component)
protectedvirtualslot

Starts specified component if it is possible (if component is enabled) and passes the initialization data to it.

Note, that components should have descending order, e.g. parents should stay before children, because parents should start first.

Returns
true, if component was started. If component is disabled or unavailabled, returns false. Also returns false if component start was failed.
virtual bool ComponentManager::enableAndStartComponent ( IComponent component)
protectedvirtualslot

Sets IComponent::Enabled availability to the specified component and tries to start up that component.

Returns
true, if component was started. If component is disabled or unavailabled, returns false. Also returns false if component start was failed.
virtual void ComponentManager::shutdownCheckedComponent ( IComponent component)
protectedvirtualslot

Shuts down specified component. Built in components are ignored.

Note, that components should have descending order, e.g. parents should stay before children, because children should shut down first.

virtual void ComponentManager::forceShutdownCheckedComponent ( IComponent component)
protectedvirtualslot

Shuts down specified component regardless whether it is built in or not.

Note, that components should have descending order, e.g. parents should stay before children, because children should shut down first.