Changeset - 9a3e4ca7c84f
[Not reviewed]
stream
0 5 0
Hasan Yavuz Ă–ZDERYA - 7 years ago 2018-05-26 15:43:58
hy@ozderya.net
disconnect previous source in `connectSink` function
5 files changed with 15 insertions and 13 deletions:
0 comments (0 inline, 0 general)
src/mainwindow.cpp
Show inline comments
 
@@ -348,12 +348,6 @@ void MainWindow::onPortToggled(bool open
 

	
 
void MainWindow::setStreamSource(Source* source)
 
{
 
    // disconnect previous source
 
    auto currentSource = stream.connectedSource();
 
    if (currentSource != nullptr)
 
    {
 
        currentSource->disconnect((Sink*) &stream);
 
    }
 
    // connect to new source
 
    source->connectSink(&stream);
 
}
src/sink.cpp
Show inline comments
 
@@ -53,7 +53,7 @@ void Sink::setNumChannels(unsigned nc, b
 
    }
 
}
 

	
 
void Sink::setSource(const Source* s)
 
void Sink::setSource(Source* s)
 
{
 
    Q_ASSERT((source == nullptr) != (s == nullptr));
 
    source = s;
src/sink.h
Show inline comments
 
@@ -53,17 +53,19 @@ protected:
 
    virtual void setNumChannels(unsigned nc, bool x);
 

	
 
    /// Set by the connected source when its connected. When
 
    /// disconnecting it's set to `NULL`.
 
    /// disconnecting it's set to `nullptr`.
 
    ///
 
    /// @note Previous source is disconnected.
 
    ///
 
    /// @important Trying to connect a source while its already
 
    /// connected is an error.
 
    void setSource(const Source* s);
 
    void setSource(Source* s);
 

	
 
    friend Source;
 

	
 
private:
 
    QList<Sink*> followers;
 
    const Source* source = nullptr;   ///< source that this sink is connected to
 
    Source* source = nullptr;   ///< source that this sink is connected to
 
    bool _hasX;
 
    unsigned _numChannels;
 
};
src/source.cpp
Show inline comments
 
@@ -32,7 +32,12 @@ Source::~Source()
 
void Source::connectSink(Sink* sink)
 
{
 
    Q_ASSERT(!sinks.contains(sink));
 
    Q_ASSERT(sink->connectedSource() == nullptr);
 

	
 
    auto prevSource = sink->connectedSource();
 
    if (prevSource != nullptr)
 
    {
 
        prevSource->disconnect(sink);
 
    }
 

	
 
    sinks.append(sink);
 
    sink->setSource(this);
src/source.h
Show inline comments
 
@@ -37,8 +37,9 @@ public:
 
    /// Returns number of channels
 
    virtual unsigned numChannels() const = 0;
 

	
 
    /// Connects a sink to this source. Trying to connect an already
 
    /// connected sink is an error.
 
    /// Connects a sink to this source.
 
    ///
 
    /// If `Sink` is already connected to a source, it's disconnected first.
 
    void connectSink(Sink* sink);
 

	
 
    /// Disconnects an already connected sink. Trying to disconnect an
0 comments (0 inline, 0 general)