Apache Celix
2.3.0
An implementation of the OSGi specification adapted to C and C++
|
Fluent builder API to use a service or services. More...
#include <UseServiceBuilder.h>
Public Member Functions | |
UseServiceBuilder (std::shared_ptr< celix_bundle_context_t > _cCtx, std::string_view _name, bool _useSingleService=true) | |
UseServiceBuilder & | operator= (UseServiceBuilder &&)=delete |
UseServiceBuilder (const UseServiceBuilder &)=delete | |
UseServiceBuilder | operator= (const UseServiceBuilder &)=delete |
UseServiceBuilder & | setFilter (std::string_view f) |
Set filter to be used to select a service. More... | |
UseServiceBuilder & | setFilter (celix::Filter f) |
Set filter to be used to matching services. More... | |
template<typename Rep , typename Period > | |
UseServiceBuilder & | setTimeout (std::chrono::duration< Rep, Period > duration) |
Sets a optional timeout. More... | |
UseServiceBuilder & | addUseCallback (std::function< void(I &)> cb) |
Adds a use callback function which will be called when the UseServiceBuilder is "build". More... | |
UseServiceBuilder & | addUseCallback (std::function< void(I &, const celix::Properties &)> cb) |
Adds a use callback function which will be called when the UseServiceBuilder is "build". More... | |
UseServiceBuilder & | addUseCallback (std::function< void(I &, const celix::Properties &, const celix::Bundle &)> cb) |
Adds a use callback function which will be called when the UseServiceBuilder is "build". More... | |
std::size_t | build () |
"Builds" the UseServiceBuild. More... | |
Friends | |
class | BundleContext |
Fluent builder API to use a service or services.
The UseServiceBuilder can be used to use a service or a set of services registered in the celix framework. The builder can be used to specify additional match filtering for services, configure use callbacks and whether a single or multiple services will be used. For a single service the highest ranking service will be used. The builder should be finished with a build
call.
ctx->useService<ICalc>() .addUseCallback([](ICalc& calc) { std::cout << "result is " << calc.add(2, 3) << std::endl; }) .build();
I | The service type to use |
|
inlineexplicit |
|
delete |
|
inline |
Adds a use callback function which will be called when the UseServiceBuilder is "build".
The use callback function has 1 argument: a reference to the matching service.
|
inline |
Adds a use callback function which will be called when the UseServiceBuilder is "build".
The use callback function has 2 arguments:
|
inline |
Adds a use callback function which will be called when the UseServiceBuilder is "build".
The use callback function has 3 arguments:
|
inline |
"Builds" the UseServiceBuild.
Blocks until:
This means this if no services are found and the timeout is 0 (default) the function will return without blocking.
|
delete |
|
delete |
|
inline |
Set filter to be used to matching services.
|
inline |
Set filter to be used to select a service.
The filter must be LDAP filter. Example: "(property_key=value)"
|
inline |
Sets a optional timeout.
If the timeout is > 0 and there is no matching service, the "build" will block until a matching service is found or the timeout is expired.
Note: timeout is only valid if the a single service is used.
|
friend |