summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/StreamStack')
-rw-r--r--Swiften/StreamStack/CompressionLayer.h9
-rw-r--r--Swiften/StreamStack/ConnectionLayer.h3
-rw-r--r--Swiften/StreamStack/HighLayer.cpp12
-rw-r--r--Swiften/StreamStack/HighLayer.h26
-rw-r--r--Swiften/StreamStack/LowLayer.cpp12
-rw-r--r--Swiften/StreamStack/LowLayer.h26
-rw-r--r--Swiften/StreamStack/StreamLayer.h7
-rw-r--r--Swiften/StreamStack/StreamStack.cpp28
-rw-r--r--Swiften/StreamStack/StreamStack.h23
-rw-r--r--Swiften/StreamStack/TLSLayer.cpp7
-rw-r--r--Swiften/StreamStack/WhitespacePingLayer.cpp6
-rw-r--r--Swiften/StreamStack/XMPPLayer.cpp15
-rw-r--r--Swiften/StreamStack/XMPPLayer.h8
13 files changed, 110 insertions, 72 deletions
diff --git a/Swiften/StreamStack/CompressionLayer.h b/Swiften/StreamStack/CompressionLayer.h
index 4da053d..b8293a8 100644
--- a/Swiften/StreamStack/CompressionLayer.h
+++ b/Swiften/StreamStack/CompressionLayer.h
@@ -4,8 +4,7 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#ifndef SWIFTEN_COMPRESSIONLAYER_H
-#define SWIFTEN_COMPRESSIONLAYER_H
+#pragma once
#include <boost/noncopyable.hpp>
#include "Swiften/Base/boost_bsignals.h"
@@ -26,7 +25,7 @@ namespace Swift {
virtual void writeData(const ByteArray& data) {
try {
- onWriteData(compressor_.process(data));
+ writeDataToChildLayer(compressor_.process(data));
}
catch (const ZLibException& e) {
onError();
@@ -35,7 +34,7 @@ namespace Swift {
virtual void handleDataRead(const ByteArray& data) {
try {
- onDataRead(decompressor_.process(data));
+ writeDataToParentLayer(decompressor_.process(data));
}
catch (const ZLibException& e) {
onError();
@@ -50,5 +49,3 @@ namespace Swift {
ZLibDecompressor decompressor_;
};
}
-
-#endif
diff --git a/Swiften/StreamStack/ConnectionLayer.h b/Swiften/StreamStack/ConnectionLayer.h
index be72979..fab014e 100644
--- a/Swiften/StreamStack/ConnectionLayer.h
+++ b/Swiften/StreamStack/ConnectionLayer.h
@@ -8,6 +8,7 @@
#include "Swiften/Base/boost_bsignals.h"
#include <boost/shared_ptr.hpp>
+#include <boost/bind.hpp>
#include "Swiften/StreamStack/LowLayer.h"
#include "Swiften/Network/Connection.h"
@@ -16,7 +17,7 @@ namespace Swift {
class ConnectionLayer : public LowLayer {
public:
ConnectionLayer(boost::shared_ptr<Connection> connection) : connection(connection) {
- connection->onDataRead.connect(onDataRead);
+ connection->onDataRead.connect(boost::bind(&ConnectionLayer::writeDataToParentLayer, this, _1));
}
void writeData(const ByteArray& data) {
diff --git a/Swiften/StreamStack/HighLayer.cpp b/Swiften/StreamStack/HighLayer.cpp
index 78b890e..da1eec9 100644
--- a/Swiften/StreamStack/HighLayer.cpp
+++ b/Swiften/StreamStack/HighLayer.cpp
@@ -4,11 +4,21 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#include "Swiften/StreamStack/HighLayer.h"
+#include <Swiften/StreamStack/HighLayer.h>
+
+#include <Swiften/StreamStack/LowLayer.h>
namespace Swift {
+HighLayer::HighLayer() : childLayer(NULL) {
+}
+
HighLayer::~HighLayer() {
}
+void HighLayer::writeDataToChildLayer(const ByteArray& data) {
+ assert(childLayer);
+ childLayer->writeData(data);
+}
+
}
diff --git a/Swiften/StreamStack/HighLayer.h b/Swiften/StreamStack/HighLayer.h
index f15621e..ca983f9 100644
--- a/Swiften/StreamStack/HighLayer.h
+++ b/Swiften/StreamStack/HighLayer.h
@@ -4,22 +4,34 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#ifndef SWIFTEN_HIGHLAYER_H
-#define SWIFTEN_HIGHLAYER_H
-
-#include "Swiften/Base/boost_bsignals.h"
+#pragma once
#include "Swiften/Base/ByteArray.h"
namespace Swift {
+ class LowLayer;
+
class HighLayer {
+ friend class StreamStack;
+
public:
+ HighLayer();
virtual ~HighLayer();
virtual void handleDataRead(const ByteArray& data) = 0;
+
+ protected:
+ LowLayer* getChildLayer() {
+ return childLayer;
+ }
- boost::signal<void (const ByteArray&)> onWriteData;
+ void setChildLayer(LowLayer* childLayer) {
+ this->childLayer = childLayer;
+ }
+
+ void writeDataToChildLayer(const ByteArray& data);
+
+ private:
+ LowLayer* childLayer;
};
}
-
-#endif
diff --git a/Swiften/StreamStack/LowLayer.cpp b/Swiften/StreamStack/LowLayer.cpp
index 6df73a2..ca7b72b 100644
--- a/Swiften/StreamStack/LowLayer.cpp
+++ b/Swiften/StreamStack/LowLayer.cpp
@@ -4,11 +4,21 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#include "Swiften/StreamStack/LowLayer.h"
+#include <Swiften/StreamStack/LowLayer.h>
+
+#include <Swiften/StreamStack/HighLayer.h>
namespace Swift {
+LowLayer::LowLayer() : parentLayer(NULL) {
+}
+
LowLayer::~LowLayer() {
}
+void LowLayer::writeDataToParentLayer(const ByteArray& data) {
+ assert(parentLayer);
+ parentLayer->handleDataRead(data);
+}
+
}
diff --git a/Swiften/StreamStack/LowLayer.h b/Swiften/StreamStack/LowLayer.h
index 2224adc..1f9645a 100644
--- a/Swiften/StreamStack/LowLayer.h
+++ b/Swiften/StreamStack/LowLayer.h
@@ -4,22 +4,34 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#ifndef SWIFTEN_LOWLAYER_H
-#define SWIFTEN_LOWLAYER_H
-
-#include "Swiften/Base/boost_bsignals.h"
+#pragma once
#include "Swiften/Base/ByteArray.h"
namespace Swift {
+ class HighLayer;
+
class LowLayer {
+ friend class StreamStack;
+
public:
+ LowLayer();
virtual ~LowLayer();
virtual void writeData(const ByteArray& data) = 0;
+
+ protected:
+ HighLayer* getParentLayer() {
+ return parentLayer;
+ }
- boost::signal<void (const ByteArray&)> onDataRead;
+ void setParentLayer(HighLayer* parentLayer) {
+ this->parentLayer = parentLayer;
+ }
+
+ void writeDataToParentLayer(const ByteArray& data);
+
+ private:
+ HighLayer* parentLayer;
};
}
-
-#endif
diff --git a/Swiften/StreamStack/StreamLayer.h b/Swiften/StreamStack/StreamLayer.h
index 7ce1149..bcc5d79 100644
--- a/Swiften/StreamStack/StreamLayer.h
+++ b/Swiften/StreamStack/StreamLayer.h
@@ -4,10 +4,7 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#ifndef SWIFTEN_STREAMLAYER_H
-#define SWIFTEN_STREAMLAYER_H
-
-#include "Swiften/Base/boost_bsignals.h"
+#pragma once
#include "Swiften/StreamStack/LowLayer.h"
#include "Swiften/StreamStack/HighLayer.h"
@@ -18,5 +15,3 @@ namespace Swift {
StreamLayer() {}
};
}
-
-#endif
diff --git a/Swiften/StreamStack/StreamStack.cpp b/Swiften/StreamStack/StreamStack.cpp
index b0c68cf..2a30768 100644
--- a/Swiften/StreamStack/StreamStack.cpp
+++ b/Swiften/StreamStack/StreamStack.cpp
@@ -15,31 +15,23 @@
namespace Swift {
-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));
+StreamStack::StreamStack(XMPPLayer* xmppLayer, LowLayer* physicalLayer) : xmppLayer_(xmppLayer), physicalLayer_(physicalLayer) {
+ physicalLayer_->setParentLayer(xmppLayer_);
+ xmppLayer_->setChildLayer(physicalLayer_);
}
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();
+void StreamStack::addLayer(StreamLayer* newLayer) {
+ LowLayer* lowLayer = layers_.empty() ? physicalLayer_ : *layers_.rbegin();
- boost::shared_ptr<LowLayer> lowLayer = (layers_.empty() ? physicalLayer_ : *layers_.rbegin());
+ xmppLayer_->setChildLayer(newLayer);
+ newLayer->setParentLayer(xmppLayer_);
+
+ lowLayer->setParentLayer(newLayer);
+ newLayer->setChildLayer(lowLayer);
- lowLayer->onDataRead.connect(boost::bind(&HighLayer::handleDataRead, newLayer, _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);
}
diff --git a/Swiften/StreamStack/StreamStack.h b/Swiften/StreamStack/StreamStack.h
index 56bc2de..562245e 100644
--- a/Swiften/StreamStack/StreamStack.h
+++ b/Swiften/StreamStack/StreamStack.h
@@ -20,31 +20,28 @@ namespace Swift {
class StreamStack {
public:
- StreamStack(boost::shared_ptr<XMPPLayer> xmppLayer, boost::shared_ptr<LowLayer> physicalLayer);
+ StreamStack(XMPPLayer* xmppLayer, LowLayer* physicalLayer);
~StreamStack();
- void addLayer(boost::shared_ptr<StreamLayer>);
+ void addLayer(StreamLayer*);
- boost::shared_ptr<XMPPLayer> getXMPPLayer() const {
+ XMPPLayer* getXMPPLayer() const {
return xmppLayer_;
}
- template<typename T> boost::shared_ptr<T> getLayer() {
- foreach(const boost::shared_ptr<StreamLayer>& streamLayer, layers_) {
- boost::shared_ptr<T> layer = boost::dynamic_pointer_cast<T>(streamLayer);
+ template<typename T> T* getLayer() {
+ foreach(StreamLayer* streamLayer, layers_) {
+ T* layer = dynamic_cast<T*>(streamLayer);
if (layer) {
return layer;
}
}
- return boost::shared_ptr<T>();
+ return NULL;
}
private:
- boost::shared_ptr<XMPPLayer> xmppLayer_;
- boost::shared_ptr<LowLayer> physicalLayer_;
- std::vector< boost::shared_ptr<StreamLayer> > layers_;
- boost::bsignals::connection xmppReadSlotConnection_;
- boost::bsignals::connection xmppWriteSignalConnection_;
- std::vector< boost::bsignals::connection > writeSignalConnections_;
+ XMPPLayer* xmppLayer_;
+ LowLayer* physicalLayer_;
+ std::vector<StreamLayer*> layers_;
};
}
diff --git a/Swiften/StreamStack/TLSLayer.cpp b/Swiften/StreamStack/TLSLayer.cpp
index 8cb06fc..8a6c008 100644
--- a/Swiften/StreamStack/TLSLayer.cpp
+++ b/Swiften/StreamStack/TLSLayer.cpp
@@ -5,6 +5,9 @@
*/
#include "Swiften/StreamStack/TLSLayer.h"
+
+#include <boost/bind.hpp>
+
#include "Swiften/TLS/TLSContextFactory.h"
#include "Swiften/TLS/TLSContext.h"
@@ -12,8 +15,8 @@ namespace Swift {
TLSLayer::TLSLayer(TLSContextFactory* factory) {
context = factory->createTLSContext();
- context->onDataForNetwork.connect(onWriteData);
- context->onDataForApplication.connect(onDataRead);
+ context->onDataForNetwork.connect(boost::bind(&TLSLayer::writeDataToChildLayer, this, _1));
+ context->onDataForApplication.connect(boost::bind(&TLSLayer::writeDataToParentLayer, this, _1));
context->onConnected.connect(onConnected);
context->onError.connect(onError);
}
diff --git a/Swiften/StreamStack/WhitespacePingLayer.cpp b/Swiften/StreamStack/WhitespacePingLayer.cpp
index a99f300..35efc3c 100644
--- a/Swiften/StreamStack/WhitespacePingLayer.cpp
+++ b/Swiften/StreamStack/WhitespacePingLayer.cpp
@@ -21,16 +21,16 @@ WhitespacePingLayer::WhitespacePingLayer(TimerFactory* timerFactory) : isActive(
}
void WhitespacePingLayer::writeData(const ByteArray& data) {
- onWriteData(data);
+ writeDataToChildLayer(data);
}
void WhitespacePingLayer::handleDataRead(const ByteArray& data) {
- onDataRead(data);
+ writeDataToParentLayer(data);
}
void WhitespacePingLayer::handleTimerTick() {
timer->stop();
- onWriteData(" ");
+ writeDataToChildLayer(" ");
timer->start();
}
diff --git a/Swiften/StreamStack/XMPPLayer.cpp b/Swiften/StreamStack/XMPPLayer.cpp
index d4e329b..3ecda95 100644
--- a/Swiften/StreamStack/XMPPLayer.cpp
+++ b/Swiften/StreamStack/XMPPLayer.cpp
@@ -29,22 +29,27 @@ XMPPLayer::~XMPPLayer() {
}
void XMPPLayer::writeHeader(const ProtocolHeader& header) {
- onWriteData(ByteArray(xmppSerializer_->serializeHeader(header)));
+ writeDataInternal(ByteArray(xmppSerializer_->serializeHeader(header)));
}
void XMPPLayer::writeFooter() {
- onWriteData(ByteArray(xmppSerializer_->serializeFooter()));
+ writeDataInternal(ByteArray(xmppSerializer_->serializeFooter()));
}
void XMPPLayer::writeElement(boost::shared_ptr<Element> element) {
- onWriteData(ByteArray(xmppSerializer_->serializeElement(element)));
+ writeDataInternal(ByteArray(xmppSerializer_->serializeElement(element)));
}
void XMPPLayer::writeData(const String& data) {
- onWriteData(ByteArray(data));
+ writeDataInternal(ByteArray(data));
}
-void XMPPLayer::parseData(ByteArray data) {
+void XMPPLayer::writeDataInternal(const ByteArray& data) {
+ onWriteData(data);
+ writeDataToChildLayer(data);
+}
+
+void XMPPLayer::handleDataRead(const ByteArray& data) {
onDataRead(data);
inParser_ = true;
if (!xmppParser_->parse(String(data.getData(), data.getSize()))) {
diff --git a/Swiften/StreamStack/XMPPLayer.h b/Swiften/StreamStack/XMPPLayer.h
index 7316afe..54bb22d 100644
--- a/Swiften/StreamStack/XMPPLayer.h
+++ b/Swiften/StreamStack/XMPPLayer.h
@@ -10,6 +10,7 @@
#include "Swiften/Base/boost_bsignals.h"
#include <boost/noncopyable.hpp>
+#include <Swiften/StreamStack/HighLayer.h>
#include "Swiften/Base/ByteArray.h"
#include "Swiften/Elements/Element.h"
#include "Swiften/Elements/StreamType.h"
@@ -22,7 +23,7 @@ namespace Swift {
class XMPPSerializer;
class PayloadSerializerCollection;
- class XMPPLayer : public XMPPParserClient, boost::noncopyable {
+ class XMPPLayer : public XMPPParserClient, public HighLayer, boost::noncopyable {
public:
XMPPLayer(
PayloadParserFactoryCollection* payloadParserFactories,
@@ -35,9 +36,12 @@ namespace Swift {
void writeElement(boost::shared_ptr<Element>);
void writeData(const String& data);
- void parseData(ByteArray data);
void resetParser();
+ private:
+ void handleDataRead(const ByteArray& data);
+ void writeDataInternal(const ByteArray& data);
+
public:
boost::signal<void (const ProtocolHeader&)> onStreamStart;
boost::signal<void (boost::shared_ptr<Element>)> onElement;