From 11f89ece8de7763f811d2fe1e45cb27ad4a77519 Mon Sep 17 00:00:00 2001
From: hjk <hjk121@nokiamail.com>
Date: Mon, 15 Sep 2014 15:43:24 +0200
Subject: [PATCH] Android: Separate debug and analyze support

The common base class contains only unused functionality.

Change-Id: I5f6db59a2972d6ab8383ce209937090cd46ae39d
Reviewed-by: Ulf Hermann <ulf.hermann@digia.com>
Reviewed-by: BogDan Vatra <bogdan@kde.org>
---
 src/plugins/android/android.pro               |   2 -
 src/plugins/android/android.qbs               |   2 -
 src/plugins/android/androidanalyzesupport.cpp |  93 +++++++---------
 src/plugins/android/androidanalyzesupport.h   |  17 +--
 src/plugins/android/androiddebugsupport.cpp   | 105 ++++++++----------
 src/plugins/android/androiddebugsupport.h     |  21 ++--
 src/plugins/android/androidrunsupport.cpp     |  67 -----------
 src/plugins/android/androidrunsupport.h       |  63 -----------
 8 files changed, 97 insertions(+), 273 deletions(-)
 delete mode 100644 src/plugins/android/androidrunsupport.cpp
 delete mode 100644 src/plugins/android/androidrunsupport.h

diff --git a/src/plugins/android/android.pro b/src/plugins/android/android.pro
index 41fc638bfc..f978d78918 100644
--- a/src/plugins/android/android.pro
+++ b/src/plugins/android/android.pro
@@ -30,7 +30,6 @@ HEADERS += \
     androiddevice.h \
     androidgdbserverkitinformation.h \
     androidanalyzesupport.h \
-    androidrunsupport.h \
     androidmanifesteditorfactory.h \
     androidmanifesteditor.h \
     androidmanifesteditorwidget.h \
@@ -73,7 +72,6 @@ SOURCES += \
     androiddevice.cpp \
     androidgdbserverkitinformation.cpp \
     androidanalyzesupport.cpp \
-    androidrunsupport.cpp \
     androidmanifesteditorfactory.cpp \
     androidmanifesteditor.cpp \
     androidmanifesteditorwidget.cpp \
