Apache Celix  2.3.0
An implementation of the OSGi specification adapted to C and C++
Functions
celix_framework.h File Reference
#include "celix_types.h"
#include "celix_properties.h"
#include "celix_log_level.h"
#include "celix_array_list.h"
Include dependency graph for celix_framework.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

const char * celix_framework_getUUID (const celix_framework_t *fw)
 Returns the framework UUID. This is unique for every created framework and will not be the same if the process is restarted. More...
 
celix_bundle_context_t * celix_framework_getFrameworkContext (const celix_framework_t *fw)
 Returns the framework bundle context. This is the same as a 'normal' bundle context and can be used to register, use and track services. The only difference is that the framework is the bundle. More...
 
celix_bundle_t * celix_framework_getFrameworkBundle (const celix_framework_t *fw)
 Returns the framework bundle. This is the same as a 'normal' bundle, expect that this bundle cannot be uninstalled and the celix_bundle_getEntry return a entries relative from the working directory. More...
 
void celix_framework_useBundles (celix_framework_t *fw, bool includeFrameworkBundle, void *callbackHandle, void(*use)(void *handle, const celix_bundle_t *bnd))
 Use the currently active (started) bundles. The provided callback will be called for all the currently started bundles. More...
 
bool celix_framework_useBundle (celix_framework_t *fw, bool onlyActive, long bndId, void *callbackHandle, void(*use)(void *handle, const celix_bundle_t *bnd))
 Use the bundle with the provided bundle id The provided callback will be called if the bundle is found. More...
 
bool celix_framework_isBundleInstalled (celix_framework_t *fw, long bndId)
 Check whether a bundle is installed. More...
 
bool celix_framework_isBundleActive (celix_framework_t *fw, long bndId)
 Check whether the bundle is active. More...
 
long celix_framework_installBundle (celix_framework_t *fw, const char *bundleLoc, bool autoStart)
 Install and optional start a bundle. Will silently ignore bundle ids < 0. More...
 
bool celix_framework_uninstallBundle (celix_framework_t *fw, long bndId)
 Uninstall the bundle with the provided bundle id. If needed the bundle will be stopped first. Will silently ignore bundle ids < 0. More...
 
bool celix_framework_stopBundle (celix_framework_t *fw, long bndId)
 Stop the bundle with the provided bundle id. Will silently ignore bundle ids < 0. More...
 
bool celix_framework_startBundle (celix_framework_t *fw, long bndId)
 Start the bundle with the provided bundle id. Will silently ignore bundle ids < 0. More...
 
long celix_framework_installBundleAsync (celix_framework_t *fw, const char *bundleLoc, bool autoStart)
 Install and optional start a bundle async. Will silently ignore bundle ids < 0. More...
 
void celix_framework_uninstallBundleAsync (celix_framework_t *fw, long bndId)
 Uninstall the bundle with the provided bundle id async. If needed the bundle will be stopped first. Will silently ignore bundle ids < 0. More...
 
void celix_framework_stopBundleAsync (celix_framework_t *fw, long bndId)
 Stop the bundle with the provided bundle id async. Will silently ignore bundle ids < 0. More...
 
void celix_framework_startBundleAsync (celix_framework_t *fw, long bndId)
 Start the bundle with the provided bundle id async. Will silently ignore bundle ids < 0. More...
 
celix_array_list_t * celix_framework_listBundles (celix_framework_t *framework)
 List the installed and started bundle ids. The bundle ids does not include the framework bundle (bundle id CELIX_FRAMEWORK_BUNDLE_ID). More...
 
celix_array_list_t * celix_framework_listInstalledBundles (celix_framework_t *framework)
 List the installed bundle ids. The bundle ids does not include the framework bundle (bundle id CELIX_FRAMEWORK_BUNDLE_ID). More...
 
void celix_framework_waitForEmptyEventQueue (celix_framework_t *fw)
 Wait until the framework event queue is empty. More...
 
void celix_framework_setLogCallback (celix_framework_t *fw, void *logHandle, void(*logFunction)(void *handle, celix_log_level_e level, const char *file, const char *function, int line, const char *format, va_list formatArgs))
 Sets the log function for this framework. Default the celix framework will log to stdout/stderr. More...
 
void celix_framework_waitUntilNoEventsForBnd (celix_framework_t *fw, long bndId)
 wait until all events for the bundle identified by the bndId are processed. More...
 
void celix_framework_waitUntilNoPendingRegistration (celix_framework_t *fw)
 wait until all pending service registration are processed. More...
 
bool celix_framework_isCurrentThreadTheEventLoop (celix_framework_t *fw)
 Returns whether the current thread is the Celix framework event loop thread. More...
 
long celix_framework_fireGenericEvent (celix_framework_t *fw, long eventId, long bndId, const char *eventName, void *processData, void(*processCallback)(void *data), void *doneData, void(*doneCallback)(void *doneData))
 Fire a generic event. The event will be added to the event loop and handled on the event loop thread. More...
 
