# HG changeset patch # User Hasan Yavuz Ă–ZDERYA # Date 2018-04-03 15:37:27 # Node ID 9ce163ba1b8887649e3c1c6a828dc4d3021d81cc # Parent 8554454db965f5fd05fc9126e2daa463a6695fbe added method for disconnecting all sinks diff --git a/src/source.cpp b/src/source.cpp --- a/src/source.cpp +++ b/src/source.cpp @@ -48,6 +48,15 @@ void Source::disconnect(Sink* sink) sinks.removeOne(sink); } +void Source::disconnectSinks() +{ + while (!sinks.isEmpty()) + { + auto sink = sinks.takeFirst(); + sink->setSource(NULL); + } +} + void Source::feedOut(const SamplePack& data) const { for (auto sink : sinks) diff --git a/src/source.h b/src/source.h --- a/src/source.h +++ b/src/source.h @@ -45,9 +45,12 @@ public: /// unconnected sink is an error. void disconnect(Sink* sink); + /// Disconnects all connected sinks. + void disconnectSinks(); + protected: /// Feeds "in" given data to connected sinks - void feedOut(const SamplePack& data) const; + virtual void feedOut(const SamplePack& data) const; /// Updates "number of channels" of connected sinks. Must be /// called when num. channels or hasX changes. diff --git a/tests/test.cpp b/tests/test.cpp --- a/tests/test.cpp +++ b/tests/test.cpp @@ -127,6 +127,24 @@ TEST_CASE("source must set/unset sink 's REQUIRE(sink.connectedSource() == NULL); } +TEST_CASE("source disconnect all sinks", "[memory, stream]") +{ + TestSink sinks[3]; + TestSource source(3, false); + + // connect sinks + for (int i = 0; i < 3; i++) + { + source.connect(&sinks[i]); + } + + source.disconnectSinks(); + for (int i = 0; i < 3; i++) + { + REQUIRE(sinks[i].connectedSource() == NULL); + } +} + TEST_CASE("IndexBuffer", "[memory, buffer]") { IndexBuffer buf(10);