From f4f97e42af6cd65ac66b0018e4479ee224f4314d Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 9 Apr 2024 12:26:49 +0200 Subject: [PATCH] Move properties containers inside class implementation --- src/ArduinoIoTCloud.cpp | 11 +++++------ src/ArduinoIoTCloud.h | 8 +++----- src/ArduinoIoTCloudLPWAN.cpp | 2 ++ src/ArduinoIoTCloudLPWAN.h | 5 +++++ src/ArduinoIoTCloudTCP.cpp | 3 +++ src/ArduinoIoTCloudTCP.h | 5 +++++ 6 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/ArduinoIoTCloud.cpp b/src/ArduinoIoTCloud.cpp index 84f08f78..ec2d4826 100644 --- a/src/ArduinoIoTCloud.cpp +++ b/src/ArduinoIoTCloud.cpp @@ -27,7 +27,6 @@ ArduinoIoTCloudClass::ArduinoIoTCloudClass() : _connection{nullptr} -, _last_checked_property_index{0} , _time_service(TimeService) , _thing_id{""} , _thing_id_property{nullptr} @@ -44,12 +43,12 @@ ArduinoIoTCloudClass::ArduinoIoTCloudClass() void ArduinoIoTCloudClass::push() { - requestUpdateForAllProperties(_thing_property_container); + requestUpdateForAllProperties(getThingPropertyContainer()); } bool ArduinoIoTCloudClass::setTimestamp(String const & prop_name, unsigned long const timestamp) { - Property * p = getProperty(_thing_property_container, prop_name); + Property * p = getProperty(getThingPropertyContainer(), prop_name); if (p == nullptr) return false; @@ -118,7 +117,7 @@ Property& ArduinoIoTCloudClass::addPropertyReal(String& property, String name, i } Property& ArduinoIoTCloudClass::addPropertyReal(Property& property, String name, int tag, Permission const permission) { - return addPropertyToContainer(_thing_property_container, property, name, permission, tag); + return addPropertyToContainer(getThingPropertyContainer(), property, name, permission, tag); } /* The following methods are deprecated but still used for non-LoRa boards */ @@ -195,9 +194,9 @@ void ArduinoIoTCloudClass::addPropertyRealInternal(Property& property, String na } if (seconds == ON_CHANGE) { - addPropertyToContainer(_thing_property_container, property, name, permission, tag).publishOnChange(minDelta, Property::DEFAULT_MIN_TIME_BETWEEN_UPDATES_MILLIS).onUpdate(fn).onSync(synFn); + addPropertyToContainer(getThingPropertyContainer(), property, name, permission, tag).publishOnChange(minDelta, Property::DEFAULT_MIN_TIME_BETWEEN_UPDATES_MILLIS).onUpdate(fn).onSync(synFn); } else { - addPropertyToContainer(_thing_property_container, property, name, permission, tag).publishEvery(seconds).onUpdate(fn).onSync(synFn); + addPropertyToContainer(getThingPropertyContainer(), property, name, permission, tag).publishEvery(seconds).onUpdate(fn).onSync(synFn); } } diff --git a/src/ArduinoIoTCloud.h b/src/ArduinoIoTCloud.h index 7436c0ba..2c5bc4fe 100644 --- a/src/ArduinoIoTCloud.h +++ b/src/ArduinoIoTCloud.h @@ -105,7 +105,7 @@ class ArduinoIoTCloudClass #define addProperty( v, ...) addPropertyReal(v, #v, __VA_ARGS__) - /* The following methods are used for non-LoRa boards which can use the + /* The following methods are used for non-LoRa boards which can use the * name of the property to identify a given property within a CBOR message. */ @@ -146,9 +146,6 @@ class ArduinoIoTCloudClass protected: ConnectionHandler * _connection; - PropertyContainer _device_property_container; - PropertyContainer _thing_property_container; - unsigned int _last_checked_property_index; TimeServiceClass & _time_service; String _thing_id; Property * _thing_id_property; @@ -158,8 +155,9 @@ class ArduinoIoTCloudClass private: - 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); + virtual PropertyContainer &getThingPropertyContainer() = 0; + 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); String _device_id; OnCloudEventCallback _cloud_event_callback[3]; }; diff --git a/src/ArduinoIoTCloudLPWAN.cpp b/src/ArduinoIoTCloudLPWAN.cpp index 0f96d36d..4cfc4f96 100644 --- a/src/ArduinoIoTCloudLPWAN.cpp +++ b/src/ArduinoIoTCloudLPWAN.cpp @@ -51,6 +51,8 @@ ArduinoIoTCloudLPWAN::ArduinoIoTCloudLPWAN() , _retryEnable{false} , _maxNumRetry{5} , _intervalRetry{1000} +, _thing_property_container{0} +, _last_checked_property_index{0} { } diff --git a/src/ArduinoIoTCloudLPWAN.h b/src/ArduinoIoTCloudLPWAN.h index 8d1f42d2..46c9e242 100644 --- a/src/ArduinoIoTCloudLPWAN.h +++ b/src/ArduinoIoTCloudLPWAN.h @@ -49,6 +49,8 @@ class ArduinoIoTCloudLPWAN : public ArduinoIoTCloudClass inline void setMaxRetry (int val) { _maxNumRetry = val; } inline void setIntervalRetry(long val) { _intervalRetry = val; } + inline PropertyContainer &getThingPropertyContainer() { return _thing_property_container; } + private: @@ -64,6 +66,9 @@ class ArduinoIoTCloudLPWAN : public ArduinoIoTCloudClass int _maxNumRetry; long _intervalRetry; + PropertyContainer _thing_property_container; + unsigned int _last_checked_property_index; + State handle_ConnectPhy(); State handle_SyncTime(); State handle_Connected(); diff --git a/src/ArduinoIoTCloudTCP.cpp b/src/ArduinoIoTCloudTCP.cpp index 794be824..7457eb8d 100644 --- a/src/ArduinoIoTCloudTCP.cpp +++ b/src/ArduinoIoTCloudTCP.cpp @@ -60,6 +60,9 @@ unsigned long getTime() ArduinoIoTCloudTCP::ArduinoIoTCloudTCP() : _state{State::ConnectPhy} , _connection_attempt(0,0) +, _device_property_container{0} +, _thing_property_container{0} +, _last_checked_property_index{0} , _tz_offset{0} , _tz_offset_property{nullptr} , _tz_dst_until{0} diff --git a/src/ArduinoIoTCloudTCP.h b/src/ArduinoIoTCloudTCP.h index 9b5ffa6c..bf8396b4 100644 --- a/src/ArduinoIoTCloudTCP.h +++ b/src/ArduinoIoTCloudTCP.h @@ -91,6 +91,8 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass inline String getBrokerAddress() const { return _brokerAddress; } inline uint16_t getBrokerPort () const { return _brokerPort; } + inline PropertyContainer &getThingPropertyContainer() { return _thing_property_container; } + #if OTA_ENABLED /* The callback is triggered when the OTA is initiated and it gets executed until _ota_req flag is cleared. * It should return true when the OTA can be applied or false otherwise. @@ -123,6 +125,9 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass State _state; TimedAttempt _connection_attempt; + PropertyContainer _device_property_container; + PropertyContainer _thing_property_container; + unsigned int _last_checked_property_index; int _tz_offset; Property * _tz_offset_property;