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.
|
Go to the documentation of this file.
56 cCtx{_cCtx, [](celix_bundle_context_t*){}},
57 dm{std::make_shared<celix::dm::DependencyManager>(_cCtx)},
82 #if __cplusplus >= 201703L //C++17 or higher
83 template<
typename I,
typename Implementer>
85 std::shared_ptr<I> svc = implementer;
89 template<
typename I,
typename Implementer>
90 ServiceRegistrationBuilder<I>
registerService(std::shared_ptr<Implementer> implementer,
const std::string& name = {}) {
91 std::shared_ptr<I> svc = implementer;
92 return ServiceRegistrationBuilder<I>{cCtx, std::move(svc), celix::typeName<I>(name)};
106 #if __cplusplus >= 201703L //C++17 or higher
107 template<
typename I,
typename Implementer>
109 auto unmanagedSvc = std::shared_ptr<I>{svc, [](I*){}};
110 return ServiceRegistrationBuilder<I>{cCtx, std::move(unmanagedSvc), celix::typeName<I>(name),
true,
false};
113 template<
typename I,
typename Implementer>
115 auto unmanagedSvc = std::shared_ptr<I>{svc, [](I*){}};
116 return ServiceRegistrationBuilder<I>{cCtx, std::move(unmanagedSvc), celix::typeName<I>(name),
true,
false};
148 #if __cplusplus >= 201703L //C++17 or higher
155 UseServiceBuilder<I>
useService(
const std::string& name = {}) {
156 return UseServiceBuilder<I>{cCtx, celix::typeName<I>(name),
true};
183 #if __cplusplus >= 201703L //C++17 or higher
190 UseServiceBuilder<I>
useServices(
const std::string& name = {}) {
191 return UseServiceBuilder<I>{cCtx, celix::typeName<I>(name),
false};
206 #if __cplusplus >= 201703L //C++17 or higher
208 long findService(std::string_view filter = {}, std::string_view versionRange = {}) {
213 long findService(
const std::string& filter = {},
const std::string& versionRange = {}) {
227 #if __cplusplus >= 201703L //C++17 or higher
228 long findServiceWithName(std::string_view name, std::string_view filter = {}, std::string_view versionRange = {}) {
231 opts.serviceName = name.empty() ? nullptr : name.data();
232 opts.filter = filter.empty() ? nullptr : filter.data();
233 opts.versionRange = versionRange.empty() ? nullptr : versionRange.data();
237 long findServiceWithName(
const std::string& name,
const std::string& filter = {},
const std::string& versionRange = {}) {
240 opts.serviceName = name.empty() ? nullptr : name.data();
241 opts.filter = filter.empty() ? nullptr : filter.data();
242 opts.versionRange = versionRange.empty() ? nullptr : versionRange.data();
258 #if __cplusplus >= 201703L //C++17 or higher
260 std::vector<long>
findServices(std::string_view filter = {}, std::string_view versionRange = {}) {
265 std::vector<long>
findServices(
const std::string& filter = {},
const std::string& versionRange = {}) {
279 #if __cplusplus >= 201703L //C++17 or higher
280 std::vector<long>
findServicesWithName(std::string_view name, std::string_view filter = {}, std::string_view versionRange = {}) {
281 return findServicesWithNameInternal(
282 name.empty() ?
nullptr : name.data(),
283 filter.empty() ?
nullptr : filter.data(),
284 versionRange.empty() ?
nullptr : versionRange.data());
287 std::vector<long>
findServicesWithName(
const std::string& name,
const std::string& filter = {},
const std::string& versionRange = {}) {
288 return findServicesWithNameInternal(
289 name.empty() ?
nullptr : name.c_str(),
290 filter.empty() ?
nullptr : filter.c_str(),
291 versionRange.empty() ?
nullptr : versionRange.c_str());
315 #if __cplusplus >= 201703L //C++17 or higher
322 ServiceTrackerBuilder<I>
trackServices(
const std::string& name = {}) {
323 return ServiceTrackerBuilder<I>{cCtx, celix::typeName<I>(name)};
377 #if __cplusplus >= 201703L //C++17 or higher
385 return MetaTrackerBuilder(cCtx, celix::typeName<I>(name));
415 #if __cplusplus >= 201703L //C++17 or higher
420 long installBundle(
const std::string& bndLocation,
bool autoStart =
true) {
493 #if __cplusplus >= 201703L //C++17 or higher
494 bool updateBundle(
long bndId, std::string_view updatedBundleUrl = {}) {
498 bool updateBundle(
long bndId,
const std::string& updatedBundleUrl = {}) {
510 return listBundlesInternal(
true);
520 return listBundlesInternal(
false);
534 #if __cplusplus >= 201703L //C++17 or higher
539 std::string
getConfigProperty(
const std::string& name,
const std::string& defaultValue)
const {
556 #if __cplusplus >= 201703L //C++17 or higher
578 #if __cplusplus >= 201703L //C++17 or higher
602 #if __cplusplus >= 201703L //C++17 or higher
632 return std::make_shared<Framework>(fwCtx, cFw);
657 void logTrace(
const char* format...) __attribute__((format(printf,2,3))) {
669 void logDebug(
const char* format...) __attribute__((format(printf,2,3))) {
681 void logInfo(
const char* format...) __attribute__((format(printf,2,3))) {
693 void logWarn(
const char* format...) __attribute__((format(printf,2,3))) {
705 void logError(
const char* format...) __attribute__((format(printf,2,3))) {
717 void logFatal(
const char* format...) __attribute__((format(printf,2,3))) {
767 std::vector<long> listBundlesInternal(
bool activeOnly)
const {
768 std::vector<long> result{};
769 auto* ids = activeOnly ?
772 result.reserve(celix_arrayList_size(ids));
773 for (
int i = 0; i < celix_arrayList_size(ids); ++i) {
774 result.push_back(celix_arrayList_getLong(ids, i));
776 celix_arrayList_destroy(ids);
780 std::vector<long> findServicesWithNameInternal(
const char* name,
const char* filter,
const char* versionRange) {
783 opts.serviceName = name;
784 opts.filter = filter;
785 opts.versionRange = versionRange;
787 std::vector<long> result{};
789 for (
int i = 0; i < celix_arrayList_size(cList); ++i) {
790 long svcId = celix_arrayList_getLong(cList, i);
791 result.push_back(svcId);
793 celix_arrayList_destroy(cList);
797 const std::shared_ptr<celix_bundle_context_t> cCtx;
798 const std::shared_ptr<celix::dm::DependencyManager> dm;
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:579
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
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:228
ServiceTrackerBuilder< I > trackServices(std::string_view name={})
Track services in the Celix framework using a fluent builder API.
Definition: BundleContext.h:317
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:333
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:557
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(std::string_view name, std::string_view defaultValue) const
Gets the config property for the provided name.
Definition: BundleContext.h:535
void waitIfAbleForAllEvents() const
Wait (if not on the Celix event thread) until all Celix events (for all bundles) are completed.
Definition: BundleContext.h:760
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:353
long getBundleId() const
Get the bundle id for the bundle of this bundle context.
Definition: BundleContext.h:622
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
const Bundle & getBundle() const
Get the bundle of this bundle context.
Definition: BundleContext.h:615
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:84
bool updateBundle(long bndId, std::string_view updatedBundleUrl={})
Update the bundle with the provided bundle id async.
Definition: BundleContext.h:494
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...
UseServiceBuilder< I > useService(std::string_view name={})
Use a service registered in the Celix framework using a fluent builder API.
Definition: BundleContext.h:150
celix_bundle_context_t * getCBundleContext() const
Get the C bundle context.
Definition: BundleContext.h:648
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.
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:208
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:394
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)
void waitIfAbleForEvents() const
Wait (if not on the Celix event thread) until all Celix events for this bundle are completed.
Definition: BundleContext.h:742
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:108
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:728
bool startBundle(long bndId)
Start the bundle with the provided bundle id.
Definition: BundleContext.h:451
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:752
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:434
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....
long installBundle(std::string_view bndLocation, bool autoStart=true)
Install and optional start a bundle.
Definition: BundleContext.h:416
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:519
UseServiceBuilder< I > useServices(std::string_view name={})
Use services registered in the Celix framework using a fluent builder API.
Definition: BundleContext.h:185
An installed bundle in the Celix framework.
Definition: Bundle.h:48
void waitForEvents() const
Wait until all Celix events for this bundle are completed.
Definition: BundleContext.h:735
std::shared_ptr< dm::DependencyManager > getDependencyManager() const
Get the Celix dependency manager for this bundle context.
Definition: BundleContext.h:638
Service filter options which can be used to query for certain services.
Definition: celix_bundle_context.h:353
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:603
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:280
MetaTrackerBuilder trackServiceTrackers(std::string_view name={})
Track service trackers in the Celix framework using a fluent builder API.
Definition: BundleContext.h:379
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:56
bool stopBundle(long bndId)
Stop the bundle with the provided bundle id.
Definition: BundleContext.h:468
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.
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:260
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:509
CELIX_FRAMEWORK_EXPORT celix_framework_t * celix_bundleContext_getFramework(const celix_bundle_context_t *ctx)
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:629
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...
ScheduledEventBuilder scheduledEvent()
Schedule a callback to be called after the given initial delay and/or interval using a fluent builder...
Definition: BundleContext.h:402
Fluent builder API to track bundles.
Definition: TrackerBuilders.h:237