Skip to content

Redefining Primitive kind property as template class #562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions extras/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ set(TEST_UTIL_SRCS

set(TEST_DUT_SRCS
../../src/property/Property.cpp
../../src/property/types/PropertyPrimitive.cpp
../../src/property/types/CloudWrapperBase.cpp
../../src/property/PropertyContainer.cpp
../../src/cbor/CBORDecoder.cpp
../../src/cbor/CBOREncoder.cpp
Expand Down
2 changes: 1 addition & 1 deletion extras/test/src/test_CloudFloat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include <CBORDecoder.h>

#include <property/types/CloudFloat.h>
#include <property/PropertyContainer.h>

/**************************************************************************************
TEST CODE
Expand Down
2 changes: 1 addition & 1 deletion extras/test/src/test_CloudWrapperFloat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include <CBORDecoder.h>

#include <property/types/CloudWrapperFloat.h>
#include <property/PropertyContainer.h>

/**************************************************************************************
TEST CODE
Expand Down
5 changes: 0 additions & 5 deletions extras/test/src/test_addPropertyReal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@

#include <PropertyContainer.h>

#include <types/CloudInt.h>
#include <types/CloudBool.h>
#include <types/CloudFloat.h>
#include <types/CloudString.h>

/**************************************************************************************
TEST CODE
**************************************************************************************/
Expand Down
1 change: 0 additions & 1 deletion extras/test/src/test_callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <util/CBORTestUtil.h>
#include <CBORDecoder.h>
#include <PropertyContainer.h>
#include "types/CloudWrapperBool.h"
#include <memory>

/**************************************************************************************
Expand Down
9 changes: 0 additions & 9 deletions extras/test/src/test_decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,9 @@
#include <util/CBORTestUtil.h>

#include <CBORDecoder.h>
#include "types/CloudWrapperBool.h"
#include "types/CloudWrapperFloat.h"
#include "types/CloudWrapperInt.h"
#include "types/CloudWrapperString.h"
#include "types/automation/CloudColoredLight.h"
#include "types/automation/CloudContactSensor.h"
#include "types/automation/CloudDimmedLight.h"
#include "types/automation/CloudLight.h"
#include "types/automation/CloudMotionSensor.h"
#include "types/automation/CloudSmartPlug.h"
#include "types/automation/CloudSwitch.h"
#include "types/automation/CloudTemperatureSensor.h"
#include "types/automation/CloudTelevision.h"

using namespace Catch;
Expand Down
3 changes: 0 additions & 3 deletions extras/test/src/test_encode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
#include <memory>

#include <util/CBORTestUtil.h>
#include "types/CloudWrapperBool.h"
#include "types/CloudWrapperFloat.h"
#include "types/CloudWrapperInt.h"
#include "types/CloudWrapperString.h"

/**************************************************************************************
Expand Down
4 changes: 0 additions & 4 deletions src/ArduinoIoTCloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@

#include "property/Property.h"
#include "property/PropertyContainer.h"
#include "property/types/CloudWrapperBool.h"
#include "property/types/CloudWrapperFloat.h"
#include "property/types/CloudWrapperInt.h"
#include "property/types/CloudWrapperUnsignedInt.h"
#include "property/types/CloudWrapperString.h"

#include "utility/time/TimeService.h"
Expand Down
2 changes: 0 additions & 2 deletions src/ArduinoIoTCloudThing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

#include "ArduinoIoTCloudThing.h"
#include "interfaces/CloudProcess.h"
#include "property/types/CloudWrapperInt.h"
#include "property/types/CloudWrapperUnsignedInt.h"

/******************************************************************************
* CTOR/DTOR
Expand Down
4 changes: 0 additions & 4 deletions src/property/Property.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,6 @@ enum class Permission {
Read, Write, ReadWrite
};

enum class Type {
Bool, Int, Float, String
};

enum class UpdatePolicy {
OnChange, TimeInterval, OnDemand
};
Expand Down
33 changes: 21 additions & 12 deletions src/property/PropertyContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,16 @@
#undef min
#include <list>

#include "types/CloudBool.h"
#include "types/CloudFloat.h"
#include "types/CloudInt.h"
#include "types/CloudUnsignedInt.h"
#include "types/PropertyPrimitive.h"

#include "types/CloudString.h"
#include "types/CloudLocation.h"
#include "types/CloudSchedule.h"
#include "types/CloudColor.h"
#include "types/CloudWrapperBase.h"

#include "types/automation/CloudColoredLight.h"
#include "types/automation/CloudContactSensor.h"
#include "types/automation/CloudDimmedLight.h"
#include "types/automation/CloudLight.h"
#include "types/automation/CloudMotionSensor.h"
#include "types/automation/CloudSmartPlug.h"
#include "types/automation/CloudSwitch.h"
#include "types/automation/CloudTemperatureSensor.h"
#include "types/automation/CloudTelevision.h"

/******************************************************************************
Expand All @@ -62,6 +54,16 @@ extern "C" unsigned long getTime();

typedef std::list<Property *> PropertyContainer;

typedef PropertyPrimitive<bool> CloudBool;
typedef PropertyPrimitive<float> CloudFloat;
typedef PropertyPrimitive<int> CloudInt;
typedef PropertyPrimitive<unsigned int> CloudUnsignedInt;

typedef CloudWrapperProperty<bool> CloudWrapperBool;
typedef CloudWrapperProperty<float> CloudWrapperFloat;
typedef CloudWrapperProperty<int> CloudWrapperInt;
typedef CloudWrapperProperty<unsigned int> CloudWrapperUnsignedInt;

typedef CloudFloat CloudEnergy;
typedef CloudFloat CloudForce;
typedef CloudFloat CloudTemperature;
Expand Down Expand Up @@ -93,6 +95,13 @@ typedef CloudInt CloudInformationContent;
typedef CloudFloat CloudPercentage;
typedef CloudFloat CloudRelativeHumidity;

typedef CloudBool CloudContactSensor;
typedef CloudBool CloudLight;
typedef CloudBool CloudMotionSensor;
typedef CloudBool CloudSmartPlug;
typedef CloudBool CloudSwitch;
typedef CloudFloat CloudTemperatureSensor;

/******************************************************************************
FUNCTION DECLARATION
******************************************************************************/
Expand All @@ -104,7 +113,7 @@ Property & addPropertyToContainer(PropertyContainer & prop_cont,
int propertyIdentifier = -1,
GetTimeCallbackFunc func = getTime);


Property * getProperty(PropertyContainer & prop_cont, String const & name);
Property * getProperty(PropertyContainer & prop_cont, int const identifier);

Expand All @@ -114,4 +123,4 @@ void requestUpdateForAllProperties(PropertyContainer & prop_cont);
void updateProperty(PropertyContainer & prop_cont, String propertyName, unsigned long cloudChangeEventTime, bool const is_sync_message, std::list<CborMapData> * map_data_list);
String getPropertyNameByIdentifier(PropertyContainer & prop_cont, int propertyIdentifier);

#endif /* ARDUINO_PROPERTY_CONTAINER_H_ */
#endif /* ARDUINO_PROPERTY_CONTAINER_H_ */
78 changes: 0 additions & 78 deletions src/property/types/CloudBool.h

This file was deleted.

12 changes: 6 additions & 6 deletions src/property/types/CloudColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class CloudColor : public Property {
CloudColor() : _value(0, 0, 0), _cloud_value(0, 0, 0) {}
CloudColor(float hue, float saturation, float brightness) : _value(hue, saturation, brightness), _cloud_value(hue, saturation, brightness) {}

virtual bool isDifferentFromCloud() {
bool isDifferentFromCloud() override {

return _value != _cloud_value;
}
Expand All @@ -182,23 +182,23 @@ class CloudColor : public Property {
return _value;
}

virtual void fromCloudToLocal() {
void fromCloudToLocal() override {
_value = _cloud_value;
}
virtual void fromLocalToCloud() {
void fromLocalToCloud() override {
_cloud_value = _value;
}
virtual CborError appendAttributesToCloud(CborEncoder *encoder) {
CborError appendAttributesToCloud(CborEncoder *encoder) override {
CHECK_CBOR_MULTI(appendAttribute(_value.hue, "hue", encoder));
CHECK_CBOR_MULTI(appendAttribute(_value.sat, "sat", encoder));
CHECK_CBOR_MULTI(appendAttribute(_value.bri, "bri", encoder));
return CborNoError;
}
virtual void setAttributesFromCloud() {
void setAttributesFromCloud() override {
setAttribute(_cloud_value.hue, "hue");
setAttribute(_cloud_value.sat, "sat");
setAttribute(_cloud_value.bri, "bri");
}
};

#endif /* CLOUDCOLOR_H_ */
#endif /* CLOUDCOLOR_H_ */
Loading
Loading