Skip to content

Commit

Permalink
Move properties containers inside class implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
pennam committed Apr 15, 2024
1 parent 256618c commit f4f97e4
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
11 changes: 5 additions & 6 deletions src/ArduinoIoTCloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

ArduinoIoTCloudClass::ArduinoIoTCloudClass()
: _connection{nullptr}
, _last_checked_property_index{0}
, _time_service(TimeService)
, _thing_id{""}
, _thing_id_property{nullptr}
Expand All @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/ArduinoIoTCloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/

Expand Down Expand Up @@ -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;
Expand All @@ -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];
};
Expand Down
2 changes: 2 additions & 0 deletions src/ArduinoIoTCloudLPWAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ ArduinoIoTCloudLPWAN::ArduinoIoTCloudLPWAN()
, _retryEnable{false}
, _maxNumRetry{5}
, _intervalRetry{1000}
, _thing_property_container{0}
, _last_checked_property_index{0}
{

}
Expand Down
5 changes: 5 additions & 0 deletions src/ArduinoIoTCloudLPWAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/ArduinoIoTCloudTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
5 changes: 5 additions & 0 deletions src/ArduinoIoTCloudTCP.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f4f97e4

Please sign in to comment.