diff options
Diffstat (limited to 'Swiften')
-rw-r--r-- | Swiften/Client/CoreClient.cpp | 8 | ||||
-rw-r--r-- | Swiften/Client/CoreClient.h | 7 | ||||
-rw-r--r-- | Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp | 4 | ||||
-rw-r--r-- | Swiften/Examples/SendFile/SendFile.cpp | 6 | ||||
-rw-r--r-- | Swiften/Examples/SendMessage/SendMessage.cpp | 4 |
5 files changed, 16 insertions, 13 deletions
diff --git a/Swiften/Client/CoreClient.cpp b/Swiften/Client/CoreClient.cpp index fa9dca0..9511dfb 100644 --- a/Swiften/Client/CoreClient.cpp +++ b/Swiften/Client/CoreClient.cpp @@ -73,9 +73,7 @@ void CoreClient::handleConnectorFinished(boost::shared_ptr<Connection> connectio connector_->onConnectFinished.disconnect(boost::bind(&CoreClient::handleConnectorFinished, this, _1)); connector_.reset(); if (!connection) { - if (!disconnectRequested_) { - onError(ClientError::ConnectionError); - } + onDisconnected(disconnectRequested_ ? boost::optional<ClientError>() : boost::optional<ClientError>(ClientError::ConnectionError)); } else { assert(!connection_); @@ -131,6 +129,7 @@ void CoreClient::handleSessionFinished(boost::shared_ptr<Error> error) { connection_->disconnect(); connection_.reset(); + boost::optional<ClientError> actualError; if (error) { ClientError clientError; if (boost::shared_ptr<ClientSession::Error> actualError = boost::dynamic_pointer_cast<ClientSession::Error>(error)) { @@ -183,8 +182,9 @@ void CoreClient::handleSessionFinished(boost::shared_ptr<Error> error) { break; } } - onError(clientError); + actualError = boost::optional<ClientError>(clientError); } + onDisconnected(actualError); } void CoreClient::handleNeedCredentials() { diff --git a/Swiften/Client/CoreClient.h b/Swiften/Client/CoreClient.h index f6e0b6d..e9e81ec 100644 --- a/Swiften/Client/CoreClient.h +++ b/Swiften/Client/CoreClient.h @@ -126,9 +126,12 @@ namespace Swift { public: /** - * Emitted when a non-recoverable error occurs. + * Emitted when the client was disconnected from the network. + * + * If the connection was due to a non-recoverable error, the type + * of error will be passed as a parameter. */ - boost::signal<void (const ClientError&)> onError; + boost::signal<void (const boost::optional<ClientError>&)> onDisconnected; /** * Emitted when the client is connected and authenticated, diff --git a/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp b/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp index e870d83..9da5cdf 100644 --- a/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp +++ b/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp @@ -46,7 +46,7 @@ void handleConnected() { discoInfoRequest->send(); } -void handleError(const ClientError&) { +void handleDisconnected(const boost::optional<ClientError>&) { exitCode = CANNOT_AUTH; eventLoop.stop(); } @@ -73,7 +73,7 @@ int main(int argc, char* argv[]) { timeout = (timeout ? timeout : 30) * 1000; ClientXMLTracer* tracer = new ClientXMLTracer(client); client->onConnected.connect(&handleConnected); - errorConnection = client->onError.connect(&handleError); + errorConnection = client->onDisconnected.connect(&handleDisconnected); std::cout << "Connecting to JID " << jid << " with timeout " << timeout << "ms on host: "; ; if (!connectHost.isEmpty()) { std::cout << connectHost << std::endl; diff --git a/Swiften/Examples/SendFile/SendFile.cpp b/Swiften/Examples/SendFile/SendFile.cpp index 6f72480..f0a2d59 100644 --- a/Swiften/Examples/SendFile/SendFile.cpp +++ b/Swiften/Examples/SendFile/SendFile.cpp @@ -32,13 +32,13 @@ class FileSender { client = new Swift::Client(&eventLoop, jid, password); client->onConnected.connect(boost::bind(&FileSender::handleConnected, this)); - client->onError.connect(boost::bind(&FileSender::handleError, this, _1)); + client->onDisconnected.connect(boost::bind(&FileSender::handleDisconnected, this, _1)); //tracer = new ClientXMLTracer(client); } ~FileSender() { //delete tracer; - client->onError.disconnect(boost::bind(&FileSender::handleError, this, _1)); + client->onDisconnected.disconnect(boost::bind(&FileSender::handleDisconnected, this, _1)); client->onConnected.disconnect(boost::bind(&FileSender::handleConnected, this)); delete client; delete socksBytestreamServer; @@ -67,7 +67,7 @@ class FileSender { transfer->start(); } - void handleError(const ClientError&) { + void handleDisconnected(const boost::optional<ClientError>&) { std::cerr << "Error!" << std::endl; exit(-1); } diff --git a/Swiften/Examples/SendMessage/SendMessage.cpp b/Swiften/Examples/SendMessage/SendMessage.cpp index d9ed923..fe020aa 100644 --- a/Swiften/Examples/SendMessage/SendMessage.cpp +++ b/Swiften/Examples/SendMessage/SendMessage.cpp @@ -37,7 +37,7 @@ void handleConnected() { eventLoop.stop(); } -void handleError(const ClientError&) { +void handleDisconnected(const boost::optional<ClientError>&) { std::cerr << "Error!" << std::endl; exitCode = 1; eventLoop.stop(); @@ -64,7 +64,7 @@ int main(int argc, char* argv[]) { ClientXMLTracer* tracer = new ClientXMLTracer(client); client->onConnected.connect(&handleConnected); - errorConnection = client->onError.connect(&handleError); + errorConnection = client->onDisconnected.connect(&handleDisconnected); if (!connectHost.isEmpty()) { client->connect(connectHost); } else { |