summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Session')
-rw-r--r--Swiften/Session/BasicSessionStream.cpp25
-rw-r--r--Swiften/Session/BasicSessionStream.h12
-rw-r--r--Swiften/Session/SessionStream.h7
3 files changed, 35 insertions, 9 deletions
diff --git a/Swiften/Session/BasicSessionStream.cpp b/Swiften/Session/BasicSessionStream.cpp
index 46d4e16..73eaf5b 100644
--- a/Swiften/Session/BasicSessionStream.cpp
+++ b/Swiften/Session/BasicSessionStream.cpp
@@ -13,13 +13,16 @@
namespace Swift {
-BasicSessionStream::BasicSessionStream(boost::shared_ptr<Connection> connection, PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers, TLSLayerFactory* tlsLayerFactory) : tlsLayerFactory(tlsLayerFactory) {
+BasicSessionStream::BasicSessionStream(boost::shared_ptr<Connection> connection, PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers, TLSLayerFactory* tlsLayerFactory) : connection(connection), payloadParserFactories(payloadParserFactories), payloadSerializers(payloadSerializers), tlsLayerFactory(tlsLayerFactory) {
+}
+
+void BasicSessionStream::initialize() {
xmppLayer = boost::shared_ptr<XMPPLayer>(
new XMPPLayer(payloadParserFactories, payloadSerializers));
- xmppLayer->onStreamStart.connect(boost::ref(onStreamStartReceived));
- xmppLayer->onElement.connect(boost::ref(onElementReceived));
+ xmppLayer->onStreamStart.connect(boost::bind(&BasicSessionStream::handleStreamStartReceived, shared_from_this(), _1));
+ xmppLayer->onElement.connect(boost::bind(&BasicSessionStream::handleElementReceived, shared_from_this(), _1));
xmppLayer->onError.connect(boost::bind(
- &BasicSessionStream::handleXMPPError, this));
+ &BasicSessionStream::handleXMPPError, shared_from_this()));
connectionLayer = boost::shared_ptr<ConnectionLayer>(
new ConnectionLayer(connection));
@@ -47,7 +50,7 @@ void BasicSessionStream::addTLSEncryption() {
tlsLayer = tlsLayerFactory->createTLSLayer();
streamStack->addLayer(tlsLayer);
// TODO: Add tls layer certificate if needed
- tlsLayer->onError.connect(boost::bind(&BasicSessionStream::handleTLSError, this));
+ tlsLayer->onError.connect(boost::bind(&BasicSessionStream::handleTLSError, shared_from_this()));
tlsLayer->connect();
}
@@ -61,12 +64,20 @@ void BasicSessionStream::resetXMPPParser() {
xmppLayer->resetParser();
}
+void BasicSessionStream::handleStreamStartReceived(const ProtocolHeader& header) {
+ onStreamStartReceived(header);
+}
+
+void BasicSessionStream::handleElementReceived(boost::shared_ptr<Element> element) {
+ onElementReceived(element);
+}
+
void BasicSessionStream::handleXMPPError() {
- // TODO
+ onError(boost::shared_ptr<Error>(new Error()));
}
void BasicSessionStream::handleTLSError() {
- // TODO
+ onError(boost::shared_ptr<Error>(new Error()));
}
};
diff --git a/Swiften/Session/BasicSessionStream.h b/Swiften/Session/BasicSessionStream.h
index bf92bbb..d248ebc 100644
--- a/Swiften/Session/BasicSessionStream.h
+++ b/Swiften/Session/BasicSessionStream.h
@@ -1,6 +1,7 @@
#pragma once
#include <boost/shared_ptr.hpp>
+#include <boost/enable_shared_from_this.hpp>
#include "Swiften/Network/Connection.h"
#include "Swiften/Session/SessionStream.h"
@@ -17,7 +18,7 @@ namespace Swift {
class BasicSessionStream :
public SessionStream,
- public boost::BOOST_SIGNALS_NAMESPACE::trackable {
+ public boost::enable_shared_from_this<BasicSessionStream> {
public:
BasicSessionStream(
boost::shared_ptr<Connection> connection,
@@ -27,6 +28,8 @@ namespace Swift {
);
~BasicSessionStream();
+ void initialize();
+
virtual void writeHeader(const ProtocolHeader& header);
virtual void writeElement(boost::shared_ptr<Element>);
@@ -40,12 +43,17 @@ namespace Swift {
private:
void handleXMPPError();
void handleTLSError();
+ void handleStreamStartReceived(const ProtocolHeader&);
+ void handleElementReceived(boost::shared_ptr<Element>);
private:
+ boost::shared_ptr<Connection> connection;
+ PayloadParserFactoryCollection* payloadParserFactories;
+ PayloadSerializerCollection* payloadSerializers;
+ TLSLayerFactory* tlsLayerFactory;
boost::shared_ptr<XMPPLayer> xmppLayer;
boost::shared_ptr<ConnectionLayer> connectionLayer;
StreamStack* streamStack;
- TLSLayerFactory* tlsLayerFactory;
boost::shared_ptr<TLSLayer> tlsLayer;
boost::shared_ptr<WhitespacePingLayer> whitespacePingLayer;
};
diff --git a/Swiften/Session/SessionStream.h b/Swiften/Session/SessionStream.h
index 17d9a24..44a1980 100644
--- a/Swiften/Session/SessionStream.h
+++ b/Swiften/Session/SessionStream.h
@@ -5,10 +5,16 @@
#include "Swiften/Elements/ProtocolHeader.h"
#include "Swiften/Elements/Element.h"
+#include "Swiften/Base/Error.h"
namespace Swift {
class SessionStream {
public:
+ class Error : public Swift::Error {
+ public:
+ Error() {}
+ };
+
virtual ~SessionStream();
virtual void writeHeader(const ProtocolHeader& header) = 0;
@@ -23,5 +29,6 @@ namespace Swift {
boost::signal<void (const ProtocolHeader&)> onStreamStartReceived;
boost::signal<void (boost::shared_ptr<Element>)> onElementReceived;
+ boost::signal<void (boost::shared_ptr<Error>)> onError;
};
}