spejsiot/spejsiot/Endpoint.h

72 lines
1.5 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;
}
void onConnected();
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-03-06 16:56:37 +00:00
struct endpoint_def {
char* name;
Endpoint* (*constructor)(void);
};
2016-09-18 08:30:34 +00:00
2017-03-06 16:56:37 +00:00
//extern int __papiez_pedofil;
2016-09-18 08:30:34 +00:00
2017-03-06 16:56:37 +00:00
extern struct endpoint_def* __stop_endpoints[];
extern struct endpoint_def* __start_endpoints[];
2016-09-19 23:03:11 +00:00
2017-03-06 16:56:37 +00:00
#define DECLARE_ENDPOINT(name, constructor) \
struct endpoint_def name ## _def __attribute__ ((section (".endpoints"))) = {\
(char*) #name, constructor \
};
2017-03-06 16:56:37 +00:00
// static struct endpoint_def name ## _def = { \
// (char*) #name, constructor \
// }; \
//& name##_def
2017-03-06 16:56:37 +00:00
#define ENDPOINTS_COUNT (((uint8_t*) __stop_endpoints - (uint8_t*) __start_endpoints) / sizeof(struct endpoint_def))
2016-09-18 08:30:34 +00:00
#endif