cumbia 1.x
general purpose multi threaded library
|
The CuServiceProvider class is the cumbia service provider where cumbia services can be registered and have their references stored throughout their lifetime. More...
#include <cuserviceprovider.h>
Public Member Functions | |
CuServiceProvider () | |
the class constructor More... | |
virtual | ~CuServiceProvider () |
void | registerService (CuServices::Type name, CuServiceI *service) |
register a service to the service provider More... | |
void | registerSharedService (CuServices::Type name, CuServiceI *service) |
Same as registerService, but mark the service as potentially shared across multiple Cumbia instances, thus preventing service from being automatically deleted. More... | |
void | unregisterService (CuServices::Type name) |
unregister a service from the service provider More... | |
bool | isShared (CuServices::Type t) const |
void | setShared (CuServices::Type t, bool shared) |
CuServiceI * | get (CuServices::Type name) const |
returns the service with the given name, if registered More... | |
std::list< CuServiceI * > | getServices () const |
returns the list of registered services More... | |
The CuServiceProvider class is the cumbia service provider where cumbia services can be registered and have their references stored throughout their lifetime.
cumbia services are classes that must implement the CuServiceI interface. It forces them to provide a name as string and a type as CuServices::Type. Services are registered to the service provider with the CuServiceProvider::registerService, removed with the CuServiceProvider::unregisterService and references to registered services can be obtained by type (CuServices::Type) with the CuServiceProvider::get method.
The CuServiceProvider::getServices returns a std::list of the registered services.
Cumbia instantiates a CuServiceProvider in its class constructor (Cumbia::Cumbia) and holds a reference to it throughout all Cumbia's lifetime (see Cumbia::finish). Within Cumbia::finish, all services still registered (as returned by CuServiceProvider::getServices) are first unregistered and then deleted, unless the service had been registered with the shared option set to true (see CuServiceProvider::registerService(CuServices::Type name, CuServiceI *service, bool shared) )
Cumbia::getServiceProvider can be called to get a reference to the service provider.
CuServiceProvider::CuServiceProvider | ( | ) |
the class constructor
no parameters needed.
|
virtual |
References pdelete.
CuServiceI * CuServiceProvider::get | ( | CuServices::Type | name | ) | const |
returns the service with the given name, if registered
name | the name of the service as a value from CuServices::Type |
References CuServiceProviderPrivate::services_map.
Referenced by CuThreadsEventBridge::CuThreadsEventBridge().
std::list< CuServiceI * > CuServiceProvider::getServices | ( | ) | const |
returns the list of registered services
References CuServiceProviderPrivate::services_map.
bool CuServiceProvider::isShared | ( | CuServices::Type | t | ) | const |
References CuServiceProviderPrivate::shared_srvcs.
void CuServiceProvider::registerService | ( | CuServices::Type | name, |
CuServiceI * | service | ||
) |
register a service to the service provider
name | the service name as CuServices::Type |
service | an instance of a CuServiceI implementation |
The service can be retrieved with CuServiceProvider::get The service can be unregistered with CuServiceProvider::unregisterService
The service is deleted automatically by Cumbia when the latter is deleted. If a service is shared across multiple Cumbia instances, like CuEventLoop, then registerSharedService must be called instead.
References CuServiceProviderPrivate::services_map.
void CuServiceProvider::registerSharedService | ( | CuServices::Type | name, |
CuServiceI * | service | ||
) |
Same as registerService, but mark the service as potentially shared across multiple Cumbia instances, thus preventing service from being automatically deleted.
name | the service name, as CuServices::Type |
service | the service to register as a shared service. |
References CuServiceProviderPrivate::services_map, and CuServiceProviderPrivate::shared_srvcs.
void CuServiceProvider::setShared | ( | CuServices::Type | t, |
bool | shared | ||
) |
References CuServiceProviderPrivate::shared_srvcs.
void CuServiceProvider::unregisterService | ( | CuServices::Type | name | ) |
unregister a service from the service provider
name | the name of the service as a value from CuServices::Type |
The service with the given name is removed from the service provider
References CuServiceProviderPrivate::services_map.