SensESP 3.4.1-alpha
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
signalk_listener.h
Go to the documentation of this file.
1#ifndef SENSESP_SIGNALK_LISTENER_H_
2#define SENSESP_SIGNALK_LISTENER_H_
3
4#include "sensesp.h"
5
6#include <ArduinoJson.h>
7#include <memory>
8#include <set>
9
13
14namespace sensesp {
15
23class SKListener : virtual public Observable, public FileSystemSaveable {
24 public:
35 SKListener(const String& sk_path, int listen_delay,
36 const String& config_path = "");
37
43 virtual ~SKListener();
44
50 String& get_sk_path() { return sk_path; }
51
52 int get_listen_delay() { return listen_delay; }
53
54 virtual void parse_value(const JsonObject& json) {}
55
63 virtual bool wants_meta() const { return false; }
64
72 virtual void parse_meta(const std::shared_ptr<const JsonDocument>& meta_doc) {}
73
74 static const std::vector<SKListener*>& get_listeners() { return listeners_; }
75
80 static void clear_registry();
81
82 static bool take_semaphore(uint64_t timeout_ms = 0);
83 static void release_semaphore();
84
85 protected:
86 String sk_path{};
87
88 private:
89 static std::vector<SKListener*> listeners_;
90 int listen_delay;
91 static StaticSemaphore_t semaphore_buffer_;
92 static SemaphoreHandle_t semaphore_;
93
94 virtual bool to_json(JsonObject& root) override;
95 virtual bool from_json(const JsonObject& config) override;
96
97 void set_sk_path(const String& path);
98};
99
100const String ConfigSchema(const SKListener& obj);
101
102} // namespace sensesp
103
104#endif
A base class which allow observers to attach callbacks to themselves. The callbacks will be called wh...
Definition observable.h:16
An Obervable class that listens for Signal K stream deltas and notifies any observers of value change...
static bool take_semaphore(uint64_t timeout_ms=0)
static void release_semaphore()
virtual void parse_value(const JsonObject &json)
virtual void parse_meta(const std::shared_ptr< const JsonDocument > &meta_doc)
static const std::vector< SKListener * > & get_listeners()
static void clear_registry()
virtual bool wants_meta() const
const String ConfigSchema(const SmartSwitchController &obj)