remotelinuxruncontrolfactory.cpp 5.43 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
Eike Ziller's avatar
Eike Ziller committed
3 4
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8 9 10 11
** 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
Eike Ziller's avatar
Eike Ziller committed
12 13
** a written agreement between you and The Qt Company.  For licensing terms and
** conditions see http://www.qt.io/terms-conditions.  For further information
Eike Ziller's avatar
Eike Ziller committed
14
** use the contact form at http://www.qt.io/contact-us.
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18 19 20 21 22 23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
hjk's avatar
hjk committed
24
**
Eike Ziller's avatar
Eike Ziller committed
25 26
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
27 28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
29
****************************************************************************/
30 31 32

#include "remotelinuxruncontrolfactory.h"

33
#include "remotelinuxanalyzesupport.h"
34
#include "remotelinuxdebugsupport.h"
35
#include "remotelinuxcustomrunconfiguration.h"
36 37 38
#include "remotelinuxrunconfiguration.h"
#include "remotelinuxruncontrol.h"

39
#include <debugger/debuggerruncontrol.h>
40
#include <debugger/debuggerstartparameters.h>
41 42 43
#include <analyzerbase/analyzerstartparameters.h>
#include <analyzerbase/analyzermanager.h>
#include <analyzerbase/analyzerruncontrol.h>
44
#include <analyzerbase/ianalyzertool.h>
Tobias Hunger's avatar
Tobias Hunger committed
45
#include <projectexplorer/kitinformation.h>
Tobias Hunger's avatar
Tobias Hunger committed
46
#include <projectexplorer/target.h>
Kai Koehne's avatar
Kai Koehne committed
47
#include <utils/portlist.h>
48
#include <utils/qtcassert.h>
49

50
using namespace Analyzer;
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
using namespace Debugger;
using namespace ProjectExplorer;

namespace RemoteLinux {
namespace Internal {

RemoteLinuxRunControlFactory::RemoteLinuxRunControlFactory(QObject *parent)
    : IRunControlFactory(parent)
{
}

RemoteLinuxRunControlFactory::~RemoteLinuxRunControlFactory()
{
}

66
bool RemoteLinuxRunControlFactory::canRun(RunConfiguration *runConfiguration, Core::Id mode) const
67
{
68 69 70 71
    if (mode != ProjectExplorer::Constants::NORMAL_RUN_MODE
            && mode != ProjectExplorer::Constants::DEBUG_RUN_MODE
            && mode != ProjectExplorer::Constants::DEBUG_RUN_MODE_WITH_BREAK_ON_MAIN
            && mode != ProjectExplorer::Constants::QML_PROFILER_RUN_MODE) {
72
        return false;
73
    }
74

75 76 77 78
    const Core::Id id = runConfiguration->id();
    return runConfiguration->isEnabled()
            && (id == RemoteLinuxCustomRunConfiguration::runConfigId()
                || id.name().startsWith(RemoteLinuxRunConfiguration::IdPrefix));
79 80
}

81
RunControl *RemoteLinuxRunControlFactory::create(RunConfiguration *runConfig, Core::Id mode,
82
                                                 QString *errorMessage)
83
{
84
    QTC_ASSERT(canRun(runConfig, mode), return 0);
85

86
    if (mode == ProjectExplorer::Constants::NORMAL_RUN_MODE)
87
        return new RemoteLinuxRunControl(runConfig);
88 89 90

    if (mode == ProjectExplorer::Constants::DEBUG_RUN_MODE
            || mode == ProjectExplorer::Constants::DEBUG_RUN_MODE_WITH_BREAK_ON_MAIN) {
91
        IDevice::ConstPtr dev = DeviceKitInformation::device(runConfig->target()->kit());
92 93 94 95
        if (!dev) {
            *errorMessage = tr("Cannot debug: Kit has no device.");
            return 0;
        }
96 97
        auto * const rc = qobject_cast<AbstractRemoteLinuxRunConfiguration *>(runConfig);
        QTC_ASSERT(rc, return 0);
98 99 100 101
        if (rc->portsUsedByDebuggers() > dev->freePorts().count()) {
            *errorMessage = tr("Cannot debug: Not enough free ports available.");
            return 0;
        }
102 103 104 105 106 107
        auto *crc = qobject_cast<RemoteLinuxCustomRunConfiguration *>(rc);
        if (crc && crc->localExecutableFilePath().isEmpty()) {
            *errorMessage = tr("Cannot debug: Local executable is not set.");
            return 0;
        }

108
        DebuggerStartParameters params = LinuxDeviceDebugSupport::startParameters(rc);
109
        DebuggerRunControl * const runControl = createDebuggerRunControl(params, runConfig, errorMessage, mode);
110 111 112
        if (!runControl)
            return 0;
        LinuxDeviceDebugSupport * const debugSupport =
hjk's avatar
hjk committed
113
                new LinuxDeviceDebugSupport(rc, runControl);
114 115 116
        connect(runControl, SIGNAL(finished()), debugSupport, SLOT(handleDebuggingFinished()));
        return runControl;
    }
117 118

    if (mode == ProjectExplorer::Constants::QML_PROFILER_RUN_MODE) {
119 120 121
        AnalyzerStartParameters params;
        params.connParams = DeviceKitInformation::device(runConfig->target()->kit())->sshParameters();
        params.analyzerHost = params.connParams.host;
122 123
        auto * const rc = qobject_cast<AbstractRemoteLinuxRunConfiguration *>(runConfig);
        QTC_ASSERT(rc, return 0);
124
        AnalyzerRunControl *runControl = AnalyzerManager::createRunControl(params, runConfig, mode);
125
        (void) new RemoteLinuxAnalyzeSupport(rc, runControl, mode);
126 127
        return runControl;
    }
128

129
    QTC_CHECK(false);
130
    return 0;
131 132 133 134
}

} // namespace Internal
} // namespace RemoteLinux