long celix_framework_nextEventId (celix_framework_t *fw)
 Get the next event id. More...
 
void celix_framework_waitForGenericEvent (celix_framework_t *fw, long eventId)
 Wait until a event with the provided event id is completely handled. This function will directly return if the provided event id is not in the event loop (already done or never issued). More...
 
void celix_framework_waitForStop (celix_framework_t *framework)
 Wait until the framework is stopped. More...
 

Function Documentation

◆ celix_framework_fireGenericEvent()

long celix_framework_fireGenericEvent ( celix_framework_t *  fw,
long  eventId,
long  bndId,
const char *  eventName,
void *  processData,
void(*)(void *data)  processCallback,
void *  doneData,
void(*)(void *doneData)  doneCallback 
)

Fire a generic event. The event will be added to the event loop and handled on the event loop thread.

if bndId >=0 the bundle usage count will be increased while the event is not yet processed or finished processing. The eventName is expected to be const char* valid during til the event is finished processing.

if eventId >=0 this will be used, otherwise a new event id will be generated return eventId

◆ celix_framework_getFrameworkBundle()

celix_bundle_t* celix_framework_getFrameworkBundle ( const celix_framework_t *  fw)

Returns the framework bundle. This is the same as a 'normal' bundle, expect that this bundle cannot be uninstalled and the celix_bundle_getEntry return a entries relative from the working directory.

Parameters
fwThe framework
Returns
A pointer to the bundle of the framework or NULL if something went wrong.

◆ celix_framework_getFrameworkContext()

celix_bundle_context_t* celix_framework_getFrameworkContext ( const celix_framework_t *  fw)

Returns the framework bundle context. This is the same as a 'normal' bundle context and can be used to register, use and track services. The only difference is that the framework is the bundle.

Parameters
fwThe framework
Returns
A pointer to the bundle context of the framework or NULL if something went wrong.

◆ celix_framework_getUUID()

const char* celix_framework_getUUID ( const celix_framework_t *  fw)

Returns the framework UUID. This is unique for every created framework and will not be the same if the process is restarted.

◆ celix_framework_installBundle()

long celix_framework_installBundle ( celix_framework_t *  fw,
const char *  bundleLoc,
bool  autoStart 
)

Install and optional start a bundle. Will silently ignore bundle ids < 0.

Parameters
fwThe Celix framework
bundleLocThe bundle location to the bundle zip file.
autoStartIf the bundle should also be started.
Returns
the bundleId (>= 0) or < 0 if the bundle could not be installed and possibly started.

◆ celix_framework_installBundleAsync()

long celix_framework_installBundleAsync ( celix_framework_t *  fw,
const char *  bundleLoc,
bool  autoStart 
)

Install and optional start a bundle async. Will silently ignore bundle ids < 0.

If the bundle needs to be started this will be done a separate spawned thread.

Parameters
fwThe Celix framework
bundleLocThe bundle location to the bundle zip file.
autoStartIf the bundle should also be started.
Returns
The bundle id of the installed bundle or -1 if the bundle could not be installed

◆ celix_framework_isBundleActive()

bool celix_framework_isBundleActive ( celix_framework_t *  fw,
long  bndId 
)

Check whether the bundle is active.

Parameters
fwThe Celix framework
bndIdThe bundle id to check
Returns
true if the bundle is installed and active.

◆ celix_framework_isBundleInstalled()

bool celix_framework_isBundleInstalled ( celix_framework_t *  fw,
long  bndId 
)

Check whether a bundle is installed.

Parameters
fwThe Celix framework
bndIdThe bundle id to check
Returns
true if the bundle is installed.

◆ celix_framework_isCurrentThreadTheEventLoop()

bool celix_framework_isCurrentThreadTheEventLoop ( celix_framework_t *  fw)

Returns whether the current thread is the Celix framework event loop thread.

◆ celix_framework_listBundles()

celix_array_list_t* celix_framework_listBundles ( celix_framework_t *  framework)

List the installed and started bundle ids. The bundle ids does not include the framework bundle (bundle id CELIX_FRAMEWORK_BUNDLE_ID).

Parameters
frameworkThe Celix framework.
Returns
A array with bundle ids (long). The caller is responsible for destroying the array.

◆ celix_framework_listInstalledBundles()

celix_array_list_t* celix_framework_listInstalledBundles ( celix_framework_t *  framework)

List the installed bundle ids. The bundle ids does not include the framework bundle (bundle id CELIX_FRAMEWORK_BUNDLE_ID).

Parameters
frameworkThe Celix framework.
Returns
A array with bundle ids (long). The caller is responsible for destroying the array.

◆ celix_framework_nextEventId()

long celix_framework_nextEventId ( celix_framework_t *  fw)

Get the next event id.

This can be used to ensure celix_framework_waitForGenericEvent can be used to wait for an event. The returned event id will not be used by the framework itself unless followed up with a celix_framework_fireGenericEvent call using the returned event id.

◆ celix_framework_setLogCallback()

