Apache Celix  2.3.0
An implementation of the OSGi specification adapted to C and C++
Public Member Functions | Static Public Member Functions | List of all members
celix::dm::Component< T > Class Template Reference

#include <Component.h>

Inheritance diagram for celix::dm::Component< T >:
Inheritance graph
[legend]
Collaboration diagram for celix::dm::Component< T >:
Collaboration graph
[legend]

Public Member Functions

 ~Component () override
 
bool isValid () const
 
T & getInstance ()
 
Component< T > & setInstance (std::shared_ptr< T > inst)
 
Component< T > & setInstance (std::unique_ptr< T > &&inst)
 
Component< T > & setInstance (T &&inst)
 
template<class I >
Component< T > & addInterfaceWithName (const std::string &serviceName, const std::string &version=std::string{}, const Properties &properties=Properties{})
 
template<class I >
Component< T > & addInterface (const std::string &version=std::string{}, const Properties &properties=Properties{})
 
template<class I >
Component< T > & addCInterface (I *svc, const std::string &serviceName, const std::string &version=std::string{}, const Properties &properties=Properties{})
 
template<class I >
ProvidedService< T, I > & createProvidedCService (I *svc, std::string serviceName)
 Creates a provided C services the component. More...
 
template<class I >
ProvidedService< T, I > & createProvidedService (std::string serviceName={})
 Creates a provided C++ services for the component. More...
 
template<class I >
ProvidedService< T, I > & createUnassociatedProvidedService (std::shared_ptr< I > svc, std::string serviceName={})
 Creates a unassociated provided services for the component. More...
 
template<class I >
Component< T > & removeCInterface (const I *svc)
 
template<class I >
ServiceDependency< T, I > & createServiceDependency (const std::string &name=std::string{})
 
template<class I >
Component< T > & remove (ServiceDependency< T, I > &dep)
 
template<typename I >
CServiceDependency< T, I > & createCServiceDependency (const std::string &name)
 
template<typename I >
Component< T > & remove (CServiceDependency< T, I > &dep)
 
Component< T > & setCallbacks (void(T::*init)(), void(T::*start)(), void(T::*stop)(), void(T::*deinit)())
 
Component< T > & setCallbacks (int(T::*init)(), int(T::*start)(), int(T::*stop)(), int(T::*deinit)())
 
Component< T > & removeCallbacks ()
 
Component< T > & addContext (std::shared_ptr< void >)
 Add context to the component. This can be used to ensure a object lifespan at least matches that of the component. More...
 
Component< T > & build ()
 
Component< T > & buildAsync ()
 
- Public Member Functions inherited from celix::dm::BaseComponent
 BaseComponent (celix_bundle_context_t *con, celix_dependency_manager_t *cdm, std::string name, std::string uuid)
 
virtual ~BaseComponent () noexcept
 
 BaseComponent (const BaseComponent &)=delete
 
BaseComponentoperator= (const BaseComponent &)=delete
 
celix_dm_component_t * cComponent () const
 
celix_bundle_context_t * bundleContext () const
 
const std::string & getUUID () const
 
const std::string & getName () const
 
ComponentState getState () const
 
void wait () const
 
void runBuild ()
 

Static Public Member Functions

static std::shared_ptr< Component< T > > create (celix_bundle_context_t *, celix_dependency_manager_t *cDepMan, std::string name, std::string uuid)
 

Additional Inherited Members

- Protected Attributes inherited from celix::dm::BaseComponent
celix_bundle_context_t * context
 
celix_dependency_manager_t * cDepMan
 
celix_dm_component_t * cCmp
 
std::string cmpUUID {}
 
std::string cmpName {}
 
std::atomic< bool > cmpAddedToDepMan {false}
 
std::mutex mutex {}
 
std::vector< std::shared_ptr< BaseServiceDependency > > dependencies {}
 
std::vector< std::shared_ptr< BaseProvidedService > > providedServices {}
 
std::vector< std::shared_ptr< void > > componentContexts {}
 

Constructor & Destructor Documentation

◆ ~Component()

template<class T >
Component::~Component ( )
overridedefault

Member Function Documentation

◆ addCInterface()

template<class T >
template<class I >
Component< T > & Component::addCInterface ( I *  svc,
const std::string &  serviceName,
const std::string &  version = std::string{},
const Properties properties = Properties{} 
)

Adds a C interface to provide as service to the Celix framework.

Parameters
svcThe service struct
serviceNameThe service name to use
versionThe version of the interface (e.g. "1.0.0"), can be an empty string
propertiesTo (meta) properties to provide with the service

◆ addContext()

template<class T >
Component< T > & Component::addContext ( std::shared_ptr< void >  context)

Add context to the component. This can be used to ensure a object lifespan at least matches that of the component.

◆ addInterface()

template<class T >
template<class I >
Component< T > & Component::addInterface ( const std::string &  version = std::string{},
const Properties properties = Properties{} 
)

Adds a C++ interface to provide as service to the Celix framework.

Parameters
serviceNameThe service name to use
versionThe version of the interface (e.g. "1.0.0"), can be an empty string
propertiesTo (meta) properties to provide with the service
Returns
the DM Component reference for chaining (fluent API)

◆ addInterfaceWithName()

template<class T >
template<class I >
Component< T > & Component::addInterfaceWithName ( const std::string &  serviceName,
const std::string &  version = std::string{},
const Properties properties = Properties{} 
)

Adds a C++ interface to provide as service to the Celix framework.

Parameters
serviceNameThe service name to use
versionThe version of the interface (e.g. "1.0.0"), can be an empty string
propertiesTo (meta) properties to provide with the service
Returns
the DM Component reference for chaining (fluent API)

