EchoMap
2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
Toggle main menu visibility
Loading...
Searching...
No Matches
ResultChannel.hpp
Go to the documentation of this file.
1
9
10
#ifndef ECHOMAP_RESULTCHANNEL_HPP
11
#define ECHOMAP_RESULTCHANNEL_HPP
12
13
#include <sigc++/signal.h>
14
15
#include <
exception
>
16
#include <
stdexcept
>
17
#include <
type_traits
>
18
#include <
utility
>
19
20
namespace
echomap
21
{
22
29
template
<
class
ResultT>
class
ResultChannel
30
{
31
public
:
39
template
<
class
SlotT>
40
[[nodiscard]] sigc::connection
observe
(
41
SlotT&& slot
42
)
43
{
44
return
observers.connect(
std::forward<SlotT>
(slot));
45
}
46
56
template
<
class
SlotT>
57
requires
(!
std::is_const_v<ResultT>
)
58
[[nodiscard]] sigc::connection
nominate_consumer
(
59
SlotT&& slot
60
)
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
}
67
68
private
:
69
friend
class
WorkerResultDespatcher
;
70
71
using
ObserverSignalT = sigc::signal<void(
const
ResultT&)>;
72
using
ConsumerSignalT = sigc::signal<void(ResultT&&)>;
73
79
void
publish
(
80
ResultT&& result
81
)
82
{
83
std::exception_ptr
observer_exception;
84
85
// Emit const ResultT& to all observers.
86
try
{
87
publish
(result);
88
}
catch
(...) {
89
observer_exception =
std::current_exception
();
90
}
91
92
// If there is a nominated consumer, send it out.
93
if
(!consumer.empty())
94
consumer.emit(std::move(result));
95
96
if
(observer_exception)
97
std::rethrow_exception
(observer_exception);
98
}
99
105
void
publish
(
106
const
ResultT& result
107
)
108
{
109
observers.emit(result);
110
}
111
112
ObserverSignalT observers;
113
ConsumerSignalT consumer;
114
};
115
116
}
// namespace echomap
117
118
#endif
// ECHOMAP_RESULTCHANNEL_HPP
echomap::ResultChannel
Maintains a type-safe multi-observer single-consumer message bus for WorkerResult objects.
Definition
ResultChannel.hpp:30
echomap::ResultChannel::observe
sigc::connection observe(SlotT &&slot)
Provide a new slot as an observer on the channel.
Definition
ResultChannel.hpp:40
echomap::ResultChannel::nominate_consumer
sigc::connection nominate_consumer(SlotT &&slot)
Nominate the consumer slot for the channel.
Definition
ResultChannel.hpp:58
echomap::ResultChannel::publish
void publish(const ResultT &result)
Publish a non-consumable result onto the channel for all observers.
Definition
ResultChannel.hpp:105
echomap::ResultChannel::publish
void publish(ResultT &&result)
Publish a consumable result onto the channel for all observers, followed by the single consumer.
Definition
ResultChannel.hpp:79
echomap::WorkerResultDespatcher
Manages channels for WorkerResult message routing.
Definition
WorkerResultDespatcher.hpp:27
std::current_exception
T current_exception(T... args)
exception
std::exception_ptr
std::forward
T forward(T... args)
std::is_const_v
T is_const_v
std::logic_error
echomap
The main EchoMap outermost namespace for all non-exported symbols.
Definition
ActionController.hpp:20
std::rethrow_exception
T rethrow_exception(T... args)
stdexcept
type_traits
utility
src
async
ResultChannel.hpp
Generated by
1.17.0