Celix  2.2.0
An implementation of the OSGi specification adapted to C and C++
Macros | Functions
celix_bundle_activator.h File Reference
#include <stdlib.h>
#include "celix_bundle_context.h"
Include dependency graph for celix_bundle_activator.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define CELIX_GEN_BUNDLE_ACTIVATOR(actType, actStart, actStop)
 

Functions

celix_status_t celix_bundleActivator_create (celix_bundle_context_t *ctx, void **userData)
 
celix_status_t celix_bundleActivator_start (void *userData, celix_bundle_context_t *ctx)
 
celix_status_t celix_bundleActivator_stop (void *userData, celix_bundle_context_t *ctx)
 
celix_status_t celix_bundleActivator_destroy (void *userData, celix_bundle_context_t *ctx)
 

Macro Definition Documentation

#define CELIX_GEN_BUNDLE_ACTIVATOR (   actType,
  actStart,
  actStop 
)
Value:
celix_status_t celix_bundleActivator_create(celix_bundle_context_t *ctx __attribute__((unused)), void **userData) { \
celix_status_t status = CELIX_SUCCESS; \
actType *data = (actType*)calloc(1, sizeof(*data)); \
if (data != NULL) { \
*userData = data; \
} else { \
status = CELIX_ENOMEM; \
} \
return status; \
} \
\
celix_status_t celix_bundleActivator_start(void *userData, celix_bundle_context_t *ctx) { \
return actStart((actType*)userData, ctx); \
} \
\
celix_status_t celix_bundleActivator_stop(void *userData, celix_bundle_context_t *ctx) { \
return actStop((actType*)userData, ctx); \
} \
\
celix_status_t celix_bundleActivator_destroy(void *userData, celix_bundle_context_t *ctx __attribute__((unused))) { \
free(userData); \
return CELIX_SUCCESS; \
}
celix_status_t celix_bundleActivator_destroy(void *userData, celix_bundle_context_t *ctx)
celix_status_t celix_bundleActivator_create(celix_bundle_context_t *ctx, void **userData)
celix_status_t celix_bundleActivator_stop(void *userData, celix_bundle_context_t *ctx)
celix_status_t celix_bundleActivator_start(void *userData, celix_bundle_context_t *ctx)

This macro generates 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 functions:

  • bundleActivator_create which allocates a pointer to the provided type.
  • bundleActivator_start/stop which will call the respectively provided typed start/stop functions.
  • bundleActivator_destroy will free the allocated for the provided type.
Parameters
typeThe activator type (e.g. 'struct shell_activator').
startthe activator actStart function with the following signature: celix_status_t (*)(<actType>*, celix_bundle_context_t*).
stopthe activator actStop function with the following signature: celix_status_t (*)(<actType>*, celix_bundle_context_t*).

Function Documentation

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. The framework does not assume any type for the activator instance, this is implementation specific. The activator instance is handle as a void pointer by the framework, the implementation must cast it to the implementation specific type.

Parameters
ctxThe execution context of the bundle being started.
[out]userDataA pointer to the specific activator instance used by this bundle.
Returns
Status code indication failure or success:
  • CELIX_SUCCESS when no errors are encountered.
  • Any other status code will mark the bundle as stopped and the framework will remove this bundle's listeners, unregister all services, and release all services used by this bundle.
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. In general, this method should undo the work that the bundleActivator_create() function initialized.

This method must complete and return to its caller in a timely manner.

Parameters
userDataThe activator instance to be used.
ctxThe execution context of the bundle being stopped.
Returns
Status code indication failure or success:
  • CELIX_SUCCESS when no errors are encountered.
  • Any other status code will mark the bundle as stopped and the framework will remove this bundle's listeners, unregister all services, and release all services used by this bundle.
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 necessary to start this bundle. This method can be used to register services or to allocate any resources that this bundle needs.

This method must complete and return to its caller in a timely manner.

Parameters
userDataThe activator instance to be used.
ctxThe execution context of the bundle being started.
Returns
Status code indication failure or success:
  • CELIX_SUCCESS when no errors are encountered.
  • Any other status code will mark the bundle as stopped and the framework will remove this bundle's listeners, unregister all services, and release all services used by this bundle.
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 necessary to stop the bundle. In general, this method should undo the work that the bundleActivator_start() function started. There should be no active threads that were started by this bundle when this bundle returns. A stopped bundle must not call any Framework objects.

This method must complete and return to its caller in a timely manner.

Parameters
userDataThe activator instance to be used.
ctxThe execution context of the bundle being stopped.
Returns
Status code indication failure or success:
  • CELIX_SUCCESS when no errors are encountered.
  • Any other status code will mark the bundle as stopped and the framework will remove this bundle's listeners, unregister all services, and release all services used by this bundle.