You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2018/05/22 20:28:17 UTC
celix git commit: CELIX-426: Moves the C++
BundleContext::useService(s)Internal to the impl class
Repository: celix
Updated Branches:
refs/heads/feature/CELIX-426-cxx-api d8ebc4ab3 -> 70308481c
CELIX-426: Moves the C++ BundleContext::useService(s)Internal to the impl class
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/70308481
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/70308481
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/70308481
Branch: refs/heads/feature/CELIX-426-cxx-api
Commit: 70308481c40019aa1a68bcee93a0adc963f9ed6f
Parents: d8ebc4a
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue May 22 22:27:36 2018 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue May 22 22:27:36 2018 +0200
----------------------------------------------------------------------
framework/include/celix/BundleContext.h | 23 ++-----------
.../include/celix/impl/BundleContextImpl.h | 35 +++++++++++++++++---
2 files changed, 33 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/70308481/framework/include/celix/BundleContext.h
----------------------------------------------------------------------
diff --git a/framework/include/celix/BundleContext.h b/framework/include/celix/BundleContext.h
index f5e2735..319cbfb 100644
--- a/framework/include/celix/BundleContext.h
+++ b/framework/include/celix/BundleContext.h
@@ -201,27 +201,13 @@ namespace celix {
* @return
*/
template<typename I>
- bool useServiceWithId(long serviceId, const std::string &/*serviceName*/ /*sanity*/, const std::function<void(I &svc, const celix::Properties &props, const celix::Bundle &svcOwner)> &/*use*/) noexcept {
- std::string filter = std::string{"(service.id="} + std::to_string(serviceId) + std::string{")"};
- //TODO use useServiceWithOptions return this->useService<I>(serviceName, "", filter, use);
- return false;
- }
+ bool useServiceWithId(long serviceId, const std::string &/*serviceName*/ /*sanity*/, const std::function<void(I &svc, const celix::Properties &props, const celix::Bundle &svcOwner)> &use) noexcept;
template<typename I>
- bool useService(const std::string &serviceName, const std::function<void(I &svc, const celix::Properties &props, const celix::Bundle &svcOwner)> &use) noexcept {
- return this->useServiceInternal(serviceName, [use](void *voidSvc, const celix::Properties &props, const celix::Bundle &svcOwner) {
- I *typedSvc = static_cast<I*>(voidSvc);
- use(*typedSvc, props, svcOwner);
- });
- }
+ bool useService(const std::string &serviceName, const std::function<void(I &svc, const celix::Properties &props, const celix::Bundle &svcOwner)> &use) noexcept;
template<typename I>
- void useServices(const std::string &serviceName, const std::function<void(I &svc, const celix::Properties &props, const celix::Bundle &svcOwner)> &use) noexcept {
- this->useServicesInternal(serviceName, [use](void *voidSvc, const celix::Properties &props, const celix::Bundle &svcOwner) {
- I *typedSvc = static_cast<I*>(voidSvc);
- use(*typedSvc, props, svcOwner);
- });
- }
+ void useServices(const std::string &serviceName, const std::function<void(I &svc, const celix::Properties &props, const celix::Bundle &svcOwner)> &use) noexcept;
//TODO add useService(s)WithOptions
//TODO add useCService(s) variants
@@ -276,9 +262,6 @@ namespace celix {
void useBundles(const std::function<void(const celix::Bundle &bnd)> &use) noexcept;
bool useBundle(long bundleId, const std::function<void(const celix::Bundle &bnd)> &use) noexcept;
- protected:
- bool useServiceInternal(const std::string &serviceName, const std::function<void(void *svc, const celix::Properties &props, const celix::Bundle &svcOwner)> &use) noexcept;
- void useServicesInternal(const std::string &serviceName, const std::function<void(void *svc, const celix::Properties &props, const celix::Bundle &svcOwner)> &use) noexcept;
private:
struct Impl;
std::unique_ptr<celix::BundleContext::Impl> pimpl{nullptr};
http://git-wip-us.apache.org/repos/asf/celix/blob/70308481/framework/include/celix/impl/BundleContextImpl.h
----------------------------------------------------------------------
diff --git a/framework/include/celix/impl/BundleContextImpl.h b/framework/include/celix/impl/BundleContextImpl.h
index b90c6fd..67f079b 100644
--- a/framework/include/celix/impl/BundleContextImpl.h
+++ b/framework/include/celix/impl/BundleContextImpl.h
@@ -59,7 +59,7 @@ namespace celix {
};
struct ServiceTrackingEntry {
- celix_service_tracking_options_t cOpts{nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
+ celix_service_tracking_options_t cOpts{{nullptr, nullptr, nullptr, nullptr}, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr};
std::unique_ptr<ServiceTrackingEntryFunctions> functions{nullptr};
};
@@ -86,6 +86,8 @@ namespace celix {
long registerServiceInternal(celix::impl::ServiceRegistrationEntry &&entry) noexcept;
long trackServicesInternal(celix::impl::ServiceTrackingEntry &&entry) noexcept;
+ bool useServiceInternal(const std::string &serviceName, const std::function<void(void *svc, const celix::Properties &props, const celix::Bundle &svcOwner)> &use) noexcept;
+ void useServicesInternal(const std::string &serviceName, const std::function<void(void *svc, const celix::Properties &props, const celix::Bundle &svcOwner)> &use) noexcept;
};
}
@@ -246,7 +248,7 @@ inline long celix::BundleContext::Impl::trackServicesInternal(celix::impl::Servi
return trkId;
}
-inline bool celix::BundleContext::useServiceInternal(
+inline bool celix::BundleContext::Impl::useServiceInternal(
const std::string &serviceName,
const std::function<void(void *svc, const celix::Properties &props, const celix::Bundle &svcOwner)> &use) noexcept {
auto c_use = [](void *handle, void *svc, const celix_properties_t *c_props, const celix_bundle_t *c_svcOwner) {
@@ -265,10 +267,10 @@ inline bool celix::BundleContext::useServiceInternal(
opts.callbackHandle = (void*)&use;
opts.useWithOwner = c_use;
- return celix_bundleContext_useServiceWithOptions(this->pimpl->c_ctx, &opts);
+ return celix_bundleContext_useServiceWithOptions(this->c_ctx, &opts);
}
-inline void celix::BundleContext::useServicesInternal(
+inline void celix::BundleContext::Impl::useServicesInternal(
const std::string &serviceName,
const std::function<void(void *svc, const celix::Properties &props, const celix::Bundle &svcOwner)> &use) noexcept {
auto c_use = [](void *handle, void *svc, const celix_properties_t *c_props, const celix_bundle_t *c_svcOwner) {
@@ -287,7 +289,7 @@ inline void celix::BundleContext::useServicesInternal(
opts.callbackHandle = (void*)&use;
opts.useWithOwner = c_use;
- celix_bundleContext_useServicesWithOptions(this->pimpl->c_ctx, &opts);
+ celix_bundleContext_useServicesWithOptions(this->c_ctx, &opts);
}
@@ -525,5 +527,28 @@ long celix::BundleContext::trackServicesWithOptions(const celix::ServiceTracking
return this->pimpl->trackServicesInternal(std::move(entry));
}
+template<typename I>
+bool celix::BundleContext::useServiceWithId(long serviceId, const std::string &/*serviceName*/ /*sanity*/, const std::function<void(I &svc, const celix::Properties &props, const celix::Bundle &svcOwner)> &/*use*/) noexcept {
+ std::string filter = std::string{"(service.id="} + std::to_string(serviceId) + std::string{")"};
+ //TODO use useServiceWithOptions return this->useService<I>(serviceName, "", filter, use);
+ return false;
+}
+
+template<typename I>
+bool celix::BundleContext::useService(const std::string &serviceName, const std::function<void(I &svc, const celix::Properties &props, const celix::Bundle &svcOwner)> &use) noexcept {
+ return this->pimpl->useServiceInternal(serviceName, [use](void *voidSvc, const celix::Properties &props, const celix::Bundle &svcOwner) {
+ I *typedSvc = static_cast<I*>(voidSvc);
+ use(*typedSvc, props, svcOwner);
+ });
+}
+
+template<typename I>
+void celix::BundleContext::useServices(const std::string &serviceName, const std::function<void(I &svc, const celix::Properties &props, const celix::Bundle &svcOwner)> &use) noexcept {
+ this->pimpl->useServicesInternal(serviceName, [use](void *voidSvc, const celix::Properties &props, const celix::Bundle &svcOwner) {
+ I *typedSvc = static_cast<I*>(voidSvc);
+ use(*typedSvc, props, svcOwner);
+ });
+}
+
#endif //CELIX_IMPL_BUNDLECONTEXTIMPL_H