diff --git a/src/plugins/android/android.qbs b/src/plugins/android/android.qbs
index 41f9f6ca29..0574d80f63 100644
--- a/src/plugins/android/android.qbs
+++ b/src/plugins/android/android.qbs
@@ -80,8 +80,6 @@ QtcPlugin {
         "androidrunfactories.h",
         "androidrunner.cpp",
         "androidrunner.h",
-        "androidrunsupport.cpp",
-        "androidrunsupport.h",
         "androidsettingspage.cpp",
         "androidsettingspage.h",
         "androidsettingswidget.cpp",
diff --git a/src/plugins/android/androidanalyzesupport.cpp b/src/plugins/android/androidanalyzesupport.cpp
index 7c5f5a5548..34d7e8d97c 100644
--- a/src/plugins/android/androidanalyzesupport.cpp
+++ b/src/plugins/android/androidanalyzesupport.cpp
@@ -75,61 +75,48 @@ RunControl *AndroidAnalyzeSupport::createAnalyzeRunControl(AndroidRunConfigurati
 
 AndroidAnalyzeSupport::AndroidAnalyzeSupport(AndroidRunConfiguration *runConfig,
     AnalyzerRunControl *runControl)
-    : AndroidRunSupport(runConfig, runControl),
-      m_runControl(0),
+    : QObject(runControl),
       m_qmlPort(0)
 {
-    if (runControl) {
-        m_runControl = runControl;
-        connect(m_runControl, SIGNAL(starting(const Analyzer::AnalyzerRunControl*)),
-                m_runner, SLOT(start()));
-    }
-    connect(&m_outputParser, SIGNAL(waitingForConnectionOnPort(quint16)),
-            SLOT(remoteIsRunning()));
-
-    connect(m_runner, &AndroidRunner::remoteProcessStarted,
-           [this](int, int qmlPort) { m_qmlPort = qmlPort; });
-
-    connect(m_runner, SIGNAL(remoteProcessFinished(QString)),
-            SLOT(handleRemoteProcessFinished(QString)));
-
-    connect(m_runner, SIGNAL(remoteErrorOutput(QByteArray)),
-            SLOT(handleRemoteErrorOutput(QByteArray)));
-    connect(m_runner, SIGNAL(remoteOutput(QByteArray)),
-            SLOT(handleRemoteOutput(QByteArray)));
-}
-
-void AndroidAnalyzeSupport::handleRemoteProcessFinished(const QString &errorMsg)
-{
-    if (m_runControl)
-        m_runControl->notifyRemoteFinished();
-    AndroidRunSupport::handleRemoteProcessFinished(errorMsg);
-}
-
-void AndroidAnalyzeSupport::handleRemoteOutput(const QByteArray &output)
-{
-    const QString msg = QString::fromUtf8(output);
-    if (m_runControl)
-        m_runControl->logApplicationMessage(msg, Utils::StdOutFormatSameLine);
-    else
-        AndroidRunSupport::handleRemoteOutput(output);
-    m_outputParser.processOutput(msg);
-}
-
-void AndroidAnalyzeSupport::handleRemoteErrorOutput(const QByteArray &output)
-{
-    const QString msg = QString::fromUtf8(output);
-    if (m_runControl)
-        m_runControl->logApplicationMessage(msg, Utils::StdErrFormatSameLine);
-    else
-        AndroidRunSupport::handleRemoteErrorOutput(output);
-    m_outputParser.processOutput(msg);
-}
-
-void AndroidAnalyzeSupport::remoteIsRunning()
-{
-    if (m_runControl)
-        m_runControl->notifyRemoteSetupDone(m_qmlPort);
+    QTC_ASSERT(runControl, return);
+
+    auto runner = new AndroidRunner(this, runConfig, runControl->runMode());
+
+    connect(runControl, &AnalyzerRunControl::finished,
+        [runner]() { runner->stop(); });
+
+    connect(runControl, &AnalyzerRunControl::starting,
+        [runner]() { runner->start(); });
+
+    connect(&m_outputParser, &QmlDebug::QmlOutputParser::waitingForConnectionOnPort,
+        [this, runControl](quint16) {
+            runControl->notifyRemoteSetupDone(m_qmlPort);
+        });
+
+    connect(runner, &AndroidRunner::remoteProcessStarted,
+        [this](int, int qmlPort) {
+            m_qmlPort = qmlPort;
+        });
+
+    connect(runner, &AndroidRunner::remoteProcessFinished,
+        [this, runControl](const QString &errorMsg)  {
+            runControl->notifyRemoteFinished();
+            runControl->appendMessage(errorMsg, Utils::NormalMessageFormat);
+        });
+
+    connect(runner, &AndroidRunner::remoteErrorOutput,
+        [this, runControl](const QByteArray &output) {
+            const QString msg = QString::fromUtf8(output);
+            runControl->logApplicationMessage(msg, Utils::StdErrFormatSameLine);
+            m_outputParser.processOutput(msg);
+        });
+
+    connect(runner, &AndroidRunner::remoteOutput,
+        [this, runControl](const QByteArray &output) {
+            const QString msg = QString::fromUtf8(output);
+            runControl->logApplicationMessage(msg, Utils::StdOutFormatSameLine);
+            m_outputParser.processOutput(msg);
+        });
 }
 
 } // namespace Internal
diff --git a/src/plugins/android/androidanalyzesupport.h b/src/plugins/android/androidanalyzesupport.h
index e685734c1e..42ce95981a 100644
--- a/src/plugins/android/androidanalyzesupport.h
+++ b/src/plugins/android/androidanalyzesupport.h
@@ -30,7 +30,7 @@
 #ifndef ANDROIDANALYZESUPPORT_H
 #define ANDROIDANALYZESUPPORT_H
 
-#include "androidrunsupport.h"
+#include "androidrunconfiguration.h"
 #include <qmldebug/qmloutputparser.h>
 
 namespace Analyzer { class AnalyzerRunControl; }
@@ -40,28 +40,19 @@ namespace Android {
 class AndroidRunConfiguration;
 
 namespace Internal {
-class AndroidRunner;
 
-class AndroidAnalyzeSupport : public AndroidRunSupport
+class AndroidAnalyzeSupport : public QObject
 {
     Q_OBJECT
 
 public:
-    static ProjectExplorer::RunControl *createAnalyzeRunControl(AndroidRunConfiguration *runConfig,
-                                                                ProjectExplorer::RunMode runMode);
-
     AndroidAnalyzeSupport(AndroidRunConfiguration *runConfig,
         Analyzer::AnalyzerRunControl *runControl);
 
-private slots:
-    void handleRemoteProcessFinished(const QString &errorMsg);
-    void handleRemoteOutput(const QByteArray &output);
-    void handleRemoteErrorOutput(const QByteArray &output);
-
-    void remoteIsRunning();
+    static ProjectExplorer::RunControl *createAnalyzeRunControl(AndroidRunConfiguration *runConfig,
+                                                                ProjectExplorer::RunMode runMode);
 
 private:
-    Analyzer::AnalyzerRunControl *m_runControl;
     QmlDebug::QmlOutputParser m_outputParser;
     int m_qmlPort;
 };
diff --git a/src/plugins/android/androiddebugsupport.cpp b/src/plugins/android/androiddebugsupport.cpp
index f9f70595f6..8b3e55d20d 100644
--- a/src/plugins/android/androiddebugsupport.cpp
+++ b/src/plugins/android/androiddebugsupport.cpp
@@ -127,83 +127,66 @@ RunControl *AndroidDebugSupport::createDebugRunControl(AndroidRunConfiguration *
 
 AndroidDebugSupport::AndroidDebugSupport(AndroidRunConfiguration *runConfig,
     DebuggerRunControl *runControl)
-    : AndroidRunSupport(runConfig, runControl),
-      m_engine(0)
+    : QObject(runControl),
+      m_engine(0),
+      m_runControl(runControl),
+      m_runner(new AndroidRunner(this, runConfig, runControl->runMode()))
 {
+    QTC_ASSERT(runControl, return);
+
+    connect(m_runControl, SIGNAL(finished()),
+            m_runner, SLOT(stop()));
+
     Debugger::DebuggerRunConfigurationAspect *aspect
             = runConfig->extraAspect<Debugger::DebuggerRunConfigurationAspect>();
     Q_ASSERT(aspect->useCppDebugger() || aspect->useQmlDebugger());
     Q_UNUSED(aspect)
 
-    if (runControl)
-        m_engine = runControl->engine();
+    m_engine = runControl->engine();
 
     if (m_engine) {
-        connect(m_engine, SIGNAL(requestRemoteSetup()),
-                m_runner, SLOT(start()));
+        connect(m_engine, &DebuggerEngine::requestRemoteSetup,
+                m_runner, &AndroidRunner::start);
+
+        // FIXME: Move signal to base class and generalize handling.
         connect(m_engine, SIGNAL(aboutToNotifyInferiorSetupOk()),
                 m_runner, SLOT(handleRemoteDebuggerRunning()));
     }
-    connect(m_runner, SIGNAL(remoteServerRunning(QByteArray,int)),
-            SLOT(handleRemoteServerRunning(QByteArray,int)));
-    connect(m_runner, SIGNAL(remoteProcessStarted(int,int)),
-            SLOT(handleRemoteProcessStarted(int,int)));
-    connect(m_runner, SIGNAL(remoteProcessFinished(QString)),
-            SLOT(handleRemoteProcessFinished(QString)));
-
-    connect(m_runner, SIGNAL(remoteErrorOutput(QByteArray)),
-            SLOT(handleRemoteErrorOutput(QByteArray)));
-    connect(m_runner, SIGNAL(remoteOutput(QByteArray)),
-            SLOT(handleRemoteOutput(QByteArray)));
-}
 
-void AndroidDebugSupport::handleRemoteServerRunning(const QByteArray &serverChannel, int pid)
-{
-    if (m_engine)
-        m_engine->notifyEngineRemoteServerRunning(serverChannel, pid);
+    connect(m_runner, &AndroidRunner::remoteServerRunning,
+        [this](const QByteArray &serverChannel, int pid) {
+            QTC_ASSERT(m_engine, return);
+            m_engine->notifyEngineRemoteServerRunning(serverChannel, pid);
+        });
+
+    connect(m_runner, &AndroidRunner::remoteProcessStarted,
+            this, &AndroidDebugSupport::handleRemoteProcessStarted);
+
+    connect(m_runner, &AndroidRunner::remoteProcessFinished,
+        [this](const QString &errorMsg) {
+            QTC_ASSERT(m_runControl, return);
+            m_runControl->showMessage(errorMsg, AppStuff);
+        });
+
+    connect(m_runner, &AndroidRunner::remoteErrorOutput,
+        [this](const QByteArray &output) {
+            QTC_ASSERT(m_engine, return);
+            m_engine->showMessage(QString::fromUtf8(output), AppError);
+        });
+
+    connect(m_runner, &AndroidRunner::remoteOutput,
+        [this](const QByteArray &output) {
+            QTC_ASSERT(m_engine, return);
+            m_engine->showMessage(QString::fromUtf8(output), AppOutput);
+        });
 }
 
 void AndroidDebugSupport::handleRemoteProcessStarted(int gdbServerPort, int qmlPort)
 {
-    disconnect(m_runner, SIGNAL(remoteProcessStarted(int,int)),
-        this, SLOT(handleRemoteProcessStarted(int,int)));
-    if (m_engine)
-        m_engine->notifyEngineRemoteSetupDone(gdbServerPort, qmlPort);
-}
-
-void AndroidDebugSupport::handleRemoteProcessFinished(const QString &errorMsg)
-{
-    DebuggerRunControl *runControl = qobject_cast<DebuggerRunControl *>(m_runControl);
-    if (runControl)
-        runControl->showMessage(errorMsg, AppStuff);
-    else
-        AndroidRunSupport::handleRemoteProcessFinished(errorMsg);
-}
-
-void AndroidDebugSupport::handleRemoteOutput(const QByteArray &output)
-{
-    if (m_engine) {
-        m_engine->showMessage(QString::fromUtf8(output), AppOutput);
-    } else {
-        DebuggerRunControl *runControl = qobject_cast<DebuggerRunControl *>(m_runControl);
-        if (runControl)
-            runControl->showMessage(QString::fromUtf8(output), AppOutput);
-        else
-            AndroidRunSupport::handleRemoteOutput(output);
-    }
-}
-
-void AndroidDebugSupport::handleRemoteErrorOutput(const QByteArray &output)
-{
-    if (m_engine) {
-        m_engine->showMessage(QString::fromUtf8(output), AppError);
-    } else {
-        DebuggerRunControl *runControl = qobject_cast<DebuggerRunControl *>(m_runControl);
-        if (runControl)
-            runControl->showMessage(QString::fromUtf8(output), AppError);
-        else
-            AndroidRunSupport::handleRemoteErrorOutput(output);
-    }
+    disconnect(m_runner, &AndroidRunner::remoteProcessStarted,
+               this, &AndroidDebugSupport::handleRemoteProcessStarted);
+    QTC_ASSERT(m_engine, return);
+    m_engine->notifyEngineRemoteSetupDone(gdbServerPort, qmlPort);
 }
 
 } // namespace Internal
diff --git a/src/plugins/android/androiddebugsupport.h b/src/plugins/android/androiddebugsupport.h
index ef705f644a..5e9b7ec886 100644
--- a/src/plugins/android/androiddebugsupport.h
+++ b/src/plugins/android/androiddebugsupport.h
@@ -30,12 +30,13 @@
 #ifndef ANDROIDDEBUGSUPPORT_H
 #define ANDROIDDEBUGSUPPORT_H
 
-#include "androidrunsupport.h"
+#include "androidrunconfiguration.h"
 
 namespace Debugger {
 class DebuggerEngine;
 class DebuggerRunControl;
 }
+
 namespace ProjectExplorer { class RunControl; }
 
 namespace Android {
@@ -44,27 +45,23 @@ class AndroidRunConfiguration;
 namespace Internal {
 class AndroidRunner;
 
-class AndroidDebugSupport : public AndroidRunSupport
+class AndroidDebugSupport : public QObject
 {
     Q_OBJECT
 
 public:
-    static ProjectExplorer::RunControl *createDebugRunControl(AndroidRunConfiguration *runConfig,
-                                                              QString *errorMessage);
-
     AndroidDebugSupport(AndroidRunConfiguration *runConfig,
         Debugger::DebuggerRunControl *runControl);
 
-private slots:
-    void handleRemoteServerRunning(const QByteArray &serverChannel, int pid);
-    void handleRemoteProcessStarted(int gdbServerPort, int qmlPort);
-    void handleRemoteProcessFinished(const QString &errorMsg);
-
-    void handleRemoteOutput(const QByteArray &output);
-    void handleRemoteErrorOutput(const QByteArray &output);
+    static ProjectExplorer::RunControl *createDebugRunControl(AndroidRunConfiguration *runConfig,
+                                                              QString *errorMessage);
 
 private:
+    void handleRemoteProcessStarted(int gdbServerPort, int qmlPort);
+
     Debugger::DebuggerEngine *m_engine;
+    Debugger::DebuggerRunControl *m_runControl;
+    AndroidRunner * const m_runner;
 };
 
 } // namespace Internal
diff --git a/src/plugins/android/androidrunsupport.cpp b/src/plugins/android/androidrunsupport.cpp
deleted file mode 100644
index f8e258d888..0000000000
--- a/src/plugins/android/androidrunsupport.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of Qt Creator.
-**
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia.  For licensing terms and
-** conditions see http://qt.digia.com/licensing.  For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file.  Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights.  These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-****************************************************************************/
-
-#include "androidrunsupport.h"
-#include "androidrunner.h"
-
-using namespace ProjectExplorer;
-
-namespace Android {
-namespace Internal {
-
-AndroidRunSupport::AndroidRunSupport(AndroidRunConfiguration *runConfig,
-                                     RunControl *runControl)
-    : QObject(runControl),
-      m_runControl(runControl),
-      m_runner(new AndroidRunner(this, runConfig, runControl->runMode()))
-{
-    connect(m_runControl, SIGNAL(finished()),
-            m_runner, SLOT(stop()));
-}
-
-void AndroidRunSupport::handleRemoteProcessFinished(const QString &errorMsg)
-{
-    if (m_runControl)
-        m_runControl->appendMessage(errorMsg, Utils::NormalMessageFormat);
-}
-
-void AndroidRunSupport::handleRemoteOutput(const QByteArray &output)
-{
-    if (m_runControl)
-        m_runControl->appendMessage(QString::fromUtf8(output), Utils::StdOutFormatSameLine);
-}
-
-void AndroidRunSupport::handleRemoteErrorOutput(const QByteArray &output)
-{
-    if (m_runControl)
-        m_runControl->appendMessage(QString::fromUtf8(output), Utils::StdErrFormatSameLine);
-}
-
-} // namespace Internal
-} // namespace Android
diff --git a/src/plugins/android/androidrunsupport.h b/src/plugins/android/androidrunsupport.h
deleted file mode 100644
index 3d12a83f3f..0000000000
--- a/src/plugins/android/androidrunsupport.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of Qt Creator.
-**
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia.  For licensing terms and
-** conditions see http://qt.digia.com/licensing.  For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file.  Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights.  These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-****************************************************************************/
-
-#ifndef ANDROIDRUNSUPPORT_H
-#define ANDROIDRUNSUPPORT_H
-
-#include "androidrunconfiguration.h"
-
-namespace ProjectExplorer { class RunControl; }
-
-namespace Android {
-namespace Internal {
-
-class AndroidRunner;
-
-class AndroidRunSupport : public QObject
-{
-    Q_OBJECT
-public:
-    AndroidRunSupport(AndroidRunConfiguration *runConfig,
-                       ProjectExplorer::RunControl *runControl);
-
-protected slots:
-    virtual void handleRemoteProcessFinished(const QString &errorMsg);
-
-    virtual void handleRemoteOutput(const QByteArray &output);
-    virtual void handleRemoteErrorOutput(const QByteArray &output);
-
-protected:
-    ProjectExplorer::RunControl* m_runControl;
-    AndroidRunner * const m_runner;
-};
-
-} // namespace Internal
-} // namespace Android
-
-#endif // ANDROIDRUNSUPPORT_H
-- 
GitLab