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.
BundleContext.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
20 #pragma once
21 
22 #include <memory>
23 #include <mutex>
24 #include <thread>
25 #include <cstdarg>
26 
27 #include "celix_bundle_context.h"
28 
31 #include "celix/TrackerBuilders.h"
33 #include "celix/Bundle.h"
34 #include "celix/Framework.h"
35 
36 #include "celix/dm/DependencyManager.h" //TODO, TBD include or forward declaration?
37 
38 namespace celix {
39 
53  class BundleContext {
54  public:
55  explicit BundleContext(celix_bundle_context_t* _cCtx) :
56  cCtx{_cCtx, [](celix_bundle_context_t*){/*nop*/}},
57  dm{std::make_shared<celix::dm::DependencyManager>(_cCtx)},
58  bnd{celix_bundleContext_getBundle(_cCtx)} {}
59 
82 #if __cplusplus >= 201703L //C++17 or higher
83  template<typename I, typename Implementer>
84  ServiceRegistrationBuilder<I> registerService(std::shared_ptr<Implementer> implementer, std::string_view name = {}) {
85  std::shared_ptr<I> svc = implementer; //note Implement should be derived from I
86  return ServiceRegistrationBuilder<I>{cCtx, std::move(svc), celix::typeName<I>(name)};
87  }
88 #else
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; //note Implement should be derived from I
92  return ServiceRegistrationBuilder<I>{cCtx, std::move(svc), celix::typeName<I>(name)};
93  }
94 #endif
95 
106 #if __cplusplus >= 201703L //C++17 or higher
107  template<typename I, typename Implementer>
108  ServiceRegistrationBuilder<I> registerUnmanagedService(Implementer* svc, std::string_view name = {}) {
109  auto unmanagedSvc = std::shared_ptr<I>{svc, [](I*){/*nop*/}};
110  return ServiceRegistrationBuilder<I>{cCtx, std::move(unmanagedSvc), celix::typeName<I>(name), true, false};
111  }
112 #else
113  template<typename I, typename Implementer>
114  ServiceRegistrationBuilder<I> registerUnmanagedService(Implementer* svc, const std::string& name = {}) {
115  auto unmanagedSvc = std::shared_ptr<I>{svc, [](I*){/*nop*/}};
116  return ServiceRegistrationBuilder<I>{cCtx, std::move(unmanagedSvc), celix::typeName<I>(name), true, false};
117  }
118 #endif
119 
120  //TODO registerServiceFactory<I>()
121 
148 #if __cplusplus >= 201703L //C++17 or higher
149  template<typename I>
150  UseServiceBuilder<I> useService(std::string_view name = {}) {
151  return UseServiceBuilder<I>{cCtx, celix::typeName<I>(name), true};
152  }
153 #else
154  template<typename I>
155  UseServiceBuilder<I> useService(const std::string& name = {}) {
156  return UseServiceBuilder<I>{cCtx, celix::typeName<I>(name), true};
157  }
158 #endif
159 
183 #if __cplusplus >= 201703L //C++17 or higher
184  template<typename I>
185  UseServiceBuilder<I> useServices(std::string_view name = {}) {
186  return UseServiceBuilder<I>{cCtx, celix::typeName<I>(name), false};
187  }
188 #else
189  template<typename I>
190  UseServiceBuilder<I> useServices(const std::string& name = {}) {
191  return UseServiceBuilder<I>{cCtx, celix::typeName<I>(name), false};
192  }
193 #endif
194 
206 #if __cplusplus >= 201703L //C++17 or higher
207  template<typename I>
208  long findService(std::string_view filter = {}, std::string_view versionRange = {}) {
209  return findServiceWithName(celix::typeName<I>(), filter, versionRange);
210  }
211 #else
212  template<typename I>
213  long findService(const std::string& filter = {}, const std::string& versionRange = {}) {
214  return findServiceWithName(celix::typeName<I>(), filter, versionRange);
215  }
216 #endif
217 
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();
234  return celix_bundleContext_findServiceWithOptions(cCtx.get(), &opts);
235  }
236 #else
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();
243  return celix_bundleContext_findServiceWithOptions(cCtx.get(), &opts);
244  }
245 #endif
246 
258 #if __cplusplus >= 201703L //C++17 or higher
259  template<typename I>
260  std::vector<long> findServices(std::string_view filter = {}, std::string_view versionRange = {}) {
261  return findServicesWithName(celix::typeName<I>(), filter, versionRange);
262  }
263 #else
264  template<typename I>
265  std::vector<long> findServices(const std::string& filter = {}, const std::string& versionRange = {}) {
266  return findServicesWithName(celix::typeName<I>(), filter, versionRange);
267  }
268 #endif
269 
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());
285  }
286 #else
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());
292  }
293 #endif
294 
315 #if __cplusplus >= 201703L //C++17 or higher
316  template<typename I>
317  ServiceTrackerBuilder<I> trackServices(std::string_view name = {}) {
318  return ServiceTrackerBuilder<I>{cCtx, celix::typeName<I>(name)};
319  }
320 #else
321  template<typename I>
322  ServiceTrackerBuilder<I> trackServices(const std::string& name = {}) {
323  return ServiceTrackerBuilder<I>{cCtx, celix::typeName<I>(name)};
324  }
325 #endif
326 
334  return ServiceTrackerBuilder<void>{cCtx, {}};
335  }
336 
337  //TODO UseBundleBuilder useBundles()
338 
354  return BundleTrackerBuilder{cCtx};
355  }
356 
377 #if __cplusplus >= 201703L //C++17 or higher
378  template<typename I>
379  MetaTrackerBuilder trackServiceTrackers(std::string_view name = {}) {
380  return MetaTrackerBuilder(cCtx, celix::typeName<I>(name));
381  }
382 #else
383  template<typename I>
384  MetaTrackerBuilder trackServiceTrackers(const std::string& name = {}) {
385  return MetaTrackerBuilder(cCtx, celix::typeName<I>(name));
386  }
387 #endif
388 
395  return MetaTrackerBuilder(cCtx, {});
396  }
397 
403  return ScheduledEventBuilder{cCtx};
404  }
405 
415 #if __cplusplus >= 201703L //C++17 or higher
416  long installBundle(std::string_view bndLocation, bool autoStart = true) {
417  return celix_bundleContext_installBundle(cCtx.get(), bndLocation.data(), autoStart);
418  }
419 #else
420  long installBundle(const std::string& bndLocation, bool autoStart = true) {
421  return celix_bundleContext_installBundle(cCtx.get(), bndLocation.c_str(), autoStart);
422  }
423 #endif
424 
434  bool uninstallBundle(long bndId) {
435  return celix_bundleContext_uninstallBundle(cCtx.get(), bndId);
436  }
437 
451  bool startBundle(long bndId) {
452  return celix_bundleContext_startBundle(cCtx.get(), bndId);
453  }
454 
468  bool stopBundle(long bndId) {
469  return celix_bundleContext_stopBundle(cCtx.get(), bndId);
470  }
471 
493 #if __cplusplus >= 201703L //C++17 or higher
494  bool updateBundle(long bndId, std::string_view updatedBundleUrl = {}) {
495  return celix_bundleContext_updateBundle(cCtx.get(), bndId, updatedBundleUrl.empty() ? nullptr : updatedBundleUrl.data());
496  }
497 #else
498  bool updateBundle(long bndId, const std::string& updatedBundleUrl = {}) {
499  return celix_bundleContext_updateBundle(cCtx.get(), bndId, updatedBundleUrl.empty() ? nullptr : updatedBundleUrl.data());
500  }
501 #endif
502 
509  std::vector<long> listBundleIds() const {
510  return listBundlesInternal(true);
511  }
512 
519  std::vector<long> listInstalledBundleIds() {
520  return listBundlesInternal(false);
521  }
522 
534 #if __cplusplus >= 201703L //C++17 or higher
535  std::string getConfigProperty(std::string_view name, std::string_view defaultValue) const {
536  return std::string{celix_bundleContext_getProperty(cCtx.get(), name.data(), defaultValue.data())};
537  }
538 #else
539  std::string getConfigProperty(const std::string& name, const std::string& defaultValue) const {
540  return std::string{celix_bundleContext_getProperty(cCtx.get(), name.c_str(), defaultValue.c_str())};
541  }
542 #endif
543 
556 #if __cplusplus >= 201703L //C++17 or higher
557  long getConfigPropertyAsLong(std::string_view name, long defaultValue) const {
558  return celix_bundleContext_getPropertyAsLong(cCtx.get(), name.data(), defaultValue);
559  }
560 #else
561  long getConfigPropertyAsLong(const std::string& name, long defaultValue) const {
562  return celix_bundleContext_getPropertyAsLong(cCtx.get(), name.c_str(), defaultValue);
563  }
564 #endif
565 
578 #if __cplusplus >= 201703L //C++17 or higher
579  double getConfigPropertyAsDouble(std::string_view name, double defaultValue) const {
580  return celix_bundleContext_getPropertyAsDouble(cCtx.get(), name.data(), defaultValue);
581  }
582 #else
583  double getConfigPropertyAsDouble(const std::string& name, double defaultValue) const {
584  return celix_bundleContext_getPropertyAsDouble(cCtx.get(), name.c_str(), defaultValue);
585  }
586 #endif
587 
602 #if __cplusplus >= 201703L //C++17 or higher
603  long getConfigPropertyAsBool(std::string_view name, bool defaultValue) const {
604  return celix_bundleContext_getPropertyAsBool(cCtx.get(), name.data(), defaultValue);
605  }
606 #else
607  long getConfigPropertyAsBool(const std::string& name, bool defaultValue) const {
608  return celix_bundleContext_getPropertyAsBool(cCtx.get(), name.c_str(), defaultValue);
609  }
610 #endif
611 
615  const Bundle& getBundle() const {
616  return bnd;
617  }
618 
622  long getBundleId() const {
623  return bnd.getId();
624  }
625 
629  std::shared_ptr<Framework> getFramework() const {
630  auto* cFw = celix_bundleContext_getFramework(cCtx.get());
631  auto fwCtx = std::make_shared<celix::BundleContext>(celix_framework_getFrameworkContext(cFw));
632  return std::make_shared<Framework>(fwCtx, cFw);
633  }
634 
638  std::shared_ptr<dm::DependencyManager> getDependencyManager() const {
639  return dm;
640  }
641 
648  celix_bundle_context_t* getCBundleContext() const {
649  return cCtx.get();
650  }
651 
657  void logTrace(const char* format...) __attribute__((format(printf,2,3))) {
658  va_list args;
659  va_start(args, format);
660  celix_bundleContext_vlog(cCtx.get(), CELIX_LOG_LEVEL_TRACE, format, args);
661  va_end(args);
662  }
663 
669  void logDebug(const char* format...) __attribute__((format(printf,2,3))) {
670  va_list args;
671  va_start(args, format);
672  celix_bundleContext_vlog(cCtx.get(), CELIX_LOG_LEVEL_DEBUG, format, args);
673  va_end(args);
674  }
675 
681  void logInfo(const char* format...) __attribute__((format(printf,2,3))) {
682  va_list args;
683  va_start(args, format);
684  celix_bundleContext_vlog(cCtx.get(), CELIX_LOG_LEVEL_INFO, format, args);
685  va_end(args);
686  }
687 
693  void logWarn(const char* format...) __attribute__((format(printf,2,3))) {
694  va_list args;
695  va_start(args, format);
696  celix_bundleContext_vlog(cCtx.get(), CELIX_LOG_LEVEL_WARNING, format, args);
697  va_end(args);
698  }
699 
705  void logError(const char* format...) __attribute__((format(printf,2,3))) {
706  va_list args;
707  va_start(args, format);
708  celix_bundleContext_vlog(cCtx.get(), CELIX_LOG_LEVEL_ERROR, format, args);
709  va_end(args);
710  }
711 
717  void logFatal(const char* format...) __attribute__((format(printf,2,3))) {
718  va_list args;
719  va_start(args, format);
720  celix_bundleContext_vlog(cCtx.get(), CELIX_LOG_LEVEL_FATAL, format, args);
721  va_end(args);
722  }
723 
728  void logTssErrors(celix_log_level_e level) {
729  celix_bundleContext_logTssErrors(cCtx.get(), level);
730  }
731 
735  void waitForEvents() const {
737  }
738 
742  void waitIfAbleForEvents() const {
743  auto* fw = celix_bundleContext_getFramework(cCtx.get());
746  }
747  }
748 
752  void waitForAllEvents() const {
753  auto* fw = celix_bundleContext_getFramework(cCtx.get());
755  }
756 
760  void waitIfAbleForAllEvents() const {
761  auto* fw = celix_bundleContext_getFramework(cCtx.get());
764  }
765  }
766  private:
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));
775  }
776  celix_arrayList_destroy(ids);
777  return result;
778  }
779 
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;
786 
787  std::vector<long> result{};
788  auto cList = celix_bundleContext_findServicesWithOptions(cCtx.get(), &opts);
789  for (int i = 0; i < celix_arrayList_size(cList); ++i) {
790  long svcId = celix_arrayList_getLong(cList, i);
791  result.push_back(svcId);
792  }
793  celix_arrayList_destroy(cList);
794  return result;
795  }
796 
797  const std::shared_ptr<celix_bundle_context_t> cCtx;
798  const std::shared_ptr<celix::dm::DependencyManager> dm;
799  const Bundle bnd;
800  };
801 }
802 
803 
celix::BundleContext::getConfigPropertyAsDouble
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
Bundle.h
celix::BundleContext::logFatal
void logFatal(const char *format...) __attribute__((format(printf
Log a message to the Celix framework logger using the FATAL log level.
celix::BundleContext::logTrace
void logTrace(const char *format...) __attribute__((format(printf
Log a message to the Celix framework logger using the TRACE log level.
celix::BundleContext::logError
void logError(const char *format...) __attribute__((format(printf
Log a message to the Celix framework logger using the ERROR log level.
celix::BundleContext
The bundle context is used to interact with the Celix framework.
Definition: BundleContext.h:53
celix::BundleContext::findServiceWithName
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
celix::BundleContext::trackServices
ServiceTrackerBuilder< I > trackServices(std::string_view name={})
Track services in the Celix framework using a fluent builder API.
Definition: BundleContext.h:317
celix::UseServiceBuilder
Fluent builder API to use a service or services.
Definition: UseServiceBuilder.h:50
celix::BundleContext::trackAnyServices
ServiceTrackerBuilder< void > trackAnyServices()
Track services in the Celix framework using a fluent builder API.
Definition: BundleContext.h:333
celix
Definition: Bundle.h:27
celix::BundleContext::getConfigPropertyAsLong
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_bundleContext_logTssErrors
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....
celix::BundleContext::getConfigProperty
std::string getConfigProperty(std::string_view name, std::string_view defaultValue) const
Gets the config property for the provided name.
Definition: BundleContext.h:535
celix::BundleContext::waitIfAbleForAllEvents
void waitIfAbleForAllEvents() const
Wait (if not on the Celix event thread) until all Celix events (for all bundles) are completed.
Definition: BundleContext.h:760
celix::ScheduledEventBuilder
A C++ builder for a ScheduledEvent object.
Definition: ScheduledEventBuilder.h:33
celix_bundleContext_findServiceWithOptions
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.
celix::BundleContext::trackBundles
BundleTrackerBuilder trackBundles()
Track bundles in the Celix framework using a fluent builder API.
Definition: BundleContext.h:353
celix::BundleContext::getBundleId
long getBundleId() const
Get the bundle id for the bundle of this bundle context.
Definition: BundleContext.h:622
celix_bundleContext_getBundle
CELIX_FRAMEWORK_EXPORT celix_bundle_t * celix_bundleContext_getBundle(const celix_bundle_context_t *ctx)
Returns the bundle for this bundle context.
celix::ServiceRegistrationBuilder
Fluent builder API to build a new service registration for a service.
Definition: ServiceRegistrationBuilder.h:38
celix::BundleContext::getBundle
const Bundle & getBundle() const
Get the bundle of this bundle context.
Definition: BundleContext.h:615
celix::BundleContext::registerService
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
celix::BundleContext::updateBundle
bool updateBundle(long bndId, std::string_view updatedBundleUrl={})
Update the bundle with the provided bundle id async.
Definition: BundleContext.h:494
celix_bundleContext_installBundle
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::celix_bundleContext_vlog
celix_bundleContext_vlog(cCtx.get(), CELIX_LOG_LEVEL_TRACE, format, args)
celix_framework_waitForEmptyEventQueue
CELIX_FRAMEWORK_EXPORT void celix_framework_waitForEmptyEventQueue(celix_framework_t *fw)
Wait until the framework event queue is empty.
celix_bundleContext_findServicesWithOptions
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.
celix::BundleContext::va_end
va_end(args)
celix::ServiceTrackerBuilder
Fluent builder API to track services.
Definition: TrackerBuilders.h:38
celix_bundleContext_listBundles
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...
celix::BundleContext::useService
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::BundleContext::getCBundleContext
celix_bundle_context_t * getCBundleContext() const
Get the C bundle context.
Definition: BundleContext.h:648
celix_bundleContext_getPropertyAsDouble
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.
celix::BundleContext::findService
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
celix::BundleContext::logInfo
void logInfo(const char *format...) __attribute__((format(printf
Log a message to the Celix framework logger using the INFO log level.
celix::BundleContext::trackAnyServiceTrackers
MetaTrackerBuilder trackAnyServiceTrackers()
Track service trackers in the Celix framework using a fluent builder API.
Definition: BundleContext.h:394
celix_bundleContext_waitForEvents
CELIX_FRAMEWORK_EXPORT void celix_bundleContext_waitForEvents(celix_bundle_context_t *ctx)
Wait until all Celix event for this bundle are completed.
celix::BundleContext::logWarn
void logWarn(const char *format...) __attribute__((format(printf
Log a message to the Celix framework logger using the WARNING log level.
celix_bundleContext_getPropertyAsBool
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.
celix::BundleContext::logDebug
void logDebug(const char *format...) __attribute__((format(printf
Log a message to the Celix framework logger using the DEBUG log level.
celix::BundleContext::va_start
void va_start(args, format)
TrackerBuilders.h
celix::BundleContext::waitIfAbleForEvents
void waitIfAbleForEvents() const
Wait (if not on the Celix event thread) until all Celix events for this bundle are completed.
Definition: BundleContext.h:742
celix::MetaTrackerBuilder
Fluent builder API to track service trackers.
Definition: TrackerBuilders.h:310
celix::BundleContext::registerUnmanagedService
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_bundleContext_stopBundle
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.
celix::BundleContext::logTssErrors
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
celix::BundleContext::startBundle
bool startBundle(long bndId)
Start the bundle with the provided bundle id.
Definition: BundleContext.h:451
celix_bundleContext_listInstalledBundles
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_...
celix::BundleContext::waitForAllEvents
void waitForAllEvents() const
Wait until all Celix events (for all bundles) are completed.
Definition: BundleContext.h:752
celix_bundleContext_getPropertyAsLong
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_isCurrentThreadTheEventLoop
CELIX_FRAMEWORK_EXPORT bool celix_framework_isCurrentThreadTheEventLoop(celix_framework_t *fw)
Returns whether the current thread is the Celix framework event loop thread.
celix::BundleContext::uninstallBundle
bool uninstallBundle(long bndId)
Uninstall the bundle with the provided bundle id.
Definition: BundleContext.h:434
celix_bundleContext_uninstallBundle
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....
celix::BundleContext::installBundle
long installBundle(std::string_view bndLocation, bool autoStart=true)
Install and optional start a bundle.
Definition: BundleContext.h:416
celix::BundleContext::BundleContext
BundleContext(celix_bundle_context_t *_cCtx)
Definition: BundleContext.h:55
celix::BundleContext::listInstalledBundleIds
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
Framework.h
celix::BundleContext::useServices
UseServiceBuilder< I > useServices(std::string_view name={})
Use services registered in the Celix framework using a fluent builder API.
Definition: BundleContext.h:185
celix::Bundle
An installed bundle in the Celix framework.
Definition: Bundle.h:48
celix::BundleContext::waitForEvents
void waitForEvents() const
Wait until all Celix events for this bundle are completed.
Definition: BundleContext.h:735
celix::BundleContext::getDependencyManager
std::shared_ptr< dm::DependencyManager > getDependencyManager() const
Get the Celix dependency manager for this bundle context.
Definition: BundleContext.h:638
celix_service_filter_options
Service filter options which can be used to query for certain services.
Definition: celix_bundle_context.h:353
celix::BundleContext::getConfigPropertyAsBool
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
DependencyManager.h
celix::BundleContext::findServicesWithName
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
celix::BundleContext::trackServiceTrackers
MetaTrackerBuilder trackServiceTrackers(std::string_view name={})
Track service trackers in the Celix framework using a fluent builder API.
Definition: BundleContext.h:379
celix_bundleContext_getProperty
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.
celix::Bundle::getId
long getId() const
get the bundle id.
Definition: Bundle.h:56
ScheduledEventBuilder.h
UseServiceBuilder.h
celix::BundleContext::stopBundle
bool stopBundle(long bndId)
Stop the bundle with the provided bundle id.
Definition: BundleContext.h:468
celix_bundleContext_updateBundle
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.
celix::BundleContext::findServices
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
celix::BundleContext::listBundleIds
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_bundleContext_getFramework
CELIX_FRAMEWORK_EXPORT celix_framework_t * celix_bundleContext_getFramework(const celix_bundle_context_t *ctx)
celix_bundle_context.h
celix_bundleContext_startBundle
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.
celix::BundleContext::getFramework
std::shared_ptr< Framework > getFramework() const
Get the Celix framework for this bundle context.
Definition: BundleContext.h:629
celix_framework_getFrameworkContext
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...
celix::BundleContext::scheduledEvent
ScheduledEventBuilder scheduledEvent()
Schedule a callback to be called after the given initial delay and/or interval using a fluent builder...
Definition: BundleContext.h:402
ServiceRegistrationBuilder.h
celix::BundleTrackerBuilder
Fluent builder API to track bundles.
Definition: TrackerBuilders.h:237