Apache Celix  latest
Apache Celix is a framework for C, C++14 and C++17 to develop dynamic modular software applications using component and in-process service-oriented programming.
Public Member Functions | Friends | List of all members
celix::dm::DependencyManager Class Reference

#include <DependencyManager.h>

Public Member Functions

 DependencyManager (celix_bundle_context_t *ctx)
 
virtual ~DependencyManager ()
 
 DependencyManager (DependencyManager &&mgr)=delete
 
DependencyManageroperator= (DependencyManager &&rhs)=delete
 
 DependencyManager (const DependencyManager &)=delete
 
DependencyManageroperator= (const DependencyManager &)=delete
 
celix_bundle_context_t * bundleContext () const
 
celix_dependency_manager_t * cDependencyManager () const
 
template<class T >
std::enable_if< std::is_default_constructible< T >::value, Component< T > & >::type createComponent (std::string name=std::string{}, std::string uuid={})
 
template<class T >
Component< T > & createComponent (std::unique_ptr< T > &&rhs, std::string name=std::string{}, std::string uuid={})
 
template<class T >
Component< T > & createComponent (std::shared_ptr< T > rhs, std::string name=std::string{}, std::string uuid={})
 
template<class T >
Component< T > & createComponent (T rhs, std::string name=std::string{}, std::string uuid={})
 
void build ()
 
void buildAsync ()
 
void start ()
 
void wait () const
 Wait for an empty Celix event queue. More...
 
void waitIfAble () const
 Wait (if not called on the Celix event thread) for an empty Celix event queue. More...
 
void destroyComponent (BaseComponent &component)
 Removes a component from the Dependency Manager and wait until the component is destroyed. More...
 
void clear ()
 Clears the dependency manager, which removes all configured components and waits until all components are removed from the dependency manager. More...
 
void clearAsync ()
 
void stop ()
 
std::size_t getNrOfComponents () const
 
template<typename T >
std::shared_ptr< Component< T > > findComponent (const std::string &uuid) const
 
bool removeComponent (const std::string &uuid)
 Removes component with provided UUID from the dependency manager and wail until the component is destroyed. More...
 
bool removeComponentAsync (const std::string &uuid)
 Removes a component from the Dependency Manager and destroys it async. More...
 
celix::dm::DependencyManagerInfo getInfo () const
 
std::vector< celix::dm::DependencyManagerInfogetInfos () const
 

Friends

std::ostream & operator<< (std::ostream &out, const DependencyManager &mng)
 

Detailed Description

The build() methods For celix::dm::DependencyManager, celix::dm::Component and celix::dm::(C)ServiceDependency should be called outside the Celix event thread. Note that bundle activators are started and stopped outside the Celix event thread and thus the build() methods can be used in bundle activators.

Inside the Celix event thread - i.e. during a useService callback or add/rem/set call from a service tracker - the buildAsync version should be used. After a buildASync method has returned, service registration and opening service trackers are (possibly) still in progress.

Constructor & Destructor Documentation

◆ DependencyManager() [1/3]

DependencyManager::DependencyManager ( celix_bundle_context_t *  ctx)
inline

◆ ~DependencyManager()

DependencyManager::~DependencyManager ( )
inlinevirtual

◆ DependencyManager() [2/3]

celix::dm::DependencyManager::DependencyManager ( DependencyManager &&  mgr)
delete

◆ DependencyManager() [3/3]

celix::dm::DependencyManager::DependencyManager ( const DependencyManager )
delete

Member Function Documentation

◆ build()

void DependencyManager::build ( )
inline

Build the dependency manager.

When building the dependency manager all created components are build. A build is needed to to enable the components. This is not done automatically so that user can first construct component with their provided service and service dependencies and when to components are complete call the build.

If a component is updated after the dependency manager build is called, an new build call will result in that the changes to the component are enabled.

After this call the components will be created and if the components can be started, they will be started and the services will be registered.

Should not be called from the Celix event thread.

◆ buildAsync()

void DependencyManager::buildAsync ( )
inline

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

◆ bundleContext()

celix_bundle_context_t* celix::dm::DependencyManager::bundleContext ( ) const
inline

◆ cDependencyManager()

celix_dependency_manager_t* celix::dm::DependencyManager::cDependencyManager ( ) const
inline

◆ clear()

void DependencyManager::clear ( )
inline

