QuasarAppLib
QuasarAppUtils::Service< Base > Class Template Reference

The Service class is a template class for creating a singleton services objects. This is manual control wrapper. You should be manually initializing your service object and manually deinitializing. If you don't destroy your service, then service object will be automatically destroyed when application will be closed. More...

#include <qaservice.h>

Collaboration diagram for QuasarAppUtils::Service< Base >:
Collaboration graph

Public Member Functions

 Service ()
 

Static Public Member Functions

static std::unique_ptr< Base > & initService ()
 initService This method initialize the Base object as a service.
 
static bool initService (std::unique_ptr< Base > obj)
 initService This is overrided static method of initialization cross libraryes object.
 
static Baseinstance ()
 instance This method return pointerer to current service object.
 
static BaseautoInstance ()
 autoInstance This method return pointerer to current service object and if it is not inited try to initialize it use default constructor.
 
static void deinitService ()
 deinitService This is distructor method for the service.
 

Detailed Description

template<class Base>
class QuasarAppUtils::Service< Base >

The Service class is a template class for creating a singleton services objects. This is manual control wrapper. You should be manually initializing your service object and manually deinitializing. If you don't destroy your service, then service object will be automatically destroyed when application will be closed.

Warning
If service was destroyed automatically, then destructor of your base class will be not invoked. Use The deinit method for this.
Todo:
Remove the template Base class. Instead, it needs to use a general inherit paradigm

Examples

Create a service class

#include <qaservice.h>
class MyService: public QuasarAppUtils::Service<MyService> {\
// some implementation
};
The Service class is a template class for creating a singleton services objects. This is manual contr...
Definition qaservice.h:68
void gen(int size, QByteArray &result)

Initialise a service object

#include <MyService.h>
// initialise service
MyService* serviceInstance = MyService::initService();
// get service instance.
serviceInstance = MyService::instance();
// remove service instance object.
MyService::deinitService();

Or you can use the autoInstance method for initialize instance object if not exists.

Note
This method try initialize base instance object use default construct.
#include <MyService.h>
// initialise service
MyService* serviceInstance = MyService::autoInstance();

Definition at line 67 of file qaservice.h.

Constructor & Destructor Documentation

◆ Service()

template<class Base >
QuasarAppUtils::Service< Base >::Service ( )
inline

Definition at line 71 of file qaservice.h.

Member Function Documentation

◆ autoInstance()

template<class Base >
static Base * QuasarAppUtils::Service< Base >::autoInstance ( )
inlinestatic

autoInstance This method return pointerer to current service object and if it is not inited try to initialize it use default constructor.

Returns
pointerer to current service object if service initialized else nullptr.
See also
instance

Definition at line 124 of file qaservice.h.

Here is the call graph for this function:

◆ deinitService()

template<class Base >
static void QuasarAppUtils::Service< Base >::deinitService ( )
inlinestatic

deinitService This is distructor method for the service.

Note
do nothink if this object alredy distroyed.
See also
instance
initService
autoInstance

Definition at line 141 of file qaservice.h.

Here is the call graph for this function:

◆ initService() [1/2]

template<class Base >
static std::unique_ptr< Base > & QuasarAppUtils::Service< Base >::initService ( )
inlinestatic

initService This method initialize the Base object as a service.

Parameters
argsThis is argumets of a constructo of the Base class.
Returns
instance pointer. If the service alredy initialized then return pointer to current service object.
See also
instance
deinitService
autoInstance

Definition at line 81 of file qaservice.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initService() [2/2]

template<class Base >
static bool QuasarAppUtils::Service< Base >::initService ( std::unique_ptr< Base obj)
inlinestatic

initService This is overrided static method of initialization cross libraryes object.

Note
If you want to create your own implementation of the settings object - you need to use this method for initioalisation instant qaservice::initService - template method. Becouse Some OS has every shared libraryes has itself isolation address space (for example Android). If you initialize instance of your settings model on one libarary the this instance will be available only on your library or upper. Bot not on the QuasarApp lib so SettingsListner will not work.
Parameters
objThis is inited settings object.
Returns
true if the obj service was saved as a service object else false.

Definition at line 98 of file qaservice.h.

Here is the call graph for this function:

◆ instance()

template<class Base >
static Base * QuasarAppUtils::Service< Base >::instance ( )
inlinestatic

instance This method return pointerer to current service object.

Note
If object was not initialized, then return false.
Returns
pointerer to current service object if service initialized else nullptr.
See also
initService
deinitService
autoInstance

Definition at line 115 of file qaservice.h.

Here is the caller graph for this function:

The documentation for this class was generated from the following file: