From aefd217fc0009432998f6e66abe028dd8c40c311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Fri, 12 Aug 2016 08:58:33 +0200 Subject: [PATCH] uorb subscription: remove _interval & use orb_get_interval() instead --- src/modules/uORB/Subscription.cpp | 10 +++++----- src/modules/uORB/Subscription.hpp | 17 +++++++++-------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/modules/uORB/Subscription.cpp b/src/modules/uORB/Subscription.cpp index 071254c80e..f07cc4820a 100644 --- a/src/modules/uORB/Subscription.cpp +++ b/src/modules/uORB/Subscription.cpp @@ -84,7 +84,7 @@ SubscriptionBase::SubscriptionBase(const struct orb_metadata *meta, _handle = orb_subscribe(getMeta()); } - if (_handle < 0) { warnx("sub failed"); } + if (_handle < 0) { PX4_ERR("sub failed"); } if (interval > 0) { orb_set_interval(getHandle(), interval); @@ -96,7 +96,7 @@ bool SubscriptionBase::updated() bool isUpdated = false; int ret = orb_check(_handle, &isUpdated); - if (ret != PX4_OK) { warnx("orb check failed"); } + if (ret != PX4_OK) { PX4_ERR("orb check failed"); } return isUpdated; } @@ -106,7 +106,7 @@ void SubscriptionBase::update(void *data) if (updated()) { int ret = orb_copy(_meta, _handle, data); - if (ret != PX4_OK) { warnx("orb copy failed"); } + if (ret != PX4_OK) { PX4_ERR("orb copy failed"); } } } @@ -114,7 +114,7 @@ SubscriptionBase::~SubscriptionBase() { int ret = orb_unsubscribe(_handle); - if (ret != PX4_OK) { warnx("orb unsubscribe failed"); } + if (ret != PX4_OK) { PX4_ERR("orb unsubscribe failed"); } } template @@ -129,7 +129,7 @@ Subscription::Subscription(const struct orb_metadata *meta, template Subscription::Subscription(const Subscription &other) : - SubscriptionNode(other._meta, other._interval, other._instance, nullptr), + SubscriptionNode(other._meta, other.getInterval(), other._instance, nullptr), _data() // initialize data structure to zero { } diff --git a/src/modules/uORB/Subscription.hpp b/src/modules/uORB/Subscription.hpp index 7b55b4a2a0..0aa2232252 100644 --- a/src/modules/uORB/Subscription.hpp +++ b/src/modules/uORB/Subscription.hpp @@ -86,7 +86,14 @@ public: // accessors const struct orb_metadata *getMeta() { return _meta; } - int getHandle() { return _handle; } + int getHandle() const { return _handle; } + + unsigned getInterval() const + { + unsigned int interval; + orb_get_interval(getHandle(), &interval); + return interval; + } protected: // accessors void setHandle(int handle) { _handle = handle; } @@ -130,8 +137,7 @@ public: unsigned interval = 0, int instance = 0, List *list = nullptr) : - SubscriptionBase(meta, interval, instance), - _interval(interval) + SubscriptionBase(meta, interval, instance) { if (list != nullptr) { list->add(this); } } @@ -141,11 +147,6 @@ public: * updates, a child class must implement it. */ virtual void update() = 0; -// accessors - unsigned getInterval() { return _interval; } -protected: -// attributes - unsigned _interval; };