Skip to navigation

hololink::module::ServicePublisher

View as Markdown
template <typename T>

Publishes service implementations into a Publisher, making them available to lookups.

Use it from a Publisher’s own code: either to publish services eagerly (for example in Publisher::setup()) or from Publisher::construct_service() to publish the service that was just asked for.

Publishing does two things. It records the implementation in the Publisher, which keeps it alive and returns it from later lookups until Publisher::invalidate() discards it. And it makes the Publisher’s self_module() the service’s owning Module (see ServiceBase::module()), so that the service’s accessors for related services, such as a device’s get_i2c, look them up in the same binary the service was published from.

#include <hololink/module/publisher.hpp>

Template parameters

T
typename

The service class to publish. It must declare or inherit a release_version.


Constructors

ServicePublisher

hololink::module::ServicePublisher<T>::ServicePublisher(
std::shared_ptr<Publisher> publisher
)

Parameters

publisher
std::shared_ptr<Publisher>

The Publisher to publish into.


Methods

publish

void hololink::module::ServicePublisher<T>::publish(
const std::string &instance_id,
std::shared_ptr<T> impl
)

Publish a service under every type id that T provides.

A service that can be used as several interfaces is made available under the type id of each, so that a lookup for any of them returns this object.

Throws: std::runtime_error if any of the (instance id, type id) pairs is already published. Pairs published before the collision was found remain published.

Parameters

instance_id
const std::string &

Instance id to publish under; lookups must use the same value.

impl
std::shared_ptr<T>

The service. Must not be null.