Signal< RT(Args...), MutexT >
Signal< RT(Args...), MutexT >
#include <icy/signal.h>template<typename RT, typename... Args, typename MutexT>
class Signal< RT(Args...), MutexT >Defined in src/base/include/icy/signal.h:142
Thread-safe signal and slot implementation for callback-based event dispatch.
List of all members
| Name | Kind | Owner |
|---|---|---|
attach | function | Declared here |
attach | function | Declared here |
detach | function | Declared here |
detach | function | Declared here |
detach | function | Declared here |
detachAll | function | Declared here |
emit | function | Declared here |
slots | function | Declared here |
nslots | function | Declared here |
operator+= | function | Declared here |
operator+= | function | Declared here |
operator-= | function | Declared here |
operator-= | function | Declared here |
operator-= | function | Declared here |
Signal | function | Declared here |
~Signal | function | Declared here |
Signal | function | Declared here |
operator= | function | Declared here |
Function | typedef | Declared here |
SlotPtr | typedef | Declared here |
Slot | typedef | Declared here |
SlotNode | typedef | Declared here |
_mutex | variable | Declared here |
_head | variable | Declared here |
_tail | variable | Declared here |
_liveCount | variable | Declared here |
_lastId | variable | Declared here |
_emitDepth | variable | Declared here |
_needsSweep | variable | Declared here |
killMatchingLocked | function | Declared here |
insertSlotLocked | function | Declared here |
appendSlotLocked | function | Declared here |
eraseNodeLocked | function | Declared here |
emitDepthLocked | function | Declared here |
beginEmitLocked | function | Declared here |
endEmitLocked | function | Declared here |
requestSweepLocked | function | Declared here |
consumeSweepRequest | function | Declared here |
sweepLocked | function | Declared here |
finishEmit | function | Declared here |
clearNodesLocked | function | Declared here |
resetEmitState | function | Declared here |
snapshotState | function | Declared here |
restoreState | function | Declared here |
threadSafe | variable | Declared here |
Public Methods
| Return | Name | Description |
|---|---|---|
int | attach const inline | Connects a lambda or std::function to the signal. |
int | attach const inline | Connects a pre-constructed SlotPtr to the signal. |
bool | detach const inline | Detaches the slot with the given ID. |
bool | detach const inline | Detaches all slots associated with the given instance pointer. |
bool | detach const inline | Detaches the slot whose delegate compares equal to other->delegate. |
void | detachAll const inline | Detaches and destroys all currently attached slots. |
RT | emit virtual inline | Emits the signal, invoking all live attached slots in priority order. |
std::vector< SlotPtr > | slots const inline | Returns a snapshot copy of the current slot list. |
size_t | nslots const inline | Returns the number of slots currently registered with this signal. |
int | operator+= inline | Attaches a function; equivalent to attach(func). |
int | operator+= inline | Attaches a pre-constructed slot; equivalent to attach(slot). |
bool | operator-= inline | Detaches the slot with the given ID; equivalent to detach(id). |
bool | operator-= inline | Detaches all slots for the given instance; equivalent to detach(instance). |
bool | operator-= inline | Detaches the slot matching slot's delegate; equivalent to detach(slot). |
Signal | Defaulted constructor. | |
Signal inline | Copy constructor; copies the slot list and last-assigned ID from r. | |
Signal & | operator= inline | Copy assignment operator; copies the slot list and last-assigned ID from r. |
attach
const inline
inline int attach(Function const & func, void * instance = nullptr, int id = -1, int priority = -1) constDefined in src/base/include/icy/signal.h:157
Connects a lambda or std::function to the signal.
Parameters
funcThe callable to invoke when the signal is emitted.instanceOptional owner pointer used for instance-based detach; passnullptrif not applicable.idExplicit slot ID to assign; pass-1to auto-assign.priorityHigher values are called first; pass-1for default ordering.
Returns
The assigned slot ID, which can be passed to [detach()](#detach-2) to disconnect.
attach
const inline
inline int attach(SlotPtr slot) constDefined in src/base/include/icy/signal.h:171
Connects a pre-constructed SlotPtr to the signal.
Duplicate slots (matched by delegate equality) are removed before insertion. Slots are kept sorted in descending priority order after insertion.
Parameters
slotThe slot to attach. Must have a valid delegate.
Returns
The assigned slot ID, which can be passed to [detach()](#detach-2) to disconnect.
Exceptions
std::logic_errorifslot->idis set explicitly and already in use.
detach
const inline
inline bool detach(int id) constDefined in src/base/include/icy/signal.h:202
Detaches the slot with the given ID.
Safe to call from within a slot's callback (the slot is marked dead before erasure).
Parameters
idThe slot ID returned by[attach()](#attach-3).
Returns
true if a slot was found and removed; false if the ID was not found.
detach
const inline
inline bool detach(const void * instance) constDefined in src/base/include/icy/signal.h:219
Detaches all slots associated with the given instance pointer.
Useful for bulk disconnect when an object is destroyed. Matches slots by their stored instance pointer, not by delegate equality.
Parameters
instanceThe owner pointer used when the slots were attached.
Returns
true if at least one slot was removed; false otherwise.
detach
const inline
inline bool detach(SlotPtr other) constDefined in src/base/include/icy/signal.h:236
Detaches the slot whose delegate compares equal to other->delegate.
Used by the [slot()](webrtcsupport.html#slot) helper overloads and operator-= to disconnect a specific class-member or function binding by value.
Parameters
otherA slot whose delegate is compared against attached slots.
Returns
true if a matching slot was found and removed; false otherwise.
detachAll
const inline
inline void detachAll() constDefined in src/base/include/icy/signal.h:249
Detaches and destroys all currently attached slots.
Each slot is marked dead before removal. After this call [nslots()](#nslots) returns 0.
emit
virtual inline
virtual inline RT emit(Args... args)Defined in src/base/include/icy/signal.h:283
Emits the signal, invoking all live attached slots in priority order.
For [Signal](icy-Signal.html#signal)<bool(...)>: iterates slots and returns true as soon as any slot returns true, stopping further propagation. Returns false if no slot handled the event.
For [Signal](icy-Signal.html#signal)<void(...)>: calls every live slot unconditionally.
Local [Signal](icy-Signal.html#signal)<...> traverses the stable slot list directly without any snapshot allocation. ThreadSignal<...> snapshots raw node pointers under a shared lock, then invokes delegates without holding the lock. Dead slots are swept after the outermost emission returns, allowing attach/detach inside callbacks without copying shared_ptrs on the hot path.
Parameters
argsArguments forwarded to each connected slot.
Returns
For bool return type: true if any slot handled the event, false otherwise. For void return type: nothing.
slots
const inline
inline std::vector< SlotPtr > slots() constDefined in src/base/include/icy/signal.h:354
Returns a snapshot copy of the current slot list.
The copy is taken under a shared lock, so it is safe to call concurrently with attach/detach operations. Only currently live slots are returned.
Returns
A vector of SlotPtr representing all currently registered slots.
nslots
const inline
inline size_t nslots() constDefined in src/base/include/icy/signal.h:372
Returns the number of slots currently registered with this signal.
The count is taken under a shared lock and tracks only currently live slots. Dead-but-not-yet-swept nodes are excluded.
Returns
The number of entries in the internal slot list.
operator+=
inline
inline int operator+=(Function const & func)Defined in src/base/include/icy/signal.h:379
Attaches a function; equivalent to attach(func).
Returns
Assigned slot ID.
operator+=
inline
inline int operator+=(SlotPtr slot)Defined in src/base/include/icy/signal.h:381
Attaches a pre-constructed slot; equivalent to attach(slot).
Returns
Assigned slot ID.
operator-=
inline
inline bool operator-=(int id)Defined in src/base/include/icy/signal.h:383
Detaches the slot with the given ID; equivalent to detach(id).
Returns
true if removed.
operator-=
inline
inline bool operator-=(const void * instance)Defined in src/base/include/icy/signal.h:385
Detaches all slots for the given instance; equivalent to detach(instance).
Returns
true if any removed.
operator-=
inline
inline bool operator-=(SlotPtr slot)Defined in src/base/include/icy/signal.h:387
Detaches the slot matching slot's delegate; equivalent to detach(slot).
Returns
true if removed.
Signal
Signal() = defaultDefined in src/base/include/icy/signal.h:389
Defaulted constructor.
Signal
inline
inline Signal(const Signal & r)Defined in src/base/include/icy/signal.h:398
Copy constructor; copies the slot list and last-assigned ID from r.
Parameters
rThe signal to copy from.
operator=
inline
inline Signal & operator=(const Signal & r)Defined in src/base/include/icy/signal.h:407
Copy assignment operator; copies the slot list and last-assigned ID from r.
Parameters
rThe signal to copy from.
Returns
Reference to this signal.
Public Types
Function
using Function = std::function< RT(Args...)>Defined in src/base/include/icy/signal.h:145
SlotPtr
using SlotPtr = std::shared_ptr< internal::Slot< RT, Args... > >Defined in src/base/include/icy/signal.h:146
Slot
using Slot = internal::Slot< RT, Args... >Defined in src/base/include/icy/signal.h:147
SlotNode
using SlotNode = internal::SlotNode< RT, Args... >Defined in src/base/include/icy/signal.h:148
Private Attributes
| Return | Name | Description |
|---|---|---|
MutexT | _mutex | |
SlotNode * | _head | |
SlotNode * | _tail | |
size_t | _liveCount | |
int | _lastId | |
EmitDepth | _emitDepth | |
SweepFlag | _needsSweep |
_mutex
MutexT _mutexDefined in src/base/include/icy/signal.h:615
_head
SlotNode * _head = nullptrDefined in src/base/include/icy/signal.h:616
_tail
SlotNode * _tail = nullptrDefined in src/base/include/icy/signal.h:617
_liveCount
size_t _liveCount = 0Defined in src/base/include/icy/signal.h:618
_lastId
int _lastId = 0Defined in src/base/include/icy/signal.h:619
_emitDepth
EmitDepth _emitDepth {}Defined in src/base/include/icy/signal.h:620
_needsSweep
SweepFlag _needsSweep {}Defined in src/base/include/icy/signal.h:621
Private Methods
| Return | Name | Description |
|---|---|---|
size_t | killMatchingLocked const inline | |
void | insertSlotLocked const inline | |
void | appendSlotLocked const inline | |
void | eraseNodeLocked const inline | |
size_t | emitDepthLocked const inline | |
void | beginEmitLocked const inline | |
bool | endEmitLocked const inline | |
void | requestSweepLocked const inline | |
bool | consumeSweepRequest const inline | |
void | sweepLocked const inline | |
void | finishEmit inline | |
void | clearNodesLocked const inline | |
void | resetEmitState inline | |
std::pair< std::vector< SlotPtr >, int > | snapshotState const inline | |
void | restoreState inline |
killMatchingLocked
const inline
template<typename Matcher> inline size_t killMatchingLocked(Matcher && matcher, bool removeAll) constDefined in src/base/include/icy/signal.h:422
insertSlotLocked
const inline
inline void insertSlotLocked(SlotPtr slot) constDefined in src/base/include/icy/signal.h:448
appendSlotLocked
const inline
inline void appendSlotLocked(SlotPtr slot) constDefined in src/base/include/icy/signal.h:475
eraseNodeLocked
const inline
inline void eraseNodeLocked(SlotNode * node) constDefined in src/base/include/icy/signal.h:487
emitDepthLocked
const inline
inline size_t emitDepthLocked() constDefined in src/base/include/icy/signal.h:502
beginEmitLocked
const inline
inline void beginEmitLocked() constDefined in src/base/include/icy/signal.h:510
endEmitLocked
const inline
inline bool endEmitLocked() constDefined in src/base/include/icy/signal.h:518
requestSweepLocked
const inline
inline void requestSweepLocked() constDefined in src/base/include/icy/signal.h:526
consumeSweepRequest
const inline
inline bool consumeSweepRequest() constDefined in src/base/include/icy/signal.h:534
sweepLocked
const inline
inline void sweepLocked() constDefined in src/base/include/icy/signal.h:545
finishEmit
inline
inline void finishEmit()Defined in src/base/include/icy/signal.h:555
clearNodesLocked
const inline
inline void clearNodesLocked() constDefined in src/base/include/icy/signal.h:570
resetEmitState
inline
inline void resetEmitState()Defined in src/base/include/icy/signal.h:583
snapshotState
const inline
inline std::pair< std::vector< SlotPtr >, int > snapshotState() constDefined in src/base/include/icy/signal.h:594
restoreState
inline
inline void restoreState(std::vector< SlotPtr > snapshot, int lastId)Defined in src/base/include/icy/signal.h:606
Private Static Attributes
| Return | Name | Description |
|---|---|---|
constexpr bool | threadSafe static constexpr |
threadSafe
static constexpr
constexpr bool threadSafe = !std::is_same_v<MutexT, >