Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::audio::AudioFocusRegistry Class Reference

#include <audio_focus.hpp>

Classes

class  Token
 RAII subscription token. Move-only; destruction unsubscribes. More...

Public Types

using Callback = std::function<void(AudioFocusState)>

Public Member Functions

Token subscribe (Callback cb)
 Subscribe a callback.
void publish (AudioFocusState state)
 Publish a new state.
AudioFocusState current () const noexcept
 Snapshot the last published state.
void reset_for_test ()
 Reset for tests — clears all subscribers + state.

Static Public Member Functions

static AudioFocusRegistry & instance ()

Friends

class Token

Member Typedef Documentation

◆ Callback

Member Function Documentation

◆ current()

AudioFocusState pulp::audio::AudioFocusRegistry::current ( ) const
inlinenoexcept

Snapshot the last published state.

Lock-free. Safe to call from the audio thread.

◆ instance()

AudioFocusRegistry & pulp::audio::AudioFocusRegistry::instance ( )
static

◆ publish()

void pulp::audio::AudioFocusRegistry::publish ( AudioFocusState state)

Publish a new state.

Dispatches to all current subscribers OUTSIDE the internal mutex so a listener that drops its own token (and re-enters unsubscribe) does not deadlock.

◆ reset_for_test()

void pulp::audio::AudioFocusRegistry::reset_for_test ( )

Reset for tests — clears all subscribers + state.

◆ subscribe()

Token pulp::audio::AudioFocusRegistry::subscribe ( Callback cb)

Subscribe a callback.

Callback fires on the thread that calls publish() — typically the JNI thread for Android, main thread on iOS. Callbacks must be cheap and must not block the audio thread; the usual pattern is to stash the state in an atomic and read it from the audio callback.

◆ Token

friend class Token
friend

The documentation for this class was generated from the following file:
  • /home/runner/work/pulp/pulp/core/audio/include/pulp/audio/audio_focus.hpp