Class RawChannel

Class Documentation

class RawChannel

A channel for messages logged to a topic.

Note

Channels are fully thread-safe. Creating channels and logging on them is safe from any number of threads concurrently. A channel can be created on one thread and sent to and destroyed on another.

Public Functions

FoxgloveError log(const std::byte *data, size_t data_len, std::optional<uint64_t> log_time = std::nullopt) noexcept

Log a message to the channel.

Note

Logging is thread-safe. The data will be logged atomically before or after data logged from other threads.

Parameters:
  • data – The message data.

  • data_len – The length of the message data, in bytes.

  • log_time – The timestamp of the message. If omitted, the current time is used.

void close() noexcept

Close the channel.

You can use this to explicitly unadvertise the channel to sinks that subscribe to channels dynamically, such as the WebSocketServer.

Attempts to log on a closed channel will elicit a throttled warning message.

uint64_t id() const noexcept

Uniquely identifies a channel in the context of this program.

Returns:

The ID of the channel.

std::string_view topic() const noexcept

Get the topic of the channel.

Returns:

The topic of the channel. The value is valid only for the lifetime of the channel.

std::string_view message_encoding() const noexcept

Get the message encoding of the channel.

Returns:

The message encoding of the channel. The value is valid only for the lifetime of the channel.

bool has_sinks() const noexcept

Find out if any sinks have been added to the channel.

Returns:

True if sinks have been added to the channel, false otherwise.

std::optional<Schema> schema() const noexcept

Get the schema of the channel.

Returns:

The schema of the channel. The value is valid only for the lifetime of the channel.

std::optional<std::map<std::string, std::string>> metadata() const noexcept

Get the metadata for the channel, set during creation.

Returns:

The metadata, or an empty map if it was not set.

RawChannel(const RawChannel&) = delete
RawChannel &operator=(const RawChannel&) = delete
RawChannel(RawChannel &&other) noexcept = default

Default move constructor.

RawChannel &operator=(RawChannel &&other) noexcept = default

Default move assignment.

~RawChannel() = default

Default destructor.

Public Static Functions

static FoxgloveResult<RawChannel> create(const std::string_view &topic, const std::string_view &message_encoding, std::optional<Schema> schema = std::nullopt, const Context &context = Context(), std::optional<std::map<std::string, std::string>> metadata = std::nullopt)

Create a new channel.

Parameters:
  • topic – The topic name. You should choose a unique topic name per channel for compatibility with the Foxglove app.

  • message_encoding – The encoding of messages logged to this channel.

  • schema – The schema of messages logged to this channel.

  • context – The context which associates logs to a sink. If omitted, the default context is used.

  • metadata – Key/value metadata for the channel.