|
23 | 23 | ******************************************************************************/
|
24 | 24 |
|
25 | 25 | #include <Arduino.h>
|
26 |
| -#include "../Property.h" |
| 26 | +#include "PropertyPrimitive.h" |
27 | 27 |
|
28 | 28 | /******************************************************************************
|
29 | 29 | CLASS DECLARATION
|
30 | 30 | ******************************************************************************/
|
31 | 31 |
|
32 |
| -class CloudWrapperBase : public Property { |
| 32 | +class CloudWrapperBaseInterface { |
33 | 33 | public:
|
34 | 34 | virtual bool isChangedLocally() = 0;
|
35 | 35 | };
|
36 | 36 |
|
| 37 | +class CloudWrapperBase : public Property, public CloudWrapperBaseInterface { |
| 38 | + public: |
| 39 | + virtual bool isChangedLocally() = 0; |
| 40 | +}; |
| 41 | + |
| 42 | +template<typename T> |
| 43 | +class CloudWrapperProperty : public PropertyPrimitive<T>, public CloudWrapperBaseInterface { |
| 44 | +public: |
| 45 | + CloudWrapperProperty(T& value) |
| 46 | + : PropertyPrimitive<T>(value), _primitive_value(value) { } |
| 47 | + |
| 48 | + bool isDifferentFromCloud() override { |
| 49 | + return _primitive_value != PropertyPrimitive<T>::_cloud_value; |
| 50 | + } |
| 51 | + |
| 52 | + void fromCloudToLocal() override { |
| 53 | + _primitive_value = PropertyPrimitive<T>::_cloud_value; |
| 54 | + } |
| 55 | + void fromLocalToCloud() override { |
| 56 | + PropertyPrimitive<T>::_cloud_value = _primitive_value; |
| 57 | + } |
| 58 | + |
| 59 | + CborError appendAttributesToCloud(CborEncoder *encoder) override { |
| 60 | + return PropertyPrimitive<T>::appendAttribute(_primitive_value, "", encoder); |
| 61 | + } |
| 62 | + void setAttributesFromCloud() override { |
| 63 | + PropertyPrimitive<T>::setAttribute(PropertyPrimitive<T>::_cloud_value, ""); |
| 64 | + } |
| 65 | + |
| 66 | + bool isChangedLocally() override { |
| 67 | + return _primitive_value != PropertyPrimitive<T>::_value; |
| 68 | + } |
| 69 | +protected: |
| 70 | + T &_primitive_value; |
| 71 | +}; |
| 72 | + |
37 | 73 |
|
38 | 74 | #endif /* CLOUDWRAPPERBASE_H_ */
|
0 commit comments