Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Add code formatting check to Travis CI build #29

Merged
merged 4 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 51 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,55 @@
language: cpp
sudo: enabled

install:
- sudo apt-get install lcov

before_script:
- cd test && mkdir build && cd build

script:
- cmake ..
- make

after_success:
- lcov --directory . --zerocounters
- bin/testArduinoCloudThing
- lcov --directory . --capture --output-file coverage.info
- lcov --remove coverage.info 'test/*' '/usr/*' 'lib/*' --output-file coverage.info
- lcov --list coverage.info
- bash <(curl -s https://codecov.io/bash) -f coverage.info
- cd ..
- rm -rf build
matrix:
include:
- env:
- NAME=Test

install:
- sudo apt-get install lcov

before_script:
- cd test && mkdir build && cd build

script:
- cmake ..
- make

after_success:
- lcov --directory . --zerocounters
- bin/testArduinoCloudThing
- lcov --directory . --capture --output-file coverage.info
- lcov --remove coverage.info 'test/*' '/usr/*' 'lib/*' --output-file coverage.info
- lcov --list coverage.info
- bash <(curl -s https://codecov.io/bash) -f coverage.info
- cd ..
- rm -rf build

- env:
- NAME=Code Formatting Check

install:
# install Artistic Style code formatter tool: http://astyle.sourceforge.net
- |
mkdir "${HOME}/astyle";
wget --no-verbose --output-document="${HOME}/astyle/astyle.tar.gz" "https://iweb.dl.sourceforge.net/project/astyle/astyle/astyle%203.1/astyle_3.1_linux.tar.gz";
tar --extract --file="${HOME}/astyle/astyle.tar.gz" --directory="${HOME}/astyle";
cd "${HOME}/astyle/astyle/build/gcc";
make;
export PATH=$PWD/bin:$PATH;
cd "$TRAVIS_BUILD_DIR"
# download Arduino's Artistic Style configuration file
- wget --directory-prefix="${HOME}/astyle" https://raw.githubusercontent.com/arduino/Arduino/master/build/shared/examples_formatter.conf

script:
# check code formatting
- find . -regextype posix-extended -path './.git' -prune -or -path './src/lib' -prune -or -path './test/external' -prune -or \( -iregex '.*\.((ino)|(h)|(hpp)|(hh)|(hxx)|(h\+\+)|(cpp)|(cc)|(cxx)|(c\+\+)|(cp)|(c)|(ipp)|(ii)|(ixx)|(inl)|(tpp)|(txx)|(tpl))$' -and -type f \) -print0 | xargs -0 -L1 bash -c 'if ! diff $0 <(astyle --options=${HOME}/astyle/examples_formatter.conf --dry-run < $0); then echo "Non-compliant code formatting in $0"; false; fi'

notifications:
webhooks:
urls:
# TravisBuddy will automatically comment on any PR that results in a failed Travis CI build, which will cause the PR author to get a notification
- https://www.travisbuddy.com/
on_success: never
on_failure: always
185 changes: 96 additions & 89 deletions src/ArduinoCloudProperty.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
#define ARDUINO_CLOUD_PROPERTY_HPP_

/******************************************************************************
* INCLUDE
INCLUDE
******************************************************************************/

#include <Arduino.h>

#include "lib/tinycbor/cbor-lib.h"

/******************************************************************************
* TYPEDEF
TYPEDEF
******************************************************************************/

/******************************************************************************
* TYPEDEF
TYPEDEF
******************************************************************************/

enum class Permission {
Expand All @@ -47,110 +47,117 @@ enum class UpdatePolicy {
};

/* Source: https://tools.ietf.org/html/rfc8428#section-6 */
enum class CborIntegerMapKey : int
{
BaseVersion = -1, /* bver */
BaseName = -2, /* bn */
BaseTime = -3, /* bt */
BaseUnit = -4, /* bu */
BaseValue = -5, /* bv */
BaseSum = -6, /* bs */
Name = 0, /* n */
Unit = 1, /* u */
Value = 2, /* v */
StringValue = 3, /* vs */
BooleanValue = 4, /* vb */
Sum = 5, /* s */
Time = 6, /* t */
UpdateTime = 7, /* ut */
DataValue = 8 /* vd */
enum class CborIntegerMapKey : int {
BaseVersion = -1, /* bver */
BaseName = -2, /* bn */
BaseTime = -3, /* bt */
BaseUnit = -4, /* bu */
BaseValue = -5, /* bv */
BaseSum = -6, /* bs */
Name = 0, /* n */
Unit = 1, /* u */
Value = 2, /* v */
StringValue = 3, /* vs */
BooleanValue = 4, /* vb */
Sum = 5, /* s */
Time = 6, /* t */
UpdateTime = 7, /* ut */
DataValue = 8 /* vd */
};

typedef void(*UpdateCallbackFunc)(void);

/******************************************************************************
* CLASS DECLARATION
CLASS DECLARATION
******************************************************************************/

template <typename T>
class ArduinoCloudProperty {
public:

ArduinoCloudProperty(T & property, String const & name, Permission const permission);

void writeByCloud(T const val);

/* Composable configuration of the ArduinoCloudProperty class */
ArduinoCloudProperty<T> & onUpdate (UpdateCallbackFunc func);
ArduinoCloudProperty<T> & onSync (void (*func)(ArduinoCloudProperty<T> property));
ArduinoCloudProperty<T> & publishOnChange(T const min_delta_property, unsigned long const min_time_between_updates_millis = 0);
ArduinoCloudProperty<T> & publishEvery (unsigned long const seconds);

inline String name () const { return _name; }
inline bool isReadableByCloud () const { return (_permission == Permission::Read ) || (_permission == Permission::ReadWrite); }
inline bool isWriteableByCloud() const { return (_permission == Permission::Write) || (_permission == Permission::ReadWrite); }

bool shouldBeUpdated ();
void execCallbackOnChange ();
void execCallbackOnSync ();
void forceCallbackOnChange ();
void setPreviousCloudChangeTimestamp (unsigned long cloudChangeTime);
void setLastCloudChangeTimestamp (unsigned long cloudChangeTime);
void setLastLocalChangeTimestamp (unsigned long localChangeTime);
unsigned long getPreviousCloudChangeTimestamp();
unsigned long getLastCloudChangeTimestamp();
unsigned long getLastLocalChangeTimestamp();
void setPropertyValue (T const val);
void setCloudShadowValue (T const val);
T getCloudShadowValue ();
void setLocalShadowValue (T const val);
T getLocalShadowValue ();
void updateTime (unsigned long changeEventTime);
bool isChangedLocally ();
void append (CborEncoder * encoder);

private:

T & _property,
_cloud_shadow_property,
_local_shadow_property;
String _name;
Permission _permission;
UpdateCallbackFunc _update_callback_func;
void (*_sync_callback_func)(ArduinoCloudProperty<T> property);

UpdatePolicy _update_policy;
bool _has_been_updated_once,
_has_been_modified_in_callback;
/* Variables used for UpdatePolicy::OnChange */
T _min_delta_property;
unsigned long _min_time_between_updates_millis;
/* Variables used for UpdatePolicy::TimeInterval */
unsigned long _last_updated_millis,
_update_interval_millis;
/* Variables used for reconnection sync*/
unsigned long _last_change_timestamp;
unsigned long _last_local_change_timestamp;
unsigned long _last_cloud_change_timestamp;
unsigned long _previous_cloud_change_timestamp;


void appendValue(CborEncoder * mapEncoder) const;
bool isValueDifferent(T const lhs, T const rhs) const;

T getInitialMinDeltaPropertyValue() const;
public:

ArduinoCloudProperty(T & property, String const & name, Permission const permission);

void writeByCloud(T const val);

/* Composable configuration of the ArduinoCloudProperty class */
ArduinoCloudProperty<T> & onUpdate(UpdateCallbackFunc func);
ArduinoCloudProperty<T> & onSync(void (*func)(ArduinoCloudProperty<T> property));
ArduinoCloudProperty<T> & publishOnChange(T const min_delta_property, unsigned long const min_time_between_updates_millis = 0);
ArduinoCloudProperty<T> & publishEvery(unsigned long const seconds);

inline String name() const {
return _name;
}
inline bool isReadableByCloud() const {
return (_permission == Permission::Read) || (_permission == Permission::ReadWrite);
}
inline bool isWriteableByCloud() const {
return (_permission == Permission::Write) || (_permission == Permission::ReadWrite);
}

bool shouldBeUpdated();
void execCallbackOnChange();
void execCallbackOnSync();
void forceCallbackOnChange();
void setPreviousCloudChangeTimestamp(unsigned long cloudChangeTime);
void setLastCloudChangeTimestamp(unsigned long cloudChangeTime);
void setLastLocalChangeTimestamp(unsigned long localChangeTime);
unsigned long getPreviousCloudChangeTimestamp();
unsigned long getLastCloudChangeTimestamp();
unsigned long getLastLocalChangeTimestamp();
void setPropertyValue(T const val);
void setCloudShadowValue(T const val);
T getCloudShadowValue();
void setLocalShadowValue(T const val);
T getLocalShadowValue();
void updateTime(unsigned long changeEventTime);
bool isChangedLocally();
void append(CborEncoder * encoder);

private:

T & _property,
_cloud_shadow_property,
_local_shadow_property;
String _name;
Permission _permission;
UpdateCallbackFunc _update_callback_func;
void (*_sync_callback_func)(ArduinoCloudProperty<T> property);

UpdatePolicy _update_policy;
bool _has_been_updated_once,
_has_been_modified_in_callback;
/* Variables used for UpdatePolicy::OnChange */
T _min_delta_property;
unsigned long _min_time_between_updates_millis;
/* Variables used for UpdatePolicy::TimeInterval */
unsigned long _last_updated_millis,
_update_interval_millis;
/* Variables used for reconnection sync*/
unsigned long _last_change_timestamp;
unsigned long _last_local_change_timestamp;
unsigned long _last_cloud_change_timestamp;
unsigned long _previous_cloud_change_timestamp;


void appendValue(CborEncoder * mapEncoder) const;
bool isValueDifferent(T const lhs, T const rhs) const;

T getInitialMinDeltaPropertyValue() const;

};

/******************************************************************************
* PROTOTYPE FREE FUNCTIONs
PROTOTYPE FREE FUNCTIONs
******************************************************************************/

template <typename T>
inline bool operator == (ArduinoCloudProperty<T> const & lhs, ArduinoCloudProperty<T> const & rhs) { return (lhs.name() == rhs.name()); }
inline bool operator == (ArduinoCloudProperty<T> const & lhs, ArduinoCloudProperty<T> const & rhs) {
return (lhs.name() == rhs.name());
}

/******************************************************************************
* TEMPLATE IMPLEMENTATION
TEMPLATE IMPLEMENTATION
******************************************************************************/

#include "ArduinoCloudProperty.ipp"
Expand Down
Loading