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

An Obervable class that listens for Signal K stream deltas and notifies any observers of value changes. This serves as a base class for code that needs to listen to the stream, with the most common descendant being SKValueListener More...

#include <sensesp/signalk/signalk_listener.h>

Inheritance diagram for sensesp::SKListener:
[legend]

Public Member Functions

 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)
 
virtual bool wants_meta () const
 
virtual void parse_meta (const std::shared_ptr< const JsonDocument > &meta_doc)
 
- 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
 

Static Public Member Functions

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

String sk_path {}
 
- Protected Attributes inherited from sensesp::Saveable
const String config_path_
 

Detailed Description

An Obervable class that listens for Signal K stream deltas and notifies any observers of value changes. This serves as a base class for code that needs to listen to the stream, with the most common descendant being SKValueListener

See also
SKValueListener

Definition at line 23 of file signalk_listener.h.

Constructor & Destructor Documentation

◆ SKListener()

sensesp::SKListener::SKListener ( const String &  sk_path,
int  listen_delay,
const String &  config_path = "" 
)

The constructor

Parameters
sk_pathThe Signal K path that identifies this particular subscription to value
listen_delayHow often you want the SK Server to send the data you're subscribing to
config_pathThe optional configuration path that allows an end user to change the configuration of this object. See the Configurable class for more information.

Definition at line 15 of file signalk_listener.cpp.

Here is the call graph for this function:

◆ ~SKListener()

sensesp::SKListener::~SKListener ( )
virtual

Unregisters this listener from the static registry so the registry never holds a dangling pointer. Takes the listener semaphore because the WS client task iterates the registry under the same lock.

Definition at line 24 of file signalk_listener.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ clear_registry()

void sensesp::SKListener::clear_registry ( )
static

Empties the listener registry. Intended for clean app restart and test isolation; not for normal runtime use. Takes the listener semaphore.

Definition at line 31 of file signalk_listener.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_listen_delay()

int sensesp::SKListener::get_listen_delay ( )
inline

Definition at line 52 of file signalk_listener.h.

◆ get_listeners()

static const std::vector< SKListener * > & sensesp::SKListener::get_listeners ( )
inlinestatic

Definition at line 86 of file signalk_listener.h.

Here is the caller graph for this function:

◆ get_sk_path()

String & sensesp::SKListener::get_sk_path ( )
inline

Returns the current Signal K path. An empty string is returned if this particular source is not configured or intended to return actual data.

Definition at line 50 of file signalk_listener.h.

◆ matches()

virtual bool sensesp::SKListener::matches ( const String &  path) const
inlinevirtual

Whether a received delta on path should be routed to this listener.

Defaults to an exact match against sk_path. Listeners that observe a family of paths (e.g. a prefix subscription like notifications.*, where the server publishes on paths the client cannot enumerate in advance) override this to widen the match. SKWSClient::process_received_updates calls it per delta instead of comparing paths directly, so the routing policy lives with the listener.

Reimplemented in sensesp::SKPrefixListener.

Definition at line 64 of file signalk_listener.h.

Here is the caller graph for this function:

◆ parse_meta()

virtual void sensesp::SKListener::parse_meta ( const std::shared_ptr< const JsonDocument > &  meta_doc)
inlinevirtual

Consume a metadata delta for this listener's path. Mirrors parse_value for the meta stream: SKWSClient::process_received_updates calls it on the main task with an owned, read-only document (shape {path, value: {...meta...}}) that outlives any deferred consumer. Default is a no-op; SKMetadataListener overrides it.

Reimplemented in sensesp::SKMetadataListener.

Definition at line 84 of file signalk_listener.h.

Here is the caller graph for this function:

◆ parse_value()

virtual void sensesp::SKListener::parse_value ( const JsonObject &  json)
inlinevirtual

Reimplemented in sensesp::SKPrefixListener, and sensesp::SKValueListener< T >.

Definition at line 66 of file signalk_listener.h.

Here is the caller graph for this function:

◆ release_semaphore()

void sensesp::SKListener::release_semaphore ( )
static

Definition at line 45 of file signalk_listener.cpp.

Here is the caller graph for this function:

◆ take_semaphore()

bool sensesp::SKListener::take_semaphore ( uint64_t  timeout_ms = 0)
static

Definition at line 37 of file signalk_listener.cpp.

Here is the caller graph for this function:

◆ wants_meta()

virtual bool sensesp::SKListener::wants_meta ( ) const
inlinevirtual

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 in sensesp::SKMetadataListener.

Definition at line 75 of file signalk_listener.h.

Here is the caller graph for this function:

Member Data Documentation

◆ sk_path

String sensesp::SKListener::sk_path {}
protected

Definition at line 98 of file signalk_listener.h.


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