QuasarAppLib 1.0.530.c9fba11
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 ()
 Service This is the default constructor of the Service template class. It does nothing and is used only to allow the inheritance from the Service class.

Static Public Member Functions

static std::unique_ptr< Base > & initService ()
 initService This method initialize the Base object as a service using the default constructor. If the service is already initialized then the current service object will be returned.
static bool initService (std::unique_ptr< Base > obj)
 initService This is overridden static method of initialization cross libraries object.
static Base * instance ()
 instance This method return pointerer to current service object.
static Base * autoInstance ()
 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 destructor 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

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

Service This is the default constructor of the Service template class. It does nothing and is used only to allow the inheritance from the Service class.

Definition at line 75 of file qaservice.h.

Member Function Documentation

◆ autoInstance()

template<class Base>
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 128 of file qaservice.h.

Here is the call graph for this function:

◆ deinitService()

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

deinitService This is destructor method for the service.

Note
do nothing if this object already destroyed.
See also
instance
initService
autoInstance

Definition at line 145 of file qaservice.h.

◆ initService() [1/2]

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

initService This method initialize the Base object as a service using the default constructor. If the service is already initialized then the current service object will be returned.

Returns
instance pointer. If the service already initialized then return pointer to current service object.
See also
instance
deinitService
autoInstance

Definition at line 85 of file qaservice.h.

Here is the caller graph for this function:

◆ initService() [2/2]

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

initService This is overridden static method of initialization cross libraries 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. Because Some OS has every shared libraries has itself isolation address space (for example Android). If you initialize instance of your settings model on one library the this instance will be available only on your library or upper. Bot not on the QuasarApp lib so SettingsListener 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 102 of file qaservice.h.

◆ instance()

template<class Base>
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 119 of file qaservice.h.

Here is the caller graph for this function:

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