> This page is for version 3.0 (Latest) (default).
> For other versions, use one of these documentation indexes:
> - 3.0 (Latest) (default): https://docs.nvidia.com/holoscan/sensor-bridge/3-0/llms.txt
> - 2.7: https://docs.nvidia.com/holoscan/sensor-bridge/2-7/llms.txt
> - Archives: https://docs.nvidia.com/holoscan/sensor-bridge/archives/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/holoscan/sensor-bridge/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/holoscan/sensor-bridge/_mcp/server.

# hololink::module::ServicePublisher

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

```cpp showLineNumbers={false}
template <typename T>
class ServicePublisher
```

Publishes service implementations into a [Publisher](publisher), making them available to lookups.

Use it from a [Publisher](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](publisher), which keeps it alive and returns it from later lookups until Publisher::invalidate() discards it. And it makes the [Publisher](publisher)'s self_module() the service's owning [Module](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.

```cpp showLineNumbers={false}
#include <hololink/module/publisher.hpp>
```

**Template parameters**

**`T`** `typename`

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

---

---

## Constructors

### ServicePublisher \[#servicepublisher]

```cpp showLineNumbers={false}
hololink::module::ServicePublisher<T>::ServicePublisher(
    std::shared_ptr<Publisher> publisher
)
```

**Parameters**

**`publisher`** `std::shared_ptr<Publisher>`

The [Publisher](publisher) to publish into.

---

---

## Methods

### publish \[#publish]

#### Overload 1

```cpp showLineNumbers={false}
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.

---

#### Publish a service under one type id

```cpp showLineNumbers={false}
void hololink::module::ServicePublisher<T>::publish(
    const std::string &instance_id,
    const char *type_id,
    std::shared_ptr<T> impl
)
```

Publish a service under one type id.

Use this to publish under a single type id, rather than all of the type ids that `T` provides.

**Throws:** `std::runtime_error` if this (instance id, type id) pair is already published.

**Parameters**

**`instance_id`** `const std::string &`

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

---

**`type_id`** `const char *`

Type id to publish under.

---

**`impl`** `std::shared_ptr<T>`

The service. Must not be null.

---