From f900b90c460eabd4acf1a7798e6c1c7a79e3decf Mon Sep 17 00:00:00 2001
From: Christian Kandeler <christian.kandeler@nokia.com>
Date: Fri, 29 Oct 2010 12:17:56 +0200
Subject: [PATCH] Maemo: Introduce generic state checking.

---
 .../qt4projectmanager/qt-maemo/maemoglobal.h   | 18 ++++++++++++++++++
 .../qt-maemo/maemoremotemounter.cpp            | 14 +-------------
 .../qt-maemo/maemoremotemounter.h              |  2 --
 .../qt-maemo/maemosshrunner.cpp                | 14 +-------------
 .../qt-maemo/maemosshrunner.h                  |  2 --
 5 files changed, 20 insertions(+), 30 deletions(-)

diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemoglobal.h b/src/plugins/qt4projectmanager/qt-maemo/maemoglobal.h
index 7305dd34286..d6ed5f24b85 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemoglobal.h
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemoglobal.h
@@ -38,6 +38,9 @@
 
 #include <QtCore/QList>
 
+#define ASSERT_STATE_GENERIC(State, expected, actual)                         \
+    MaemoGlobal::assertState<State>(expected, actual, Q_FUNC_INFO)
+
 QT_BEGIN_NAMESPACE
 class QString;
 QT_END_NAMESPACE
@@ -67,6 +70,21 @@ public:
         }
         return 0;
     }
+
+    template<typename State> static void assertState(State expected,
+        State actual, const char *func)
+    {
+        assertState(QList<State>() << expected, actual, func);
+    }
+
+    template<typename State> static void assertState(const QList<State> &expected,
+        State actual, const char *func)
+    {
+        if (!expected.contains(actual)) {
+            qWarning("Warning: Unexpected state %d in function %s.",
+                actual, func);
+        }
+    }
 };
 
 } // namespace Internal
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemoremotemounter.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemoremotemounter.cpp
index 8431fea3ca1..5c4189ff809 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemoremotemounter.cpp
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemoremotemounter.cpp
@@ -39,7 +39,7 @@
 
 #include <QtCore/QTimer>
 
-#define ASSERT_STATE(state) assertState(state, Q_FUNC_INFO)
+#define ASSERT_STATE(state) ASSERT_STATE_GENERIC(State, state, m_state)
 
 using namespace Core;
 
@@ -442,18 +442,6 @@ void MaemoRemoteMounter::handleUtfsServerTimeout()
     setState(Inactive);
 }
 
-void MaemoRemoteMounter::assertState(State expectedState, const char *func)
-{
-    assertState(QList<State>() << expectedState, func);
-}
-
-void MaemoRemoteMounter::assertState(const QList<State> &expectedStates,
-    const char *func)
-{
-    QTC_ASSERT(expectedStates.contains(m_state),
-        qDebug("Unexpected state %d at %s.", m_state, func))
-}
-
 void MaemoRemoteMounter::setState(State newState)
 {
     if (newState == Inactive)
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemoremotemounter.h b/src/plugins/qt4projectmanager/qt-maemo/maemoremotemounter.h
index 8e297be80df..ddd70a67ae1 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemoremotemounter.h
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemoremotemounter.h
@@ -101,8 +101,6 @@ private:
         UtfsClientsStarting, UtfsClientsStarted, UtfsServersStarted
     };
 
-    void assertState(State expectedState, const char *func);
-    void assertState(const QList<State> &expectedStates, const char *func);
     void setState(State newState);
 
     void deployUtfsClient();
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemosshrunner.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemosshrunner.cpp
index 16db4f43869..f431c65c5a6 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemosshrunner.cpp
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemosshrunner.cpp
@@ -48,7 +48,7 @@
 
 #include <limits>
 
-#define ASSERT_STATE(state) assertState(state, Q_FUNC_INFO)
+#define ASSERT_STATE(state) ASSERT_STATE_GENERIC(State, state, m_state)
 
 using namespace Core;
 
@@ -309,18 +309,6 @@ bool MaemoSshRunner::isConnectionUsable() const
         && m_connection->connectionParameters() == m_devConfig.server;
 }
 
-void MaemoSshRunner::assertState(State expectedState, const char *func)
-{
-    assertState(QList<State>() << expectedState, func);
-}
-
-void MaemoSshRunner::assertState(const QList<State> &expectedStates,
-    const char *func)
-{
-    if (!expectedStates.contains(m_state))
-        qWarning("Unexpected state %d at %s.", m_state, func);
-}
-
 void MaemoSshRunner::setState(State newState)
 {
     if (newState == Inactive) {
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemosshrunner.h b/src/plugins/qt4projectmanager/qt-maemo/maemosshrunner.h
index 2c756a2382b..b79b0ca2a2e 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemosshrunner.h
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemosshrunner.h
@@ -94,8 +94,6 @@ private:
         ProcessStarting, StopRequested
     };
 
-    void assertState(State expectedState, const char *func);
-    void assertState(const QList<State> &expectedStates, const char *func);
     void setState(State newState);
     void emitError(const QString &errorMsg);
 
-- 
GitLab