Skip to content

Commit 27c05bc

Browse files
authored
Merge pull request #339 from pennam/attributes-fix
Remove attributes macros
2 parents 9828845 + 7d5221c commit 27c05bc

18 files changed

+111
-127
lines changed

Diff for: src/property/Property.cpp

+18-25
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ void Property::execCallbackOnSync() {
170170
CborError Property::append(CborEncoder *encoder, bool lightPayload) {
171171
_lightPayload = lightPayload;
172172
_attributeIdentifier = 0;
173-
CHECK_CBOR(appendAttributesToCloudReal(encoder));
173+
CHECK_CBOR(appendAttributesToCloud(encoder));
174174
fromLocalToCloud();
175175
_has_been_updated_once = true;
176176
_has_been_modified_in_callback = false;
@@ -181,7 +181,7 @@ CborError Property::append(CborEncoder *encoder, bool lightPayload) {
181181
return CborNoError;
182182
}
183183

184-
CborError Property::appendAttributeReal(bool value, String attributeName, CborEncoder *encoder) {
184+
CborError Property::appendAttribute(bool value, String attributeName, CborEncoder *encoder) {
185185
return appendAttributeName(attributeName, [value](CborEncoder & mapEncoder)
186186
{
187187
CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast<int>(CborIntegerMapKey::BooleanValue)));
@@ -190,7 +190,7 @@ CborError Property::appendAttributeReal(bool value, String attributeName, CborEn
190190
}, encoder);
191191
}
192192

193-
CborError Property::appendAttributeReal(int value, String attributeName, CborEncoder *encoder) {
193+
CborError Property::appendAttribute(int value, String attributeName, CborEncoder *encoder) {
194194
return appendAttributeName(attributeName, [value](CborEncoder & mapEncoder)
195195
{
196196
CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast<int>(CborIntegerMapKey::Value)));
@@ -199,7 +199,7 @@ CborError Property::appendAttributeReal(int value, String attributeName, CborEnc
199199
}, encoder);
200200
}
201201

202-
CborError Property::appendAttributeReal(unsigned int value, String attributeName, CborEncoder *encoder) {
202+
CborError Property::appendAttribute(unsigned int value, String attributeName, CborEncoder *encoder) {
203203
return appendAttributeName(attributeName, [value](CborEncoder & mapEncoder)
204204
{
205205
CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast<int>(CborIntegerMapKey::Value)));
@@ -208,7 +208,7 @@ CborError Property::appendAttributeReal(unsigned int value, String attributeName
208208
}, encoder);
209209
}
210210

211-
CborError Property::appendAttributeReal(float value, String attributeName, CborEncoder *encoder) {
211+
CborError Property::appendAttribute(float value, String attributeName, CborEncoder *encoder) {
212212
return appendAttributeName(attributeName, [value](CborEncoder & mapEncoder)
213213
{
214214
CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast<int>(CborIntegerMapKey::Value)));
@@ -217,7 +217,7 @@ CborError Property::appendAttributeReal(float value, String attributeName, CborE
217217
}, encoder);
218218
}
219219

220-
CborError Property::appendAttributeReal(String value, String attributeName, CborEncoder *encoder) {
220+
CborError Property::appendAttribute(String value, String attributeName, CborEncoder *encoder) {
221221
return appendAttributeName(attributeName, [value](CborEncoder & mapEncoder)
222222
{
223223
CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast<int>(CborIntegerMapKey::StringValue)));
@@ -278,8 +278,8 @@ void Property::setAttributesFromCloud(std::list<CborMapData> * map_data_list) {
278278
setAttributesFromCloud();
279279
}
280280

281-
void Property::setAttributeReal(bool& value, String attributeName) {
282-
setAttributeReal(attributeName, [&value](CborMapData & md) {
281+
void Property::setAttribute(bool& value, String attributeName) {
282+
setAttribute(attributeName, [&value](CborMapData & md) {
283283
// Manage the case to have boolean values received as integers 0/1
284284
if (md.bool_val.isSet()) {
285285
value = md.bool_val.get();
@@ -295,34 +295,34 @@ void Property::setAttributeReal(bool& value, String attributeName) {
295295
});
296296
}
297297

298-
void Property::setAttributeReal(int& value, String attributeName) {
299-
setAttributeReal(attributeName, [&value](CborMapData & md) {
298+
void Property::setAttribute(int& value, String attributeName) {
299+
setAttribute(attributeName, [&value](CborMapData & md) {
300300
value = md.val.get();
301301
});
302302
}
303303

304-
void Property::setAttributeReal(unsigned int& value, String attributeName) {
305-
setAttributeReal(attributeName, [&value](CborMapData & md) {
304+
void Property::setAttribute(unsigned int& value, String attributeName) {
305+
setAttribute(attributeName, [&value](CborMapData & md) {
306306
value = md.val.get();
307307
});
308308
}
309309

310-
void Property::setAttributeReal(float& value, String attributeName) {
311-
setAttributeReal(attributeName, [&value](CborMapData & md) {
310+
void Property::setAttribute(float& value, String attributeName) {
311+
setAttribute(attributeName, [&value](CborMapData & md) {
312312
value = md.val.get();
313313
});
314314
}
315315

316-
void Property::setAttributeReal(String& value, String attributeName) {
317-
setAttributeReal(attributeName, [&value](CborMapData & md) {
316+
void Property::setAttribute(String& value, String attributeName) {
317+
setAttribute(attributeName, [&value](CborMapData & md) {
318318
value = md.str_val.get();
319319
});
320320
}
321321

322322
#ifdef __AVR__
323-
void Property::setAttributeReal(String attributeName, nonstd::function<void (CborMapData & md)>setValue)
323+
void Property::setAttribute(String attributeName, nonstd::function<void (CborMapData & md)>setValue)
324324
#else
325-
void Property::setAttributeReal(String attributeName, std::function<void (CborMapData & md)>setValue)
325+
void Property::setAttribute(String attributeName, std::function<void (CborMapData & md)>setValue)
326326
#endif
327327
{
328328
if (attributeName != "") {
@@ -354,13 +354,6 @@ void Property::setAttributeReal(String attributeName, std::function<void (CborMa
354354
});
355355
}
356356

357-
String Property::getAttributeName(String propertyName, char separator) {
358-
int colonPos;
359-
String attributeName = "";
360-
(colonPos = propertyName.indexOf(separator)) != -1 ? attributeName = propertyName.substring(colonPos + 1) : "";
361-
return attributeName;
362-
}
363-
364357
void Property::updateLocalTimestamp() {
365358
if (isReadableByCloud()) {
366359
if (_get_time_func) {

Diff for: src/property/Property.h

+13-22
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,6 @@
4343

4444
#include "../cbor/lib/tinycbor/cbor-lib.h"
4545

46-
/******************************************************************************
47-
DEFINE
48-
******************************************************************************/
49-
50-
#define appendAttributesToCloud() appendAttributesToCloudReal(CborEncoder *encoder)
51-
#define appendAttribute(x) appendAttributeReal(x, getAttributeName(#x, '.'), encoder)
52-
#define setAttribute(x) setAttributeReal(x, getAttributeName(#x, '.'))
53-
5446
/******************************************************************************
5547
CONST
5648
******************************************************************************/
@@ -194,30 +186,29 @@ class Property
194186

195187
void updateLocalTimestamp();
196188
CborError append(CborEncoder * encoder, bool lightPayload);
197-
CborError appendAttributeReal(bool value, String attributeName = "", CborEncoder *encoder = nullptr);
198-
CborError appendAttributeReal(int value, String attributeName = "", CborEncoder *encoder = nullptr);
199-
CborError appendAttributeReal(unsigned int value, String attributeName = "", CborEncoder *encoder = nullptr);
200-
CborError appendAttributeReal(float value, String attributeName = "", CborEncoder *encoder = nullptr);
201-
CborError appendAttributeReal(String value, String attributeName = "", CborEncoder *encoder = nullptr);
189+
CborError appendAttribute(bool value, String attributeName = "", CborEncoder *encoder = nullptr);
190+
CborError appendAttribute(int value, String attributeName = "", CborEncoder *encoder = nullptr);
191+
CborError appendAttribute(unsigned int value, String attributeName = "", CborEncoder *encoder = nullptr);
192+
CborError appendAttribute(float value, String attributeName = "", CborEncoder *encoder = nullptr);
193+
CborError appendAttribute(String value, String attributeName = "", CborEncoder *encoder = nullptr);
202194
#ifndef __AVR__
203195
CborError appendAttributeName(String attributeName, std::function<CborError (CborEncoder& mapEncoder)>f, CborEncoder *encoder);
204-
void setAttributeReal(String attributeName, std::function<void (CborMapData & md)>setValue);
196+
void setAttribute(String attributeName, std::function<void (CborMapData & md)>setValue);
205197
#else
206198
CborError appendAttributeName(String attributeName, nonstd::function<CborError (CborEncoder& mapEncoder)>f, CborEncoder *encoder);
207-
void setAttributeReal(String attributeName, nonstd::function<void (CborMapData & md)>setValue);
199+
void setAttribute(String attributeName, nonstd::function<void (CborMapData & md)>setValue);
208200
#endif
209201
void setAttributesFromCloud(std::list<CborMapData> * map_data_list);
210-
void setAttributeReal(bool& value, String attributeName = "");
211-
void setAttributeReal(int& value, String attributeName = "");
212-
void setAttributeReal(unsigned int& value, String attributeName = "");
213-
void setAttributeReal(float& value, String attributeName = "");
214-
void setAttributeReal(String& value, String attributeName = "");
215-
String getAttributeName(String propertyName, char separator);
202+
void setAttribute(bool& value, String attributeName = "");
203+
void setAttribute(int& value, String attributeName = "");
204+
void setAttribute(unsigned int& value, String attributeName = "");
205+
void setAttribute(float& value, String attributeName = "");
206+
void setAttribute(String& value, String attributeName = "");
216207

217208
virtual bool isDifferentFromCloud() = 0;
218209
virtual void fromCloudToLocal() = 0;
219210
virtual void fromLocalToCloud() = 0;
220-
virtual CborError appendAttributesToCloudReal(CborEncoder *encoder) = 0;
211+
virtual CborError appendAttributesToCloud(CborEncoder *encoder) = 0;
221212
virtual void setAttributesFromCloud() = 0;
222213
virtual bool isPrimitive() {
223214
return false;

Diff for: src/property/types/CloudBool.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ class CloudBool : public Property {
5252
virtual void fromLocalToCloud() {
5353
_cloud_value = _value;
5454
}
55-
virtual CborError appendAttributesToCloud() {
56-
return appendAttribute(_value);
55+
virtual CborError appendAttributesToCloud(CborEncoder *encoder) {
56+
return appendAttribute(_value, "", encoder);
5757
}
5858
virtual void setAttributesFromCloud() {
59-
setAttribute(_cloud_value);
59+
setAttribute(_cloud_value, "");
6060
}
6161
//modifiers
6262
CloudBool& operator=(bool v) {

Diff for: src/property/types/CloudColor.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,16 @@ class CloudColor : public Property {
188188
virtual void fromLocalToCloud() {
189189
_cloud_value = _value;
190190
}
191-
virtual CborError appendAttributesToCloud() {
192-
CHECK_CBOR_MULTI(appendAttribute(_value.hue));
193-
CHECK_CBOR_MULTI(appendAttribute(_value.sat));
194-
CHECK_CBOR_MULTI(appendAttribute(_value.bri));
191+
virtual CborError appendAttributesToCloud(CborEncoder *encoder) {
192+
CHECK_CBOR_MULTI(appendAttribute(_value.hue, "hue", encoder));
193+
CHECK_CBOR_MULTI(appendAttribute(_value.sat, "sat", encoder));
194+
CHECK_CBOR_MULTI(appendAttribute(_value.bri, "bri", encoder));
195195
return CborNoError;
196196
}
197197
virtual void setAttributesFromCloud() {
198-
setAttribute(_cloud_value.hue);
199-
setAttribute(_cloud_value.sat);
200-
setAttribute(_cloud_value.bri);
198+
setAttribute(_cloud_value.hue, "hue");
199+
setAttribute(_cloud_value.sat, "sat");
200+
setAttribute(_cloud_value.bri, "bri");
201201
}
202202
};
203203

Diff for: src/property/types/CloudFloat.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ class CloudFloat : public Property {
5454
virtual void fromLocalToCloud() {
5555
_cloud_value = _value;
5656
}
57-
virtual CborError appendAttributesToCloud() {
58-
return appendAttribute(_value);
57+
virtual CborError appendAttributesToCloud(CborEncoder *encoder) {
58+
return appendAttribute(_value, "", encoder);
5959
}
6060
virtual void setAttributesFromCloud() {
61-
setAttribute(_cloud_value);
61+
setAttribute(_cloud_value, "");
6262
}
6363
//modifiers
6464
CloudFloat& operator=(float v) {

Diff for: src/property/types/CloudInt.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ class CloudInt : public Property {
5252
virtual void fromLocalToCloud() {
5353
_cloud_value = _value;
5454
}
55-
virtual CborError appendAttributesToCloud() {
56-
return appendAttribute(_value);
55+
virtual CborError appendAttributesToCloud(CborEncoder *encoder) {
56+
return appendAttribute(_value, "", encoder);
5757
}
5858
virtual void setAttributesFromCloud() {
59-
setAttribute(_cloud_value);
59+
setAttribute(_cloud_value, "");
6060
}
6161
//modifiers
6262
CloudInt& operator=(int v) {

Diff for: src/property/types/CloudLocation.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ class CloudLocation : public Property {
8989
virtual void fromLocalToCloud() {
9090
_cloud_value = _value;
9191
}
92-
virtual CborError appendAttributesToCloud() {
93-
CHECK_CBOR_MULTI(appendAttribute(_value.lat));
94-
CHECK_CBOR_MULTI(appendAttribute(_value.lon));
92+
virtual CborError appendAttributesToCloud(CborEncoder *encoder) {
93+
CHECK_CBOR_MULTI(appendAttribute(_value.lat, "lat", encoder));
94+
CHECK_CBOR_MULTI(appendAttribute(_value.lon, "lon", encoder));
9595
return CborNoError;
9696
}
9797
virtual void setAttributesFromCloud() {
98-
setAttribute(_cloud_value.lat);
99-
setAttribute(_cloud_value.lon);
98+
setAttribute(_cloud_value.lat, "lat");
99+
setAttribute(_cloud_value.lon, "lon");
100100
}
101101
};
102102

Diff for: src/property/types/CloudSchedule.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -417,18 +417,18 @@ class CloudSchedule : public Property {
417417
virtual void fromLocalToCloud() {
418418
_cloud_value = _value;
419419
}
420-
virtual CborError appendAttributesToCloud() {
421-
CHECK_CBOR_MULTI(appendAttribute(_value.frm));
422-
CHECK_CBOR_MULTI(appendAttribute(_value.to));
423-
CHECK_CBOR_MULTI(appendAttribute(_value.len));
424-
CHECK_CBOR_MULTI(appendAttribute(_value.msk));
420+
virtual CborError appendAttributesToCloud(CborEncoder *encoder) {
421+
CHECK_CBOR_MULTI(appendAttribute(_value.frm, "frm", encoder));
422+
CHECK_CBOR_MULTI(appendAttribute(_value.to, "to", encoder));
423+
CHECK_CBOR_MULTI(appendAttribute(_value.len, "len", encoder));
424+
CHECK_CBOR_MULTI(appendAttribute(_value.msk, "msk", encoder));
425425
return CborNoError;
426426
}
427427
virtual void setAttributesFromCloud() {
428-
setAttribute(_cloud_value.frm);
429-
setAttribute(_cloud_value.to);
430-
setAttribute(_cloud_value.len);
431-
setAttribute(_cloud_value.msk);
428+
setAttribute(_cloud_value.frm, "frm");
429+
setAttribute(_cloud_value.to, "to");
430+
setAttribute(_cloud_value.len, "len");
431+
setAttribute(_cloud_value.msk, "msk");
432432
}
433433
};
434434

Diff for: src/property/types/CloudString.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ class CloudString : public Property {
5858
virtual void fromLocalToCloud() {
5959
_cloud_value = _value;
6060
}
61-
virtual CborError appendAttributesToCloud() {
62-
return appendAttribute(_value);
61+
virtual CborError appendAttributesToCloud(CborEncoder *encoder) {
62+
return appendAttribute(_value, "", encoder);
6363
}
6464
virtual void setAttributesFromCloud() {
65-
setAttribute(_cloud_value);
65+
setAttribute(_cloud_value, "");
6666
}
6767
//modifiers
6868
CloudString& operator=(String v) {

Diff for: src/property/types/CloudUnsignedInt.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ class CloudUnsignedInt : public Property {
5252
virtual void fromLocalToCloud() {
5353
_cloud_value = _value;
5454
}
55-
virtual CborError appendAttributesToCloud() {
56-
return appendAttribute(_value);
55+
virtual CborError appendAttributesToCloud(CborEncoder *encoder) {
56+
return appendAttribute(_value, "", encoder);
5757
}
5858
virtual void setAttributesFromCloud() {
59-
setAttribute(_cloud_value);
59+
setAttribute(_cloud_value, "");
6060
}
6161
//modifiers
6262
CloudUnsignedInt& operator=(unsigned int v) {

Diff for: src/property/types/CloudWrapperBool.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ class CloudWrapperBool : public CloudWrapperBase {
4545
virtual void fromLocalToCloud() {
4646
_cloud_value = _primitive_value;
4747
}
48-
virtual CborError appendAttributesToCloud() {
49-
return appendAttribute(_primitive_value);
48+
virtual CborError appendAttributesToCloud(CborEncoder *encoder) {
49+
return appendAttribute(_primitive_value, "", encoder);
5050
}
5151
virtual void setAttributesFromCloud() {
52-
setAttribute(_cloud_value);
52+
setAttribute(_cloud_value, "");
5353
}
5454
virtual bool isPrimitive() {
5555
return true;

Diff for: src/property/types/CloudWrapperFloat.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ class CloudWrapperFloat : public CloudWrapperBase {
4747
virtual void fromLocalToCloud() {
4848
_cloud_value = _primitive_value;
4949
}
50-
virtual CborError appendAttributesToCloud() {
51-
return appendAttribute(_primitive_value);
50+
virtual CborError appendAttributesToCloud(CborEncoder *encoder) {
51+
return appendAttribute(_primitive_value, "", encoder);
5252
}
5353
virtual void setAttributesFromCloud() {
54-
setAttribute(_cloud_value);
54+
setAttribute(_cloud_value, "");
5555
}
5656
virtual bool isPrimitive() {
5757
return true;

Diff for: src/property/types/CloudWrapperInt.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ class CloudWrapperInt : public CloudWrapperBase {
4545
virtual void fromLocalToCloud() {
4646
_cloud_value = _primitive_value;
4747
}
48-
virtual CborError appendAttributesToCloud() {
49-
return appendAttribute(_primitive_value);
48+
virtual CborError appendAttributesToCloud(CborEncoder *encoder) {
49+
return appendAttribute(_primitive_value, "", encoder);
5050
}
5151
virtual void setAttributesFromCloud() {
52-
setAttribute(_cloud_value);
52+
setAttribute(_cloud_value, "");
5353
}
5454
virtual bool isPrimitive() {
5555
return true;

Diff for: src/property/types/CloudWrapperString.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ class CloudWrapperString : public CloudWrapperBase {
4949
virtual void fromLocalToCloud() {
5050
_cloud_value = _primitive_value;
5151
}
52-
virtual CborError appendAttributesToCloud() {
53-
return appendAttribute(_primitive_value);
52+
virtual CborError appendAttributesToCloud(CborEncoder *encoder) {
53+
return appendAttribute(_primitive_value, "", encoder);
5454
}
5555
virtual void setAttributesFromCloud() {
56-
setAttribute(_cloud_value);
56+
setAttribute(_cloud_value, "");
5757
}
5858
virtual bool isPrimitive() {
5959
return true;

0 commit comments

Comments
 (0)