diff options
| author | Tobias Markmann <tm@ayena.de> | 2018-08-02 09:00:25 (GMT) |
|---|---|---|
| committer | Tobias Markmann <tm@ayena.de> | 2018-08-02 09:00:25 (GMT) |
| commit | 091f6e520694360a0407ab0cf3bb036fb461e6e3 (patch) | |
| tree | 717ff863e8cd799842e5c82fc2d833ae026c9b20 /Swiften/Session/Session.cpp | |
| parent | 80f74201f0a35718642e434c58b631b238fd85df (diff) | |
| download | swift-091f6e520694360a0407ab0cf3bb036fb461e6e3.zip swift-091f6e520694360a0407ab0cf3bb036fb461e6e3.tar.bz2 | |
Have StreamStack own the top and bottom layer
Test-Information:
Builds, unit tests and integration tests pass on macOS with
clang 7.0 master.
Change-Id: I0db411e49339ccb2301edd1a16612cb1ad2c927c
Diffstat (limited to 'Swiften/Session/Session.cpp')
| -rw-r--r-- | Swiften/Session/Session.cpp | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/Swiften/Session/Session.cpp b/Swiften/Session/Session.cpp index ebdb5d1..b1525b8 100644 --- a/Swiften/Session/Session.cpp +++ b/Swiften/Session/Session.cpp | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2010-2016 Isode Limited. | 2 | * Copyright (c) 2010-2018 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| @@ -22,16 +22,10 @@ Session::Session( | |||
| 22 | payloadParserFactories(payloadParserFactories), | 22 | payloadParserFactories(payloadParserFactories), |
| 23 | payloadSerializers(payloadSerializers), | 23 | payloadSerializers(payloadSerializers), |
| 24 | xmlParserFactory(xmlParserFactory), | 24 | xmlParserFactory(xmlParserFactory), |
| 25 | xmppLayer(nullptr), | ||
| 26 | connectionLayer(nullptr), | ||
| 27 | streamStack(nullptr), | ||
| 28 | finishing(false) { | 25 | finishing(false) { |
| 29 | } | 26 | } |
| 30 | 27 | ||
| 31 | Session::~Session() { | 28 | Session::~Session() { |
| 32 | delete streamStack; | ||
| 33 | delete connectionLayer; | ||
| 34 | delete xmppLayer; | ||
| 35 | } | 29 | } |
| 36 | 30 | ||
| 37 | void Session::startSession() { | 31 | void Session::startSession() { |
| @@ -44,7 +38,7 @@ void Session::finishSession() { | |||
| 44 | return; | 38 | return; |
| 45 | } | 39 | } |
| 46 | finishing = true; | 40 | finishing = true; |
| 47 | if (xmppLayer) { | 41 | if (auto xmppLayer = getXMPPLayer()) { |
| 48 | xmppLayer->writeFooter(); | 42 | xmppLayer->writeFooter(); |
| 49 | } | 43 | } |
| 50 | connection->disconnect(); | 44 | connection->disconnect(); |
| @@ -55,14 +49,14 @@ void Session::finishSession(const SessionError& /*error*/) { | |||
| 55 | return; | 49 | return; |
| 56 | } | 50 | } |
| 57 | finishing = true; | 51 | finishing = true; |
| 58 | if (xmppLayer) { | 52 | if (auto xmppLayer = getXMPPLayer()) { |
| 59 | xmppLayer->writeFooter(); | 53 | xmppLayer->writeFooter(); |
| 60 | } | 54 | } |
| 61 | connection->disconnect(); | 55 | connection->disconnect(); |
| 62 | } | 56 | } |
| 63 | 57 | ||
| 64 | void Session::initializeStreamStack() { | 58 | void Session::initializeStreamStack() { |
| 65 | xmppLayer = new XMPPLayer(payloadParserFactories, payloadSerializers, xmlParserFactory, ClientStreamType); | 59 | auto xmppLayer = std::unique_ptr<XMPPLayer>(new XMPPLayer(payloadParserFactories, payloadSerializers, xmlParserFactory, ClientStreamType)); |
| 66 | xmppLayer->onStreamStart.connect( | 60 | xmppLayer->onStreamStart.connect( |
| 67 | boost::bind(&Session::handleStreamStart, this, _1)); | 61 | boost::bind(&Session::handleStreamStart, this, _1)); |
| 68 | xmppLayer->onElement.connect(boost::bind(&Session::handleElement, this, _1)); | 62 | xmppLayer->onElement.connect(boost::bind(&Session::handleElement, this, _1)); |
| @@ -72,12 +66,20 @@ void Session::initializeStreamStack() { | |||
| 72 | xmppLayer->onWriteData.connect(boost::bind(boost::ref(onDataWritten), _1)); | 66 | xmppLayer->onWriteData.connect(boost::bind(boost::ref(onDataWritten), _1)); |
| 73 | connection->onDisconnected.connect( | 67 | connection->onDisconnected.connect( |
| 74 | boost::bind(&Session::handleDisconnected, this, _1)); | 68 | boost::bind(&Session::handleDisconnected, this, _1)); |
| 75 | connectionLayer = new ConnectionLayer(connection); | 69 | streamStack = std::unique_ptr<StreamStack>(new StreamStack(std::move(xmppLayer), std::unique_ptr<ConnectionLayer>(new ConnectionLayer(connection)))); |
| 76 | streamStack = new StreamStack(xmppLayer, connectionLayer); | ||
| 77 | } | 70 | } |
| 78 | 71 | ||
| 72 | XMPPLayer* Session::getXMPPLayer() const { | ||
| 73 | return dynamic_cast<XMPPLayer*>(streamStack->getTopLayer()); | ||
| 74 | } | ||
| 75 | |||
| 76 | StreamStack* Session::getStreamStack() const { | ||
| 77 | return streamStack.get(); | ||
| 78 | } | ||
| 79 | |||
| 80 | |||
| 79 | void Session::sendElement(std::shared_ptr<ToplevelElement> stanza) { | 81 | void Session::sendElement(std::shared_ptr<ToplevelElement> stanza) { |
| 80 | xmppLayer->writeElement(stanza); | 82 | getXMPPLayer()->writeElement(stanza); |
| 81 | } | 83 | } |
| 82 | 84 | ||
| 83 | void Session::handleDisconnected(const boost::optional<Connection::Error>& connectionError) { | 85 | void Session::handleDisconnected(const boost::optional<Connection::Error>& connectionError) { |
Swift