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.
|
Go to the documentation of this file.
56 cCtx{_cCtx, [](celix_bundle_context_t*){}},
57 dm{std::make_shared<celix::dm::DependencyManager>(_cCtx)},
82 template<
typename I,
typename Implementer>
84 std::shared_ptr<I> svc = implementer;
98 template<
typename I,
typename Implementer>
100 auto unmanagedSvc = std::shared_ptr<I>{svc, [](I*){}};
101 return ServiceRegistrationBuilder<I>{cCtx, std::move(unmanagedSvc), celix::typeName<I>(name),
true,
false};
189 long findService(
const std::string& filter = {},
const std::string& versionRange = {}) {
202 long findServiceWithName(
const std::string& name,
const std::string& filter = {},
const std::string& versionRange = {}) {
205 opts.serviceName = name.empty() ? nullptr : name.data();
206 opts.filter = filter.empty() ? nullptr : filter.data();
207 opts.versionRange = versionRange.empty() ? nullptr : versionRange.data();
223 std::vector<long>
findServices(
const std::string& filter = {},
const std::string& versionRange = {}) {
236 std::vector<long>
findServicesWithName(
const std::string& name,
const std::string& filter = {},
const std::string& versionRange = {}) {
237 return findServicesWithNameInternal(
238 name.empty() ?
nullptr : name.c_str(),
239 filter.empty() ?
nullptr : filter.c_str(),
240 versionRange.empty() ?
nullptr : versionRange.c_str());
421 bool updateBundle(
long bndId,
const std::string& updatedBundleUrl = {}) {
432 return listBundlesInternal(
true);
442 return listBundlesInternal(
false);
530 return std::make_shared<Framework>(fwCtx, cFw);
555 void logTrace(
const char* format...) __attribute__((format(printf,2,3))) {
567 void logDebug(
const char* format...) __attribute__((format(printf,2,3))) {
579 void logInfo(
const char* format...) __attribute__((format(printf,2,3))) {
591 void logWarn(
const char* format...) __attribute__((format(printf,2,3))) {
603 void logError(
const char* format...) __attribute__((format(printf,2,3))) {
615 void logFatal(
const char* format...) __attribute__((format(printf,2,3))) {
665 std::vector<long> listBundlesInternal(
bool activeOnly)
const {
666 std::vector<long> result{};
667 auto* ids = activeOnly ?
670 result.reserve(celix_arrayList_size(ids));
671 for (
int i = 0; i < celix_arrayList_size(ids); ++i) {
672 result.push_back(celix_arrayList_getLong(ids, i));
674 celix_arrayList_destroy(ids);
678 std::vector<long> findServicesWithNameInternal(
const char* name,
const char* filter,
const char* versionRange) {
681 opts.serviceName = name;
682 opts.filter = filter;
683 opts.versionRange = versionRange;
685 std::vector<long> result{};
687 for (
int i = 0; i < celix_arrayList_size(cList); ++i) {
688 long svcId = celix_arrayList_getLong(cList, i);
689 result.push_back(svcId);
691 celix_arrayList_destroy(cList);
695 const std::shared_ptr<celix_bundle_context_t> cCtx;
696 const std::shared_ptr<celix::dm::DependencyManager> dm;
ServiceTrackerBuilder< I > trackServices(const std::string &name={})
Track services in the Celix framework using a fluent builder API.
Definition: BundleContext.h:264
void logFatal(const char *format...) __attribute__((format(printf
Log a message to the Celix framework logger using the FATAL log level.
void logTrace(const char *format...) __attribute__((format(printf
Log a message to the Celix framework logger using the TRACE log level.
void logError(const char *format...) __attribute__((format(printf
Log a message to the Celix framework logger using the ERROR log level.
The bundle context is used to interact with the Celix framework.
Definition: BundleContext.h:53
Fluent builder API to use a service or services.
Definition: UseServiceBuilder.h:50
ServiceTrackerBuilder< void > trackAnyServices()
Track services in the Celix framework using a fluent builder API.
Definition: BundleContext.h:274
CELIX_FRAMEWORK_EXPORT void CELIX_FRAMEWORK_EXPORT void CELIX_FRAMEWORK_EXPORT void celix_bundleContext_logTssErrors(const celix_bundle_context_t *ctx, celix_log_level_e level)
Logs celix thread-specific storage error messages(celix_err) ith the provided celix log level....
std::string getConfigProperty(const std::string &name, const std::string &defaultValue) const
Gets the config property for the provided name.
Definition: BundleContext.h:456
ServiceRegistrationBuilder< I > registerService(std::shared_ptr< Implementer > implementer, const std::string &name={})
Register a service in the Celix framework using a fluent builder API.
Definition: BundleContext.h:83
void waitIfAbleForAllEvents() const
Wait (if not on the Celix event thread) until all Celix events (for all bundles) are completed.
Definition: BundleContext.h:658
A C++ builder for a ScheduledEvent object.
Definition: ScheduledEventBuilder.h:33
CELIX_FRAMEWORK_EXPORT long celix_bundleContext_findServiceWithOptions(celix_bundle_context_t *ctx, const celix_service_filter_options_t *opts)
Finds the highest ranking service and returns the service id.
BundleTrackerBuilder trackBundles()
Track bundles in the Celix framework using a fluent builder API.
Definition: BundleContext.h:294
UseServiceBuilder< I > useServices(const std::string &name={})
Use services registered in the Celix framework using a fluent builder API.
Definition: BundleContext.h:173
long getBundleId() const
Get the bundle id for the bundle of this bundle context.
Definition: BundleContext.h:520
CELIX_FRAMEWORK_EXPORT celix_bundle_t * celix_bundleContext_getBundle(const celix_bundle_context_t *ctx)
Returns the bundle for this bundle context.
Fluent builder API to build a new service registration for a service.
Definition: ServiceRegistrationBuilder.h:38
long findService(const std::string &filter={}, const std::string &versionRange={})
Finds the highest ranking service using the optional provided (LDAP) filter and version range.
Definition: BundleContext.h:189
const Bundle & getBundle() const
Get the bundle of this bundle context.
Definition: BundleContext.h:513
CELIX_FRAMEWORK_EXPORT long celix_bundleContext_installBundle(celix_bundle_context_t *ctx, const char *bundleUrl, bool autoStart)
Install and optional start a bundle. Will silently ignore bundle ids < 0.
celix_bundleContext_vlog(cCtx.get(), CELIX_LOG_LEVEL_TRACE, format, args)
CELIX_FRAMEWORK_EXPORT void celix_framework_waitForEmptyEventQueue(celix_framework_t *fw)
Wait until the framework event queue is empty.
CELIX_FRAMEWORK_EXPORT celix_array_list_t * celix_bundleContext_findServicesWithOptions(celix_bundle_context_t *ctx, const celix_service_filter_options_t *opts)
Finds the services conform the provider filter options and returns a list of the found service ids.
Fluent builder API to track services.
Definition: TrackerBuilders.h:38
CELIX_FRAMEWORK_EXPORT celix_array_list_t * celix_bundleContext_listBundles(celix_bundle_context_t *ctx)
List the installed and started bundle ids. The bundle ids does not include the framework bundle (bund...
MetaTrackerBuilder trackServiceTrackers(const std::string &name={})
Track service trackers in the Celix framework using a fluent builder API.
Definition: BundleContext.h:319
long getConfigPropertyAsLong(const std::string &name, long defaultValue) const
Gets the config property for the provided name and returns it as a long.
Definition: BundleContext.h:472
celix_bundle_context_t * getCBundleContext() const
Get the C bundle context.
Definition: BundleContext.h:546
CELIX_FRAMEWORK_EXPORT double celix_bundleContext_getPropertyAsDouble(celix_bundle_context_t *ctx, const char *name, double defaultValue)
Get the config property for the given key converted as double value.
void logInfo(const char *format...) __attribute__((format(printf
Log a message to the Celix framework logger using the INFO log level.
MetaTrackerBuilder trackAnyServiceTrackers()
Track service trackers in the Celix framework using a fluent builder API.
Definition: BundleContext.h:328
CELIX_FRAMEWORK_EXPORT void celix_bundleContext_waitForEvents(celix_bundle_context_t *ctx)
Wait until all Celix event for this bundle are completed.
void logWarn(const char *format...) __attribute__((format(printf
Log a message to the Celix framework logger using the WARNING log level.
CELIX_FRAMEWORK_EXPORT bool celix_bundleContext_getPropertyAsBool(celix_bundle_context_t *ctx, const char *name, bool defaultValue)
Get the config property for the given key converted as bool value.
void logDebug(const char *format...) __attribute__((format(printf
Log a message to the Celix framework logger using the DEBUG log level.
void va_start(args, format)
std::vector< long > findServicesWithName(const std::string &name, const std::string &filter={}, const std::string &versionRange={})
Finds all service matching the provided service name and the optional (LDAP) filter and version range...
Definition: BundleContext.h:236
void waitIfAbleForEvents() const
Wait (if not on the Celix event thread) until all Celix events for this bundle are completed.
Definition: BundleContext.h:640
CELIX_FRAMEWORK_EXPORT bool celix_bundleContext_stopBundle(celix_bundle_context_t *ctx, long bndId)
Stop the bundle with the provided bundle id. Will silently ignore bundle ids < 0.
void logTssErrors(celix_log_level_e level)
Log celix per-thread error messages to the Celix framework logger using the provided log level....
Definition: BundleContext.h:626
bool startBundle(long bndId)
Start the bundle with the provided bundle id.
Definition: BundleContext.h:379
CELIX_FRAMEWORK_EXPORT celix_array_list_t * celix_bundleContext_listInstalledBundles(celix_bundle_context_t *ctx)
List the installed bundle ids. The bundle ids does not include the framework bundle (bundle id CELIX_...
void waitForAllEvents() const
Wait until all Celix events (for all bundles) are completed.
Definition: BundleContext.h:650
CELIX_FRAMEWORK_EXPORT long celix_bundleContext_getPropertyAsLong(celix_bundle_context_t *ctx, const char *name, long defaultValue)
Get the config property for the given key converted as long value.
CELIX_FRAMEWORK_EXPORT bool celix_framework_isCurrentThreadTheEventLoop(celix_framework_t *fw)
Returns whether the current thread is the Celix framework event loop thread.
bool uninstallBundle(long bndId)
Uninstall the bundle with the provided bundle id.
Definition: BundleContext.h:362
CELIX_FRAMEWORK_EXPORT bool celix_bundleContext_uninstallBundle(celix_bundle_context_t *ctx, long bndId)
Uninstall the bundle with the provided bundle id. If needed the bundle will be stopped first....
BundleContext(celix_bundle_context_t *_cCtx)
Definition: BundleContext.h:55
std::vector< long > listInstalledBundleIds()
List the installed bundle ids. The bundle ids does not include the framework bundle (bundle id CELIX_...
Definition: BundleContext.h:441
double getConfigPropertyAsDouble(const std::string &name, double defaultValue) const
Gets the config property for the provided name and returns it as a double.
Definition: BundleContext.h:488
An installed bundle in the Celix framework.
Definition: Bundle.h:49
long installBundle(const std::string &bndLocation, bool autoStart=true)
Install and optional start a bundle.
Definition: BundleContext.h:349
void waitForEvents() const
Wait until all Celix events for this bundle are completed.
Definition: BundleContext.h:633
std::shared_ptr< dm::DependencyManager > getDependencyManager() const
Get the Celix dependency manager for this bundle context.
Definition: BundleContext.h:536
Service filter options which can be used to query for certain services.
Definition: celix_bundle_context.h:340
const CELIX_FRAMEWORK_EXPORT char * celix_bundleContext_getProperty(celix_bundle_context_t *ctx, const char *key, const char *defaultVal)
Get the config property for the given key.
long getId() const
get the bundle id.
Definition: Bundle.h:57
bool stopBundle(long bndId)
Stop the bundle with the provided bundle id.
Definition: BundleContext.h:396
CELIX_FRAMEWORK_EXPORT bool celix_bundleContext_updateBundle(celix_bundle_context_t *ctx, long bndId, const char *updatedBundleUrl)
Update the bundle with the provided bundle id.
ServiceRegistrationBuilder< I > registerUnmanagedService(Implementer *svc, const std::string &name={})
Register a (unmanaged) service in the Celix framework using a fluent builder API.
Definition: BundleContext.h:99
long findServiceWithName(const std::string &name, const std::string &filter={}, const std::string &versionRange={})
Finds the highest ranking service using the provided service name and the optional (LDAP) filter and ...
Definition: BundleContext.h:202
UseServiceBuilder< I > useService(const std::string &name={})
Use a service registered in the Celix framework using a fluent builder API.
Definition: BundleContext.h:139
std::vector< long > listBundleIds() const
List the installed and started bundle ids. The bundle ids does not include the framework bundle (bund...
Definition: BundleContext.h:431
bool updateBundle(long bndId, const std::string &updatedBundleUrl={})
Update the bundle with the provided bundle id async.
Definition: BundleContext.h:421
CELIX_FRAMEWORK_EXPORT celix_framework_t * celix_bundleContext_getFramework(const celix_bundle_context_t *ctx)
std::vector< long > findServices(const std::string &filter={}, const std::string &versionRange={})
Finds all services matching the optional provided (LDAP) filter and version range.
Definition: BundleContext.h:223
CELIX_FRAMEWORK_EXPORT bool celix_bundleContext_startBundle(celix_bundle_context_t *ctx, long bndId)
Start the bundle with the provided bundle id. Will silently ignore bundle ids < 0.
std::shared_ptr< Framework > getFramework() const
Get the Celix framework for this bundle context.
Definition: BundleContext.h:527
CELIX_FRAMEWORK_EXPORT 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 t...
long getConfigPropertyAsBool(const std::string &name, bool defaultValue) const
Gets the config property for the provided name and returns it as a bool.
Definition: BundleContext.h:506
ScheduledEventBuilder scheduledEvent()
Schedule a callback to be called after the given initial delay and/or interval using a fluent builder...
Definition: BundleContext.h:336
Fluent builder API to track bundles.
Definition: TrackerBuilders.h:233