Skip to content

Commit c754099

Browse files
committed
Extracting constants and device sync functions to modules where they belong better than to ArduinoCloudThing
1 parent 8c1da19 commit c754099

File tree

8 files changed

+70
-39
lines changed

8 files changed

+70
-39
lines changed

extras/test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ project(testArduinoIoTCloud)
99
##########################################################################
1010

1111
include_directories(include)
12+
include_directories(../../src)
1213
include_directories(../../src/cbor)
1314
include_directories(../../src/property)
1415
include_directories(../../src/utility/ota)

extras/test/src/test_publishEvery.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <catch.hpp>
1010

1111
#include <util/CBORTestUtil.h>
12+
#include <AIoTC_Const.h>
1213
#include <ArduinoCloudThing.h>
1314

1415
/**************************************************************************************

src/AIoTC_Const.h

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
This file is part of ArduinoIoTCloud.
3+
4+
Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
5+
6+
This software is released under the GNU General Public License version 3,
7+
which covers the main part of arduino-cli.
8+
The terms of this license can be found at:
9+
https://www.gnu.org/licenses/gpl-3.0.en.html
10+
11+
You can be released from the requirements of the above licenses by purchasing
12+
a commercial license. Buying such a license is mandatory if you want to modify or
13+
otherwise use the software for commercial activities involving the Arduino
14+
software without disclosing the source code of your own applications. To purchase
15+
a commercial license, send an email to [email protected].
16+
*/
17+
18+
#ifndef ARDUINO_AIOTC_CONST_H_
19+
#define ARDUINO_AIOTC_CONST_H_
20+
21+
/******************************************************************************
22+
CONSTANTS
23+
******************************************************************************/
24+
25+
static bool const ON = true;
26+
static bool const OFF = false;
27+
28+
static long const ON_CHANGE = -1;
29+
static long const SECONDS = 1;
30+
static long const MINUTES = 60;
31+
static long const HOURS = 3600;
32+
static long const DAYS = 86400;
33+
34+
#endif /* ARDUINO_AIOTC_CONST_H_ */

src/ArduinoIoTCloud.h

+3
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@
2727
#include <Arduino_ConnectionHandler.h>
2828
#include <Arduino_DebugUtils.h>
2929

30+
#include "AIoTC_Const.h"
31+
3032
#include "cbor/ArduinoCloudThing.h"
3133

34+
#include "property/Property.h"
3235
#include "property/PropertyContainer.h"
3336
#include "property/types/CloudWrapperBool.h"
3437
#include "property/types/CloudWrapperFloat.h"

src/cbor/ArduinoCloudThing.cpp

-15
Original file line numberDiff line numberDiff line change
@@ -418,18 +418,3 @@ double ArduinoCloudThing::convertCborHalfFloatToDouble(uint16_t const half_val)
418418
}
419419
return half_val & 0x8000 ? -val : val;
420420
}
421-
422-
void onAutoSync(Property & property) {
423-
if (property.getLastCloudChangeTimestamp() > property.getLastLocalChangeTimestamp()) {
424-
property.fromCloudToLocal();
425-
property.execCallbackOnChange();
426-
}
427-
}
428-
429-
void onForceCloudSync(Property & property) {
430-
property.fromCloudToLocal();
431-
property.execCallbackOnChange();
432-
}
433-
434-
void onForceDeviceSync(Property & /* property */) {
435-
}

src/cbor/ArduinoCloudThing.h

-24
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,6 @@
4646
#include "../property/types/automation/CloudTemperature.h"
4747
#include "../property/types/automation/CloudTelevision.h"
4848

49-
/******************************************************************************
50-
CONSTANTS
51-
******************************************************************************/
52-
53-
static bool const ON = true;
54-
static bool const OFF = false;
55-
56-
static long const ON_CHANGE = -1;
57-
static long const SECONDS = 1;
58-
static long const MINUTES = 60;
59-
static long const HOURS = 3600;
60-
static long const DAYS = 86400;
61-
62-
/******************************************************************************
63-
SYNCHRONIZATION CALLBACKS
64-
******************************************************************************/
65-
66-
void onAutoSync(Property & property);
67-
#define MOST_RECENT_WINS onAutoSync
68-
void onForceCloudSync(Property & property);
69-
#define CLOUD_WINS onForceCloudSync
70-
void onForceDeviceSync(Property & property);
71-
#define DEVICE_WINS onForceDeviceSync // The device property value is already the correct one. The cloud property value will be synchronized at the next update cycle.
72-
7349
/******************************************************************************
7450
CLASS DECLARATION
7551
******************************************************************************/

src/property/Property.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,23 @@ unsigned long Property::getLastLocalChangeTimestamp() {
325325
void Property::setIdentifier(int identifier) {
326326
_identifier = identifier;
327327
}
328+
329+
/******************************************************************************
330+
SYNCHRONIZATION CALLBACKS
331+
******************************************************************************/
332+
333+
void onAutoSync(Property & property) {
334+
if (property.getLastCloudChangeTimestamp() > property.getLastLocalChangeTimestamp()) {
335+
property.fromCloudToLocal();
336+
property.execCallbackOnChange();
337+
}
338+
}
339+
340+
void onForceCloudSync(Property & property) {
341+
property.fromCloudToLocal();
342+
property.execCallbackOnChange();
343+
}
344+
345+
void onForceDeviceSync(Property & /* property */) {
346+
347+
}

src/property/Property.h

+11
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,15 @@ inline bool operator == (Property const & lhs, Property const & rhs) {
235235
return (lhs.name() == rhs.name());
236236
}
237237

238+
/******************************************************************************
239+
SYNCHRONIZATION CALLBACKS
240+
******************************************************************************/
241+
242+
void onAutoSync(Property & property);
243+
#define MOST_RECENT_WINS onAutoSync
244+
void onForceCloudSync(Property & property);
245+
#define CLOUD_WINS onForceCloudSync
246+
void onForceDeviceSync(Property & property);
247+
#define DEVICE_WINS onForceDeviceSync // The device property value is already the correct one. The cloud property value will be synchronized at the next update cycle.
248+
238249
#endif /* ARDUINO_CLOUD_PROPERTY_HPP_ */

0 commit comments

Comments
 (0)