Skip to navigation

hololink::module::ConfigurableService

View as Markdown
template <typename Derived>

A service whose instance is constructed from EnumerationMetadata.

Services are instances addressed by instance_id; ConfigurableService constructs the instance_id from fields in EnumerationData, via Derived::locator_id, (frequently of the form “serial=X;instance=Y” or another string uniquely identifying the implementation object). When the Module doesn’t yet have an instance of that service, EnumerationMetadata will be used to initialize it.

#include <hololink/module/service.hpp>

Template parameters

Derived
typename

The service class being resolved.

Inherits from: hololink::module::Service< Derived > (public)


Methods

configure

virtual void hololink::module::ConfigurableService<Derived>::configure(
)

Use metadata contents to initialize this instance.

This routine is guaranteed to be called the first time a call to get_service(metadata) is called on a specific service instance.

module

std::shared_ptr<Module> hololink::module::ServiceBase::module() const

The Module that this service was published from.

The service holds no strong reference to its Module, so this does not extend the Module’s lifetime.

Returns: The owning Module, or an empty pointer if the service has not been published or its Module no longer exists.


Static methods

get_service

static std::shared_ptr<Derived> hololink::module::ConfigurableService<Derived>::get_service(
const EnumerationMetadata &metadata,
bool allow_null = false
)

Fetch a service, configured by EnumerationMetadata.

Module usually caches service objects; so when a specific service instance isn’t found, it will be constructed with the current values in EnumerationMetadata. Later calls to get_service are likely to return that cached instance, ignoring changes to any enumeration metadata that aren’t specifically related to service addressing.

Returns: A shared pointer to the requested service (<Derived>).

Throws: std::runtime_error when allow_null==false and the service lookup (or construction) fails.

Parameters

metadata
const EnumerationMetadata &

Addressing and configuration for the service.

allow_null
boolDefaults to false

Use true to return nullptr when the service cannot be resolved; the default false value raises a std::runtime_error.

for_each_type_id

template <typename Callback>
static bool hololink::module::Service<Derived>::for_each_type_id(
Callback &&cb
)

Iterate over every type_id supported by this instance.

The callback signature is bool(const char*) — returning false halts the walk; true continues. Iteration is depth-first, so you’ll see the most specific implementation types first.