Skip to navigation

hololink::module::Service

View as Markdown
template <typename Derived>
class Service

Service provides a get_service method which provides a type-safe way to fetch a <Derived> service implementation from a module.

Note that the same service instance may implement any number of Service interfaces, so an interface is provided allowing a visitor to see the list of service names that these objects support.

#include <hololink/module/service.hpp>

Template parameters

Derived
typename

Inherits from: hololink::module::ServiceBase (public)


Methods

module

std::shared_ptr<Module> hololink::module::Service::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::Service<Derived>::get_service(
std::shared_ptr<Module> module,
const char *instance_id,
bool allow_null = false
)

Type-safe way to fetch a std::shared_ptr to an instance of <Derived> from a Module.

Note that Module usually caches instances, it’s likely that calls to get_service with the same locator_id will return pointers to the same implementation object.

Returns: A shared pointer to the service instance.

Parameters

module
std::shared_ptr<Module>

Is the shared object that owns the instance we wish to fetch

instance_id
const char *

Names the specific object, usually expressed as a set of “name=value;…” pairs, as defined by the implementations themselves. This name is normally fetched by calling Derived::locator_id(enumeration_metadata).

allow_null
boolDefaults to false

The default value of false causes this routine to throw a std::runtime_error if the service cannot be found within the module; this would be expected to terminate the calling program. If the application wants to handle the error, pass in true here and get_service will return nullptr when this module doesn’t provide the requested service.

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.