From: APTX Date: Sat, 9 Jun 2012 17:03:17 +0000 (+0200) Subject: Allow the client to recover from errors and provide a way to leave error state. X-Git-Url: https://gitweb.aptx.org/?a=commitdiff_plain;h=44b96d200ac2feb59e7bf90586a9015689cef681;p=anidbudpclient.git Allow the client to recover from errors and provide a way to leave error state. --- diff --git a/client.cpp b/client.cpp index e8afc70..c34bda6 100644 --- a/client.cpp +++ b/client.cpp @@ -89,6 +89,9 @@ qDebug() << "Api instance init!"; connectedHistoryState->setDefaultState(sendState); // ------------- Transitions --------------------- + errorState->addTransition(this, SIGNAL(clearErrorsRequested()), disconnectedState); + errorState->addTransition(this, SIGNAL(startConnecting()), connectingState); + connectedState->addTransition(this, SIGNAL(startDisconnecting()), disconnectedState); connectedState->addTransition(socket, SIGNAL(readyRead()), recieveState); connectedState->addTransition(this, SIGNAL(sendFailed()), recieveFailState); @@ -96,6 +99,7 @@ qDebug() << "Api instance init!"; disconnectedState->addTransition(this, SIGNAL(startConnecting()), connectingState); connectingState->addTransition(this, SIGNAL(connected()), connectedState); + connectingState->addTransition(this, SIGNAL(connectionError()), errorState); authenticatingState->addTransition(this, SIGNAL(startSending()), sendState); authenticatingState->addTransition(this, SIGNAL(authenticated()), sendState); @@ -127,6 +131,7 @@ qDebug() << "Api instance init!"; // ------------- Methods --------------------- QObject::connect(errorState, SIGNAL(entered()), this, SLOT(enterErrorState())); + QObject::connect(errorState, SIGNAL(exited()), this, SLOT(exitErrorState())); QObject::connect(disconnectedState, SIGNAL(entered()), this, SLOT(enterDisconnectedState())); QObject::connect(connectingState, SIGNAL(entered()), this, SLOT(enterConnectingState())); QObject::connect(connectedState, SIGNAL(entered()), this, SLOT(enterConnectedState())); @@ -261,6 +266,15 @@ qDebug() << "Entering Error State"; disconnect(); } +void Client::exitErrorState() +{ +#ifdef ANIDBUDPCLIENT_CLIENT_STATE_MACHINE_DEBUG +qDebug() << "Exiting Error State"; +#endif + m_error = NoError; + m_errorString = QString(); +} + void Client::enterDisconnectedState() { #ifdef ANIDBUDPCLIENT_CLIENT_STATE_MACHINE_DEBUG @@ -268,6 +282,8 @@ qDebug() << "Entering Disconnected State"; #endif if (socket->state() == QAbstractSocket::BoundState) socket->disconnectFromHost(); + commandsTimedOut = 0; + m_hostAddress = QHostAddress(); m_salt.clear(); usingEncryption = false; } @@ -900,6 +916,11 @@ void Client::cancel(AbstractReply *reply) sentCommands.remove(reply->id()); } +void Client::clearErrors() +{ + emit clearErrorsRequested(); +} + void Client::logout() { logout(false); diff --git a/client.h b/client.h index 5784f55..a2e1d62 100644 --- a/client.h +++ b/client.h @@ -100,6 +100,8 @@ public slots: void sendRaw(QByteArray command); void cancel(AbstractReply *command); + void clearErrors(); + signals: void newVersionAvailable(); @@ -121,6 +123,8 @@ signals: void replyRecieved(); void sendFailed(); + void clearErrorsRequested(); + void model_queuedCommandAdded(int index); void model_queuedCommandRemoved(int index); void model_sentCommandAdded(int index); @@ -128,6 +132,7 @@ signals: private slots: void enterErrorState(); + void exitErrorState(); void enterDisconnectedState(); void enterConnectingState(); @@ -188,7 +193,6 @@ private: // Misc params IdlePolicy m_idlePolicy; - Error m_error; bool disconnecting; bool authenticatingStarted;