#ifndef ENDPOINT_H #define ENDPOINT_H #include 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: SpejsNode* parent; String name; public: String type; Endpoint(String _type = "unknown") : type(_type) { } virtual void bind(String _name, SpejsNode* _parent); void notify(String property, String value); virtual void onMessage(String topic, String payload); virtual EndpointResult onValue(String property, String value) { return 400; } virtual void onConnected(); }; template class ValueEndpoint : public Endpoint { protected: T value; void updateValue(T newValue); public: ValueEndpoint(String _type) : Endpoint(_type) {} }; struct endpoint_def { char* name; Endpoint* (*constructor)(void); }; //extern int __papiez_pedofil; extern struct endpoint_def* __stop_endpoints[]; extern struct endpoint_def* __start_endpoints[]; #define DECLARE_ENDPOINT(name, constructor) \ struct endpoint_def name ## _def __attribute__ ((section (".endpoints"))) = {\ (char*) #name, constructor \ }; // static struct endpoint_def name ## _def = { \ // (char*) #name, constructor \ // }; \ //& name##_def #define ENDPOINTS_COUNT (((uint8_t*) __stop_endpoints - (uint8_t*) __start_endpoints) / sizeof(struct endpoint_def)) #endif