diff options
author | Thomas Gubler <thomasgubler@gmail.com> | 2015-01-06 11:09:11 +0100 |
---|---|---|
committer | Thomas Gubler <thomasgubler@gmail.com> | 2015-01-06 11:09:11 +0100 |
commit | f871b777abe841149ed537349ff7a6bd3156e9c9 (patch) | |
tree | 73c0cea31a18f67937232d0e66fee6684013510a /src/platforms/px4_nodehandle.h | |
parent | 94b9251a69ffbb94b7b1e4292f7ee2d9779cc8ff (diff) | |
download | px4-firmware-f871b777abe841149ed537349ff7a6bd3156e9c9.tar.gz px4-firmware-f871b777abe841149ed537349ff7a6bd3156e9c9.tar.bz2 px4-firmware-f871b777abe841149ed537349ff7a6bd3156e9c9.zip |
destructors for px4_nodehandle
Diffstat (limited to 'src/platforms/px4_nodehandle.h')
-rw-r--r-- | src/platforms/px4_nodehandle.h | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/platforms/px4_nodehandle.h b/src/platforms/px4_nodehandle.h index 0e77852f2..3c2bb2d44 100644 --- a/src/platforms/px4_nodehandle.h +++ b/src/platforms/px4_nodehandle.h @@ -68,7 +68,8 @@ public: ~NodeHandle() { - //XXX empty lists + _subs.clear(); + _pubs.clear(); }; /** @@ -154,7 +155,36 @@ public: _sub_min_interval(nullptr) {} - ~NodeHandle() {}; + ~NodeHandle() + { + /* Empty subscriptions list */ + uORB::SubscriptionNode *sub = _subs.getHead(); + int count = 0; + while (sub != nullptr) { + if (count++ > kMaxSubscriptions) { + PX4_WARN("exceeded max subscriptions"); + break; + } + + uORB::SubscriptionNode *sib = sub->getSibling(); + delete sub; + sub = sib; + } + + /* Empty publications list */ + uORB::PublicationNode *pub = _pubs.getHead(); + count = 0; + while (pub != nullptr) { + if (count++ > kMaxPublications) { + PX4_WARN("exceeded max publications"); + break; + } + + uORB::PublicationNode *sib = pub->getSibling(); + delete pub; + pub = sib; + } + }; /** * Subscribe with callback to function @@ -254,6 +284,7 @@ public: } private: static const uint16_t kMaxSubscriptions = 100; + static const uint16_t kMaxPublications = 100; List<uORB::SubscriptionNode *> _subs; /**< Subcriptions of node */ List<uORB::PublicationNode *> _pubs; /**< Publications of node */ uORB::SubscriptionNode *_sub_min_interval; /**< Points to the sub wtih the smallest interval |