]> Some of my projects - anidbudpclient.git/commitdiff
Allow the client to recover from errors and provide a way to leave error state.
authorAPTX <marek321@gmail.com>
Sat, 9 Jun 2012 17:03:17 +0000 (19:03 +0200)
committerAPTX <marek321@gmail.com>
Sat, 9 Jun 2012 17:03:17 +0000 (19:03 +0200)
client.cpp
client.h

index e8afc70671ec9b5e00301f19e0c7d888f0dc6ceb..c34bda652e6890aff3efd6793792cecf915b2849 100644 (file)
@@ -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);
index 5784f55bf461da36cc64acf56f033bdce348a8c5..a2e1d628bd4c25f7f212f19a31c300b9316a7245 100644 (file)
--- 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;