This repository has been archived by the owner on Nov 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
WebThings.h
67 lines (59 loc) · 2.09 KB
/
WebThings.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Web of Things Framework for Arduino IDE
#ifndef _WOTF_FRAMEWORK
#define _WOTF_FRAMEWORK
#include "WebCore.h"
#define MAX_STALE 10
class Thing : public CoreThing
{
public:
void set_start(ThingFunc handler);
void set_stop(ThingFunc handler);
void set_property(Symbol property, JSON *value);
JSON *get_property(Symbol property);
int invoke(Symbol action, ...);
void register_action_handler(Symbol action, ActionFunc handler);
void register_observer(Symbol event, EventFunc handler);
void raise_event(Symbol event, ...);
void reachable(boolean phase);
void sweep(boolean phase);
void remove();
void print();
};
class Proxy : public CoreThing
{
public:
void set_property(Symbol property, JSON *value);
JSON *get_property(Symbol property);
int invoke(Symbol action, ...);
void register_response_handler(Symbol action, ResponseFunc handler);
void register_observer(Symbol event, EventFunc handler);
void raise_event(Symbol event, ...);
void reachable(boolean phase);
void sweep(boolean phase);
void remove();
void print();
};
class WebThings
{
public:
WebThings();
static unsigned int used();
#if defined(pgm_read_byte)
static void thing(const char *name, const __FlashStringHelper *model, SetupFunc setup);
#endif
static void thing(const char *name, char *model, SetupFunc setup);
static void register_proxy(const char *uri, ThingFunc setup);
static JSON *get_json(NPIndex index);
static NPIndex get_index(JSON *json);
static void collect_garbage();
static void remove_thing(Thing *thing);
static void remove_proxy(Proxy *proxy);
static void add_stale(JSON *json);
private:
static void reachable(NPIndex index);
static Thing *find_thing(const char *name);
static Proxy *find_proxy(const char *name);
static void register_thing(Thing *thing);
static boolean strcmp(const char *s1, const char *s2);
};
#endif