SensESP 3.5.1-alpha
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
sensesp::SKMetadataListener Class Reference

A ValueProducer that listens to the metadata stream for a single Signal K path and emits a typed SKMetaView whenever it changes. More...

#include <sensesp/signalk/signalk_metadata_listener.h>

Inheritance diagram for sensesp::SKMetadataListener:
[legend]

Public Member Functions

 SKMetadataListener (const String &sk_path, int listen_delay=1000, const String &config_path="")
 
bool wants_meta () const override
 
void parse_meta (const std::shared_ptr< const JsonDocument > &meta_doc) override
 
- Public Member Functions inherited from sensesp::SKListener
 SKListener (const String &sk_path, int listen_delay, const String &config_path="")
 
virtual ~SKListener ()
 
String & get_sk_path ()
 
int get_listen_delay ()
 
virtual bool matches (const String &path) const
 
virtual void parse_value (const JsonObject &json)
 
- Public Member Functions inherited from sensesp::Observable
 Observable ()
 
 Observable (Observable &&other)
 Move constructor.
 
void notify ()
 
int attach (std::function< void()> observer)
 Attach an observer callback.
 
void detach (int id)
 Remove a previously attached observer by its ID.
 
- Public Member Functions inherited from sensesp::FileSystemSaveable
 FileSystemSaveable (const String &config_path)
 
virtual bool load () override
 Load and populate the object from a persistent storage.
 
virtual bool save () override
 Save the object to a persistent storage.
 
virtual bool clear () override
 Delete the data from a persistent storage.
 
bool find_config_file (const String &config_path, String &filename)
 
- Public Member Functions inherited from sensesp::Saveable
 Saveable (const String &config_path)
 
virtual bool refresh ()
 Refresh the object. This may or may not access the persistent storage but is not expected to overwrite the object's state.
 
const String & get_config_path () const
 
- Public Member Functions inherited from sensesp::ValueProducer< SKMetaView >
 ValueProducer ()
 
 ValueProducer (const SKMetaView &initial_value)
 
virtual const SKMetaViewget () const
 
std::enable_if< std::is_base_of< ValueConsumer< typenameVConsumer::input_type >, VConsumer >::value &&std::is_convertible< SKMetaView, typenameVConsumer::input_type >::value, std::shared_ptr< VConsumer > >::type connect_to (std::shared_ptr< VConsumer > consumer)
 Connect a producer to a transform with a different input type.
 
std::enable_if< std::is_base_of< ValueConsumer< typenameVConsumer::input_type >, VConsumer >::value &&std::is_convertible< SKMetaView, typenameVConsumer::input_type >::value, VConsumer * >::type connect_to (VConsumer *consumer)
 
std::enable_if< std::is_base_of< ValueConsumer< typenameVConsumer::input_type >, VConsumer >::value &&std::is_convertible< SKMetaView, typenameVConsumer::input_type >::value, VConsumer * >::type connect_to (VConsumer &consumer)
 
void emit (const SKMetaView &new_value)
 

Additional Inherited Members

- Static Public Member Functions inherited from sensesp::SKListener
static const std::vector< SKListener * > & get_listeners ()
 
static void clear_registry ()
 
static bool take_semaphore (uint64_t timeout_ms=0)
 
static void release_semaphore ()
 
- Protected Attributes inherited from sensesp::SKListener
String sk_path {}
 
- Protected Attributes inherited from sensesp::Saveable
const String config_path_
 
- Protected Attributes inherited from sensesp::ValueProducer< SKMetaView >
SKMetaView output_
 

Detailed Description

A ValueProducer that listens to the metadata stream for a single Signal K path and emits a typed SKMetaView whenever it changes.

Mirrors SKValueListener but consumes updates[].meta[] entries instead of updates[].values[]. Metadata deltas are only pushed by the server when the stream is subscribed with sendMeta=all (the SKWSClient default).

The emitted SKMetaView exposes the common fields (units, displayName, zones, ...) as typed members and retains the full meta object in raw, so it is both ergonomic and lossless. It is safe for any deferred consumer (e.g. UI work marshalled onto the event loop): the typed members are owned values and raw is a refcounted owned document, so nothing aliases the transient receive document.

Because it is-a SKListener, its path is subscribed automatically by SKWSClient::subscribe_listeners(), and process_received_updates routes meta deltas to it via the out-of-band queue tag plus wants_meta().

Example:

auto ml = std::make_shared<SKMetadataListener>("environment.depth.belowKeel");
ml->connect_to(new LambdaConsumer<SKMetaView>([](const SKMetaView& m) {
gauge.set_units(m.units);
gauge.set_zones(m.zones);
}));
Provides an easy way of calling a function based on the output of any ValueProducer.
A typed, read-only view of Signal K metadata received for a path.
std::vector< SKZone > zones
See also
SKValueListener
SKMetaView
SKWSClient

Definition at line 121 of file signalk_metadata_listener.h.

Constructor & Destructor Documentation

◆ SKMetadataListener()

sensesp::SKMetadataListener::SKMetadataListener ( const String &  sk_path,
int  listen_delay = 1000,
const String &  config_path = "" 
)
inline
Parameters
sk_pathThe Signal K path to listen to for metadata changes
listen_delayThe minimum interval between updates in ms
config_pathOptional configuration path

Definition at line 129 of file signalk_metadata_listener.h.

Member Function Documentation

◆ parse_meta()

void sensesp::SKMetadataListener::parse_meta ( const std::shared_ptr< const JsonDocument > &  meta_doc)
inlineoverridevirtual

Called on the main task by SKWSClient::process_received_updates with an already-owned, read-only metadata document moved off the receive queue (shape {path, value: {...meta...}}). Parses the typed view and emits it; the owned document backs SKMetaView::raw so the lossless data outlives any deferred consumer with no extra deep copy.

Reimplemented from sensesp::SKListener.

Definition at line 147 of file signalk_metadata_listener.h.

Here is the call graph for this function:

◆ wants_meta()

bool sensesp::SKMetadataListener::wants_meta ( ) const
inlineoverridevirtual

Whether this listener consumes metadata deltas (updates[].meta[]) rather than value deltas (updates[].values[]). Defaults to false; SKMetadataListener overrides it to true. Used by SKWSClient::process_received_updates to route a queued delta to the correct listener kind without RTTI (RTTI is commonly disabled on ESP32).

Reimplemented from sensesp::SKListener.

Definition at line 138 of file signalk_metadata_listener.h.


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