SensESP 3.6.1-alpha
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
signalk_put_request_listener.h
Go to the documentation of this file.
1#ifndef SENSESP_SIGNALK_SIGNALK_PUT_REQUEST_LISTENER_H_
2#define SENSESP_SIGNALK_SIGNALK_PUT_REQUEST_LISTENER_H_
3
4#include "sensesp.h"
5
6#include <ArduinoJson.h>
7#include <set>
8
11
12namespace sensesp {
13
20class SKPutListener : virtual public Observable {
21 public:
27 SKPutListener(const String& sk_path);
28
34 virtual ~SKPutListener();
35
36 String& get_sk_path() { return sk_path; }
37
38 virtual void parse_value(const JsonObject& put) = 0;
39
40 static const std::vector<SKPutListener*>& get_listeners() {
41 return listeners_;
42 }
43
48 static void clear_registry();
49
50 protected:
51 String sk_path{};
52
53 private:
54 static std::vector<SKPutListener*> listeners_;
55 int listen_delay{};
56};
57
63template <class T>
65 public:
67 if (sk_path == "") {
68 ESP_LOGE(
69 __FILENAME__,
70 "SKPutRequestListener: User has provided no sk_path to respond to.");
71 }
72 }
73
74 void parse_value(const JsonObject& put) override {
75 this->emit(put["value"].as<T>());
76 }
77};
78
83
84} // namespace sensesp
85
86#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 PUT requests coming over the websocket connection and no...
static const std::vector< SKPutListener * > & get_listeners()
virtual void parse_value(const JsonObject &put)=0
An object that listens for PUT requests to come in for the specified SignalK path....
void parse_value(const JsonObject &put) override
A base class for any sensor or piece of code that outputs a value for consumption elsewhere.
void emit(const T &new_value)
SKPutRequestListener< int > IntSKPutRequestListener
SKPutRequestListener< bool > BoolSKPutRequestListener
SKPutRequestListener< String > StringSKPutRequestListener
SKPutRequestListener< float > FloatSKPutRequestListener