From 6ede0e2f18f001afb390f3bbb0b989bdd2759c24 Mon Sep 17 00:00:00 2001 From: px4dev Date: Sat, 29 Dec 2012 12:58:10 -0800 Subject: Add the ability to reset a mixer group. Report the remaining buffer size from load_from_buf. --- apps/systemlib/mixer/mixer.h | 10 ++++++++-- apps/systemlib/mixer/mixer_group.cpp | 24 +++++++++++++++--------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/apps/systemlib/mixer/mixer.h b/apps/systemlib/mixer/mixer.h index 0023dc380..95b576d41 100644 --- a/apps/systemlib/mixer/mixer.h +++ b/apps/systemlib/mixer/mixer.h @@ -233,6 +233,11 @@ public: */ void add_mixer(Mixer *mixer); + /** + * Remove all the mixers from the group. + */ + void reset(); + /** * Adds mixers to the group based on a text description in a buffer. * @@ -269,10 +274,11 @@ public: * R: * * @param buf The mixer configuration buffer. - * @param buflen The length of the buffer. + * @param buflen The length of the buffer, updated to reflect + * bytes as they are consumed. * @return Zero on successful load, nonzero otherwise. */ - int load_from_buf(const char *buf, unsigned buflen); + int load_from_buf(const char *buf, unsigned &buflen); private: Mixer *_first; /**< linked list of mixers */ diff --git a/apps/systemlib/mixer/mixer_group.cpp b/apps/systemlib/mixer/mixer_group.cpp index af5569001..6dfe4fbef 100644 --- a/apps/systemlib/mixer/mixer_group.cpp +++ b/apps/systemlib/mixer/mixer_group.cpp @@ -64,14 +64,7 @@ MixerGroup::MixerGroup(ControlCallback control_cb, uintptr_t cb_handle) : MixerGroup::~MixerGroup() { - Mixer *mixer; - - /* discard sub-mixers */ - while (_first != nullptr) { - mixer = _first; - _first = mixer->_next; - delete mixer; - } + reset(); } void @@ -88,6 +81,19 @@ MixerGroup::add_mixer(Mixer *mixer) mixer->_next = nullptr; } +void +MixerGroup::reset() +{ + Mixer *mixer; + + /* discard sub-mixers */ + while (_first != nullptr) { + mixer = _first; + _first = mixer->_next; + delete mixer; + } +} + unsigned MixerGroup::mix(float *outputs, unsigned space) { @@ -114,7 +120,7 @@ MixerGroup::groups_required(uint32_t &groups) } int -MixerGroup::load_from_buf(const char *buf, unsigned buflen) +MixerGroup::load_from_buf(const char *buf, unsigned &buflen) { int ret = -1; const char *end = buf + buflen; -- cgit v1.2.3