summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-19 11:44:20 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-19 11:59:04 (GMT)
commit1de12ed346fc0018527afe082886129088e27a95 (patch)
tree16013a9294588f505a559a99fe27a603584f2ac2 /Swiften/Client/Session.cpp
parent5d504472c63b7acaa7df99ff1097024cf463f1bd (diff)
downloadswift-contrib-1de12ed346fc0018527afe082886129088e27a95.zip
swift-contrib-1de12ed346fc0018527afe082886129088e27a95.tar.bz2
(Client)Session & Connection refactoring.
ClientSession no longer sets up a connection. Connection no longer resolves addresses.
Diffstat (limited to 'Swiften/Client/Session.cpp')
-rw-r--r--Swiften/Client/Session.cpp46
1 files changed, 19 insertions, 27 deletions
diff --git a/Swiften/Client/Session.cpp b/Swiften/Client/Session.cpp
index 6c2a873..1bd2b22 100644
--- a/Swiften/Client/Session.cpp
+++ b/Swiften/Client/Session.cpp
@@ -24,16 +24,21 @@
namespace Swift {
-Session::Session(const JID& jid, ConnectionFactory* connectionFactory, TLSLayerFactory* tlsLayerFactory, PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers) :
- jid_(jid),
- connectionFactory_(connectionFactory),
- tlsLayerFactory_(tlsLayerFactory),
- payloadParserFactories_(payloadParserFactories),
- payloadSerializers_(payloadSerializers),
- state_(Initial),
- error_(NoError),
- streamStack_(0),
- needSessionStart_(false) {
+Session::Session(
+ const JID& jid,
+ boost::shared_ptr<Connection> connection,
+ TLSLayerFactory* tlsLayerFactory,
+ PayloadParserFactoryCollection* payloadParserFactories,
+ PayloadSerializerCollection* payloadSerializers) :
+ jid_(jid),
+ tlsLayerFactory_(tlsLayerFactory),
+ payloadParserFactories_(payloadParserFactories),
+ payloadSerializers_(payloadSerializers),
+ state_(Initial),
+ error_(NoError),
+ connection_(connection),
+ streamStack_(0),
+ needSessionStart_(false) {
}
Session::~Session() {
@@ -42,11 +47,11 @@ Session::~Session() {
void Session::start() {
assert(state_ == Initial);
- state_ = Connecting;
- connection_ = connectionFactory_->createConnection();
- connection_->onConnected.connect(boost::bind(&Session::handleConnected, this));
+
connection_->onDisconnected.connect(boost::bind(&Session::handleDisconnected, this, _1));
- connection_->connect(jid_.getDomain());
+ initializeStreamStack();
+ state_ = WaitingForStreamStart;
+ sendStreamHeader();
}
void Session::stop() {
@@ -54,13 +59,6 @@ void Session::stop() {
connection_->disconnect();
}
-void Session::handleConnected() {
- assert(state_ == Connecting);
- initializeStreamStack();
- state_ = WaitingForStreamStart;
- sendStreamHeader();
-}
-
void Session::sendStreamHeader() {
ProtocolHeader header;
header.setTo(jid_.getDomain());
@@ -81,18 +79,12 @@ void Session::initializeStreamStack() {
void Session::handleDisconnected(const boost::optional<Connection::Error>& error) {
if (error) {
switch (*error) {
- case Connection::DomainNameResolveError:
- setError(DomainNameResolveError);
- break;
case Connection::ReadError:
setError(ConnectionReadError);
break;
case Connection::WriteError:
setError(ConnectionWriteError);
break;
- case Connection::ConnectionError:
- setError(ConnectionError);
- break;
}
}
}