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

In-process notifier. More...

#include <environment.hpp>

Classes

class  Token
 RAII subscription. Drop to unsubscribe. More...

Public Types

using Listener

Public Member Functions

EnvironmentState snapshot () const
 Snapshot the current state. Safe from any thread.
Token subscribe (Listener listener)
 Subscribe to changes.
void publish (const EnvironmentState &next)
 Push a new state.

Static Public Member Functions

static Environment & instance ()
 Get the process singleton.
static void inject_for_test (const EnvironmentState &state)
 Replace the singleton state and notify listeners.
static void reset_for_test ()
 Reset the singleton to defaults and remove every listener.

Detailed Description

In-process notifier.

Listeners survive until the returned token is destroyed (RAII subscription pattern, same as runtime::Logger).

The notifier is intentionally a singleton — there's exactly one OS reporting these signals per process. Tests can call inject_for_test to drive the singleton without a real platform adapter.

Member Typedef Documentation

◆ Listener

Initial value:
std::function<void(const EnvironmentState&,
Bitmask of fields that changed in the snapshot delivered to a listener.
Definition environment.hpp:119
Snapshot of the full environment state.
Definition environment.hpp:142

Member Function Documentation

◆ inject_for_test()

void pulp::platform::Environment::inject_for_test ( const EnvironmentState & state)
static

Replace the singleton state and notify listeners.

Used by unit tests to simulate platform events without a real OS callback.

◆ instance()

Environment & pulp::platform::Environment::instance ( )
static

Get the process singleton.

◆ publish()

void pulp::platform::Environment::publish ( const EnvironmentState & next)

Push a new state.

Computes EnvironmentChange against the prior snapshot and dispatches to every listener. Intended for platform adapter code; tests use inject_for_test (which forwards here after taking the test mutex).

◆ reset_for_test()

void pulp::platform::Environment::reset_for_test ( )
static

Reset the singleton to defaults and remove every listener.

Tests call this in TEST_CASE setup so prior tests don't leak listeners or stale state.

◆ snapshot()

EnvironmentState pulp::platform::Environment::snapshot ( ) const

Snapshot the current state. Safe from any thread.

◆ subscribe()

Token pulp::platform::Environment::subscribe ( Listener listener)

Subscribe to changes.

The callback fires after publish returns the new state. The returned token unsubscribes on destruction.


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