Skip to content

Commit 5492d93

Browse files
committed
Removing the need for _get_time_func to be a member variable
1 parent c2b4ee0 commit 5492d93

File tree

3 files changed

+18
-27
lines changed

3 files changed

+18
-27
lines changed

src/ArduinoIoTCloudTCP.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const static int CONNECT_FAILURE_SUBSCRIBE = -1;
5050
LOCAL MODULE FUNCTIONS
5151
******************************************************************************/
5252

53-
static unsigned long getTime()
53+
extern "C" unsigned long getTime()
5454
{
5555
return time_service.getTime();
5656
}
@@ -135,7 +135,6 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort)
135135
_ota_topic_in = getTopic_ota_in();
136136

137137
_thing.begin(&_property_container);
138-
_property_container.begin(getTime);
139138

140139
printConnectionStatus(_iot_status);
141140

src/property/PropertyContainer.cpp

+2-17
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,18 @@
2525

2626
#include "types/CloudWrapperBase.h"
2727

28-
/******************************************************************************
29-
CTOR/DTOR
30-
******************************************************************************/
31-
32-
PropertyContainer::PropertyContainer()
33-
: _get_time_func{nullptr}
34-
{
35-
36-
}
37-
3828
/******************************************************************************
3929
PUBLIC MEMBER FUNCTIONS
4030
******************************************************************************/
4131

42-
void PropertyContainer::begin(GetTimeCallbackFunc func)
43-
{
44-
_get_time_func = func;
45-
}
46-
47-
Property & PropertyContainer::addPropertyReal(Property & property, String const & name, Permission const permission, int propertyIdentifier)
32+
Property & PropertyContainer::addPropertyReal(Property & property, String const & name, Permission const permission, int propertyIdentifier, GetTimeCallbackFunc func)
4833
{
4934
/* Check whether or not the property already has been added to the container */
5035
Property * p = getProperty(name);
5136
if(p != nullptr) return (*p);
5237

5338
/* Initialize property and add it to the container */
54-
property.init(name, permission, _get_time_func);
39+
property.init(name, permission, func);
5540

5641
addProperty(&property, propertyIdentifier);
5742
return property;

src/property/PropertyContainer.h

+15-8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@
2828
#undef min
2929
#include <list>
3030

31+
/******************************************************************************
32+
DECLARATION OF getTime
33+
******************************************************************************/
34+
35+
#ifdef HAS_LORA
36+
static unsigned long constexpr getTime() { return 0; }
37+
#else
38+
extern "C" unsigned long getTime();
39+
#endif
40+
3141
/******************************************************************************
3242
CLASS DECLARATION
3343
******************************************************************************/
@@ -37,13 +47,11 @@ class PropertyContainer
3747

3848
public:
3949

40-
PropertyContainer();
41-
42-
43-
void begin(GetTimeCallbackFunc func);
44-
45-
46-
Property & addPropertyReal(Property & property, String const & name, Permission const permission, int propertyIdentifier = -1);
50+
Property & addPropertyReal(Property & property,
51+
String const & name,
52+
Permission const permission,
53+
int propertyIdentifier = -1,
54+
GetTimeCallbackFunc func = getTime);
4755

4856

4957
Property * getProperty (String const & name);
@@ -58,7 +66,6 @@ class PropertyContainer
5866

5967
private:
6068

61-
GetTimeCallbackFunc _get_time_func;
6269
std::list<Property *> _property_list;
6370

6471
void addProperty(Property * property_obj, int propertyIdentifier);

0 commit comments

Comments
 (0)