EchoMap 2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
Loading...
Searching...
No Matches
echomap::ResultChannel< ResultT > Class Template Reference

Maintains a type-safe multi-observer single-consumer message bus for WorkerResult objects. More...

#include <ResultChannel.hpp>

Public Member Functions

template<class SlotT>
sigc::connection observe (SlotT &&slot)
 Provide a new slot as an observer on the channel.
template<class SlotT>
requires (!std::is_const_v<ResultT>)
sigc::connection nominate_consumer (SlotT &&slot)
 Nominate the consumer slot for the channel.

Private Types

using ObserverSignalT = sigc::signal<void(const ResultT&)>
using ConsumerSignalT = sigc::signal<void(ResultT&&)>

Private Member Functions

void publish (ResultT &&result)
 Publish a consumable result onto the channel for all observers, followed by the single consumer.
void publish (const ResultT &result)
 Publish a non-consumable result onto the channel for all observers.

Private Attributes

ObserverSignalT observers
ConsumerSignalT consumer

Friends

class WorkerResultDespatcher

Detailed Description

template<class ResultT>
class echomap::ResultChannel< ResultT >

Maintains a type-safe multi-observer single-consumer message bus for WorkerResult objects.

Template Parameters
ResultTThe type of result to broadcast on the channel. In practice, this is the first parameter of the subscribed slots.

Definition at line 29 of file ResultChannel.hpp.

Member Typedef Documentation

◆ ConsumerSignalT

template<class ResultT>
using echomap::ResultChannel< ResultT >::ConsumerSignalT = sigc::signal<void(ResultT&&)>
private

Definition at line 72 of file ResultChannel.hpp.

◆ ObserverSignalT

template<class ResultT>
using echomap::ResultChannel< ResultT >::ObserverSignalT = sigc::signal<void(const ResultT&)>
private

Definition at line 71 of file ResultChannel.hpp.

Member Function Documentation

◆ nominate_consumer()

template<class ResultT>
template<class SlotT>
requires (!std::is_const_v<ResultT>)
sigc::connection echomap::ResultChannel< ResultT >::nominate_consumer ( SlotT && slot)
inlinenodiscard

Nominate the consumer slot for the channel.

Template Parameters
SlotTThe slot type signature, accepting ResultT&&.
Parameters
slotThe slot to consume the result following broadcast to observers.
Exceptions
std::runtime_errorThe channel already had a nominated consumer.
Warning
This function may only be called once for each channel; otherwise, an exception will be thrown.

Definition at line 58 of file ResultChannel.hpp.

61 {
62 if (!consumer.empty())
63 throw std::logic_error("Result channel already has a nominated consumer.");
64
65 return consumer.connect(std::forward<SlotT>(slot));
66 }
Maintains a type-safe multi-observer single-consumer message bus for WorkerResult objects.

◆ observe()

template<class ResultT>
template<class SlotT>
sigc::connection echomap::ResultChannel< ResultT >::observe ( SlotT && slot)
inlinenodiscard

Provide a new slot as an observer on the channel.

Template Parameters
SlotTThe slot type signature, accepting const ResultT&.
Parameters
slotThe slot to add to the subscribers of the channel.
Returns
The connection between the slot and the signal.

Definition at line 40 of file ResultChannel.hpp.

43 {
44 return observers.connect(std::forward<SlotT>(slot));
45 }

◆ publish() [1/2]

template<class ResultT>
void echomap::ResultChannel< ResultT >::publish ( const ResultT & result)
inlineprivate

Publish a non-consumable result onto the channel for all observers.

Parameters
resultA constant l-value reference to the result to publish on the channel.

Definition at line 105 of file ResultChannel.hpp.

108 {
109 observers.emit(result);
110 }

◆ publish() [2/2]

template<class ResultT>
void echomap::ResultChannel< ResultT >::publish ( ResultT && result)
inlineprivate

Publish a consumable result onto the channel for all observers, followed by the single consumer.

Parameters
resultAn r-value reference to the result to publish on the channel.

Definition at line 79 of file ResultChannel.hpp.

82 {
84
85 // Emit const ResultT& to all observers.
86 try {
88 } catch (...) {
90 }
91
92 // If there is a nominated consumer, send it out.
93 if (!consumer.empty())
94 consumer.emit(std::move(result));
95
98 }
void publish(ResultT &&result)
Publish a consumable result onto the channel for all observers, followed by the single consumer.
T current_exception(T... args)
T rethrow_exception(T... args)

◆ WorkerResultDespatcher

template<class ResultT>
friend class WorkerResultDespatcher
friend

Definition at line 69 of file ResultChannel.hpp.

Member Data Documentation

◆ consumer

template<class ResultT>
ConsumerSignalT echomap::ResultChannel< ResultT >::consumer
private

Definition at line 113 of file ResultChannel.hpp.

◆ observers

template<class ResultT>
ObserverSignalT echomap::ResultChannel< ResultT >::observers
private

Definition at line 112 of file ResultChannel.hpp.


The documentation for this class was generated from the following file: