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.
Classes | Namespaces | Macros | Functions
BundleActivator.h File Reference
#include <memory>
#include "celix/dm/DependencyManager.h"
#include "celix_bundle_activator.h"
#include "celix/BundleContext.h"
Include dependency graph for BundleActivator.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  celix::impl::BundleActivatorData< I >
 

Namespaces

 celix
 
 celix::impl
 

Macros

#define CELIX_GEN_CXX_BUNDLE_ACTIVATOR(actType)
 Macro to generate the required bundle activator functions for C++. This can be used to more type safe bundle activator entries. More...
 

Functions

template<typename I >
std::enable_if< std::is_constructible< I, std::shared_ptr< celix::BundleContext > >::value, celix_status_t >::type celix::impl::createActivator (celix_bundle_context_t *cCtx, void **out)
 
template<typename I >
std::enable_if< std::is_constructible< I, std::shared_ptr< celix::dm::DependencyManager > >::value, celix_status_t >::type celix::impl::createActivator (celix_bundle_context_t *cCtx, void **out)
 
template<typename T >
void celix::impl::waitForExpired (long bndId, std::weak_ptr< celix::BundleContext > &weakCtx, const char *name, std::weak_ptr< T > &observe)
 
template<typename I >
celix_status_t celix::impl::destroyActivator (void *userData)
 

Macro Definition Documentation

◆ CELIX_GEN_CXX_BUNDLE_ACTIVATOR

#define CELIX_GEN_CXX_BUNDLE_ACTIVATOR (   actType)
Value:
extern "C" celix_status_t celix_bundleActivator_create(celix_bundle_context_t *context, void** userData) { \
return celix::impl::createActivator<actType>(context, userData); \
} \
\
extern "C" celix_status_t celix_bundleActivator_start(void *, celix_bundle_context_t *) { \
/*nop*/ \
return CELIX_SUCCESS; \
} \
\
extern "C" celix_status_t celix_bundleActivator_stop(void *userData, celix_bundle_context_t*) { \
return celix::impl::destroyActivator<actType>(userData); \
} \
\
extern "C" celix_status_t celix_bundleActivator_destroy(void *, celix_bundle_context_t*) { \
/*nop*/ \
return CELIX_SUCCESS; \
}

Macro to generate the required bundle activator functions for C++. This can be used to more type safe bundle activator entries.

The macro will create the following bundle activator C functions:

  • bundleActivator_create, which will create the required C++ object (bundle context and dependency manager) and create the C++ bundle activator class (RAII)
  • bundleActivator_start function, which for C++ will do nothing.
  • bundleActivator_stop function, which will trigger the destruction of the C++ BundleActivator and ensure that there is no dangling usage of the bundle context and/or dependency manager.
  • bundleActivator_destroy function, which for C++ will do nothing.

The destruction of the C++ BundleActivator is triggered in the bundleActivator_stop instead of bundleActivator_destroy to ensure that the C++ dependency manager does is cleanup before the C dependency manager. This is needed, because the C dependency manager is not aware of "above lying" C++ objects.

Parameters
typeThe activator type (e.g. 'ShellActivator'). A type which should have a constructor with a single argument of std::shared_ptr<celix::BundleContext> or std::shared_ptr<DependencyManager>.
celix_bundleActivator_stop
CELIX_BUNDLE_ACTIVATOR_EXPORT celix_status_t celix_bundleActivator_stop(void *userData, celix_bundle_context_t *ctx)
Called when this bundle is stopped so the Framework can perform the bundle-specific activities necess...
celix_bundleActivator_destroy
CELIX_BUNDLE_ACTIVATOR_EXPORT celix_status_t celix_bundleActivator_destroy(void *userData, celix_bundle_context_t *ctx)
Called when this bundle is stopped so the bundle can destroy the instance of its activator.
celix_bundleActivator_start
CELIX_BUNDLE_ACTIVATOR_EXPORT celix_status_t celix_bundleActivator_start(void *userData, celix_bundle_context_t *ctx)
Called when this bundle is started so the Framework can perform the bundle-specific activities necess...
celix_bundleActivator_create
CELIX_BUNDLE_ACTIVATOR_EXPORT celix_status_t celix_bundleActivator_create(celix_bundle_context_t *ctx, void **userData)
Called when this bundle is started so the bundle can create an instance for its activator.