Configuration

class Configuration
#include <cppmicroservices/cm/Configuration.hpp>

The Configuration object (normally obtained as a std::shared_ptr<Configuration>) is the principal means for clients of ConfigurationAdmin to inspect or update the Configuration of a given service or service factory.

Public Functions

virtual ~Configuration() noexcept = default
virtual std::string GetPid() const = 0

Get the PID of this Configuration.

Throws:

std::runtime_error – if this Configuration object has been Removed

Returns:

the PID of this Configuration

virtual std::string GetFactoryPid() const = 0

Get the Factory PID which is responsible for this Configuration.

If this Configuration does not belong to any Factory, returns an empty string.

Throws:

std::runtime_error – if this Configuration object has been Removed

Returns:

the Factory PID associated with this Configuration, if applicable

virtual AnyMap GetProperties() const = 0

Get the properties of this Configuration.

Returns a copy.

Throws:

std::runtime_error – if this Configuration object has been Removed

Returns:

the properties of this Configuration

virtual unsigned long GetChangeCount() const = 0

Get the change count.

Each Configuration must maintain a change counter that is incremented with a positive value every time the configuration is updated and its properties are stored. The counter must be incremented before the targets are updated and events are sent out.

Throws:

std::runtime_error – if this Configuration object has been Removed

Returns:

A monotonically increasing value reflecting changes in this Configuration.

virtual std::shared_ptr<ThreadpoolSafeFuture> SafeUpdate(AnyMap properties = AnyMap{AnyMap::UNORDERED_MAP_CASEINSENSITIVE_KEYS}) = 0

Update the properties of this Configuration.

Invoking this method will trigger the ConfigurationAdmin impl to push the updated properties to any ManagedService / ManagedServiceFactory / ConfigurationListener which has a matching PID / Factory PID.

If the properties are empty, the Configuration will not be removed, but instead updated with an empty properties map.

Remark

The shared_ptr<ThreadpoolSafeFuture> returned can contain a cppmicroservices::SecurityException if the Configuration caused a bundle’s shared library to be loaded and the bundle failed a security check.

Throws:

std::runtime_error – if this Configuration object has been Removed

Parameters:

properties – The properties to update this Configuration with.

Returns:

a shared_ptr<ThreadpoolSafeFuture> which can be used to wait for the asynchronous operation that pushed the update to a ManagedService, ManagedServiceFactory or ConfigurationListener to complete. This can be safely done from the same asyncWorkService on which the update is done. If an exception occurs during the execution of the service component’s Modified method, this exception is intercepted and logged by Declarative Services. This exception is not returned in the shared_ptr<ThreadpoolSafeFuture>.

virtual std::shared_future<void> Update(AnyMap properties = AnyMap{AnyMap::UNORDERED_MAP_CASEINSENSITIVE_KEYS}) = 0

Same as SafeUpdate() except:

Returns:

a std::shared_future<void> that is unsafe to wait on from within a thread allocated to the AsyncWorkService

virtual std::pair<bool, std::shared_ptr<ThreadpoolSafeFuture>> SafeUpdateIfDifferent(AnyMap properties = AnyMap{AnyMap::UNORDERED_MAP_CASEINSENSITIVE_KEYS}) = 0

Update the properties of this Configuration if they differ from the current properties.

Invoking this method will trigger the ConfigurationAdmin impl to push the updated properties to any ManagedService / ManagedServiceFactory / ConfigurationListener which has a matching PID / Factory PID, but only if the properties differ from the current properties. It will return true in this case, and false otherwise.

If the properties are empty, the Configuration will not be removed, but instead updated with an empty properties map, unless it already had empty properties.

Remark

The shared_ptr<ThreadpoolSafeFuture> returned can contain a cppmicroservices::SecurityException if the Configuration caused a bundle’s shared library to be loaded and the bundle failed a security check.

Throws:

std::runtime_error – if this Configuration object has been Removed

Parameters:

properties – The properties to update this Configuration with (if they differ)

Returns:

std::pair<boolean, std::shared_ptr<ThreadpoolSafeFuture>> The boolean indicates whether the properties were updated or not. The shared_ptr<ThreadpoolSafeFuture> allows access to the result of the asynchronous operation that pushed the update operation to a ManagedService, ManagedServiceFactory or ConfigurationListener. This can be safely done from the same asyncWorkService on which the update is done. If an exception occurs during the execution of the service component’s Modified method, this exception is intercepted and logged by Declarative Services. This exception is not returned in the shared_ptr<ThreadpoolSafeFuture>.

virtual std::pair<bool, std::shared_future<void>> UpdateIfDifferent(AnyMap properties = AnyMap{AnyMap::UNORDERED_MAP_CASEINSENSITIVE_KEYS}) = 0

Same as SafeUpdateIfDifferent() except:

Returns:

a std::shared_future<void> that is unsafe to wait on from within a thread allocated to the AsyncWorkService

virtual std::shared_ptr<ThreadpoolSafeFuture> SafeRemove() = 0

Remove this Configuration from ConfigurationAdmin.

This will trigger a push to any ConfigurationListener. This will also trigger the ConfigurationAdmin implementation to update any corresponding ManagedService with an empty AnyMap. Any corresponding ManagedServiceFactory will have its Removed method invoked with the corresponding PID.

Throws:

std::runtime_error – if this Configuration object has been Removed already

Returns:

a shared_ptr<ThreadpoolSafeFuture> to access the result of the asynchronous operation that pushed the remove operation to a ManagedService, ManagedServiceFactory or ConfigurationListener. This can be safely done from the same asyncWorkService on which the update is done. If an exception occurs during the execution of the service component’s Modified method, this exception is intercepted and logged by Declarative Services. This exception is not returned in the shared_ptr<ThreadpoolSafeFuture>.

virtual std::shared_future<void> Remove() = 0

Same as SafeRemove() except:

Returns:

a std::shared_future<void> that is unsafe to wait on from within a thread allocated to the AsyncWorkService