summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-15 18:07:44 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-15 18:07:44 (GMT)
commitf061668e3c1d5eac01b85303e2c81df2bc560e9a (patch)
treede56afe6d93cb36425f7c2e458575d27bd9105a4 /Swiften/StreamStack/StreamStack.cpp
parent0930cd940963be0edfe7c80b4925babca0e01443 (diff)
downloadswift-f061668e3c1d5eac01b85303e2c81df2bc560e9a.zip
swift-f061668e3c1d5eac01b85303e2c81df2bc560e9a.tar.bz2
Make stream stack layers reference counted.
Diffstat (limited to 'Swiften/StreamStack/StreamStack.cpp')
-rw-r--r--Swiften/StreamStack/StreamStack.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/Swiften/StreamStack/StreamStack.cpp b/Swiften/StreamStack/StreamStack.cpp
index 7dde858..9eb9b4e 100644
--- a/Swiften/StreamStack/StreamStack.cpp
+++ b/Swiften/StreamStack/StreamStack.cpp
@@ -2,25 +2,36 @@
#include <boost/bind.hpp>
+#include "Swiften/Base/foreach.h"
#include "Swiften/StreamStack/XMPPLayer.h"
#include "Swiften/StreamStack/LowLayer.h"
#include "Swiften/StreamStack/StreamLayer.h"
namespace Swift {
-StreamStack::StreamStack(XMPPLayer* xmppLayer, LowLayer* physicalLayer) : xmppLayer_(xmppLayer), physicalLayer_(physicalLayer) {
+StreamStack::StreamStack(boost::shared_ptr<XMPPLayer> xmppLayer, boost::shared_ptr<LowLayer> physicalLayer) : xmppLayer_(xmppLayer), physicalLayer_(physicalLayer) {
xmppReadSlotConnection_ = physicalLayer_->onDataRead.connect(boost::bind(&XMPPLayer::parseData, xmppLayer_, _1));
xmppWriteSignalConnection_ = xmppLayer_->onWriteData.connect(boost::bind(&LowLayer::writeData, physicalLayer_, _1));
}
-void StreamStack::addLayer(StreamLayer* newLayer) {
+StreamStack::~StreamStack() {
+ // Disconnect the write signal connections to break cyclic signal
+ // dependencies. The read signal connections have
+ // to remain, since these can be reached from the main event loop.
+ xmppWriteSignalConnection_.disconnect();
+ foreach(const boost::bsignals::connection& connection, writeSignalConnections_) {
+ connection.disconnect();
+ }
+}
+
+void StreamStack::addLayer(boost::shared_ptr<StreamLayer> newLayer) {
xmppReadSlotConnection_.disconnect();
xmppWriteSignalConnection_.disconnect();
- LowLayer* lowLayer = (layers_.empty() ? physicalLayer_ : *layers_.rbegin());
+ boost::shared_ptr<LowLayer> lowLayer = (layers_.empty() ? physicalLayer_ : *layers_.rbegin());
lowLayer->onDataRead.connect(boost::bind(&HighLayer::handleDataRead, newLayer, _1), boost::bsignals::at_front);
- newLayer->onWriteData.connect(boost::bind(&LowLayer::writeData, lowLayer, _1), boost::bsignals::at_front);
+ writeSignalConnections_.push_back(newLayer->onWriteData.connect(boost::bind(&LowLayer::writeData, lowLayer, _1), boost::bsignals::at_front));
xmppWriteSignalConnection_ = xmppLayer_->onWriteData.connect(boost::bind(&LowLayer::writeData, newLayer, _1), boost::bsignals::at_front);
xmppReadSlotConnection_ = newLayer->onDataRead.connect(boost::bind(&XMPPLayer::parseData, xmppLayer_, _1), boost::bsignals::at_front);
layers_.push_back(newLayer);