◆ build()

template<typename T >
Component< T > & Component::build

Build the component.

When building the component all provided services and services dependencies are enabled. This is not done automatically so that user can first construct component with their provided service and service dependencies.

Note that the after this call the component will be created and if the component can be started, it will be started and the services will be registered.

Should not be called from the Celix event thread.

◆ buildAsync()

template<typename T >
Component< T > & Component::buildAsync

Same as build, but this call will not wait til all service registrations and tracker are registered/openend on the Celix event thread. Can be called on the Celix event thread.

◆ create()

template<class T >
std::shared_ptr< Component< T > > Component::create ( celix_bundle_context_t *  context,
celix_dependency_manager_t *  cDepMan,
std::string  name,
std::string  uuid 
)
static

Creates a Component using the provided bundle context and component name.

Returns
newly created DM Component.

◆ createCServiceDependency()

template<class T >
template<typename I >
CServiceDependency< T, I > & Component::createCServiceDependency ( const std::string &  name)

Adds a C service dependency to the component

Returns
the DM Component reference for chaining (fluent API)

◆ createProvidedCService()

template<class T >
template<class I >
ProvidedService< T, I > & Component::createProvidedCService ( I *  svc,
std::string  serviceName 
)

Creates a provided C services the component.

The provided service can be fine tuned and build using a fluent API

Parameters
svcThe pointer to a C service (c struct)
serviceNameThe service name to use

◆ createProvidedService()

template<class T >
template<class I >
ProvidedService< T, I > & Component::createProvidedService ( std::string  serviceName = {})

Creates a provided C++ services for the component.

The provided service can be fine tuned and build using a fluent API

Note
The service type I must be a base of component type T.
Parameters
serviceNameThe optional service name. If not provided the service name is inferred from I.

◆ createServiceDependency()

template<class T >
template<class I >
ServiceDependency< T, I > & Component::createServiceDependency ( const std::string &  name = std::string{})

Creates and adds a C++ service dependency to the component

Returns
the Service Dependency reference for chaining (fluent API)

◆ createUnassociatedProvidedService()

template<class T >
template<class I >
ProvidedService< T, I > & Component::createUnassociatedProvidedService ( std::shared_ptr< I >  svc,
std::string  serviceName = {} 
)

Creates a unassociated provided services for the component.

The provided service can be fine tuned and build using a fluent API

Note
The provided service can - and is expected to be - be unassociated with the component type. I.e. it can be a C service. The ProvidedService result will store the shared_ptr of the service during its lifecycle.
Parameters
serviceNameThe optional service name. If not provided the service name is inferred from I.

◆ getInstance()

template<class T >
T & Component::getInstance

Get the component instance. If no instance is explicitly set with setInstance than a instance will be create using a default constructor.

Returns
A reference to the component instance.

◆ isValid()

template<class T >
bool Component::isValid

Whether the component is valid. Invalid component can occurs when no new components can be created and exceptions are not allowed.

Returns

◆ remove() [1/2]

template<class T >
template<typename I >
Component< T > & Component::remove ( CServiceDependency< T, I > &  dep)

Removes a C service dependency to the component

Returns
the DM Component reference for chaining (fluent API)

◆ remove() [2/2]

template<class T >
template<class I >
Component< T > & Component::remove ( ServiceDependency< T, I > &  dep)

Removes a C++ service dependency from the component

Returns
the DM Component reference for chaining (fluent API)

◆ removeCallbacks()

template<class T >
Component< T > & Component::removeCallbacks

Remove the previously registered callbacks for the component life cycle control

Returns
the DM Component reference for chaining (fluent API)

◆ removeCInterface()

template<class T >
template<class I >
Component< T > & Component::removeCInterface ( const I *  svc)

Adds a C interface to provide as service to the Celix framework.

Parameters
svcThe service struct
serviceNameThe service name to use
versionThe version of the interface (e.g. "1.0.0"), can be an empty string
propertiesTo (meta) properties to provide with the service

◆ setCallbacks() [1/2]

template<class T >
Component< T > & Component::setCallbacks ( int(T::*)()  init,
int(T::*)()  start,
int(T::*)()  stop,
int(T::*)()  deinit 
)

Set the callback for the component life cycle control with a int return to indicate an error.

Parameters
initThe init callback.
startThe start callback.
stopThe stop callback.
deinitThe deinit callback.
Returns
the DM Component reference for chaining (fluent API)

◆ setCallbacks() [2/2]

template<class T >
Component< T > & Component::setCallbacks ( void(T::*)()  init,
void(T::*)()  start,
void(T::*)()  stop,
void(T::*)()  deinit 
)

Set the callback for the component life cycle control

Parameters
initThe init callback.
startThe start callback.
stopThe stop callback.
deinitThe deinit callback.
Returns
the DM Component reference for chaining (fluent API)

◆ setInstance() [1/3]

template<class T >
Component< T > & Component::setInstance ( std::shared_ptr< T >  inst)

Set the component instance using a shared pointer.

Returns
the DM Component reference for chaining (fluent API)

◆ setInstance() [2/3]

template<class T >
Component< T > & Component::setInstance ( std::unique_ptr< T > &&  inst)

Set the component instance using a unique pointer.

Returns
the DM Component reference for chaining (fluent API)

◆ setInstance() [3/3]

template<class T >
Component< T > & Component::setInstance ( T &&  inst)

Set the component instance using a value or rval reference The DM Component will contain the instance.

Returns
the DM Component reference for chaining (fluent API)

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