2010-07-27 17:56:07 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
|
** All rights reserved.
|
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
|
**
|
|
|
|
|
** This file is part of the Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
|
|
|
|
** No Commercial Usage
|
|
|
|
|
** This file contains pre-release code and may not be distributed.
|
|
|
|
|
** You may use this file in accordance with the terms and conditions
|
|
|
|
|
** contained in the Technology Preview License Agreement accompanying
|
|
|
|
|
** this package.
|
|
|
|
|
**
|
|
|
|
|
** 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, Nokia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
|
** Nokia at qt-info@nokia.com.
|
|
|
|
|
**
|
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
#include "maemodeviceenvreader.h"
|
|
|
|
|
|
2010-09-13 16:50:30 +02:00
|
|
|
#include "maemoglobal.h"
|
2010-07-27 17:56:07 +02:00
|
|
|
#include "maemorunconfiguration.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/ssh/sshconnection.h>
|
|
|
|
|
#include <coreplugin/ssh/sshremoteprocess.h>
|
|
|
|
|
|
|
|
|
|
namespace Qt4ProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
MaemoDeviceEnvReader::MaemoDeviceEnvReader(QObject *parent, MaemoRunConfiguration *config)
|
2010-07-27 17:56:07 +02:00
|
|
|
: QObject(parent)
|
|
|
|
|
, m_stop(false)
|
|
|
|
|
, m_devConfig(config->deviceConfig())
|
2010-10-06 15:11:46 +02:00
|
|
|
, m_runConfig(config)
|
2010-07-27 17:56:07 +02:00
|
|
|
{
|
2010-10-06 15:11:46 +02:00
|
|
|
connect(config, SIGNAL(deviceConfigurationChanged(ProjectExplorer::Target*)),
|
|
|
|
|
this, SLOT(handleCurrentDeviceConfigChanged()));
|
2010-07-27 17:56:07 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
MaemoDeviceEnvReader::~MaemoDeviceEnvReader()
|
2010-07-27 17:56:07 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoDeviceEnvReader::start()
|
2010-07-27 17:56:07 +02:00
|
|
|
{
|
|
|
|
|
m_stop = false;
|
|
|
|
|
if (m_connection)
|
|
|
|
|
disconnect(m_connection.data(), 0, this, 0);
|
2010-10-06 15:11:46 +02:00
|
|
|
|
2010-07-27 17:56:07 +02:00
|
|
|
const bool reuse = m_connection
|
|
|
|
|
&& m_connection->state() == Core::SshConnection::Connected
|
|
|
|
|
&& m_connection->connectionParameters() == m_devConfig.server;
|
2010-10-06 15:11:46 +02:00
|
|
|
|
2010-07-27 17:56:07 +02:00
|
|
|
if (!reuse)
|
|
|
|
|
m_connection = Core::SshConnection::create();
|
|
|
|
|
|
|
|
|
|
connect(m_connection.data(), SIGNAL(connected()), this,
|
|
|
|
|
SLOT(executeRemoteCall()));
|
2010-10-11 12:19:17 +02:00
|
|
|
connect(m_connection.data(), SIGNAL(error(Core::SshError)), this,
|
2010-07-27 17:56:07 +02:00
|
|
|
SLOT(handleConnectionFailure()));
|
2010-10-06 15:11:46 +02:00
|
|
|
|
2010-07-27 17:56:07 +02:00
|
|
|
if (reuse)
|
|
|
|
|
executeRemoteCall();
|
|
|
|
|
else
|
|
|
|
|
m_connection->connectToHost(m_devConfig.server);
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoDeviceEnvReader::stop()
|
2010-07-27 17:56:07 +02:00
|
|
|
{
|
|
|
|
|
m_stop = true;
|
|
|
|
|
|
2010-10-13 11:04:24 +02:00
|
|
|
if (m_connection)
|
|
|
|
|
disconnect(m_connection.data(), 0, this, 0);
|
2010-07-27 17:56:07 +02:00
|
|
|
if (m_remoteProcess) {
|
|
|
|
|
disconnect(m_remoteProcess.data());
|
|
|
|
|
m_remoteProcess->closeChannel();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoDeviceEnvReader::executeRemoteCall()
|
2010-07-27 17:56:07 +02:00
|
|
|
{
|
|
|
|
|
if (m_stop)
|
|
|
|
|
return;
|
|
|
|
|
|
2010-10-06 15:11:46 +02:00
|
|
|
const QByteArray remoteCall = MaemoGlobal::remoteSourceProfilesCommand()
|
|
|
|
|
.toUtf8() + "; env";
|
2010-07-27 17:56:07 +02:00
|
|
|
m_remoteProcess = m_connection->createRemoteProcess(remoteCall);
|
|
|
|
|
|
|
|
|
|
connect(m_remoteProcess.data(), SIGNAL(closed(int)), this,
|
|
|
|
|
SLOT(remoteProcessFinished(int)));
|
|
|
|
|
connect(m_remoteProcess.data(), SIGNAL(outputAvailable(QByteArray)), this,
|
|
|
|
|
SLOT(remoteOutput(QByteArray)));
|
|
|
|
|
connect(m_remoteProcess.data(), SIGNAL(errorOutputAvailable(QByteArray)), this,
|
|
|
|
|
SLOT(remoteErrorOutput(QByteArray)));
|
|
|
|
|
|
|
|
|
|
m_remoteOutput.clear();
|
2010-10-13 11:04:24 +02:00
|
|
|
m_remoteErrorOutput.clear();
|
2010-07-27 17:56:07 +02:00
|
|
|
m_remoteProcess->start();
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoDeviceEnvReader::handleConnectionFailure()
|
2010-07-27 17:56:07 +02:00
|
|
|
{
|
|
|
|
|
emit error(tr("Could not connect to host: %1")
|
|
|
|
|
.arg(m_connection->errorString()));
|
2010-10-13 11:04:24 +02:00
|
|
|
setFinished();
|
2010-07-27 17:56:07 +02:00
|
|
|
}
|
|
|
|
|
|
2010-10-06 15:11:46 +02:00
|
|
|
void MaemoDeviceEnvReader::handleCurrentDeviceConfigChanged()
|
|
|
|
|
{
|
|
|
|
|
m_devConfig = m_runConfig->deviceConfig();
|
|
|
|
|
|
|
|
|
|
m_env.clear();
|
2010-10-13 11:04:24 +02:00
|
|
|
setFinished();
|
2010-10-06 15:11:46 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoDeviceEnvReader::remoteProcessFinished(int exitCode)
|
2010-07-27 17:56:07 +02:00
|
|
|
{
|
|
|
|
|
Q_ASSERT(exitCode == Core::SshRemoteProcess::FailedToStart
|
|
|
|
|
|| exitCode == Core::SshRemoteProcess::KilledBySignal
|
|
|
|
|
|| exitCode == Core::SshRemoteProcess::ExitedNormally);
|
|
|
|
|
|
|
|
|
|
if (m_stop)
|
|
|
|
|
return;
|
|
|
|
|
|
2010-10-06 15:11:46 +02:00
|
|
|
m_env.clear();
|
2010-07-27 17:56:07 +02:00
|
|
|
if (exitCode == Core::SshRemoteProcess::ExitedNormally) {
|
2010-10-06 15:11:46 +02:00
|
|
|
if (!m_remoteOutput.isEmpty()) {
|
|
|
|
|
m_env = Utils::Environment(m_remoteOutput.split(QLatin1Char('\n'),
|
|
|
|
|
QString::SkipEmptyParts));
|
|
|
|
|
}
|
2010-07-27 17:56:07 +02:00
|
|
|
} else {
|
2010-10-13 11:04:24 +02:00
|
|
|
QString errorMsg = tr("Error running remote process: %1")
|
|
|
|
|
.arg(m_remoteProcess->errorString());
|
|
|
|
|
if (!m_remoteErrorOutput.isEmpty()) {
|
|
|
|
|
errorMsg += tr("\nRemote stderr was: '%1'")
|
|
|
|
|
.arg(QString::fromUtf8(m_remoteErrorOutput));
|
|
|
|
|
}
|
|
|
|
|
emit error(errorMsg);
|
2010-07-27 17:56:07 +02:00
|
|
|
}
|
2010-10-13 11:04:24 +02:00
|
|
|
setFinished();
|
2010-07-27 17:56:07 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoDeviceEnvReader::remoteOutput(const QByteArray &data)
|
2010-07-27 17:56:07 +02:00
|
|
|
{
|
|
|
|
|
m_remoteOutput.append(QString::fromUtf8(data));
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoDeviceEnvReader::remoteErrorOutput(const QByteArray &data)
|
2010-07-27 17:56:07 +02:00
|
|
|
{
|
2010-10-13 11:04:24 +02:00
|
|
|
m_remoteErrorOutput += data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoDeviceEnvReader::setFinished()
|
|
|
|
|
{
|
|
|
|
|
stop();
|
|
|
|
|
emit finished();
|
2010-07-27 17:56:07 +02:00
|
|
|
}
|
|
|
|
|
|
2010-10-13 11:04:24 +02:00
|
|
|
} // Internal
|
2010-07-27 17:56:07 +02:00
|
|
|
} // Qt4ProjectManager
|