Commit 0b939667 authored by Tobias Hunger's avatar Tobias Hunger

SDKtool: Add basic commands to add/remove devices

Change-Id: I2df53b2585875c4dc5fcba3012901530b963e70d
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent c0a5a21a
This diff is collapsed.
/****************************************************************************
**
** 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 ADDDEVICEOPERATION_H
#define ADDDEVICEOPERATION_H
#include "operation.h"
#include <QString>
extern const char DEVICEMANAGER_ID[];
extern const char DEFAULT_DEVICES_ID[];
extern const char DEVICE_LIST_ID[];
extern const char DEVICE_ID_ID[];
class AddDeviceOperation : public Operation
{
public:
AddDeviceOperation();
QString name() const;
QString helpText() const;
QString argumentsHelpText() const;
bool setArguments(const QStringList &args);
int execute() const;
#ifdef WITH_TESTS
bool test() const;
#endif
static QVariantMap addDevice(const QVariantMap &map,
const QString &id, const QString &displayName, int type,
int auth, const QString &hwPlatform, const QString &swPlatform,
const QString &debugServer, const QString &freePorts,
const QString &host, const QString &keyFile,
int origin, const QString &osType, const QString &passwd,
int sshPort, int timeout, const QString &uname, int version,
const KeyValuePairList &extra);
static QVariantMap initializeDevices();
private:
static KeyValuePairList createDevice(const QString &id, const QString &displayName, int type,
int auth, const QString &hwPlatform, const QString &swPlatform,
const QString &debugServer, const QString &freePorts,
const QString &host, const QString &keyFile,
int origin, const QString &osType, const QString &passwd,
int sshPort, int timeout, const QString &uname, int version,
const KeyValuePairList &extra);
int m_authentication;
QString m_b2q_platformHardware;
QString m_b2q_platformSoftware;
QString m_debugServer;
QString m_freePortsSpec;
QString m_host;
QString m_id;
QString m_keyFile;
QString m_displayName;
int m_origin;
QString m_osType;
QString m_password;
int m_sshPort;
int m_timeout;
int m_type;
QString m_uname;
int m_version;
KeyValuePairList m_extra;
};
#endif // ADDDEVICEOPERATION_H
......@@ -32,6 +32,7 @@
#include "operation.h"
#include "adddebuggeroperation.h"
#include "adddeviceoperation.h"
#include "addkeysoperation.h"
#include "addkitoperation.h"
#include "addqtoperation.h"
......@@ -40,6 +41,7 @@
#include "findvalueoperation.h"
#include "getoperation.h"
#include "rmdebuggeroperation.h"
#include "rmdeviceoperation.h"
#include "rmkeysoperation.h"
#include "rmkitoperation.h"
#include "rmqtoperation.h"
......@@ -163,6 +165,7 @@ int main(int argc, char *argv[])
QList<Operation *> operations;
operations << new AddDebuggerOperation
<< new AddDeviceOperation
<< new AddKeysOperation
<< new AddKitOperation
<< new AddQtOperation
......@@ -171,6 +174,7 @@ int main(int argc, char *argv[])
<< new FindValueOperation
<< new GetOperation
<< new RmDebuggerOperation
<< new RmDeviceOperation
<< new RmKeysOperation
<< new RmKitOperation
<< new RmQtOperation
......
/****************************************************************************
**
** 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 "rmdeviceoperation.h"
#include "adddeviceoperation.h"
#include "getoperation.h"
#include "settings.h"
#include <iostream>
QString RmDeviceOperation::name() const
{
return QLatin1String("rmDev");
}
QString RmDeviceOperation::helpText() const
{
return QLatin1String("remove a Device from Qt Creator");
}
QString RmDeviceOperation::argumentsHelpText() const
{
return QLatin1String(" --id <ID> id of the device to remove.\n");
}
bool RmDeviceOperation::setArguments(const QStringList &args)
{
if (args.count() != 2)
return false;
if (args.at(0) != QLatin1String("--id"))
return false;
m_id = args.at(1);
if (m_id.isEmpty())
std::cerr << "No id given." << std::endl << std::endl;
return !m_id.isEmpty();
}
int RmDeviceOperation::execute() const
{
QVariantMap map = load(QLatin1String("devices"));
if (map.isEmpty())
map = AddDeviceOperation::initializeDevices();
QVariantMap result = rmDevice(map, m_id);
if (result == map)
return 2;
return save(result, QLatin1String("devices")) ? 0 : 3;
}
#ifdef WITH_TESTS
bool RmDeviceOperation::test() const
{
return true;
}
#endif
QVariantMap RmDeviceOperation::rmDevice(const QVariantMap &map, const QString &id)
{
QVariantMap result = map;
QVariantMap dmMap = map.value(QLatin1String(DEVICEMANAGER_ID)).toMap();
bool found = false;
QVariantList devList = GetOperation::get(dmMap, QLatin1String(DEVICE_LIST_ID)).toList();
for (int i = 0; i < devList.count(); ++i) {
QVariant value = devList.at(i);
if (value.type() != QVariant::Map)
continue;
QVariantMap deviceData = value.toMap();
QString devId = deviceData.value(QLatin1String(DEVICE_ID_ID)).toString();
if (devId == id) {
found = true;
devList.removeAt(i);
break;
}
}
dmMap.insert(QLatin1String(DEVICE_LIST_ID), devList);
result.insert(QLatin1String(DEVICEMANAGER_ID), dmMap);
if (!found)
std::cerr << "Device " << qPrintable(id) << " not found." << std::endl;
return result;
}
/****************************************************************************
**
** 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 RMDEVICEOPERATION_H
#define RMDEVICEOPERATION_H
#include "operation.h"
#include <QString>
class RmDeviceOperation : public Operation
{
public:
QString name() const;
QString helpText() const;
QString argumentsHelpText() const;
bool setArguments(const QStringList &args);
int execute() const;
#ifdef WITH_TESTS
bool test() const;
#endif
static QVariantMap rmDevice(const QVariantMap &map, const QString &id);
private:
QString m_id;
};
#endif // RMDEVICEOPERATION_H
......@@ -14,6 +14,7 @@ isEmpty(PRECOMPILED_HEADER):PRECOMPILED_HEADER = $$PWD/../../shared/qtcreator_pc
SOURCES += \
main.cpp \
adddebuggeroperation.cpp \
adddeviceoperation.cpp \
addkeysoperation.cpp \
addkitoperation.cpp \
addqtoperation.cpp \
......@@ -23,6 +24,7 @@ SOURCES += \
getoperation.cpp \
operation.cpp \
rmdebuggeroperation.cpp \
rmdeviceoperation.cpp \
rmkeysoperation.cpp \
rmkitoperation.cpp \
rmqtoperation.cpp \
......@@ -31,6 +33,7 @@ SOURCES += \
HEADERS += \
adddebuggeroperation.h \
adddeviceoperation.h \
addkeysoperation.h \
addkitoperation.h \
addqtoperation.h \
......@@ -40,6 +43,7 @@ HEADERS += \
getoperation.h \
operation.h \
rmdebuggeroperation.h \
rmdeviceoperation.h \
rmkeysoperation.h \
rmkitoperation.h \
rmqtoperation.h \
......
......@@ -13,6 +13,7 @@ QtcTool {
files: [
"adddebuggeroperation.cpp", "adddebuggeroperation.h",
"adddeviceoperation.cpp", "adddeviceoperation.h",
"addkeysoperation.cpp",
"addkeysoperation.h",
"addkitoperation.cpp",
......@@ -31,6 +32,7 @@ QtcTool {
"operation.cpp",
"operation.h",
"rmdebuggeroperation.cpp", "rmdebuggeroperation.h",
"rmdeviceoperation.cpp", "rmdeviceoperation.h",
"rmkeysoperation.cpp",
"rmkeysoperation.h",
"rmkitoperation.cpp",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment