Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions libs/framework/include/celix/Bundle.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace celix {
* Each bundle installed in the Celix framework must have an associated Bundle object.
* A bundle must have a unique identity, a long, chosen by the Celix framework.
*
* @note Provided `std::string_view` values must be null terminated strings.
* @note Thread safe.
*/
class Bundle {
Expand All @@ -63,9 +64,9 @@ namespace celix {
* @param path The relative path to a bundle resource
* @return The use-able entry path or an empty string if the entry is not found.
*/
[[nodiscard]] std::string getEntry(const std::string& path) const {
[[nodiscard]] std::string getEntry(std::string_view path) const {
std::string result{};
char* entry = celix_bundle_getEntry(cBnd.get(), path.c_str());
char* entry = celix_bundle_getEntry(cBnd.get(), path.data());
if (entry != nullptr) {
result = std::string{entry};
free(entry);
Expand Down Expand Up @@ -95,7 +96,7 @@ namespace celix {
}

/**
* @brief The descriptoin of the bundle.
* @brief The description of the bundle.
*/
[[nodiscard]] std::string getDescription() const {
return std::string{celix_bundle_getDescription(cBnd.get())};
Expand Down
53 changes: 27 additions & 26 deletions libs/framework/include/celix/BundleContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace celix {
* - Access bundles
* - Get config properties
*
* @note Provided `std::string_view` values must be null terminated strings.
* @note Thread safe.
*/
class BundleContext {
Expand Down Expand Up @@ -78,7 +79,7 @@ namespace celix {
* @return A ServiceRegistrationBuilder object.
*/
template<typename I, typename Implementer>
ServiceRegistrationBuilder<I> registerService(std::shared_ptr<Implementer> implementer, const std::string& name = {}) {
ServiceRegistrationBuilder<I> registerService(std::shared_ptr<Implementer> implementer, std::string_view name = {}) {
std::shared_ptr<I> svc = implementer; //note Implement should be derived from I
return ServiceRegistrationBuilder<I>{cCtx, std::move(svc), celix::typeName<I>(name)};
}
Expand All @@ -94,7 +95,7 @@ namespace celix {
* service sync (because the svc pointer is unmanaged).
*/
template<typename I, typename Implementer>
ServiceRegistrationBuilder<I> registerUnmanagedService(Implementer* svc, const std::string& name = {}) {
ServiceRegistrationBuilder<I> registerUnmanagedService(Implementer* svc, std::string_view name = {}) {
auto unmanagedSvc = std::shared_ptr<I>{svc, [](I*){/*nop*/}};
return ServiceRegistrationBuilder<I>{cCtx, std::move(unmanagedSvc), celix::typeName<I>(name), true, false};
}
Expand Down Expand Up @@ -128,7 +129,7 @@ namespace celix {
* @return A UseServiceBuilder object.
*/
template<typename I>
UseServiceBuilder<I> useService(const std::string& name = {}) {
UseServiceBuilder<I> useService(std::string_view name = {}) {
return UseServiceBuilder<I>{cCtx, celix::typeName<I>(name), true};
}

Expand Down Expand Up @@ -156,7 +157,7 @@ namespace celix {
* @return A UseServiceBuilder object.
*/
template<typename I>
UseServiceBuilder<I> useServices(const std::string& name = {}) {
UseServiceBuilder<I> useServices(std::string_view name = {}) {
return UseServiceBuilder<I>{cCtx, celix::typeName<I>(name), false};
}

Expand All @@ -172,7 +173,7 @@ namespace celix {
* @return The service id of the found service or -1 if the service was not found.
*/
template<typename I>
long findService(const std::string& filter = {}, const std::string& versionRange = {}) {
long findService(std::string_view filter = {}, std::string_view versionRange = {}) {
return findServiceWithName(celix::typeName<I>(), filter, versionRange);
}

Expand All @@ -185,12 +186,12 @@ namespace celix {
* @param versionRange An optional version range.
* @return The service id of the found service or -1 if the service was not found.
*/
long findServiceWithName(const std::string& name, const std::string& filter = {}, const std::string& versionRange = {}) {
long findServiceWithName(std::string_view name, std::string_view filter = {}, std::string_view versionRange = {}) {
waitIfAbleForEvents();
celix_service_filter_options_t opts{};
opts.serviceName = name.empty() ? nullptr : name.c_str();
opts.filter = filter.empty() ? nullptr : filter.c_str();
opts.versionRange = versionRange.empty() ? nullptr : versionRange.c_str();
opts.serviceName = name.empty() ? nullptr : name.data();
opts.filter = filter.empty() ? nullptr : filter.data();
opts.versionRange = versionRange.empty() ? nullptr : versionRange.data();
return celix_bundleContext_findServiceWithOptions(cCtx.get(), &opts);
}

Expand All @@ -206,7 +207,7 @@ namespace celix {
* @return A vector of service ids.
*/
template<typename I>
std::vector<long> findServices(const std::string& filter = {}, const std::string& versionRange = {}) {
std::vector<long> findServices(std::string_view filter = {}, std::string_view versionRange = {}) {
return findServicesWithName(celix::typeName<I>(), filter, versionRange);
}

Expand All @@ -219,12 +220,12 @@ namespace celix {
* @param versionRange An optional version range.
* @return A vector of service ids.
*/
std::vector<long> findServicesWithName(const std::string& name, const std::string& filter = {}, const std::string& versionRange = {}) {
std::vector<long> findServicesWithName(std::string_view name, std::string_view filter = {}, std::string_view versionRange = {}) {
waitIfAbleForEvents();
celix_service_filter_options_t opts{};
opts.serviceName = name.empty() ? nullptr : name.c_str();
opts.filter = filter.empty() ? nullptr : filter.c_str();
opts.versionRange = versionRange.empty() ? nullptr : versionRange.c_str();
opts.serviceName = name.empty() ? nullptr : name.data();
opts.filter = filter.empty() ? nullptr : filter.data();
opts.versionRange = versionRange.empty() ? nullptr : versionRange.data();

std::vector<long> result{};
auto cList = celix_bundleContext_findServicesWithOptions(cCtx.get(), &opts);
Expand Down Expand Up @@ -257,7 +258,7 @@ namespace celix {
* @return A ServiceTrackerBuilder object.
*/
template<typename I>
ServiceTrackerBuilder<I> trackServices(const std::string& name = {}) {
ServiceTrackerBuilder<I> trackServices(std::string_view name = {}) {
return ServiceTrackerBuilder<I>{cCtx, celix::typeName<I>(name)};
}

Expand Down Expand Up @@ -310,7 +311,7 @@ namespace celix {
* @return A MetaTrackerBuilder object.
*/
template<typename I>
MetaTrackerBuilder trackServiceTrackers(const std::string& name = {}) {
MetaTrackerBuilder trackServiceTrackers(std::string_view name = {}) {
return MetaTrackerBuilder(cCtx, celix::typeName<I>(name));
}

Expand All @@ -332,8 +333,8 @@ namespace celix {
* @param autoStart If the bundle should also be started.
* @return the bundleId (>= 0) or < 0 if the bundle could not be installed and possibly started.
*/
long installBundle(const std::string& bndLocation, bool autoStart = true) {
return celix_bundleContext_installBundle(cCtx.get(), bndLocation.c_str(), autoStart);
long installBundle(std::string_view bndLocation, bool autoStart = true) {
return celix_bundleContext_installBundle(cCtx.get(), bndLocation.data(), autoStart);
}

/**
Expand Down Expand Up @@ -399,8 +400,8 @@ namespace celix {
* @param defaultVal The default value to use if the property is not found.
* @return The config property value for the provided key or the provided defaultValue is the name is not found.
*/
[[nodiscard]] std::string getConfigProperty(const std::string& name, const std::string& defaultValue) const {
return std::string{celix_bundleContext_getProperty(cCtx.get(), name.c_str(), defaultValue.c_str())};
[[nodiscard]] std::string getConfigProperty(std::string_view name, std::string_view defaultValue) const {
return std::string{celix_bundleContext_getProperty(cCtx.get(), name.data(), defaultValue.data())};
}

/**
Expand All @@ -415,8 +416,8 @@ namespace celix {
* @return The config property value (as long) for the provided key or the provided defaultValue is the name
* is not found or not a valid long.
*/
[[nodiscard]] long getConfigPropertyAsLong(const std::string& name, long defaultValue) const {
return celix_bundleContext_getPropertyAsLong(cCtx.get(), name.c_str(), defaultValue);
[[nodiscard]] long getConfigPropertyAsLong(std::string_view name, long defaultValue) const {
return celix_bundleContext_getPropertyAsLong(cCtx.get(), name.data(), defaultValue);
}

/**
Expand All @@ -431,8 +432,8 @@ namespace celix {
* @return The config property value (as double) for the provided key or the provided defaultValue is the name
* is not found or not a valid double.
*/
[[nodiscard]] double getConfigPropertyAsDouble(const std::string& name, double defaultValue) const {
return celix_bundleContext_getPropertyAsDouble(cCtx.get(), name.c_str(), defaultValue);
[[nodiscard]] double getConfigPropertyAsDouble(std::string_view name, double defaultValue) const {
return celix_bundleContext_getPropertyAsDouble(cCtx.get(), name.data(), defaultValue);
}

/**
Expand All @@ -449,8 +450,8 @@ namespace celix {
* @return The config property value (as boolean) for the provided key or the provided defaultValue is the name
* is not found or not a valid boolean.
*/
[[nodiscard]] long getConfigPropertyAsBool(const std::string& name, bool defaultValue) const {
return celix_bundleContext_getPropertyAsBool(cCtx.get(), name.c_str(), defaultValue);
[[nodiscard]] long getConfigPropertyAsBool(std::string_view name, bool defaultValue) const {
return celix_bundleContext_getPropertyAsBool(cCtx.get(), name.data(), defaultValue);
}

/**
Expand Down
16 changes: 8 additions & 8 deletions libs/framework/include/celix/ServiceRegistration.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ namespace celix {
*/
static std::shared_ptr<ServiceRegistration> create(std::shared_ptr<celix_bundle_context_t> cCtx,
std::shared_ptr<void> svc,
std::string name,
std::string version,
std::string_view name,
std::string_view version,
celix::Properties properties,
bool registerAsync,
bool unregisterAsync,
Expand Down Expand Up @@ -111,8 +111,8 @@ namespace celix {
new ServiceRegistration{
std::move(cCtx),
std::move(svc),
std::move(name),
std::move(version),
name,
version,
std::move(properties),
registerAsync,
unregisterAsync,
Expand Down Expand Up @@ -256,16 +256,16 @@ namespace celix {
ServiceRegistration(
std::shared_ptr<celix_bundle_context_t> _cCtx,
std::shared_ptr<void> _svc,
std::string _name,
std::string _version,
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) :
cCtx{std::move(_cCtx)},
name{std::move(_name)},
version{std::move(_version)},
name{_name},
version{_version},
properties{std::move(_properties)},
registerAsync{_registerAsync},
unregisterAsync{_unregisterAsync},
Expand Down
24 changes: 5 additions & 19 deletions libs/framework/include/celix/ServiceRegistrationBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ namespace celix {
ServiceRegistrationBuilder(
std::shared_ptr<celix_bundle_context_t> _cCtx,
std::shared_ptr<I> _svc,
std::string _name,
std::string_view _name,
bool _registerAsync = true,
bool _unregisterAsync = true) :
cCtx{std::move(_cCtx)},
svc{std::move(_svc)},
name{std::move(_name)},
name{_name},
version{celix::typeVersion<I>()},
registerAsync{_registerAsync},
unregisterAsync{_unregisterAsync}{}
Expand All @@ -64,34 +64,20 @@ namespace celix {
*
* This will lead to a 'service.version' service property.
*/
ServiceRegistrationBuilder& setVersion(std::string v) { version = std::move(v); return *this; }

/**
* @brief Add a property to the service properties.
*
* If a key is already present the value will be overridden.
*/
ServiceRegistrationBuilder& addProperty(const std::string& key, const std::string& value) { properties.set(key, value); return *this; }

/**
* @brief Add a property to the service properties.
*
* If a key is already present the value will be overridden.
*/
ServiceRegistrationBuilder& addProperty(const std::string& key, const char* value) { properties.set(key, std::string{value}); return *this; }
ServiceRegistrationBuilder& setVersion(std::string_view v) { version = v; return *this; }

/**
* @brief Add a property to the service properties.
*
* If a key is already present the value will be overridden.
*/
template<typename T>
ServiceRegistrationBuilder& addProperty(const std::string& key, T value) { properties.set(key, std::to_string(std::move(value))); return *this; }
ServiceRegistrationBuilder& addProperty(std::string_view key, T&& value) { properties.template set(key, std::forward<T>(value)); return *this; }

/**
* @brief Set the service properties.
*
* Note this call will clear any already set properties.
* Note this call will clear already set properties.
*/
ServiceRegistrationBuilder& setProperties(celix::Properties p) { properties = std::move(p); return *this; }

Expand Down
10 changes: 5 additions & 5 deletions libs/framework/include/celix/TrackerBuilders.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ namespace celix {
//NOTE private to prevent move so that a build() call cannot be forgotten
ServiceTrackerBuilder(ServiceTrackerBuilder&&) noexcept = default;
public:
explicit ServiceTrackerBuilder(std::shared_ptr<celix_bundle_context_t> _cCtx, std::string _name) :
explicit ServiceTrackerBuilder(std::shared_ptr<celix_bundle_context_t> _cCtx, std::string_view _name) :
cCtx{std::move(_cCtx)},
name{std::move(_name)} {}
name{_name} {}

ServiceTrackerBuilder& operator=(ServiceTrackerBuilder&&) = delete;
ServiceTrackerBuilder(const ServiceTrackerBuilder&) = delete;
Expand All @@ -57,7 +57,7 @@ namespace celix {
* Example:
* "(property_key=value)"
*/
ServiceTrackerBuilder& setFilter(const std::string& f) { filter = celix::Filter{f}; return *this; }
ServiceTrackerBuilder& setFilter(std::string_view f) { filter = celix::Filter{f}; return *this; }

/**
* @brief Set filter to be used to matching services.
Expand Down Expand Up @@ -310,9 +310,9 @@ namespace celix {
//NOTE private to prevent move so that a build() call cannot be forgotten
MetaTrackerBuilder(MetaTrackerBuilder &&) = default;
public:
explicit MetaTrackerBuilder(std::shared_ptr<celix_bundle_context_t> _cCtx, std::string _serviceName) :
explicit MetaTrackerBuilder(std::shared_ptr<celix_bundle_context_t> _cCtx, std::string_view _serviceName) :
cCtx{std::move(_cCtx)},
serviceName{std::move(_serviceName)}
serviceName{_serviceName}
{}

MetaTrackerBuilder &operator=(MetaTrackerBuilder &&) = delete;
Expand Down
Loading