Apache Celix
2.4.0
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.
|
The bundle context is used to interact with the Celix framework. More...
#include <BundleContext.h>
Public Member Functions | |
BundleContext (celix_bundle_context_t *_cCtx) | |
template<typename I , typename Implementer > | |
ServiceRegistrationBuilder< I > | registerService (std::shared_ptr< Implementer > implementer, std::string_view name={}) |
Register a service in the Celix framework using a fluent builder API. More... | |
template<typename I , typename Implementer > | |
ServiceRegistrationBuilder< I > | registerUnmanagedService (Implementer *svc, std::string_view name={}) |
Register a (unmanaged) service in the Celix framework using a fluent builder API. More... | |
template<typename I > | |
UseServiceBuilder< I > | useService (std::string_view name={}) |
Use a service registered in the Celix framework using a fluent builder API. More... | |
template<typename I > | |
UseServiceBuilder< I > | useServices (std::string_view name={}) |
Use services registered in the Celix framework using a fluent builder API. More... | |
template<typename I > | |
long | findService (std::string_view filter={}, std::string_view versionRange={}) |
Finds the highest ranking service using the optional provided (LDAP) filter and version range. More... | |
long | findServiceWithName (std::string_view name, std::string_view filter={}, std::string_view versionRange={}) |
Finds the highest ranking service using the provided service name and the optional (LDAP) filter and version range. More... | |
template<typename I > | |
std::vector< long > | findServices (std::string_view filter={}, std::string_view versionRange={}) |
Finds all services matching the optional provided (LDAP) filter and version range. More... | |
std::vector< long > | findServicesWithName (std::string_view name, std::string_view filter={}, std::string_view versionRange={}) |
Finds all service matching the provided service name and the optional (LDAP) filter and version range. More... | |
template<typename I > | |
ServiceTrackerBuilder< I > | trackServices (std::string_view name={}) |
Track services in the Celix framework using a fluent builder API. More... | |
ServiceTrackerBuilder< void > | trackAnyServices () |
Track services in the Celix framework using a fluent builder API. More... | |
BundleTrackerBuilder | trackBundles () |
Track bundles in the Celix framework using a fluent builder API. More... | |
template<typename I > | |
MetaTrackerBuilder | trackServiceTrackers (std::string_view name={}) |
Track service trackers in the Celix framework using a fluent builder API. More... | |
MetaTrackerBuilder | trackAnyServiceTrackers () |
Track service trackers in the Celix framework using a fluent builder API. More... | |
ScheduledEventBuilder | scheduledEvent () |
Schedule a callback to be called after the given initial delay and/or interval using a fluent builder API. More... | |
long | installBundle (std::string_view bndLocation, bool autoStart=true) |
Install and optional start a bundle. More... | |
bool | uninstallBundle (long bndId) |
Uninstall the bundle with the provided bundle id. More... | |
bool | startBundle (long bndId) |
Start the bundle with the provided bundle id. More... | |
bool | stopBundle (long bndId) |
Stop the bundle with the provided bundle id. More... | |
bool | updateBundle (long bndId, std::string_view updatedBundleUrl={}) |
Update the bundle with the provided bundle id async. More... | |
std::vector< long > | listBundleIds () const |
List the installed and started bundle ids. The bundle ids does not include the framework bundle (bundle id CELIX_FRAMEWORK_BUNDLE_ID). More... | |
std::vector< long > | listInstalledBundleIds () |
List the installed bundle ids. The bundle ids does not include the framework bundle (bundle id CELIX_FRAMEWORK_BUNDLE_ID). More... | |
std::string | getConfigProperty (std::string_view name, std::string_view defaultValue) const |
Gets the config property for the provided name. More... | |
long | getConfigPropertyAsLong (std::string_view name, long defaultValue) const |
Gets the config property for the provided name and returns it as a long. More... | |
double | getConfigPropertyAsDouble (std::string_view name, double defaultValue) const |
Gets the config property for the provided name and returns it as a double. More... | |
long | getConfigPropertyAsBool (std::string_view name, bool defaultValue) const |
Gets the config property for the provided name and returns it as a bool. More... | |
const Bundle & | getBundle () const |
Get the bundle of this bundle context. More... | |
long | getBundleId () const |
Get the bundle id for the bundle of this bundle context. More... | |
std::shared_ptr< Framework > | getFramework () const |
Get the Celix framework for this bundle context. More... | |
std::shared_ptr< dm::DependencyManager > | getDependencyManager () const |
Get the Celix dependency manager for this bundle context. More... | |
celix_bundle_context_t * | getCBundleContext () const |
Get the C bundle context. More... | |
void | logTrace (const char *format...) __attribute__((format(printf |
Log a message to the Celix framework logger using the TRACE log level. More... | |
void | va_start (args, format) |
celix_bundleContext_vlog (cCtx.get(), CELIX_LOG_LEVEL_TRACE, format, args) | |
va_end (args) | |
void | logDebug (const char *format...) __attribute__((format(printf |
Log a message to the Celix framework logger using the DEBUG log level. More... | |
void | va_start (args, format) |
celix_bundleContext_vlog (cCtx.get(), CELIX_LOG_LEVEL_DEBUG, format, args) | |
va_end (args) | |
void | logInfo (const char *format...) __attribute__((format(printf |
Log a message to the Celix framework logger using the INFO log level. More... | |
void | va_start (args, format) |
celix_bundleContext_vlog (cCtx.get(), CELIX_LOG_LEVEL_INFO, format, args) | |
va_end (args) | |
void | logWarn (const char *format...) __attribute__((format(printf |
Log a message to the Celix framework logger using the WARNING log level. More... | |
void | va_start (args, format) |
celix_bundleContext_vlog (cCtx.get(), CELIX_LOG_LEVEL_WARNING, format, args) | |
va_end (args) | |
void | logError (const char *format...) __attribute__((format(printf |
Log a message to the Celix framework logger using the ERROR log level. More... | |
void | va_start (args, format) |
celix_bundleContext_vlog (cCtx.get(), CELIX_LOG_LEVEL_ERROR, format, args) | |
va_end (args) | |
void | logFatal (const char *format...) __attribute__((format(printf |
Log a message to the Celix framework logger using the FATAL log level. More... | |
void | va_start (args, format) |
celix_bundleContext_vlog (cCtx.get(), CELIX_LOG_LEVEL_FATAL, format, args) | |
va_end (args) | |
void | logTssErrors (celix_log_level_e level) |
Log celix per-thread error messages to the Celix framework logger using the provided log level. Silently ignores log level CELIX_LOG_LEVEL_DISABLED. More... | |
void | waitForEvents () const |
Wait until all Celix events for this bundle are completed. More... | |
void | waitIfAbleForEvents () const |
Wait (if not on the Celix event thread) until all Celix events for this bundle are completed. More... | |
void | waitForAllEvents () const |
Wait until all Celix events (for all bundles) are completed. More... | |
void | waitIfAbleForAllEvents () const |
Wait (if not on the Celix event thread) until all Celix events (for all bundles) are completed. More... | |
The bundle context is used to interact with the Celix framework.
The bundle context represent a bundle and can be used to:
std::string_view
values must be null terminated strings.
|
inlineexplicit |
celix::BundleContext::celix_bundleContext_vlog | ( | cCtx. | get(), |
CELIX_LOG_LEVEL_DEBUG | , | ||
format | , | ||
args | |||
) |
celix::BundleContext::celix_bundleContext_vlog | ( | cCtx. | get(), |
CELIX_LOG_LEVEL_ERROR | , | ||
format | , | ||
args | |||
) |
celix::BundleContext::celix_bundleContext_vlog | ( | cCtx. | get(), |
CELIX_LOG_LEVEL_FATAL | , | ||
format | , | ||
args | |||
) |
celix::BundleContext::celix_bundleContext_vlog | ( | cCtx. | get(), |
CELIX_LOG_LEVEL_INFO | , | ||
format | , | ||
args | |||
) |
celix::BundleContext::celix_bundleContext_vlog | ( | cCtx. | get(), |
CELIX_LOG_LEVEL_TRACE | , | ||
format | , | ||
args | |||
) |
celix::BundleContext::celix_bundleContext_vlog | ( | cCtx. | get(), |
CELIX_LOG_LEVEL_WARNING | , | ||
format | , | ||
args | |||
) |
|
inline |
Finds the highest ranking service using the optional provided (LDAP) filter and version range.
Uses celix::typeName<I> to defer the service name.
I | the service type to found. |
filter | An optional LDAP filter. |
versionRange | An optional version range. |
|
inline |
Finds all services matching the optional provided (LDAP) filter and version range.
Note uses celix::typeName<I> to defer the service name.
I | the service type to found. |
filter | An optional LDAP filter. |
versionRange | An optional version range. |
|
inline |
Finds all service matching the provided service name and the optional (LDAP) filter and version range.
The | service name. (Can be empty to find service with any name). |
filter | An optional LDAP filter. |
versionRange | An optional version range. |
|
inline |
Finds the highest ranking service using the provided service name and the optional (LDAP) filter and version range.
The | service name. (Can be empty to find service with any name). |
filter | An optional LDAP filter. |
versionRange | An optional version range. |
|
inline |
Get the bundle of this bundle context.
|
inline |
Get the bundle id for the bundle of this bundle context.
|
inline |
Get the C bundle context.
|
inline |
Gets the config property for the provided name.
First the provided name will be used to lookup an environment variable of that name. If this is not found, the config properties of the Celix framework will be used (config.properties). Note that by design this means that environment variable can be used to override config properties.
name | The name of the property to receive. |
defaultVal | The default value to use if the property is not found. |
|
inline |
Gets the config property for the provided name and returns it as a bool.
First the provided name will be used to lookup an environment variable of that name. If no this is not found or not a valid bool, the config properties of the Celix framework will be used (config.properties). Note that by design this means that environment variable can be used to override config properties.
Valid bools are "true" and "false" (case insensitive)
name | The name of the property to receive. |
defaultVal | The default value to use if the property is not found. |
|
inline |
Gets the config property for the provided name and returns it as a double.
First the provided name will be used to lookup an environment variable of that name. If no this is not found or not a valid double, the config properties of the Celix framework will be used (config.properties). Note that by design this means that environment variable can be used to override config properties.
name | The name of the property to receive. |
defaultVal | The default value to use if the property is not found. |
|
inline |
Gets the config property for the provided name and returns it as a long.
First the provided name will be used to lookup an environment variable of that name. If no this is not found or not a valid long, the config properties of the Celix framework will be used (config.properties). Note that by design this means that environment variable can be used to override config properties.
name | The name of the property to receive. |
defaultVal | The default value to use if the property is not found. |
|
inline |
Get the Celix dependency manager for this bundle context.
|
inline |
Get the Celix framework for this bundle context.
|
inline |
Install and optional start a bundle.
Will silently ignore bundle ids < 0.
bndLocation | The bundle location to the bundle zip file. |
autoStart | If the bundle should also be started. |
|
inline |
List the installed and started bundle ids. The bundle ids does not include the framework bundle (bundle id CELIX_FRAMEWORK_BUNDLE_ID).
|
inline |
List the installed bundle ids. The bundle ids does not include the framework bundle (bundle id CELIX_FRAMEWORK_BUNDLE_ID).
void celix::BundleContext::logDebug | ( | const char * | format... | ) |
Log a message to the Celix framework logger using the DEBUG log level.
void celix::BundleContext::logError | ( | const char * | format... | ) |
Log a message to the Celix framework logger using the ERROR log level.
void celix::BundleContext::logFatal | ( | const char * | format... | ) |
Log a message to the Celix framework logger using the FATAL log level.
void celix::BundleContext::logInfo | ( | const char * | format... | ) |
Log a message to the Celix framework logger using the INFO log level.
void celix::BundleContext::logTrace | ( | const char * | format... | ) |
Log a message to the Celix framework logger using the TRACE log level.
|
inline |
Log celix per-thread error messages to the Celix framework logger using the provided log level. Silently ignores log level CELIX_LOG_LEVEL_DISABLED.
void celix::BundleContext::logWarn | ( | const char * | format... | ) |
Log a message to the Celix framework logger using the WARNING log level.
|
inline |
Register a service in the Celix framework using a fluent builder API.
The service registration can be fine tuned using the returned ServiceRegistrationBuilder API.
std::shared_ptr<celix::BundleContext> ctx = ... auto svcReg = ctx->registerService<IExample>(std::make_shared<ExampleImpl>()) .setVersion("1.0.0") .addProperty("key1", "value1") .addOnRegistered([](const std::shared_ptr<celix::ServiceRegistration>& reg) { std::cout << "Done registering service '" << reg->getServiceName() << "' with id " << reg->getServiceId() << std::endl; }) .build();
By default the service registration is configure to register and unregister the service async.
I | The service type (Note should be the abstract interface, not the interface implementer) |
Implementer | The service implementer. |
implementer | The service implementer. |
name | The optional name of the service. If not provided celix::typeName<I> will be used to defer the service name. |
|
inline |
Register a (unmanaged) service in the Celix framework using a fluent builder API.
Same as registerService, but then with an unmanaged service pointer. Note that the user is responsible for ensuring that the service pointer is valid as long as the service is registered in the Celix framework.
By default the service registration is configure to register the service async, but to unregister the service sync (because the svc pointer is unmanaged).
|
inline |
Schedule a callback to be called after the given initial delay and/or interval using a fluent builder API.
|
inline |
Start the bundle with the provided bundle id.
Will silently ignore bundle ids < 0.
If this function is called on the Celix event thread, the actual starting of the bundle will be done async and on a separate thread. If this function is called from a different thread than the Celix event thread, then the function will return after the bundle start is completed.
bndId | The bundle id to start. |
|
inline |
Stop the bundle with the provided bundle id.
Will silently ignore bundle ids < 0.
If this function is called on the Celix event thread, the actual stopping of the bundle will be done async and on a separate thread. If this function is called from a different thread than the Celix event thread, then the function will return after the bundle stop is completed.
bndId | The bundle id to stop. |
|
inline |
Track services in the Celix framework using a fluent builder API.
Same as trackerService, but than for any service. Note that the service shared ptr is of the type std::shared_ptr<void>.
|
inline |
Track service trackers in the Celix framework using a fluent builder API.
Same as trackServiceTrackers, but than for service tracker for any service types.
|
inline |
Track bundles in the Celix framework using a fluent builder API.
The bundle tracker can be fine tuned using the returned BundleTrackerBuilder API.
std::shared_ptr<celix::BundleContext> ctx = ... auto tracker = ctx->trackBundles<>() .addOnInstallCallback([](const celix::Bundle& bnd) { std::cout << "Bundle installed with id '" << bnd.getId() << std::endl; }) .build();
|
inline |
Track services in the Celix framework using a fluent builder API.
The service tracker can be fine tuned using the returned ServiceTrackerBuilder API.
std::shared_ptr<celix::BundleContext> ctx = ... auto tracker = ctx->trackServices<IExample>() .setFilter("(property_key=value)") .addAddCallback([](std::shared_ptr<IExample>, std::shared_ptr<const celix::Properties> props) { std::cout << "Adding service with id '" << props->get("service.id", "-1") << std::endl; }) .addRemCallback([](std::shared_ptr<IExample>, std::shared_ptr<const celix::Properties> props) { std::cout << "Removing service with id '" << props->get("service.id", "-1") << std::endl; }) .build();
I | The service type to track |
name | The optional service name. If empty celix::typeName<I> will be used to defer the service name. |
|
inline |
Track service trackers in the Celix framework using a fluent builder API.
The meta tracker (service tracker tracker) can be fine tuned using the returned MetaTrackerBuilder API.
std::shared_ptr<celix::BundleContext> ctx = ... auto tracker = ctx->trackServiceTrackers<IExample>() .addOnTrackerCreatedCallback([](const ServiceTrackerInfo& info) { std::cout << "Tracker created for service name '" << info.serviceName << std::endl; }) .addOnTrackerDestroyedCallback([](const ServiceTrackerInfo& info) { std::cout << "Tracker destroyed for service name '" << info.serviceName << std::endl; }) .build();
I | The service tracker service type to track. |
name | The optional service name. If empty celix::typeName<I> will be used to defer the service name. |
|
inline |
Uninstall the bundle with the provided bundle id.
If needed the bundle will be stopped first. Will silently ignore bundle ids < 0.
bndId | The bundle id to uninstall. |
|
inline |
Update the bundle with the provided bundle id async.
This will do the following:
Will silently ignore bundle ids < 0.
If this function is called on the Celix event thread, the actual updating of the bundle will be done async and on a separate thread. If this function is called from a different thread than the Celix event thread, then the function will return after the bundle update is completed.
ctx | The bundle context |
bndId | The bundle id to start. |
updatedBundleUrl | The optional updated bundle url to the bundle zip file. If empty, the existing bundle url from the bundle cache will be used. |
|
inline |
Use a service registered in the Celix framework using a fluent builder API.
The service use can be fine tuned using the returned UseServiceBuilder API.
With this API a Celix service can be used by providing use functions. The use function will be executed on the Celix event thread and the Celix framework will ensure that the service cannot be removed while in use.
If there are more 1 matching service, the highest ranking service will be used. If no service can be found the use callbacks with not be called.
std::shared_ptr<celix::BundleContext> ctx = ... auto callCount = ctx->useService<IExample>() .setTimeout(std::chrono::seconds{1}) .addUseCallback([](IExample& service, const celix::Properties& props){ std::cout << "Calling service with id " << props.get("service.id", "-1") << std::endl; service.method(); }) .build();
I | The service type to use |
name | The optional service name to use. If not provided celix::typeName<I> will be used to defer the service name. |
|
inline |
Use services registered in the Celix framework using a fluent builder API.
The service use can be fine tuned using the returned UseServiceBuilder API.
With this API Celix services can be used by providing use functions. The use function will be executed on the Celix event thread and the Celix framework will ensure that the service cannot be removed while in use.
The use callbacks will be called for every matching service found.
std::shared_ptr<celix::BundleContext> ctx = ... auto callCount = ctx->useServices<IExample>() .addUseCallback([](IExample& service, const celix::Properties& props){ std::cout << "Calling service with id " << props.get("service.id", "-1") << std::endl; service.method(); }) .build();
I | The service type to use |
name | The optional service name to use. If not provided celix::typeName<I> will be used to defer the service name. |
celix::BundleContext::va_end | ( | args | ) |
celix::BundleContext::va_end | ( | args | ) |
celix::BundleContext::va_end | ( | args | ) |
celix::BundleContext::va_end | ( | args | ) |
celix::BundleContext::va_end | ( | args | ) |
celix::BundleContext::va_end | ( | args | ) |
void celix::BundleContext::va_start | ( | args | , |
format | |||
) |
void celix::BundleContext::va_start | ( | args | , |
format | |||
) |
void celix::BundleContext::va_start | ( | args | , |
format | |||
) |
void celix::BundleContext::va_start | ( | args | , |
format | |||
) |
void celix::BundleContext::va_start | ( | args | , |
format | |||
) |
void celix::BundleContext::va_start | ( | args | , |
format | |||
) |
|
inline |
Wait until all Celix events (for all bundles) are completed.
|
inline |
Wait until all Celix events for this bundle are completed.
|
inline |
Wait (if not on the Celix event thread) until all Celix events (for all bundles) are completed.
|
inline |
Wait (if not on the Celix event thread) until all Celix events for this bundle are completed.