SensESP 3.4.0
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
29 String& get_sk_path() { return sk_path; }
30
31 virtual void parse_value(const JsonObject& put) = 0;
32
33 static const std::vector<SKPutListener*>& get_listeners() {
34 return listeners_;
35 }
36
37 protected:
38 String sk_path{};
39
40 private:
41 static std::vector<SKPutListener*> listeners_;
42 int listen_delay{};
43};
44
50template <class T>
52 public:
54 if (sk_path == "") {
55 ESP_LOGE(
56 __FILENAME__,
57 "SKPutRequestListener: User has provided no sk_path to respond to.");
58 }
59 }
60
61 void parse_value(const JsonObject& put) override {
62 this->emit(put["value"].as<T>());
63 }
64};
65
70
71} // namespace sensesp
72
73#endif
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
void emit(const T &new_value)
SKPutRequestListener< int > IntSKPutRequestListener
SKPutRequestListener< bool > BoolSKPutRequestListener
SKPutRequestListener< String > StringSKPutRequestListener
SKPutRequestListener< float > FloatSKPutRequestListener