Skip to content

Commit 01332e7

Browse files
committed
Fully replacing PropertyContained as a self-contained class with just a typedef
1 parent 5492d93 commit 01332e7

6 files changed

+53
-59
lines changed

src/ArduinoIoTCloud.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
void ArduinoIoTCloudClass::push()
2929
{
30-
_property_container.requestUpdateForAllProperties();
30+
requestUpdateForAllProperties(_property_container);
3131
}
3232

3333
void ArduinoIoTCloudClass::addCallback(ArduinoIoTCloudEvent const event, OnCloudEventCallback callback)
@@ -52,9 +52,9 @@ void ArduinoIoTCloudClass::addPropertyReal(Property& property, String name, int
5252
}
5353

5454
if (seconds == ON_CHANGE) {
55-
_property_container.addPropertyReal(property, name, permission, tag).publishOnChange(minDelta, DEFAULT_MIN_TIME_BETWEEN_UPDATES_MILLIS).onUpdate(fn).onSync(synFn);
55+
addPropertyToContainer(_property_container, property, name, permission, tag).publishOnChange(minDelta, DEFAULT_MIN_TIME_BETWEEN_UPDATES_MILLIS).onUpdate(fn).onSync(synFn);
5656
} else {
57-
_property_container.addPropertyReal(property, name, permission, tag).publishEvery(seconds).onUpdate(fn).onSync(synFn);
57+
addPropertyToContainer(_property_container, property, name, permission, tag).publishEvery(seconds).onUpdate(fn).onSync(synFn);
5858
}
5959
}
6060

