spejsiot/spejsiot/Endpoint.h

55 lines
1.1 KiB
C
Raw Normal View History

2016-09-18 08:30:34 +00:00
#ifndef ENDPOINT_H
#define ENDPOINT_H
#include <SmingCore/SmingCore.h>
class SpejsNode;
class EndpointResult {
public:
int status;
String description;
EndpointResult(int _status) : status(_status) {}
EndpointResult(int _status, String _description) :
status(_status), description(_description) {}
};
class Endpoint {
protected:
2016-09-19 23:03:11 +00:00
SpejsNode* parent;
String name;
2016-09-18 08:30:34 +00:00
public:
String type;
Endpoint(String _type = "unknown") : type(_type) { }
virtual void bind(String _name, SpejsNode* _parent);
void notify(String property, String value);
2016-09-18 08:30:34 +00:00
2017-03-06 16:56:37 +00:00
virtual void onMessage(String topic, String payload);
virtual EndpointResult onValue(String property, String value) {
2016-09-18 08:30:34 +00:00
return 400;
}
2017-06-12 15:40:23 +00:00
virtual void onConnected();
2017-10-01 21:24:41 +00:00
static Endpoint* fromJSON(JsonObject& obj) {
return NULL;
}
2016-09-18 08:30:34 +00:00
};
2016-09-19 23:03:11 +00:00
template <class T> class ValueEndpoint : public Endpoint {
2016-09-18 08:30:34 +00:00
protected:
T value;
void updateValue(T newValue);
public:
2016-09-19 23:03:11 +00:00
ValueEndpoint(String _type) : Endpoint(_type) {}
2016-09-18 08:30:34 +00:00
};
2017-10-01 21:24:41 +00:00
typedef Endpoint* (*EndpointInitializer) (JsonObject&);
2016-09-18 08:30:34 +00:00
#endif