Apache Celix
2.3.0
An implementation of the OSGi specification adapted to C and C++
|
Go to the documentation of this file.
55 cCtx{_cCtx, [](celix_bundle_context_t*){}},
56 dm{std::make_shared<celix::dm::DependencyManager>(_cCtx)},
81 template<
typename I,
typename Implementer>
83 std::shared_ptr<I> svc = implementer;
97 template<
typename I,
typename Implementer>
99 auto unmanagedSvc = std::shared_ptr<I>{svc, [](I*){}};
100 return ServiceRegistrationBuilder<I>{cCtx, std::move(unmanagedSvc), celix::typeName<I>(name),
true,
false};
176 long findService(std::string_view filter = {}, std::string_view versionRange = {}) {
189 long findServiceWithName(std::string_view name, std::string_view filter = {}, std::string_view versionRange = {}) {
192 opts.serviceName = name.empty() ? nullptr : name.data();
193 opts.filter = filter.empty() ? nullptr : filter.data();
194 opts.versionRange = versionRange.empty() ? nullptr : versionRange.data();
210 std::vector<long>
findServices(std::string_view filter = {}, std::string_view versionRange = {}) {
223 std::vector<long>
findServicesWithName(std::string_view name, std::string_view filter = {}, std::string_view versionRange = {}) {
226 opts.serviceName = name.empty() ? nullptr : name.data();
227 opts.filter = filter.empty() ? nullptr : filter.data();
228 opts.versionRange = versionRange.empty() ? nullptr : versionRange.data();
230 std::vector<long> result{};
232 for (
int i = 0; i < celix_arrayList_size(cList); ++i) {
233 long svcId = celix_arrayList_getLong(cList, i);
234 result.push_back(svcId);
236 celix_arrayList_destroy(cList);
384 return listBundlesInternal(
true);
394 return listBundlesInternal(
false);
408 [[nodiscard]] std::string
getConfigProperty(std::string_view name, std::string_view defaultValue)
const {
482 return std::make_shared<Framework>(fwCtx, cFw);
509 va_start(args, format);
521 va_start(args, format);
533 va_start(args, format);
545 va_start(args, format);
557 va_start(args, format);
569 va_start(args, format);
609 [[nodiscard]] std::vector<long> listBundlesInternal(
bool activeOnly)
const {
610 std::vector<long> result{};
611 auto* ids = activeOnly ?
614 result.reserve(celix_arrayList_size(ids));
615 for (
int i = 0; i < celix_arrayList_size(ids); ++i) {
616 result.push_back(celix_arrayList_getLong(ids, i));
618 celix_arrayList_destroy(ids);
622 const std::shared_ptr<celix_bundle_context_t> cCtx;
623 const std::shared_ptr<celix::dm::DependencyManager> dm;
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....
double getConfigPropertyAsDouble(std::string_view name, double defaultValue) const
Gets the config property for the provided name and returns it as a double.
Definition: BundleContext.h:440
The bundle context is used to interact with the Celix framework.
Definition: BundleContext.h:52
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 ...
Definition: BundleContext.h:189
ServiceTrackerBuilder< I > trackServices(std::string_view name={})
Track services in the Celix framework using a fluent builder API.
Definition: BundleContext.h:261
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:271
long getConfigPropertyAsLong(std::string_view name, long defaultValue) const
Gets the config property for the provided name and returns it as a long.
Definition: BundleContext.h:424
const char * celix_bundleContext_getProperty(celix_bundle_context_t *ctx, const char *key, const char *defaultVal)
Gets the config property - or environment variable if the config property does not exist - for the pr...
std::string getConfigProperty(std::string_view name, std::string_view defaultValue) const
Gets the config property for the provided name.
Definition: BundleContext.h:408
void waitIfAbleForAllEvents() const
Wait (if not on the Celix event thread) until all Celix events (for all bundles) are completed.
Definition: BundleContext.h:602
void logInfo(const char *format...)
Logs a message to the Celix framework logger using the INFO log level.
Definition: BundleContext.h:531
BundleTrackerBuilder trackBundles()
Track bundles in the Celix framework using a fluent builder API.
Definition: BundleContext.h:289
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.
void celix_bundleContext_waitForEvents(celix_bundle_context_t *ctx)
Wait until all Celix event for this bundle are completed.
long getBundleId() const
Get the bundle id for the bundle of this bundle context.
Definition: BundleContext.h:472
Fluent builder API to build a new service registration for a service.
Definition: ServiceRegistrationBuilder.h:38
const Bundle & getBundle() const
Get the bundle of this bundle context.
Definition: BundleContext.h:465
ServiceRegistrationBuilder< I > registerService(std::shared_ptr< Implementer > implementer, std::string_view name={})
Register a service in the Celix framework using a fluent builder API.
Definition: BundleContext.h:82
Fluent builder API to track services.
Definition: TrackerBuilders.h:38
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.
UseServiceBuilder< I > useService(std::string_view name={})
Use a service registered in the Celix framework using a fluent builder API.
Definition: BundleContext.h:132
celix_bundle_context_t * getCBundleContext() const
Get the C bundle context.
Definition: BundleContext.h:498
long findService(std::string_view filter={}, std::string_view versionRange={})
Finds the highest ranking service using the optional provided (LDAP) filter and version range.
Definition: BundleContext.h:176
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.
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.
MetaTrackerBuilder trackAnyServiceTrackers()
Track service trackers in the Celix framework using a fluent builder API.
Definition: BundleContext.h:323
bool celix_bundleContext_getPropertyAsBool(celix_bundle_context_t *ctx, const char *key, bool defaultValue)
Gets the config property as converts it to bool. If the property is not a valid bool,...
void waitIfAbleForEvents() const
Wait (if not on the Celix event thread) until all Celix events for this bundle are completed.
Definition: BundleContext.h:584
ServiceRegistrationBuilder< I > registerUnmanagedService(Implementer *svc, std::string_view name={})
Register a (unmanaged) service in the Celix framework using a fluent builder API.
Definition: BundleContext.h:98
double celix_bundleContext_getPropertyAsDouble(celix_bundle_context_t *ctx, const char *key, double defaultValue)
Gets the config property as converts it to double. If the property is not a valid double,...
bool startBundle(long bndId)
Start the bundle with the provided bundle id.
Definition: BundleContext.h:361
void logDebug(const char *format...)
Logs a message to the Celix framework logger using the DEBUG log level.
Definition: BundleContext.h:519
void waitForAllEvents() const
Wait until all Celix events (for all bundles) are completed.
Definition: BundleContext.h:594
void logError(const char *format...)
Logs a message to the Celix framework logger using the ERROR log level.
Definition: BundleContext.h:555
bool uninstallBundle(long bndId)
Uninstall the bundle with the provided bundle id.
Definition: BundleContext.h:349
long installBundle(std::string_view bndLocation, bool autoStart=true)
Install and optional start a bundle.
Definition: BundleContext.h:336
BundleContext(celix_bundle_context_t *_cCtx)
Definition: BundleContext.h:54
long celix_bundleContext_installBundle(celix_bundle_context_t *ctx, const char *bundleLoc, bool autoStart)
Install and optional start a bundle. Will silently ignore bundle ids < 0.
celix_framework_t * celix_bundleContext_getFramework(const celix_bundle_context_t *ctx)
std::vector< long > listInstalledBundleIds()
List the installed bundle ids. The bundle ids does not include the framework bundle (bundle id CELIX_...
Definition: BundleContext.h:393
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_...
UseServiceBuilder< I > useServices(std::string_view name={})
Use services registered in the Celix framework using a fluent builder API.
Definition: BundleContext.h:160
An installed bundle in the Celix framework.
Definition: Bundle.h:47
void waitForEvents() const
Wait until all Celix events for this bundle are completed.
Definition: BundleContext.h:577
std::shared_ptr< dm::DependencyManager > getDependencyManager() const
Get the Celix dependency manager for this bundle context.
Definition: BundleContext.h:488
Service filter options which can be used to query for certain services.
Definition: celix_bundle_context.h:321
void celix_bundleContext_vlog(const celix_bundle_context_t *ctx, celix_log_level_e level, const char *format, va_list formatArgs)
Logs a message to Celix framework logger with the provided log level.
void logFatal(const char *format...)
Logs a message to the Celix framework logger using the FATAL log level.
Definition: BundleContext.h:567
void celix_framework_waitForEmptyEventQueue(celix_framework_t *fw)
Wait until the framework event queue is empty.
long getConfigPropertyAsBool(std::string_view name, bool defaultValue) const
Gets the config property for the provided name and returns it as a bool.
Definition: BundleContext.h:458
long celix_bundleContext_getPropertyAsLong(celix_bundle_context_t *ctx, const char *key, long defaultValue)
Gets the config property as converts it to long. If the property is not a valid long,...
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...
Definition: BundleContext.h:223
MetaTrackerBuilder trackServiceTrackers(std::string_view name={})
Track service trackers in the Celix framework using a fluent builder API.
Definition: BundleContext.h:314
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...
void logTrace(const char *format...)
Logs a message to the Celix framework logger using the TRACE log level.
Definition: BundleContext.h:507
long getId() const
get the bundle id.
Definition: Bundle.h:55
bool stopBundle(long bndId)
Stop the bundle with the provided bundle id.
Definition: BundleContext.h:373
bool celix_framework_isCurrentThreadTheEventLoop(celix_framework_t *fw)
Returns whether the current thread is the Celix framework event loop thread.
std::vector< long > findServices(std::string_view filter={}, std::string_view versionRange={})
Finds all services matching the optional provided (LDAP) filter and version range.
Definition: BundleContext.h:210
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:383
void logWarn(const char *format...)
Logs a message to the Celix framework logger using the WARNING log level.
Definition: BundleContext.h:543
std::shared_ptr< Framework > getFramework() const
Get the Celix framework for this bundle context.
Definition: BundleContext.h:479
celix_bundle_t * celix_bundleContext_getBundle(const celix_bundle_context_t *ctx)
Returns the bundle for this bundle context.
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...
Fluent builder API to track bundles.
Definition: TrackerBuilders.h:233