cumbia 1.x
general purpose multi threaded library
Loading...
Searching...
No Matches
CuServiceProvider Class Reference

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)
 
CuServiceIget (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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ CuServiceProvider()

CuServiceProvider::CuServiceProvider ( )

the class constructor

no parameters needed.

◆ ~CuServiceProvider()

CuServiceProvider::~CuServiceProvider ( )
virtual

References pdelete.

Member Function Documentation

◆ get()

CuServiceI * CuServiceProvider::get ( CuServices::Type  name) const

returns the service with the given name, if registered

Parameters
namethe name of the service as a value from CuServices::Type
Returns
the instance of the service with that name, if registered, NULL otherwise
warning
The method can return NULL if no service with the given name is registered.

References CuServiceProviderPrivate::services_map.

Referenced by CuThreadsEventBridge::CuThreadsEventBridge().

◆ getServices()

std::list< CuServiceI * > CuServiceProvider::getServices ( ) const

returns the list of registered services

Returns
the list of registered services

References CuServiceProviderPrivate::services_map.

◆ isShared()

bool CuServiceProvider::isShared ( CuServices::Type  t) const

◆ registerService()

void CuServiceProvider::registerService ( CuServices::Type  name,
CuServiceI service 
)

register a service to the service provider

Parameters
namethe service name as CuServices::Type
servicean 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.

◆ registerSharedService()

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.

Parameters
namethe service name, as CuServices::Type
servicethe service to register as a shared service.
Note
The object ownership is left to the caller, and service must be manually deleted.

References CuServiceProviderPrivate::services_map, and CuServiceProviderPrivate::shared_srvcs.

◆ setShared()

void CuServiceProvider::setShared ( CuServices::Type  t,
bool  shared 
)

◆ unregisterService()

void CuServiceProvider::unregisterService ( CuServices::Type  name)

unregister a service from the service provider

Parameters
namethe 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.


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