Clears the dependency manager, which removes all configured components and waits until all components are removed from the dependency manager.

Should not be called from the Celix event thread.

◆ clearAsync()

void DependencyManager::clearAsync ( )
inline

Clears the dependency manager, which removes all configured components.

This is done async and this can be called from the Celix event thread.

◆ createComponent() [1/4]

template<class T >
Component< T > & DependencyManager::createComponent ( std::shared_ptr< T >  rhs,
std::string  name = std::string{},
std::string  uuid = {} 
)

Creates and adds a new DM Component for a component of type T and setting the instance using a shared ptr.

Returns
Returns a reference to the DM Component

◆ createComponent() [2/4]

template<class T >
std::enable_if< std::is_default_constructible< T >::value, Component< T > & >::type DependencyManager::createComponent ( std::string  name = std::string{},
std::string  uuid = {} 
)
inline

Creates and adds a new DM Component for a component of type T.

Returns
Returns a reference to the DM Component

◆ createComponent() [3/4]

template<class T >
Component< T > & DependencyManager::createComponent ( std::unique_ptr< T > &&  rhs,
std::string  name = std::string{},
std::string  uuid = {} 
)

Creates and adds a new DM Component for a component of type T and setting the instance using a unique ptr.

Returns
Returns a reference to the DM Component

◆ createComponent() [4/4]

template<class T >
Component< T > & DependencyManager::createComponent ( rhs,
std::string  name = std::string{},
std::string  uuid = {} 
)

Creates and adds a new DM Component for a component of type T and setting the instance.

Returns
Returns a reference to the DM Component

◆ destroyComponent()

void DependencyManager::destroyComponent ( BaseComponent component)
inline

Removes a component from the Dependency Manager and wait until the component is destroyed.

The use of removeComponent is preferred.

◆ findComponent()

template<typename T >
std::shared_ptr< Component< T > > DependencyManager::findComponent ( const std::string &  uuid) const
inline

Tries to find the component with UUID and statically cast it to dm component of type T

Returns
pointer to found component or null if the component cannot be found.

◆ getInfo()

celix::dm::DependencyManagerInfo DependencyManager::getInfo ( ) const
inline

Get Dependency Management info for this component manager.

Returns
A DependencyManagerInfo struct.

◆ getInfos()

std::vector< celix::dm::DependencyManagerInfo > DependencyManager::getInfos ( ) const
inline

Get Dependency Management info for all component manager (for all bundles).

Returns
A vector of DependencyManagerInfo structs.

◆ getNrOfComponents()

std::size_t DependencyManager::getNrOfComponents ( ) const
inline

Returns the nr of configured components for this dependency manager.

◆ operator=() [1/2]

DependencyManager& celix::dm::DependencyManager::operator= ( const DependencyManager )
delete

◆ operator=() [2/2]

DependencyManager& celix::dm::DependencyManager::operator= ( DependencyManager &&  rhs)
delete

◆ removeComponent()

bool DependencyManager::removeComponent ( const std::string &  uuid)
inline

Removes component with provided UUID from the dependency manager and wail until the component is destroyed.

Should not be called from the Celix event thread.

Returns
whether the component is found and removed.

◆ removeComponentAsync()

bool DependencyManager::removeComponentAsync ( const std::string &  uuid)
inline

Removes a component from the Dependency Manager and destroys it async.

Can be called from the Celix event thread.

Returns
whether the component is found and removed.

◆ start()

void DependencyManager::start ( )
inline

Starts the Dependency Manager Note this call is considered deprecated, please use build() instead.

◆ stop()

void DependencyManager::stop ( )
inline

Stops the Dependency Manager Note this call is considered deprecated, please use clear() instead.

◆ wait()

void DependencyManager::wait ( ) const
inline

Wait for an empty Celix event queue.

Should not be called on the Celix event queue thread. Note scheduled events are not part of the event queue.

Can be used to ensure that all created/updated components are completely processed (services registered and/or service trackers are created).

◆ waitIfAble()

void DependencyManager::waitIfAble ( ) const
inline

Wait (if not called on the Celix event thread) for an empty Celix event queue.

Note scheduled events are not part of the event queue.

Can be used to ensure that all created/updated components are completely processed (services registered and/or service trackers are created).

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const DependencyManager mng 
)
friend

Stream outputs the full dependency manager info.


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