diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..91248ad0 --- /dev/null +++ b/.clang-format @@ -0,0 +1,6 @@ +BasedOnStyle: LLVM +ColumnLimit: 100 +IndentWidth: 4 +TabWidth: 4 +UseTab: ForContinuationAndIndentation +AlignTrailingComments: true diff --git a/.editorconfig b/.editorconfig index b4d31cee..dc99d92a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,19 +1,16 @@ -# This file is for unifying the coding style for different editors and IDEs -# editorconfig.org - +# top-most EditorConfig file root = true +# Unix-style newlines with a newline ending every file [*] +charset = utf-8 trim_trailing_whitespace = true +end_of_line = lf +insert_final_newline = true -[**.cpp] -indent_style = tab -indent_size = 4 - -[**.hpp] +# Tab indentation (no size specified) +[Makefile] indent_style = tab -indent_size = 4 -[**.h] -indent_style = tab -indent_size = 4 +[*.{c,h,cpp,hpp}] +indent_size = 4 \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 7f6ac5c2..163e4de2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,72 +1,87 @@ sudo: required -dist: trusty +dist: xenial language: cpp -compiler: - - clang - - gcc - -env: - - CTEST_OUTPUT_ON_FAILURE=1 USE_GCC7=0 - - CTEST_OUTPUT_ON_FAILURE=1 USE_GCC7=1 +addons: + apt: + sources: + - llvm-toolchain-trusty + packages: + - clang-format-9 matrix: - exclude: - - compiler: clang - env: CTEST_OUTPUT_ON_FAILURE=1 USE_GCC7=1 + include: + - env: BUILD=1 CTEST_OUTPUT_ON_FAILURE=1 USE_GCC7=1 + compiler: clang + - env: BUILD=1 CTEST_OUTPUT_ON_FAILURE=1 USE_GCC7=1 + compiler: gcc + - env: BUILD=1 CTEST_OUTPUT_ON_FAILURE=1 USE_GCC7=0 + compiler: gcc + - env: FORMAT=1 before_install: - - sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y - - sudo apt-get update -qq -# uncomment for ubuntu precise. not needed for >=trusty - if [ "$CXX" = "g++" ]; then sudo apt-get install -y -qq g++-4.8; export CXX="g++-4.8" CC="gcc-4.8"; else echo "yes" | sudo add-apt-repository 'deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu precise main'; echo "yes" | sudo add-apt-repository 'deb http://llvm.org/apt/precise/ llvm-toolchain-precise-3.6 main'; wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key | sudo apt-key add -; sudo apt-get update; sudo apt-get install -qq --allow-unauthenticated llvm-3.6 llvm-3.6-dev clang-3.6 libstdc++-4.8-dev; export CXX="clang++-3.6" CC="clang-3.6"; fi - - if [ "$USE_GCC7" = "1" ]; then sudo apt-get install -y -qq g++-7; export CXX="g++-7" CC="gcc-7"; fi - - $CXX --version -# install json-c - - sudo apt-get install -y build-essential - - sudo apt-get install -y wget - - sudo apt-get install -y libtool - - git clone -b json-c-0.12 https://github.com/json-c/json-c - - cd json-c - - sh autogen.sh - - ./configure - - make - - sudo make install - - cd .. - - sudo apt-get install -y libcurl4-openssl-dev openssl libmicrohttpd-dev uuid-dev uuid-runtime libunistring-dev -# -- get libsml -- - - git clone https://github.com/volkszaehler/libsml.git # or github.com/TheCount/libsml.git # or https://github.com/dailab/libsml.git - - cd libsml - - # git checkout develop # only dev branch seems to work - - make -# -- install libsml -- - - sudo cp sml/lib/libsml.* /usr/lib/. - - sudo cp -R sml/include/* /usr/include/. - - sudo cp sml.pc /usr/lib/pkgconfig/. - - cd .. + - clang-format --version + +install: + - | + if [ -n "$BUILD" ]; then + sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y + sudo apt-get update -qq + if [ "$USE_GCC7" = "1" ]; then sudo apt-get install -y -qq g++-7; export CXX="g++-7" CC="gcc-7"; fi + $CXX --version + # install json-c + sudo apt-get install -y build-essential + sudo apt-get install -y wget + sudo apt-get install -y libtool + git clone -b json-c-0.12 https://github.com/json-c/json-c + cd json-c + sh autogen.sh + ./configure + make + sudo make install + cd .. + sudo apt-get install -y libcurl4-openssl-dev openssl libmicrohttpd-dev uuid-dev uuid-runtime libunistring-dev + # -- get libsml -- + git clone https://github.com/volkszaehler/libsml.git # or github.com/TheCount/libsml.git # or https://github.com/dailab/libsml.git + cd libsml + # git checkout develop # only dev branch seems to work + make + # -- install libsml -- + sudo cp sml/lib/libsml.* /usr/lib/. + sudo cp -R sml/include/* /usr/include/. + sudo cp sml.pc /usr/lib/pkgconfig/. + cd .. + + # -- install leptonica + sudo apt-get install -y libpng-dev libtiff-dev + wget http://www.leptonica.org/source/leptonica-1.71.tar.gz + tar -zxvf leptonica-1.71.tar.gz + cd leptonica-1.71 + ./configure --disable-programs + make + sudo make install + sudo ldconfig + cd .. -# -- install leptonica - - sudo apt-get install -y libpng-dev libtiff-dev - - wget http://www.leptonica.org/source/leptonica-1.71.tar.gz - - tar -zxvf leptonica-1.71.tar.gz - - cd leptonica-1.71 - - ./configure --disable-programs - - make - - sudo make install - - sudo ldconfig - - cd .. + # -- install libmbus + git clone https://github.com/rscada/libmbus + cd libmbus + ./build.sh + sudo make install + cd .. + sudo apt-get install -y lcov -# -- install libmbus - - git clone https://github.com/rscada/libmbus - - cd libmbus - - ./build.sh - - sudo make install - - cd .. - - sudo apt-get install -y lcov + # -- install libmosquitto-dev + sudo add-apt-repository ppa:mosquitto-dev/mosquitto-ppa -y + sudo apt-get update -qq + sudo apt-get install -qq libmosquitto-dev + fi -# -- install libmosquitto-dev - - sudo add-apt-repository ppa:mosquitto-dev/mosquitto-ppa -y - - sudo apt-get update -qq - - sudo apt-get install -qq libmosquitto-dev script: - - cmake . -DMETEREXEC_ROOTACCESS=OFF -DENABLE_OCR=ON -DSML_HOME=/usr/local/src/libsml/sml && make && make test + - if [ -n "$BUILD" ]; then cmake . -DMETEREXEC_ROOTACCESS=OFF -DENABLE_OCR=ON -DSML_HOME=/usr/local/src/libsml/sml && make && make test; fi + - | + if [ -n "$FORMAT" ]; then + clang-format -i include/**/*.{h,hpp} src/**/*.cpp tests/**/*.{cpp,hpp} + test -z "$(git status --porcelain)" || (git status; git diff; false) + fi diff --git a/include/ApiIF.hpp b/include/ApiIF.hpp index 01d4bfc8..51e175c0 100644 --- a/include/ApiIF.hpp +++ b/include/ApiIF.hpp @@ -35,30 +35,30 @@ #include -#include #include +#include namespace vz { - class ApiIF { - public: - typedef vz::shared_ptr Ptr; +class ApiIF { + public: + typedef vz::shared_ptr Ptr; - ApiIF(Channel::Ptr ch) : _ch(ch){} - virtual ~ApiIF(){}; + ApiIF(Channel::Ptr ch) : _ch(ch) {} + virtual ~ApiIF(){}; -/** - * @brief send measurement values to middleware - * to be implemented specific API. - **/ - virtual void send() = 0; - virtual void register_device() = 0; - - protected: - Channel::Ptr channel() { return _ch; } + /** + * @brief send measurement values to middleware + * to be implemented specific API. + **/ + virtual void send() = 0; + virtual void register_device() = 0; + + protected: + Channel::Ptr channel() { return _ch; } - private: - Channel::Ptr _ch; /**< pointer to channel where API belongs to */ - }; //class ApiIF + private: + Channel::Ptr _ch; /**< pointer to channel where API belongs to */ +}; // class ApiIF } // namespace vz #endif /* _ApiIF_hpp_ */ diff --git a/include/Buffer.hpp b/include/Buffer.hpp index 415a815d..2c4ed1df 100644 --- a/include/Buffer.hpp +++ b/include/Buffer.hpp @@ -28,15 +28,15 @@ #ifndef _BUFFER_H_ #define _BUFFER_H_ +#include #include #include -#include #include class Buffer { - public: + public: typedef vz::shared_ptr Ptr; typedef std::list::iterator iterator; typedef std::list::const_iterator const_iterator; @@ -54,45 +54,41 @@ class Buffer { std::string dump(); inline iterator begin() { return _sent.begin(); } - inline iterator end() { return _sent.end(); } - inline size_t size() { lock(); size_t s = _sent.size(); unlock(); return s; } + inline iterator end() { return _sent.end(); } + inline size_t size() { + lock(); + size_t s = _sent.size(); + unlock(); + return s; + } inline bool newValues() const { return _newValues; } inline void clear_newValues() { _newValues = false; } - inline void lock() { pthread_mutex_lock(&_mutex); } + inline void lock() { pthread_mutex_lock(&_mutex); } inline void unlock() { pthread_mutex_unlock(&_mutex); } inline void wait(pthread_cond_t *condition) { pthread_cond_wait(condition, &_mutex); } - inline void have_newValues() { _newValues = true; } + inline void have_newValues() { _newValues = true; } - inline void set_aggmode(Buffer::aggmode m) {_aggmode=m;} + inline void set_aggmode(Buffer::aggmode m) { _aggmode = m; } inline aggmode get_aggmode() const { return _aggmode; } - private: - Buffer(const Buffer &); // don't allow copy constructor - Buffer & operator=(const Buffer &); // and no assignment op. + private: + Buffer(const Buffer &); // don't allow copy constructor + Buffer &operator=(const Buffer &); // and no assignment op. std::list _sent; bool _newValues; Buffer::aggmode _aggmode; - size_t _keep; /**< number of readings to cache for local interface */ + size_t _keep; /**< number of readings to cache for local interface */ pthread_mutex_t _mutex; - Reading *_last_avg; // keeps value and time from last reading from aggregate call for aggmode AVG + Reading + *_last_avg; // keeps value and time from last reading from aggregate call for aggmode AVG }; #endif /* _BUFFER_H_ */ - - -/* - * Local variables: - * tab-width: 2 - * c-indent-level: 2 - * c-basic-offset: 2 - * project-name: vzlogger - * End: - */ diff --git a/include/Channel.hpp b/include/Channel.hpp index 181c777c..3a2ad9b7 100644 --- a/include/Channel.hpp +++ b/include/Channel.hpp @@ -29,22 +29,23 @@ #include #include -#include "Reading.hpp" #include "Buffer.hpp" -#include +#include "Reading.hpp" #include #include +#include class Channel { - public: + public: typedef vz::shared_ptr Ptr; // This shared_ptr is set when a logging_thread for an object of this class is started. // Inside the logging_thread, a Channel::Ptr is used. Data is passed via the void* // argument of pthread_create, and thus directly passing a shared pointer will break it. Ptr _this_forthread; - Channel(const std::list