Skip to content

Commit 71059d0

Browse files
committed
Make ArduinoIoTCloudTimeService return a reference instead of a pointer
1 parent d42e419 commit 71059d0

File tree

7 files changed

+17
-17
lines changed

7 files changed

+17
-17
lines changed

extras/test/src/util/PropertyTestUtil.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ unsigned long getTime()
1919
return 0;
2020
}
2121

22-
TimeService* ArduinoIoTCloudTimeService() {
22+
TimeService & ArduinoIoTCloudTimeService() {
2323
static TimeService _timeService_instance;
24-
return &_timeService_instance;
24+
return _timeService_instance;
2525
}

src/ArduinoIoTCloud.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ class ArduinoIoTCloudClass
9797

9898
inline ConnectionHandler * getConnection() { return _connection; }
9999

100-
inline unsigned long getInternalTime() { return _time_service->getTime(); }
101-
inline unsigned long getLocalTime() { return _time_service->getLocalTime(); }
102-
inline void updateInternalTimezoneInfo() { _time_service->setTimeZoneData(_tz_offset, _tz_dst_until); }
100+
inline unsigned long getInternalTime() { return _time_service.getTime(); }
101+
inline unsigned long getLocalTime() { return _time_service.getLocalTime(); }
102+
inline void updateInternalTimezoneInfo() { _time_service.setTimeZoneData(_tz_offset, _tz_dst_until); }
103103

104104
void addCallback(ArduinoIoTCloudEvent const event, OnCloudEventCallback callback);
105105

@@ -147,7 +147,7 @@ class ArduinoIoTCloudClass
147147

148148
ConnectionHandler * _connection = nullptr;
149149
PropertyContainer _property_container;
150-
TimeService * _time_service = ArduinoIoTCloudTimeService();
150+
TimeService & _time_service = ArduinoIoTCloudTimeService();
151151
int _tz_offset = 0;
152152
unsigned int _tz_dst_until = 0;
153153

src/ArduinoIoTCloudLPWAN.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ int ArduinoIoTCloudLPWAN::begin(ConnectionHandler& connection, bool retry)
6868
{
6969
_connection = &connection;
7070
_retryEnable = retry;
71-
_time_service->begin(nullptr);
71+
_time_service.begin(nullptr);
7272
return 1;
7373
}
7474

@@ -105,7 +105,7 @@ ArduinoIoTCloudLPWAN::State ArduinoIoTCloudLPWAN::handle_ConnectPhy()
105105

106106
ArduinoIoTCloudLPWAN::State ArduinoIoTCloudLPWAN::handle_SyncTime()
107107
{
108-
unsigned long const internal_posix_time = _time_service->getTime();
108+
unsigned long const internal_posix_time = _time_service.getTime();
109109
DEBUG_VERBOSE("ArduinoIoTCloudLPWAN::%s internal clock configured to posix timestamp %d", __FUNCTION__, internal_posix_time);
110110
DEBUG_INFO("Connected to Arduino IoT Cloud");
111111
return State::Connected;

src/ArduinoIoTCloudTCP.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ int ArduinoIoTCloudTCP::begin(ConnectionHandler & connection, bool const enable_
115115
_connection = &connection;
116116
_brokerAddress = brokerAddress;
117117
_brokerPort = brokerPort;
118-
_time_service->begin(&connection);
118+
_time_service.begin(&connection);
119119
return begin(enable_watchdog, _brokerAddress, _brokerPort);
120120
}
121121

@@ -371,7 +371,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_ConnectPhy()
371371

372372
ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_SyncTime()
373373
{
374-
unsigned long const internal_posix_time = _time_service->getTime();
374+
unsigned long const internal_posix_time = _time_service.getTime();
375375
DEBUG_VERBOSE("ArduinoIoTCloudTCP::%s internal clock configured to posix timestamp %d", __FUNCTION__, internal_posix_time);
376376
return State::ConnectMqttBroker;
377377
}
@@ -535,7 +535,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
535535
*/
536536
sendPropertiesToCloud();
537537

538-
unsigned long const internal_posix_time = _time_service->getTime();
538+
unsigned long const internal_posix_time = _time_service.getTime();
539539
if(internal_posix_time < _tz_dst_until) {
540540
return State::Connected;
541541
} else {
@@ -568,7 +568,7 @@ void ArduinoIoTCloudTCP::handleMessage(int length)
568568
DEBUG_VERBOSE("ArduinoIoTCloudTCP::%s [%d] last values received", __FUNCTION__, millis());
569569
CBORDecoder::decode(_property_container, (uint8_t*)bytes, length, true);
570570
sendPropertiesToCloud();
571-
_time_service->setTimeZoneData(_tz_offset, _tz_dst_until);
571+
_time_service.setTimeZoneData(_tz_offset, _tz_dst_until);
572572
execCloudEventCallback(ArduinoIoTCloudEvent::SYNC);
573573
_last_sync_request_cnt = 0;
574574
_last_sync_request_tick = 0;

src/property/types/CloudSchedule.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class Schedule {
115115

116116
bool isActive() {
117117

118-
ScheduleTimeType now = _schedule_time_service->getLocalTime();
118+
ScheduleTimeType now = _schedule_time_service.getLocalTime();
119119

120120
if(checkTimeValid(now)) {
121121
/* We have to wait RTC configuration and Timezone setting from the cloud */
@@ -201,7 +201,7 @@ class Schedule {
201201
return !(operator==(aSchedule));
202202
}
203203
private:
204-
TimeService * _schedule_time_service = ArduinoIoTCloudTimeService();
204+
TimeService & _schedule_time_service = ArduinoIoTCloudTimeService();
205205

206206
ScheduleUnit getScheduleUnit(ScheduleConfigurationType msk) {
207207
return static_cast<ScheduleUnit>((msk & SCHEDULE_UNIT_MASK) >> SCHEDULE_UNIT_SHIFT);

src/utility/time/TimeService.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ time_t cvt_time(char const * time)
268268
return mktime(&t);
269269
}
270270

271-
TimeService* ArduinoIoTCloudTimeService() {
271+
TimeService & ArduinoIoTCloudTimeService() {
272272
static TimeService _timeService_instance;
273-
return &_timeService_instance;
273+
return _timeService_instance;
274274
}

src/utility/time/TimeService.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ class TimeService
6868

6969
};
7070

71-
TimeService* ArduinoIoTCloudTimeService();
71+
TimeService & ArduinoIoTCloudTimeService();
7272

7373
#endif /* ARDUINO_IOT_CLOUD_TIME_SERVICE_H_ */

0 commit comments

Comments
 (0)