Skip to content

Commit 4599853

Browse files
committed
Move properties containers inside class implementation
1 parent 87f28a3 commit 4599853

6 files changed

+23
-11
lines changed

src/ArduinoIoTCloud.cpp

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

2828
ArduinoIoTCloudClass::ArduinoIoTCloudClass()
2929
: _connection{nullptr}
30-
, _last_checked_property_index{0}
3130
, _time_service(TimeService)
3231
, _thing_id{""}
3332
, _thing_id_property{nullptr}
@@ -44,12 +43,12 @@ ArduinoIoTCloudClass::ArduinoIoTCloudClass()
4443

4544
void ArduinoIoTCloudClass::push()
4645
{
47-
requestUpdateForAllProperties(_thing_property_container);
46+
requestUpdateForAllProperties(getThingPropertyContainer());
4847
}
4948

5049
bool ArduinoIoTCloudClass::setTimestamp(String const & prop_name, unsigned long const timestamp)
5150
{
52-
Property * p = getProperty(_thing_property_container, prop_name);
51+
Property * p = getProperty(getThingPropertyContainer(), prop_name);
5352

5453
if (p == nullptr)
5554
return false;
@@ -118,7 +117,7 @@ Property& ArduinoIoTCloudClass::addPropertyReal(String& property, String name, i
118117
}
119118
Property& ArduinoIoTCloudClass::addPropertyReal(Property& property, String name, int tag, Permission const permission)
120119
{
121-
return addPropertyToContainer(_thing_property_container, property, name, permission, tag);
120+
return addPropertyToContainer(getThingPropertyContainer(), property, name, permission, tag);
122121
}
123122

124123
/* The following methods are deprecated but still used for non-LoRa boards */
@@ -195,9 +194,9 @@ void ArduinoIoTCloudClass::addPropertyRealInternal(Property& property, String na
195194
}
196195

197196
if (seconds == ON_CHANGE) {
198-
addPropertyToContainer(_thing_property_container, property, name, permission, tag).publishOnChange(minDelta, Property::DEFAULT_MIN_TIME_BETWEEN_UPDATES_MILLIS).onUpdate(fn).onSync(synFn);
197+
addPropertyToContainer(getThingPropertyContainer(), property, name, permission, tag).publishOnChange(minDelta, Property::DEFAULT_MIN_TIME_BETWEEN_UPDATES_MILLIS).onUpdate(fn).onSync(synFn);
199198
} else {
200-
addPropertyToContainer(_thing_property_container, property, name, permission, tag).publishEvery(seconds).onUpdate(fn).onSync(synFn);
199+
addPropertyToContainer(getThingPropertyContainer(), property, name, permission, tag).publishEvery(seconds).onUpdate(fn).onSync(synFn);
201200
}
202201
}
203202

src/ArduinoIoTCloud.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class ArduinoIoTCloudClass
105105

106106
#define addProperty( v, ...) addPropertyReal(v, #v, __VA_ARGS__)
107107

108-
/* The following methods are used for non-LoRa boards which can use the
108+
/* The following methods are used for non-LoRa boards which can use the
109109
* name of the property to identify a given property within a CBOR message.
110110
*/
111111

@@ -146,9 +146,6 @@ class ArduinoIoTCloudClass
146146
protected:
147147

148148
ConnectionHandler * _connection;
149-
PropertyContainer _device_property_container;
150-
PropertyContainer _thing_property_container;
151-
unsigned int _last_checked_property_index;
152149
TimeServiceClass & _time_service;
153150
String _thing_id;
154151
Property * _thing_id_property;
@@ -158,8 +155,9 @@ class ArduinoIoTCloudClass
158155

159156
private:
160157

161-
void addPropertyRealInternal(Property& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS);
158+
virtual PropertyContainer &getThingPropertyContainer() = 0;
162159

160+
void addPropertyRealInternal(Property& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, float minDelta = 0.0f, void(*synFn)(Property & property) = CLOUD_WINS);
163161
String _device_id;
164162
OnCloudEventCallback _cloud_event_callback[3];
165163
};

src/ArduinoIoTCloudLPWAN.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ ArduinoIoTCloudLPWAN::ArduinoIoTCloudLPWAN()
5151
, _retryEnable{false}
5252
, _maxNumRetry{5}
5353
, _intervalRetry{AIOT_CONFIG_INTERVAL_RETRY_DELAY_ms}
54+
, _thing_property_container{0}
55+
, _last_checked_property_index{0}
5456
{
5557

5658
}

src/ArduinoIoTCloudLPWAN.h

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class ArduinoIoTCloudLPWAN : public ArduinoIoTCloudClass
4949
inline void setMaxRetry (int val) { _maxNumRetry = val; }
5050
inline void setIntervalRetry(long val) { _intervalRetry = val; }
5151

52+
inline PropertyContainer &getThingPropertyContainer() { return _thing_property_container; }
53+
5254

5355
private:
5456

@@ -64,6 +66,9 @@ class ArduinoIoTCloudLPWAN : public ArduinoIoTCloudClass
6466
int _maxNumRetry;
6567
long _intervalRetry;
6668

69+
PropertyContainer _thing_property_container;
70+
unsigned int _last_checked_property_index;
71+
6772
State handle_ConnectPhy();
6873
State handle_SyncTime();
6974
State handle_Connected();

src/ArduinoIoTCloudTCP.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ unsigned long getTime()
6060
ArduinoIoTCloudTCP::ArduinoIoTCloudTCP()
6161
: _state{State::ConnectPhy}
6262
, _connection_attempt(0,0)
63+
, _device_property_container{0}
64+
, _thing_property_container{0}
65+
, _last_checked_property_index{0}
6366
, _tz_offset{0}
6467
, _tz_offset_property{nullptr}
6568
, _tz_dst_until{0}

src/ArduinoIoTCloudTCP.h

+5
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass
9191
inline String getBrokerAddress() const { return _brokerAddress; }
9292
inline uint16_t getBrokerPort () const { return _brokerPort; }
9393

94+
inline PropertyContainer &getThingPropertyContainer() { return _thing_property_container; }
95+
9496
#if OTA_ENABLED
9597
/* The callback is triggered when the OTA is initiated and it gets executed until _ota_req flag is cleared.
9698
* It should return true when the OTA can be applied or false otherwise.
@@ -123,6 +125,9 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass
123125

124126
State _state;
125127
TimedAttempt _connection_attempt;
128+
PropertyContainer _device_property_container;
129+
PropertyContainer _thing_property_container;
130+
unsigned int _last_checked_property_index;
126131

127132
int _tz_offset;
128133
Property * _tz_offset_property;

0 commit comments

Comments
 (0)