summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-19 13:21:38 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-19 13:27:00 (GMT)
commita6fcd9e7aa12c5e00c61ff809e81fba14babd70c (patch)
treef65419f4f9a78a1db574f8fa792e745f7fbdf76c /Swiften/Session
parent9ccf1973ec3e23e4ba061b774c3f3e3bde4f1040 (diff)
downloadswift-a6fcd9e7aa12c5e00c61ff809e81fba14babd70c.zip
swift-a6fcd9e7aa12c5e00c61ff809e81fba14babd70c.tar.bz2
Factor out common session stuff into Session class.
Diffstat (limited to 'Swiften/Session')
-rw-r--r--Swiften/Session/Session.cpp24
-rw-r--r--Swiften/Session/Session.h32
2 files changed, 41 insertions, 15 deletions
diff --git a/Swiften/Session/Session.cpp b/Swiften/Session/Session.cpp
index 9ab8e4d..84354e5 100644
--- a/Swiften/Session/Session.cpp
+++ b/Swiften/Session/Session.cpp
@@ -28,12 +28,14 @@ void Session::startSession() {
void Session::finishSession() {
connection->disconnect();
- onSessionFinished(boost::optional<Error>());
+ handleSessionFinished(boost::optional<SessionError>());
+ onSessionFinished(boost::optional<SessionError>());
}
-void Session::finishSession(const Error& error) {
+void Session::finishSession(const SessionError& error) {
connection->disconnect();
- onSessionFinished(boost::optional<Error>(error));
+ handleSessionFinished(boost::optional<SessionError>(error));
+ onSessionFinished(boost::optional<SessionError>(error));
}
void Session::initializeStreamStack() {
@@ -41,23 +43,31 @@ void Session::initializeStreamStack() {
new XMPPLayer(payloadParserFactories, payloadSerializers));
xmppLayer->onStreamStart.connect(
boost::bind(&Session::handleStreamStart, this, _1));
- xmppLayer->onElement.connect(
- boost::bind(&Session::handleElement, this, _1));
+ xmppLayer->onElement.connect(boost::bind(&Session::handleElement, this, _1));
xmppLayer->onError.connect(
boost::bind(&Session::finishSession, this, XMLError));
+ xmppLayer->onDataRead.connect(boost::bind(boost::ref(onDataRead), _1));
+ xmppLayer->onWriteData.connect(boost::bind(boost::ref(onDataWritten), _1));
connection->onDisconnected.connect(
boost::bind(&Session::handleDisconnected, shared_from_this(), _1));
connectionLayer = boost::shared_ptr<ConnectionLayer>(new ConnectionLayer(connection));
streamStack = new StreamStack(xmppLayer, connectionLayer);
}
-void Session::sendStanza(boost::shared_ptr<Stanza> stanza) {
+void Session::sendElement(boost::shared_ptr<Element> stanza) {
xmppLayer->writeElement(stanza);
}
void Session::handleDisconnected(const boost::optional<Connection::Error>& connectionError) {
if (connectionError) {
- finishSession(ConnectionError);
+ switch (*connectionError) {
+ case Connection::ReadError:
+ finishSession(ConnectionReadError);
+ break;
+ case Connection::WriteError:
+ finishSession(ConnectionWriteError);
+ break;
+ }
}
else {
finishSession();
diff --git a/Swiften/Session/Session.h b/Swiften/Session/Session.h
index bf8049a..b35179c 100644
--- a/Swiften/Session/Session.h
+++ b/Swiften/Session/Session.h
@@ -14,7 +14,7 @@ namespace Swift {
class ProtocolHeader;
class StreamStack;
class JID;
- class Stanza;
+ class Element;
class ByteArray;
class PayloadParserFactoryCollection;
class PayloadSerializerCollection;
@@ -22,9 +22,18 @@ namespace Swift {
class Session : public boost::enable_shared_from_this<Session> {
public:
- enum Error {
- ConnectionError,
- XMLError
+ enum SessionError {
+ ConnectionReadError,
+ ConnectionWriteError,
+ XMLError,
+ AuthenticationFailedError,
+ NoSupportedAuthMechanismsError,
+ UnexpectedElementError,
+ ResourceBindError,
+ SessionStartError,
+ TLSError,
+ ClientCertificateLoadError,
+ ClientCertificateError
};
Session(
@@ -35,18 +44,19 @@ namespace Swift {
void startSession();
void finishSession();
- void sendStanza(boost::shared_ptr<Stanza>);
+ void sendElement(boost::shared_ptr<Element>);
- boost::signal<void (boost::shared_ptr<Stanza>)> onStanzaReceived;
+ boost::signal<void (boost::shared_ptr<Element>)> onElementReceived;
boost::signal<void ()> onSessionStarted;
- boost::signal<void (const boost::optional<Error>&)> onSessionFinished;
+ boost::signal<void (const boost::optional<SessionError>&)> onSessionFinished;
boost::signal<void (const ByteArray&)> onDataWritten;
boost::signal<void (const ByteArray&)> onDataRead;
protected:
- void finishSession(const Error&);
+ void finishSession(const SessionError&);
virtual void handleSessionStarted() {}
+ virtual void handleSessionFinished(const boost::optional<SessionError>&) {}
virtual void handleElement(boost::shared_ptr<Element>) = 0;
virtual void handleStreamStart(const ProtocolHeader&) = 0;
@@ -56,11 +66,17 @@ namespace Swift {
return xmppLayer;
}
+ StreamStack* getStreamStack() const {
+ return streamStack;
+ }
+
void setInitialized();
bool isInitialized() const {
return initialized;
}
+ void setFinished();
+
private:
void handleDisconnected(const boost::optional<Connection::Error>& error);