Apache Celix  2.3.0
An implementation of the OSGi specification adapted to C and C++
Classes | Namespaces | Macros | Functions
BundleActivator.h File Reference
#include <memory>
#include "celix/dm/DependencyManager.h"
#include "celix_bundle_activator.h"
Include dependency graph for BundleActivator.h:

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::dm::DependencyManager > >::value, celix_status_t >::type celix::impl::createActivator (celix_bundle_context_t *cCtx, void **out)
 
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 bundleActivator_create(celix_bundle_context_t *context, void** userData) { \
return celix::impl::createActivator<actType>(context, userData); \
} \
\
extern "C" celix_status_t bundleActivator_start(void *, celix_bundle_context_t *) { \
/*nop*/ \
return CELIX_SUCCESS; \
} \
\
extern "C" celix_status_t bundleActivator_stop(void *userData, celix_bundle_context_t*) { \
return celix::impl::destroyActivator<actType>(userData); \
} \
\
extern "C" celix_status_t 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>.