diff options
Diffstat (limited to 'Swiften/Client/Client.cpp')
| -rw-r--r-- | Swiften/Client/Client.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Swiften/Client/Client.cpp b/Swiften/Client/Client.cpp index 2406b0f..bf651cc 100644 --- a/Swiften/Client/Client.cpp +++ b/Swiften/Client/Client.cpp | |||
| @@ -35,11 +35,11 @@ Client::~Client() { | |||
| 35 | delete timerFactory_; | 35 | delete timerFactory_; |
| 36 | delete connectionFactory_; | 36 | delete connectionFactory_; |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | bool Client::isAvailable() { | 39 | bool Client::isAvailable() { |
| 40 | return session_; | 40 | return session_ && session_->getState() == ClientSession::Initialized; |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | void Client::connect() { | 43 | void Client::connect() { |
| 44 | connect(jid_.getDomain()); | 44 | connect(jid_.getDomain()); |
| 45 | } | 45 | } |
| @@ -78,11 +78,11 @@ void Client::handleConnectorFinished(boost::shared_ptr<Connection> connection, C | |||
| 78 | sessionStream_->onDataRead.connect(boost::bind(&Client::handleDataRead, this, _1)); | 78 | sessionStream_->onDataRead.connect(boost::bind(&Client::handleDataRead, this, _1)); |
| 79 | sessionStream_->onDataWritten.connect(boost::bind(&Client::handleDataWritten, this, _1)); | 79 | sessionStream_->onDataWritten.connect(boost::bind(&Client::handleDataWritten, this, _1)); |
| 80 | sessionStream_->initialize(); | 80 | sessionStream_->initialize(); |
| 81 | 81 | ||
| 82 | session_ = ClientSession::create(jid_, sessionStream_); | 82 | session_ = ClientSession::create(jid_, sessionStream_); |
| 83 | session_->onInitialized.connect(boost::bind(boost::ref(onConnected))); | 83 | session_->onInitialized.connect(boost::bind(&Client::handleSessionInitialized, this)); |
| 84 | session_->onStanzaAcked.connect(boost::bind(&Client::handleStanzaAcked, this, _1)); | 84 | session_->onStanzaAcked.connect(boost::bind(&Client::handleStanzaAcked, this, _1)); |
| 85 | session_->onFinished.connect(boost::bind(&Client::handleSessionFinished, this, _1)); | 85 | session_->onFinished.connect(boost::bind(&Client::handleSessionFinished, this, _1)); |
| 86 | session_->onNeedCredentials.connect(boost::bind(&Client::handleNeedCredentials, this)); | 86 | session_->onNeedCredentials.connect(boost::bind(&Client::handleNeedCredentials, this)); |
| 87 | session_->onStanzaReceived.connect(boost::bind(&Client::handleStanza, this, _1)); | 87 | session_->onStanzaReceived.connect(boost::bind(&Client::handleStanza, this, _1)); |
| 88 | session_->start(); | 88 | session_->start(); |
| @@ -160,10 +160,11 @@ void Client::setCertificate(const String& certificate) { | |||
| 160 | } | 160 | } |
| 161 | 161 | ||
| 162 | void Client::handleSessionFinished(boost::shared_ptr<Error> error) { | 162 | void Client::handleSessionFinished(boost::shared_ptr<Error> error) { |
| 163 | session_.reset(); | 163 | session_.reset(); |
| 164 | closeConnection(); | 164 | closeConnection(); |
| 165 | onAvailableChanged(false); | ||
| 165 | if (error) { | 166 | if (error) { |
| 166 | ClientError clientError; | 167 | ClientError clientError; |
| 167 | if (boost::shared_ptr<ClientSession::Error> actualError = boost::dynamic_pointer_cast<ClientSession::Error>(error)) { | 168 | if (boost::shared_ptr<ClientSession::Error> actualError = boost::dynamic_pointer_cast<ClientSession::Error>(error)) { |
| 168 | switch(actualError->type) { | 169 | switch(actualError->type) { |
| 169 | case ClientSession::Error::AuthenticationFailedError: | 170 | case ClientSession::Error::AuthenticationFailedError: |
| @@ -240,6 +241,11 @@ void Client::handleDataWritten(const String& data) { | |||
| 240 | 241 | ||
| 241 | void Client::handleStanzaAcked(boost::shared_ptr<Stanza> stanza) { | 242 | void Client::handleStanzaAcked(boost::shared_ptr<Stanza> stanza) { |
| 242 | onStanzaAcked(stanza); | 243 | onStanzaAcked(stanza); |
| 243 | } | 244 | } |
| 244 | 245 | ||
| 246 | void Client::handleSessionInitialized() { | ||
| 247 | onConnected(); | ||
| 248 | onAvailableChanged(true); | ||
| 249 | } | ||
| 250 | |||
| 245 | } | 251 | } |
Swift