Apache Celix
2.3.0
An implementation of the OSGi specification adapted to C and C++
|
Go to the documentation of this file.
26 #include "celix/Utils.h"
46 std::shared_ptr<celix_bundle_context_t> _cCtx,
47 std::shared_ptr<I> _svc,
48 std::string_view _name,
49 bool _registerAsync = true,
50 bool _unregisterAsync = true) :
51 cCtx{std::move(_cCtx)},
54 version{celix::typeVersion<I>()},
55 registerAsync{_registerAsync},
56 unregisterAsync{_unregisterAsync}{}
58 ServiceRegistrationBuilder&
operator=(ServiceRegistrationBuilder&&) =
delete;
59 ServiceRegistrationBuilder(
const ServiceRegistrationBuilder&) =
delete;
60 ServiceRegistrationBuilder
operator=(
const ServiceRegistrationBuilder&) =
delete;
91 for (
const auto& pair : props) {
92 properties.set(pair.first, pair.second);
103 onRegisteredCallbacks.emplace_back(std::move(callback));
113 onUnregisteredCallbacks.emplace_back(std::move(callback));
133 registerAsync = async;
156 unregisterAsync = async;
167 std::shared_ptr<ServiceRegistration>
build() {
173 std::move(properties),
176 std::move(onRegisteredCallbacks),
177 std::move(onUnregisteredCallbacks));
180 const std::shared_ptr<celix_bundle_context_t> cCtx;
181 std::shared_ptr<I> svc;
185 bool unregisterAsync;
187 std::vector<std::function<void(ServiceRegistration&)>> onRegisteredCallbacks{};
188 std::vector<std::function<void(ServiceRegistration&)>> onUnregisteredCallbacks{};
The bundle context is used to interact with the Celix framework.
Definition: BundleContext.h:52
ServiceRegistrationBuilder & setUnregisterAsync(bool async)
Configure if the service un-registration will be done synchronized or asynchronized.
Definition: ServiceRegistrationBuilder.h:155
ServiceRegistrationBuilder & addProperty(std::string_view key, T &&value)
Add a property to the service properties.
Definition: ServiceRegistrationBuilder.h:75
ServiceRegistrationBuilder & addOnRegistered(std::function< void(ServiceRegistration &)> callback)
Adds an on registered callback for the service registration.
Definition: ServiceRegistrationBuilder.h:102
static std::shared_ptr< ServiceRegistration > create(std::shared_ptr< celix_bundle_context_t > cCtx, std::shared_ptr< void > svc, std::string_view name, std::string_view version, celix::Properties properties, bool registerAsync, bool unregisterAsync, std::vector< std::function< void(ServiceRegistration &)>> onRegisteredCallbacks, std::vector< std::function< void(ServiceRegistration &)>> onUnregisteredCallbacks)
Definition: ServiceRegistration.h:70
A registered service.
Definition: ServiceRegistration.h:53
ServiceRegistrationBuilder & addProperties(const celix::Properties &props)
Add the properties to the service properties.
Definition: ServiceRegistrationBuilder.h:90
Fluent builder API to build a new service registration for a service.
Definition: ServiceRegistrationBuilder.h:38
ServiceRegistrationBuilder & operator=(ServiceRegistrationBuilder &&)=delete
ServiceRegistrationBuilder & addOnUnregistered(std::function< void(ServiceRegistration &)> callback)
Adds an on unregistered callback for the service registration.
Definition: ServiceRegistrationBuilder.h:112
ServiceRegistrationBuilder & setProperties(celix::Properties p)
Set the service properties.
Definition: ServiceRegistrationBuilder.h:82
ServiceRegistrationBuilder & setRegisterAsync(bool async)
Configure if the service registration will be done synchronized or asynchronized.
Definition: ServiceRegistrationBuilder.h:132
std::shared_ptr< ServiceRegistration > build()
"Builds" the service registration and return a ServiceRegistration.
Definition: ServiceRegistrationBuilder.h:167
ServiceRegistrationBuilder & setVersion(std::string_view v)
Set the service version.
Definition: ServiceRegistrationBuilder.h:67
celix::Properties Properties
Definition: Properties.h:25