@@ -77,7 +77,7 @@ Property& ArduinoIoTCloudClass::addPropertyReal(bool& property, String name, Per
7777
Property& ArduinoIoTCloudClass::addPropertyReal(bool& property, String name, int tag, Permission const permission)
7878
{
7979
Property* p = new CloudWrapperBool(property);
80-
return _property_container.addPropertyReal(*p, name, permission, tag);
80+
return addPropertyToContainer(_property_container, *p, name, permission, tag);
8181
}
8282

8383
void ArduinoIoTCloudClass::addPropertyReal(float& property, String name, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property))
@@ -99,7 +99,7 @@ Property& ArduinoIoTCloudClass::addPropertyReal(float& property, String name, Pe
9999
Property& ArduinoIoTCloudClass::addPropertyReal(float& property, String name, int tag, Permission const permission)
100100
{
101101
Property* p = new CloudWrapperFloat(property);
102-
return _property_container.addPropertyReal(*p, name, permission, tag);
102+
return addPropertyToContainer(_property_container, *p, name, permission, tag);
103103
}
104104

105105
void ArduinoIoTCloudClass::addPropertyReal(int& property, String name, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property))
@@ -121,7 +121,7 @@ Property& ArduinoIoTCloudClass::addPropertyReal(int& property, String name, Perm
121121
Property& ArduinoIoTCloudClass::addPropertyReal(int& property, String name, int tag, Permission const permission)
122122
{
123123
Property* p = new CloudWrapperInt(property);
124-
return _property_container.addPropertyReal(*p, name, permission, tag);
124+
return addPropertyToContainer(_property_container, *p, name, permission, tag);
125125
}
126126

127127
void ArduinoIoTCloudClass::addPropertyReal(String& property, String name, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(Property & property))
@@ -143,7 +143,7 @@ Property& ArduinoIoTCloudClass::addPropertyReal(String& property, String name, P
143143
Property& ArduinoIoTCloudClass::addPropertyReal(String& property, String name, int tag, Permission const permission)
144144
{
145145
Property* p = new CloudWrapperString(property);
146-
return _property_container.addPropertyReal(*p, name, permission, tag);
146+
return addPropertyToContainer(_property_container, *p, name, permission, tag);
147147
}
148148

149149
/******************************************************************************

src/ArduinoIoTCloudLPWAN.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ int ArduinoIoTCloudLPWAN::begin(ConnectionHandler& connection, bool retry)
6363
void ArduinoIoTCloudLPWAN::update()
6464
{
6565
// Check if a primitive property wrapper is locally changed
66-
_property_container.updateTimestampOnLocallyChangedProperties();
66+
updateTimestampOnLocallyChangedProperties(_property_container);
6767

6868
ArduinoIoTConnectionStatus next_iot_status = _iot_status;
6969

src/ArduinoIoTCloudTCP.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void ArduinoIoTCloudTCP::update()
153153
#endif /* OTA_ENABLED */
154154

155155
// Check if a primitive property wrapper is locally changed
156-
_property_container.updateTimestampOnLocallyChangedProperties();
156+
updateTimestampOnLocallyChangedProperties(_property_container);
157157

158158
if(checkPhyConnection() != NetworkConnectionState::CONNECTED) return;
159159
if(checkCloudConnection() != ArduinoIoTConnectionStatus::CONNECTED) return;

src/cbor/ArduinoCloudThing.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ int ArduinoCloudThing::encode(uint8_t * data, size_t const size, bool lightPaylo
6060
return -1;
6161
}
6262

63-
if (_property_container->appendChangedProperties(&arrayEncoder, lightPayload) < 1) {
63+
if (appendChangedProperties(*_property_container, &arrayEncoder, lightPayload) < 1) {
6464
return -1;
6565
}
6666

@@ -398,7 +398,7 @@ void ArduinoCloudThing::freeMapDataList(std::list<CborMapData *> * map_data_list
398398
}
399399

400400
void ArduinoCloudThing::updateProperty(String propertyName, unsigned long cloudChangeEventTime) {
401-
Property* property = _property_container->getProperty(propertyName);
401+
Property* property = getProperty(*_property_container, propertyName);
402402
if (property && property->isWriteableByCloud()) {
403403
property->setLastCloudChangeTimestamp(cloudChangeEventTime);
404404
property->setAttributesFromCloud(&_map_data_list);
@@ -415,9 +415,9 @@ void ArduinoCloudThing::updateProperty(String propertyName, unsigned long cloudC
415415
String ArduinoCloudThing::getPropertyNameByIdentifier(int propertyIdentifier) {
416416
Property* property;
417417
if (propertyIdentifier > 255) {
418-
property = _property_container->getProperty(propertyIdentifier & 255);
418+
property = getProperty(*_property_container, propertyIdentifier & 255);
419419
} else {
420-
property = _property_container->getProperty(propertyIdentifier);
420+
property = getProperty(*_property_container, propertyIdentifier);
421421
}
422422
return property->name();
423423
}

src/property/PropertyContainer.cpp

+23-23
Original file line numberDiff line numberDiff line change
@@ -29,59 +29,59 @@
2929
PUBLIC MEMBER FUNCTIONS
3030
******************************************************************************/
3131

32-
Property & PropertyContainer::addPropertyReal(Property & property, String const & name, Permission const permission, int propertyIdentifier, GetTimeCallbackFunc func)
32+
Property & addPropertyToContainer(PropertyContainer & prop_cont, Property & property, String const & name, Permission const permission, int propertyIdentifier, GetTimeCallbackFunc func)
3333
{
3434
/* Check whether or not the property already has been added to the container */
35-
Property * p = getProperty(name);
35+
Property * p = getProperty(prop_cont, name);
3636
if(p != nullptr) return (*p);
3737

3838
/* Initialize property and add it to the container */
3939
property.init(name, permission, func);
4040

41-
addProperty(&property, propertyIdentifier);
41+
addProperty(prop_cont, &property, propertyIdentifier);
4242
return property;
4343
}
4444

4545

46-
Property * PropertyContainer::getProperty(String const & name)
46+
Property * getProperty(PropertyContainer & prop_cont, String const & name)
4747
{
4848
std::list<Property *>::iterator iter;
4949

50-
iter = std::find_if(_property_list.begin(),
51-
_property_list.end(),
50+
iter = std::find_if(prop_cont.begin(),
51+
prop_cont.end(),
5252
[name](Property * p) -> bool
5353
{
5454
return (p->name() == name);
5555
});
5656

57-
if (iter == _property_list.end())
57+
if (iter == prop_cont.end())
5858
return nullptr;
5959
else
6060
return (*iter);
6161
}
6262

63-
Property * PropertyContainer::getProperty(int const identifier)
63+
Property * getProperty(PropertyContainer & prop_cont, int const identifier)
6464
{
6565
std::list<Property *>::iterator iter;
6666

67-
iter = std::find_if(_property_list.begin(),
68-
_property_list.end(),
67+
iter = std::find_if(prop_cont.begin(),
68+
prop_cont.end(),
6969
[identifier](Property * p) -> bool
7070
{
7171
return (p->identifier() == identifier);
7272
});
7373

74-
if (iter == _property_list.end())
74+
if (iter == prop_cont.end())
7575
return nullptr;
7676
else
7777
return (*iter);
7878
}
7979

80-
int PropertyContainer::appendChangedProperties(CborEncoder * arrayEncoder, bool lightPayload)
80+
int appendChangedProperties(PropertyContainer & prop_cont, CborEncoder * arrayEncoder, bool lightPayload)
8181
{
8282
int appendedProperties = 0;
83-
std::for_each(_property_list.begin(),
84-
_property_list.end(),
83+
std::for_each(prop_cont.begin(),
84+
prop_cont.end(),
8585
[arrayEncoder, lightPayload, &appendedProperties](Property * p)
8686
{
8787
if (p->shouldBeUpdated() && p->isReadableByCloud())
@@ -93,23 +93,23 @@ int PropertyContainer::appendChangedProperties(CborEncoder * arrayEncoder, bool
9393
return appendedProperties;
9494
}
9595

96-
void PropertyContainer::requestUpdateForAllProperties()
96+
void requestUpdateForAllProperties(PropertyContainer & prop_cont)
9797
{
98-
std::for_each(_property_list.begin(),
99-
_property_list.end(),
98+
std::for_each(prop_cont.begin(),
99+
prop_cont.end(),
100100
[](Property * p)
101101
{
102102
p->requestUpdate();
103103
});
104104
}
105105

106-
void PropertyContainer::updateTimestampOnLocallyChangedProperties()
106+
void updateTimestampOnLocallyChangedProperties(PropertyContainer & prop_cont)
107107
{
108108
/* This function updates the timestamps on the primitive properties
109109
* that have been modified locally since last cloud synchronization
110110
*/
111-
std::for_each(_property_list.begin(),
112-
_property_list.end(),
111+
std::for_each(prop_cont.begin(),
112+
prop_cont.end(),
113113
[](Property * p)
114114
{
115115
CloudWrapperBase * pbase = reinterpret_cast<CloudWrapperBase *>(p);
@@ -124,7 +124,7 @@ void PropertyContainer::updateTimestampOnLocallyChangedProperties()
124124
PRIVATE MEMBER FUNCTIONS
125125
******************************************************************************/
126126

127-
void PropertyContainer::addProperty(Property * property_obj, int propertyIdentifier)
127+
void addProperty(PropertyContainer & prop_cont, Property * property_obj, int propertyIdentifier)
128128
{
129129
if (propertyIdentifier != -1)
130130
{
@@ -133,7 +133,7 @@ void PropertyContainer::addProperty(Property * property_obj, int propertyIdentif
133133
/* If property identifier is -1, an incremental value will be assigned as identifier. */
134134
else
135135
{
136-
property_obj->setIdentifier(_property_list.size() + 1); /* This is in order to stay compatible to the old system of first increasing _numProperties and then assigning it here. */
136+
property_obj->setIdentifier(prop_cont.size() + 1); /* This is in order to stay compatible to the old system of first increasing _numProperties and then assigning it here. */
137137
}
138-
_property_list.push_back(property_obj);
138+
prop_cont.push_back(property_obj);
139139
}

src/property/PropertyContainer.h

+17-23
Original file line numberDiff line numberDiff line change
@@ -39,37 +39,31 @@ extern "C" unsigned long getTime();
3939
#endif
4040

4141
/******************************************************************************
42-
CLASS DECLARATION
42+
TYPEDEF
4343
******************************************************************************/
4444

45-
class PropertyContainer
46-
{
45+
typedef std::list<Property *> PropertyContainer;
4746

48-
public:
47+
/******************************************************************************
48+
FUNCTION DECLARATION
49+
******************************************************************************/
4950

50-
Property & addPropertyReal(Property & property,
51-
String const & name,
52-
Permission const permission,
53-
int propertyIdentifier = -1,
54-
GetTimeCallbackFunc func = getTime);
51+
Property & addPropertyToContainer(PropertyContainer & prop_cont,
52+
Property & property,
53+
String const & name,
54+
Permission const permission,
55+
int propertyIdentifier = -1,
56+
GetTimeCallbackFunc func = getTime);
5557

5658

57-
Property * getProperty (String const & name);
58-
Property * getProperty (int const identifier);
59-
60-
61-
int appendChangedProperties(CborEncoder * arrayEncoder, bool lightPayload);
62-
void updateTimestampOnLocallyChangedProperties();
63-
void requestUpdateForAllProperties();
64-
65-
66-
67-
private:
59+
Property * getProperty(PropertyContainer & prop_cont, String const & name);
60+
Property * getProperty(PropertyContainer & prop_cont, int const identifier);
6861

69-
std::list<Property *> _property_list;
7062

71-
void addProperty(Property * property_obj, int propertyIdentifier);
63+
int appendChangedProperties(PropertyContainer & prop_cont, CborEncoder * arrayEncoder, bool lightPayload);
64+
void updateTimestampOnLocallyChangedProperties(PropertyContainer & prop_cont);
65+
void requestUpdateForAllProperties(PropertyContainer & prop_cont);
7266

73-
};
67+
void addProperty(PropertyContainer & prop_cont, Property * property_obj, int propertyIdentifier);
7468

7569
#endif /* ARDUINO_PROPERTY_CONTAINER_H_ */

0 commit comments

Comments
 (0)