@@ -48,9 +48,7 @@ void PrintFreeRam(void) {
48
48
******************************************************************************/
49
49
50
50
ArduinoCloudThing::ArduinoCloudThing () :
51
- _get_time_func{nullptr },
52
- _numPrimitivesProperties (0 ),
53
- _numProperties(0 ),
51
+ _property_container{nullptr },
54
52
_isSyncMessage (false ),
55
53
_currentPropertyName(" " ),
56
54
_currentPropertyBaseTime(0 ),
@@ -61,11 +59,9 @@ ArduinoCloudThing::ArduinoCloudThing() :
61
59
PUBLIC MEMBER FUNCTIONS
62
60
******************************************************************************/
63
61
64
- void ArduinoCloudThing::begin () {
65
- }
66
-
67
- void ArduinoCloudThing::registerGetTimeCallbackFunc (GetTimeCallbackFunc func) {
68
- _get_time_func = func;
62
+ void ArduinoCloudThing::begin (PropertyContainer * property_container)
63
+ {
64
+ _property_container = property_container;
69
65
}
70
66
71
67
int ArduinoCloudThing::encode (uint8_t * data, size_t const size, bool lightPayload) {
@@ -80,7 +76,7 @@ int ArduinoCloudThing::encode(uint8_t * data, size_t const size, bool lightPaylo
80
76
return -1 ;
81
77
}
82
78
83
- if (appendChangedProperties (&arrayEncoder, lightPayload) < 1 ) {
79
+ if (_property_container-> appendChangedProperties (&arrayEncoder, lightPayload) < 1 ) {
84
80
return -1 ;
85
81
}
86
82
@@ -95,21 +91,6 @@ int ArduinoCloudThing::encode(uint8_t * data, size_t const size, bool lightPaylo
95
91
return bytes_encoded;
96
92
}
97
93
98
- ArduinoCloudProperty& ArduinoCloudThing::addPropertyReal (ArduinoCloudProperty & property, String const & name, Permission const permission, int propertyIdentifier) {
99
- property.init (name, permission, _get_time_func);
100
- if (isPropertyInContainer (name)) {
101
- return (*getProperty (name));
102
- } else {
103
- if (property.isPrimitive ()) {
104
- _numPrimitivesProperties++;
105
- }
106
- _numProperties++;
107
- addProperty (&property, propertyIdentifier);
108
- return (property);
109
- }
110
-
111
- }
112
-
113
94
void ArduinoCloudThing::decode (uint8_t const * const payload, size_t const length, bool isSyncMessage) {
114
95
_isSyncMessage = isSyncMessage;
115
96
@@ -161,81 +142,6 @@ void ArduinoCloudThing::decode(uint8_t const * const payload, size_t const lengt
161
142
}
162
143
}
163
144
164
- bool ArduinoCloudThing::isPropertyInContainer (String const & name)
165
- {
166
- return (getProperty (name) != nullptr );
167
- }
168
-
169
- int ArduinoCloudThing::appendChangedProperties (CborEncoder * arrayEncoder, bool lightPayload)
170
- {
171
- int appendedProperties = 0 ;
172
- std::for_each (_property_list.begin (),
173
- _property_list.end (),
174
- [arrayEncoder, lightPayload, &appendedProperties](ArduinoCloudProperty * p)
175
- {
176
- if (p->shouldBeUpdated () && p->isReadableByCloud ())
177
- {
178
- p->append (arrayEncoder, lightPayload);
179
- appendedProperties++;
180
- }
181
- });
182
- return appendedProperties;
183
- }
184
-
185
- // retrieve property by name
186
- ArduinoCloudProperty * ArduinoCloudThing::getProperty (String const & name)
187
- {
188
- std::list<ArduinoCloudProperty *>::iterator iter;
189
-
190
- iter = std::find_if (_property_list.begin (),
191
- _property_list.end (),
192
- [name](ArduinoCloudProperty * p) -> bool
193
- {
194
- return (p->name () == name);
195
- });
196
-
197
- if (iter == _property_list.end ())
198
- return nullptr ;
199
- else
200
- return (*iter);
201
- }
202
-
203
- // retrieve property by identifier
204
- ArduinoCloudProperty * ArduinoCloudThing::getProperty (int const & pos)
205
- {
206
- std::list<ArduinoCloudProperty *>::iterator iter;
207
-
208
- iter = std::find_if (_property_list.begin (),
209
- _property_list.end (),
210
- [pos](ArduinoCloudProperty * p) -> bool
211
- {
212
- return (p->identifier () == pos);
213
- });
214
-
215
- if (iter == _property_list.end ())
216
- return nullptr ;
217
- else
218
- return (*iter);
219
- }
220
-
221
- // this function updates the timestamps on the primitive properties that have been modified locally since last cloud synchronization
222
- void ArduinoCloudThing::updateTimestampOnLocallyChangedProperties ()
223
- {
224
- if (_numPrimitivesProperties > 0 )
225
- {
226
- std::for_each (_property_list.begin (),
227
- _property_list.end (),
228
- [](ArduinoCloudProperty * p)
229
- {
230
- CloudWrapperBase * pbase = reinterpret_cast <CloudWrapperBase *>(p);
231
- if (pbase->isPrimitive () && pbase->isChangedLocally () && pbase->isReadableByCloud ())
232
- {
233
- p->updateLocalTimestamp ();
234
- }
235
- });
236
- }
237
- }
238
-
239
145
/* *****************************************************************************
240
146
PRIVATE MEMBER FUNCTIONS
241
147
******************************************************************************/
@@ -511,7 +417,7 @@ void ArduinoCloudThing::freeMapDataList(std::list<CborMapData *> * map_data_list
511
417
}
512
418
513
419
void ArduinoCloudThing::updateProperty (String propertyName, unsigned long cloudChangeEventTime) {
514
- ArduinoCloudProperty* property = getProperty (propertyName);
420
+ ArduinoCloudProperty* property = _property_container-> getProperty (propertyName);
515
421
if (property && property->isWriteableByCloud ()) {
516
422
property->setLastCloudChangeTimestamp (cloudChangeEventTime);
517
423
property->setAttributesFromCloud (&_map_data_list);
@@ -528,9 +434,9 @@ void ArduinoCloudThing::updateProperty(String propertyName, unsigned long cloudC
528
434
String ArduinoCloudThing::getPropertyNameByIdentifier (int propertyIdentifier) {
529
435
ArduinoCloudProperty* property;
530
436
if (propertyIdentifier > 255 ) {
531
- property = getProperty (propertyIdentifier & 255 );
437
+ property = _property_container-> getProperty (propertyIdentifier & 255 );
532
438
} else {
533
- property = getProperty (propertyIdentifier);
439
+ property = _property_container-> getProperty (propertyIdentifier);
534
440
}
535
441
return property->name ();
536
442
}
0 commit comments