From 3d6792c0198ed2d923d9aa8e50cdf46fa2bbbd0a Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Fri, 2 Jun 2017 22:01:16 -0400 Subject: [PATCH] Block and SuperBlock minor cleanup --- src/lib/controllib/block/Block.cpp | 28 ++++------ src/lib/controllib/block/Block.hpp | 74 ++++++++++++++----------- src/lib/controllib/block/BlockParam.cpp | 2 +- 3 files changed, 54 insertions(+), 50 deletions(-) diff --git a/src/lib/controllib/block/Block.cpp b/src/lib/controllib/block/Block.cpp index 291468d28d..6815f60164 100644 --- a/src/lib/controllib/block/Block.cpp +++ b/src/lib/controllib/block/Block.cpp @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * Copyright (C) 2012-2017 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -37,25 +37,20 @@ * Controller library code */ -#include -#include -#include +#include "Block.hpp" +#include "BlockParam.hpp" #include #include #include -#include "Block.hpp" -#include "BlockParam.hpp" - namespace control { Block::Block(SuperBlock *parent, const char *name) : _name(name), - _parent(parent), - _dt(0) + _parent(parent) { if (getParent() != nullptr) { getParent()->getChildren().add(this); @@ -93,7 +88,7 @@ void Block::updateParams() if (count++ > maxParamsPerBlock) { char name[blockNameLengthMax]; getName(name, blockNameLengthMax); - printf("exceeded max params for block: %s\n", name); + PX4_ERR("exceeded max params for block: %s", name); break; } @@ -112,7 +107,7 @@ void Block::updateSubscriptions() if (count++ > maxSubscriptionsPerBlock) { char name[blockNameLengthMax]; getName(name, blockNameLengthMax); - printf("exceeded max subscriptions for block: %s\n", name); + PX4_ERR("exceeded max subscriptions for block: %s", name); break; } @@ -130,7 +125,7 @@ void Block::updatePublications() if (count++ > maxPublicationsPerBlock) { char name[blockNameLengthMax]; getName(name, blockNameLengthMax); - printf("exceeded max publications for block: %s\n", name); + PX4_ERR("exceeded max publications for block: %s", name); break; } @@ -149,7 +144,7 @@ void SuperBlock::setDt(float dt) if (count++ > maxChildrenPerBlock) { char name[blockNameLengthMax]; getName(name, blockNameLengthMax); - printf("exceeded max children for block: %s\n", name); + PX4_ERR("exceeded max children for block: %s", name); break; } @@ -167,7 +162,7 @@ void SuperBlock::updateChildParams() if (count++ > maxChildrenPerBlock) { char name[blockNameLengthMax]; getName(name, blockNameLengthMax); - printf("exceeded max children for block: %s\n", name); + PX4_ERR("exceeded max children for block: %s", name); break; } @@ -185,7 +180,7 @@ void SuperBlock::updateChildSubscriptions() if (count++ > maxChildrenPerBlock) { char name[blockNameLengthMax]; getName(name, blockNameLengthMax); - printf("exceeded max children for block: %s\n", name); + PX4_ERR("exceeded max children for block: %s", name); break; } @@ -203,7 +198,7 @@ void SuperBlock::updateChildPublications() if (count++ > maxChildrenPerBlock) { char name[blockNameLengthMax]; getName(name, blockNameLengthMax); - printf("exceeded max children for block: %s\n", name); + PX4_ERR("exceeded max children for block: %s", name); break; } @@ -212,7 +207,6 @@ void SuperBlock::updateChildPublications() } } - } // namespace control template class List; diff --git a/src/lib/controllib/block/Block.hpp b/src/lib/controllib/block/Block.hpp index 21d216f4fd..47838b4b4b 100644 --- a/src/lib/controllib/block/Block.hpp +++ b/src/lib/controllib/block/Block.hpp @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * Copyright (C) 2012-2017 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,16 +32,13 @@ ****************************************************************************/ /** - * @file Block.h + * @file Block.hpp * * Controller library code */ #pragma once -#include -#include - #include #include #include @@ -50,11 +47,11 @@ namespace control { -static const uint16_t maxChildrenPerBlock = 100; -static const uint16_t maxParamsPerBlock = 100; -static const uint16_t maxSubscriptionsPerBlock = 100; -static const uint16_t maxPublicationsPerBlock = 100; -static const uint8_t blockNameLengthMax = 40; +static constexpr uint8_t maxChildrenPerBlock = 100; +static constexpr uint8_t maxParamsPerBlock = 100; +static constexpr uint8_t maxSubscriptionsPerBlock = 100; +static constexpr uint8_t maxPublicationsPerBlock = 100; +static constexpr uint8_t blockNameLengthMax = 40; // forward declaration class BlockParamBase; @@ -62,39 +59,43 @@ class SuperBlock; /** */ -class __EXPORT Block : - public ListNode +class __EXPORT Block : public ListNode { public: friend class BlockParamBase; -// methods + Block(SuperBlock *parent, const char *name); + virtual ~Block() = default; + + // no copy, assignment, move, move assignment + Block(const Block &) = delete; + Block &operator=(const Block &) = delete; + Block(Block &&) = delete; + Block &operator=(Block &&) = delete; + void getName(char *name, size_t n); - virtual ~Block() {}; + virtual void updateParams(); virtual void updateSubscriptions(); virtual void updatePublications(); + virtual void setDt(float dt) { _dt = dt; } -// accessors float getDt() { return _dt; } + protected: -// accessors + SuperBlock *getParent() { return _parent; } List &getSubscriptions() { return _subscriptions; } List &getPublications() { return _publications; } List &getParams() { return _params; } -// attributes + const char *_name; SuperBlock *_parent; - float _dt; + float _dt{0.0f}; + List _subscriptions; List _publications; List _params; - -private: - /* this class has pointer data members and should not be copied (private constructor) */ - Block(const control::Block &); - Block operator=(const control::Block &); }; class __EXPORT SuperBlock : @@ -102,35 +103,44 @@ class __EXPORT SuperBlock : { public: friend class Block; -// methods - SuperBlock(SuperBlock *parent, const char *name) : Block(parent, name) {} - virtual ~SuperBlock() {}; - virtual void setDt(float dt); - virtual void updateParams() + + SuperBlock(SuperBlock *parent, const char *name) : Block(parent, name) {}; + ~SuperBlock() = default; + + // no copy, assignment, move, move assignment + SuperBlock(const SuperBlock &) = delete; + SuperBlock &operator=(const SuperBlock &) = delete; + SuperBlock(SuperBlock &&) = delete; + SuperBlock &operator=(SuperBlock &&) = delete; + + void setDt(float dt) override; + + void updateParams() override { Block::updateParams(); if (getChildren().getHead() != nullptr) { updateChildParams(); } } - virtual void updateSubscriptions() + + void updateSubscriptions() override { Block::updateSubscriptions(); if (getChildren().getHead() != nullptr) { updateChildSubscriptions(); } } - virtual void updatePublications() + void updatePublications() override { Block::updatePublications(); if (getChildren().getHead() != nullptr) { updateChildPublications(); } } + protected: -// methods List &getChildren() { return _children; } void updateChildParams(); void updateChildSubscriptions(); void updateChildPublications(); -// attributes + List _children; }; diff --git a/src/lib/controllib/block/BlockParam.cpp b/src/lib/controllib/block/BlockParam.cpp index c23f5f17fe..947cc0133b 100644 --- a/src/lib/controllib/block/BlockParam.cpp +++ b/src/lib/controllib/block/BlockParam.cpp @@ -77,7 +77,7 @@ BlockParamBase::BlockParamBase(Block *parent, const char *name, bool parent_pref _handle = param_find(fullname); if (_handle == PARAM_INVALID) { - PX4_ERR("error finding param: %s\n", fullname); + PX4_ERR("error finding param: %s", fullname); } };