void celix_framework_setLogCallback ( celix_framework_t *  fw,
void *  logHandle,
void(*)(void *handle, celix_log_level_e level, const char *file, const char *function, int line, const char *format, va_list formatArgs)  logFunction 
)

Sets the log function for this framework. Default the celix framework will log to stdout/stderr.

A log function can be injected to change how the Celix framework logs. Can be reset by setting the log function to NULL.

◆ celix_framework_startBundle()

bool celix_framework_startBundle ( celix_framework_t *  fw,
long  bndId 
)

Start the bundle with the provided bundle id. Will silently ignore bundle ids < 0.

Parameters
fwThe Celix framework
bndIdThe bundle id to start.
Returns
true if the bundle is found & correctly started. False if not.

◆ celix_framework_startBundleAsync()

void celix_framework_startBundleAsync ( celix_framework_t *  fw,
long  bndId 
)

Start the bundle with the provided bundle id async. Will silently ignore bundle ids < 0.

The bundle will be started on a separate spawned thread.

Parameters
fwThe Celix framework
bndIdThe bundle id to start.

◆ celix_framework_stopBundle()

bool celix_framework_stopBundle ( celix_framework_t *  fw,
long  bndId 
)

Stop the bundle with the provided bundle id. Will silently ignore bundle ids < 0.

Parameters
fwThe Celix framework
bndIdThe bundle id to stop.
Returns
true if the bundle is found & correctly stop. False if not.

◆ celix_framework_stopBundleAsync()

void celix_framework_stopBundleAsync ( celix_framework_t *  fw,
long  bndId 
)

Stop the bundle with the provided bundle id async. Will silently ignore bundle ids < 0.

The bundle will be stopped on a separate spawned thread.

Parameters
fwThe Celix framework
bndIdThe bundle id to stop.

◆ celix_framework_uninstallBundle()

bool celix_framework_uninstallBundle ( celix_framework_t *  fw,
long  bndId 
)

Uninstall the bundle with the provided bundle id. If needed the bundle will be stopped first. Will silently ignore bundle ids < 0.

Parameters
fwThe Celix framework
bndIdThe bundle id to uninstall.
Returns
true if the bundle is correctly uninstalled. False if not.

◆ celix_framework_uninstallBundleAsync()

void celix_framework_uninstallBundleAsync ( celix_framework_t *  fw,
long  bndId 
)

Uninstall the bundle with the provided bundle id async. If needed the bundle will be stopped first. Will silently ignore bundle ids < 0.

The bundle will be uninstalled on a separate spawned thread.

Parameters
fwThe Celix framework
bndIdThe bundle id to uninstall.

◆ celix_framework_useBundle()

bool celix_framework_useBundle ( celix_framework_t *  fw,
bool  onlyActive,
long  bndId,
void *  callbackHandle,
void(*)(void *handle, const celix_bundle_t *bnd)  use 
)

Use the bundle with the provided bundle id The provided callback will be called if the bundle is found.

Parameters
fwThe framework.
onlyActiveIf true only starting and active bundles will trigger the callback.
bundleIdThe bundle id.
callbackHandleThe data pointer, which will be used in the callbacks
useThe callback which will be called for the currently started bundles. The bundle pointers are only guaranteed to be valid during the callback.
Returns
Returns true if the bundle is found and the callback is called.

◆ celix_framework_useBundles()

void celix_framework_useBundles ( celix_framework_t *  fw,
bool  includeFrameworkBundle,
void *  callbackHandle,
void(*)(void *handle, const celix_bundle_t *bnd)  use 
)

Use the currently active (started) bundles. The provided callback will be called for all the currently started bundles.

Parameters
ctxThe bundle context.
includeFrameworkBundleIf true the callback will also be triggered for the framework bundle.
callbackHandleThe data pointer, which will be used in the callbacks
useThe callback which will be called for the currently started bundles. The bundle pointers are only guaranteed to be valid during the callback.

◆ celix_framework_waitForEmptyEventQueue()

void celix_framework_waitForEmptyEventQueue ( celix_framework_t *  fw)

Wait until the framework event queue is empty.

The Celix framework has an event queue which (among others) handles bundle events. This function can be used to ensure that all queue event are handled, mainly useful for testing.

Parameters
fwThe Celix Framework

◆ celix_framework_waitForGenericEvent()

void celix_framework_waitForGenericEvent ( celix_framework_t *  fw,
long  eventId 
)

Wait until a event with the provided event id is completely handled. This function will directly return if the provided event id is not in the event loop (already done or never issued).

◆ celix_framework_waitForStop()

void celix_framework_waitForStop ( celix_framework_t *  framework)

Wait until the framework is stopped.

◆ celix_framework_waitUntilNoEventsForBnd()

void celix_framework_waitUntilNoEventsForBnd ( celix_framework_t *  fw,
long  bndId 
)

wait until all events for the bundle identified by the bndId are processed.

◆ celix_framework_waitUntilNoPendingRegistration()

void celix_framework_waitUntilNoPendingRegistration ( celix_framework_t *  fw)

wait until all pending service registration are processed.