forked from WebThingsIO/webthing-arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Thing.h
80 lines (68 loc) · 1.57 KB
/
Thing.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
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* Thing.h
*
* Provides ThingProperty and ThingDevice classes for creating modular Web
* Things.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef MOZILLA_IOT_THING_H
#define MOZILLA_IOT_THING_H
enum ThingPropertyType {
BOOLEAN,
NUMBER,
STRING
};
union ThingPropertyValue {
bool boolean;
double number;
String* string;
};
class ThingProperty {
public:
String id;
String description;
ThingPropertyType type;
String atType;
ThingProperty* next = nullptr;
ThingProperty(const char* id_, const char* description_, ThingPropertyType type_, const char* atType_):
id(id_),
description(description_),
type(type_),
atType(atType_) {
}
void setValue(ThingPropertyValue newValue) {
this->value = newValue;
}
ThingPropertyValue getValue() {
return this->value;
}
private:
ThingPropertyValue value = {false};
};
class ThingDevice {
public:
String id;
String name;
const char** type;
ThingDevice* next = nullptr;
ThingProperty* firstProperty = nullptr;
ThingProperty* lastProperty = nullptr;
ThingDevice(const char* _id, const char* _name, const char** _type):
id(_id),
name(_name),
type(_type) {
}
void addProperty(ThingProperty* property) {
if (lastProperty == nullptr) {
firstProperty = property;
lastProperty = property;
} else {
lastProperty->next = property;
lastProperty = property;
}
}
};
#endif