forked from qt-creator/qt-creator
IOS: Unify error handling
Instead of using some flags in some struct, we convert the error handling to use expected_str<ResponseData> to clean up the error handling with the outside. Change-Id: I0f8d10c99715989e0069568ebc1d799d412a0600 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -74,8 +74,10 @@ static SimulatorInfoList selectedSimulators(const QTreeView *deviceTreeView)
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onSimOperation(const SimulatorInfo &simInfo, SimulatorOperationDialog* dlg,
|
static void onSimOperation(const SimulatorInfo &simInfo,
|
||||||
const QString &contextStr, const SimulatorControl::ResponseData &response)
|
SimulatorOperationDialog *dlg,
|
||||||
|
const QString &contextStr,
|
||||||
|
const SimulatorControl::Response &response)
|
||||||
{
|
{
|
||||||
dlg->addMessage(simInfo, response, contextStr);
|
dlg->addMessage(simInfo, response, contextStr);
|
||||||
}
|
}
|
||||||
@@ -224,14 +226,17 @@ void IosSettingsWidget::onCreate()
|
|||||||
statusDialog->setAttribute(Qt::WA_DeleteOnClose);
|
statusDialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
statusDialog->addMessage(Tr::tr("Creating simulator device..."), Utils::NormalMessageFormat);
|
statusDialog->addMessage(Tr::tr("Creating simulator device..."), Utils::NormalMessageFormat);
|
||||||
const auto onSimulatorCreate = [statusDialog](const QString &name,
|
const auto onSimulatorCreate = [statusDialog](const QString &name,
|
||||||
const SimulatorControl::ResponseData &response) {
|
const SimulatorControl::Response &response) {
|
||||||
if (response.success) {
|
if (response) {
|
||||||
statusDialog->addMessage(Tr::tr("Simulator device (%1) created.\nUDID: %2")
|
statusDialog->addMessage(Tr::tr("Simulator device (%1) created.\nUDID: %2")
|
||||||
.arg(name).arg(response.simUdid), Utils::StdOutFormat);
|
.arg(name)
|
||||||
|
.arg(response->simUdid),
|
||||||
|
Utils::StdOutFormat);
|
||||||
} else {
|
} else {
|
||||||
statusDialog->addMessage(Tr::tr("Simulator device (%1) creation failed.\nError: %2").
|
statusDialog->addMessage(Tr::tr("Simulator device (%1) creation failed.\nError: %2")
|
||||||
arg(name).arg(response.commandOutput),
|
.arg(name)
|
||||||
Utils::StdErrFormat);
|
.arg(response.error()),
|
||||||
|
Utils::StdErrFormat);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -738,16 +738,16 @@ void IosSimulatorToolHandlerPrivate::requestTransferApp(const FilePath &appBundl
|
|||||||
m_deviceId = deviceIdentifier;
|
m_deviceId = deviceIdentifier;
|
||||||
isTransferringApp(m_bundlePath, m_deviceId, 0, 100, "");
|
isTransferringApp(m_bundlePath, m_deviceId, 0, 100, "");
|
||||||
|
|
||||||
auto onSimulatorStart = [this](const SimulatorControl::ResponseData &response) {
|
auto onSimulatorStart = [this](const SimulatorControl::Response &response) {
|
||||||
if (!isResponseValid(response))
|
if (response) {
|
||||||
return;
|
if (!isResponseValid(*response))
|
||||||
|
return;
|
||||||
|
|
||||||
if (response.success) {
|
|
||||||
installAppOnSimulator();
|
installAppOnSimulator();
|
||||||
} else {
|
} else {
|
||||||
errorMsg(Tr::tr("Application install on simulator failed. Simulator not running."));
|
errorMsg(Tr::tr("Application install on simulator failed. Simulator not running."));
|
||||||
if (!response.commandOutput.isEmpty())
|
if (!response.error().isEmpty())
|
||||||
errorMsg(response.commandOutput);
|
errorMsg(response.error());
|
||||||
didTransferApp(m_bundlePath, m_deviceId, IosToolHandler::Failure);
|
didTransferApp(m_bundlePath, m_deviceId, IosToolHandler::Failure);
|
||||||
emit q->finished(q);
|
emit q->finished(q);
|
||||||
}
|
}
|
||||||
@@ -778,13 +778,15 @@ void IosSimulatorToolHandlerPrivate::requestRunApp(const FilePath &appBundlePath
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto onSimulatorStart = [this, extraArgs](const SimulatorControl::ResponseData &response) {
|
auto onSimulatorStart = [this, extraArgs](const SimulatorControl::Response &response) {
|
||||||
if (!isResponseValid(response))
|
if (response) {
|
||||||
return;
|
if (!isResponseValid(*response))
|
||||||
if (response.success) {
|
return;
|
||||||
|
|
||||||
launchAppOnSimulator(extraArgs);
|
launchAppOnSimulator(extraArgs);
|
||||||
} else {
|
} else {
|
||||||
errorMsg(Tr::tr("Application launch on simulator failed. Simulator not running."));
|
errorMsg(Tr::tr("Application launch on simulator failed. Simulator not running. %1")
|
||||||
|
.arg(response.error()));
|
||||||
didStartApp(m_bundlePath, m_deviceId, Ios::IosToolHandler::Failure);
|
didStartApp(m_bundlePath, m_deviceId, Ios::IosToolHandler::Failure);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -827,16 +829,14 @@ void IosSimulatorToolHandlerPrivate::stop(int errorCode)
|
|||||||
|
|
||||||
void IosSimulatorToolHandlerPrivate::installAppOnSimulator()
|
void IosSimulatorToolHandlerPrivate::installAppOnSimulator()
|
||||||
{
|
{
|
||||||
auto onResponseAppInstall = [this](const SimulatorControl::ResponseData &response) {
|
auto onResponseAppInstall = [this](const SimulatorControl::Response &response) {
|
||||||
if (!isResponseValid(response))
|
if (response) {
|
||||||
return;
|
if (!isResponseValid(*response))
|
||||||
|
return;
|
||||||
if (response.success) {
|
|
||||||
isTransferringApp(m_bundlePath, m_deviceId, 100, 100, "");
|
isTransferringApp(m_bundlePath, m_deviceId, 100, 100, "");
|
||||||
didTransferApp(m_bundlePath, m_deviceId, IosToolHandler::Success);
|
didTransferApp(m_bundlePath, m_deviceId, IosToolHandler::Success);
|
||||||
} else {
|
} else {
|
||||||
errorMsg(Tr::tr("Application install on simulator failed. %1")
|
errorMsg(Tr::tr("Application install on simulator failed. %1").arg(response.error()));
|
||||||
.arg(response.commandOutput));
|
|
||||||
didTransferApp(m_bundlePath, m_deviceId, IosToolHandler::Failure);
|
didTransferApp(m_bundlePath, m_deviceId, IosToolHandler::Failure);
|
||||||
}
|
}
|
||||||
emit q->finished(q);
|
emit q->finished(q);
|
||||||
@@ -884,22 +884,21 @@ void IosSimulatorToolHandlerPrivate::launchAppOnSimulator(const QStringList &ext
|
|||||||
stop(0);
|
stop(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto onResponseAppLaunch = [=](const SimulatorControl::ResponseData &response) {
|
auto onResponseAppLaunch = [=](const SimulatorControl::Response &response) {
|
||||||
if (!isResponseValid(response))
|
if (response) {
|
||||||
return;
|
if (!isResponseValid(*response))
|
||||||
if (response.success) {
|
return;
|
||||||
m_pid = response.pID;
|
m_pid = response->inferiorPid;
|
||||||
gotInferiorPid(m_bundlePath, m_deviceId, response.pID);
|
gotInferiorPid(m_bundlePath, m_deviceId, response->inferiorPid);
|
||||||
didStartApp(m_bundlePath, m_deviceId, Ios::IosToolHandler::Success);
|
didStartApp(m_bundlePath, m_deviceId, Ios::IosToolHandler::Success);
|
||||||
// Start monitoring app's life signs.
|
// Start monitoring app's life signs.
|
||||||
futureSynchronizer.addFuture(Utils::asyncRun(monitorPid, response.pID));
|
futureSynchronizer.addFuture(Utils::asyncRun(monitorPid, response->inferiorPid));
|
||||||
if (captureConsole)
|
if (captureConsole)
|
||||||
futureSynchronizer.addFuture(Utils::asyncRun(&LogTailFiles::exec, &outputLogger,
|
futureSynchronizer.addFuture(Utils::asyncRun(&LogTailFiles::exec, &outputLogger,
|
||||||
stdoutFile, stderrFile));
|
stdoutFile, stderrFile));
|
||||||
} else {
|
} else {
|
||||||
m_pid = -1;
|
m_pid = -1;
|
||||||
errorMsg(Tr::tr("Application launch on simulator failed. %1")
|
errorMsg(Tr::tr("Application launch on simulator failed. %1").arg(response.error()));
|
||||||
.arg(response.commandOutput));
|
|
||||||
didStartApp(m_bundlePath, m_deviceId, Ios::IosToolHandler::Failure);
|
didStartApp(m_bundlePath, m_deviceId, Ios::IosToolHandler::Failure);
|
||||||
stop(-1);
|
stop(-1);
|
||||||
emit q->finished(q);
|
emit q->finished(q);
|
||||||
|
@@ -188,30 +188,27 @@ static SimulatorInfo deviceInfo(const QString &simUdid);
|
|||||||
static QString bundleIdentifier(const Utils::FilePath &bundlePath);
|
static QString bundleIdentifier(const Utils::FilePath &bundlePath);
|
||||||
static QString bundleExecutable(const Utils::FilePath &bundlePath);
|
static QString bundleExecutable(const Utils::FilePath &bundlePath);
|
||||||
|
|
||||||
static void startSimulator(QPromise<SimulatorControl::ResponseData> &promise,
|
static void startSimulator(QPromise<SimulatorControl::Response> &promise, const QString &simUdid);
|
||||||
const QString &simUdid);
|
static void installApp(QPromise<SimulatorControl::Response> &promise,
|
||||||
static void installApp(QPromise<SimulatorControl::ResponseData> &promise,
|
|
||||||
const QString &simUdid,
|
const QString &simUdid,
|
||||||
const Utils::FilePath &bundlePath);
|
const Utils::FilePath &bundlePath);
|
||||||
static void launchApp(QPromise<SimulatorControl::ResponseData> &promise,
|
static void launchApp(QPromise<SimulatorControl::Response> &promise,
|
||||||
const QString &simUdid,
|
const QString &simUdid,
|
||||||
const QString &bundleIdentifier,
|
const QString &bundleIdentifier,
|
||||||
bool waitForDebugger,
|
bool waitForDebugger,
|
||||||
const QStringList &extraArgs,
|
const QStringList &extraArgs,
|
||||||
const QString &stdoutPath,
|
const QString &stdoutPath,
|
||||||
const QString &stderrPath);
|
const QString &stderrPath);
|
||||||
static void deleteSimulator(QPromise<SimulatorControl::ResponseData> &promise,
|
static void deleteSimulator(QPromise<SimulatorControl::Response> &promise, const QString &simUdid);
|
||||||
const QString &simUdid);
|
static void resetSimulator(QPromise<SimulatorControl::Response> &promise, const QString &simUdid);
|
||||||
static void resetSimulator(QPromise<SimulatorControl::ResponseData> &promise,
|
static void renameSimulator(QPromise<SimulatorControl::Response> &promise,
|
||||||
const QString &simUdid);
|
|
||||||
static void renameSimulator(QPromise<SimulatorControl::ResponseData> &promise,
|
|
||||||
const QString &simUdid,
|
const QString &simUdid,
|
||||||
const QString &newName);
|
const QString &newName);
|
||||||
static void createSimulator(QPromise<SimulatorControl::ResponseData> &promise,
|
static void createSimulator(QPromise<SimulatorControl::Response> &promise,
|
||||||
const QString &name,
|
const QString &name,
|
||||||
const DeviceTypeInfo &deviceType,
|
const DeviceTypeInfo &deviceType,
|
||||||
const RuntimeInfo &runtime);
|
const RuntimeInfo &runtime);
|
||||||
static void takeSceenshot(QPromise<SimulatorControl::ResponseData> &promise,
|
static void takeSceenshot(QPromise<SimulatorControl::Response> &promise,
|
||||||
const QString &simUdid,
|
const QString &simUdid,
|
||||||
const QString &filePath);
|
const QString &filePath);
|
||||||
|
|
||||||
@@ -309,23 +306,23 @@ QString SimulatorControl::bundleExecutable(const Utils::FilePath &bundlePath)
|
|||||||
return Internal::bundleExecutable(bundlePath);
|
return Internal::bundleExecutable(bundlePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
QFuture<SimulatorControl::ResponseData> SimulatorControl::startSimulator(const QString &simUdid)
|
QFuture<SimulatorControl::Response> SimulatorControl::startSimulator(const QString &simUdid)
|
||||||
{
|
{
|
||||||
return Utils::asyncRun(Internal::startSimulator, simUdid);
|
return Utils::asyncRun(Internal::startSimulator, simUdid);
|
||||||
}
|
}
|
||||||
|
|
||||||
QFuture<SimulatorControl::ResponseData> SimulatorControl::installApp(
|
QFuture<SimulatorControl::Response> SimulatorControl::installApp(const QString &simUdid,
|
||||||
const QString &simUdid, const Utils::FilePath &bundlePath)
|
const Utils::FilePath &bundlePath)
|
||||||
{
|
{
|
||||||
return Utils::asyncRun(Internal::installApp, simUdid, bundlePath);
|
return Utils::asyncRun(Internal::installApp, simUdid, bundlePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
QFuture<SimulatorControl::ResponseData> SimulatorControl::launchApp(const QString &simUdid,
|
QFuture<SimulatorControl::Response> SimulatorControl::launchApp(const QString &simUdid,
|
||||||
const QString &bundleIdentifier,
|
const QString &bundleIdentifier,
|
||||||
bool waitForDebugger,
|
bool waitForDebugger,
|
||||||
const QStringList &extraArgs,
|
const QStringList &extraArgs,
|
||||||
const QString &stdoutPath,
|
const QString &stdoutPath,
|
||||||
const QString &stderrPath)
|
const QString &stderrPath)
|
||||||
{
|
{
|
||||||
return Utils::asyncRun(Internal::launchApp,
|
return Utils::asyncRun(Internal::launchApp,
|
||||||
simUdid,
|
simUdid,
|
||||||
@@ -336,32 +333,30 @@ QFuture<SimulatorControl::ResponseData> SimulatorControl::launchApp(const QStrin
|
|||||||
stderrPath);
|
stderrPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
QFuture<SimulatorControl::ResponseData> SimulatorControl::deleteSimulator(const QString &simUdid)
|
QFuture<SimulatorControl::Response> SimulatorControl::deleteSimulator(const QString &simUdid)
|
||||||
{
|
{
|
||||||
return Utils::asyncRun(Internal::deleteSimulator, simUdid);
|
return Utils::asyncRun(Internal::deleteSimulator, simUdid);
|
||||||
}
|
}
|
||||||
|
|
||||||
QFuture<SimulatorControl::ResponseData> SimulatorControl::resetSimulator(const QString &simUdid)
|
QFuture<SimulatorControl::Response> SimulatorControl::resetSimulator(const QString &simUdid)
|
||||||
{
|
{
|
||||||
return Utils::asyncRun(Internal::resetSimulator, simUdid);
|
return Utils::asyncRun(Internal::resetSimulator, simUdid);
|
||||||
}
|
}
|
||||||
|
|
||||||
QFuture<SimulatorControl::ResponseData> SimulatorControl::renameSimulator(const QString &simUdid,
|
QFuture<SimulatorControl::Response> SimulatorControl::renameSimulator(const QString &simUdid,
|
||||||
const QString &newName)
|
const QString &newName)
|
||||||
{
|
{
|
||||||
return Utils::asyncRun(Internal::renameSimulator, simUdid, newName);
|
return Utils::asyncRun(Internal::renameSimulator, simUdid, newName);
|
||||||
}
|
}
|
||||||
|
|
||||||
QFuture<SimulatorControl::ResponseData>
|
QFuture<SimulatorControl::Response> SimulatorControl::createSimulator(
|
||||||
SimulatorControl::createSimulator(const QString &name,
|
const QString &name, const DeviceTypeInfo &deviceType, const RuntimeInfo &runtime)
|
||||||
const DeviceTypeInfo &deviceType,
|
|
||||||
const RuntimeInfo &runtime)
|
|
||||||
{
|
{
|
||||||
return Utils::asyncRun(Internal::createSimulator, name, deviceType, runtime);
|
return Utils::asyncRun(Internal::createSimulator, name, deviceType, runtime);
|
||||||
}
|
}
|
||||||
|
|
||||||
QFuture<SimulatorControl::ResponseData> SimulatorControl::takeSceenshot(const QString &simUdid,
|
QFuture<SimulatorControl::Response> SimulatorControl::takeSceenshot(const QString &simUdid,
|
||||||
const QString &filePath)
|
const QString &filePath)
|
||||||
{
|
{
|
||||||
return Utils::asyncRun(Internal::takeSceenshot, simUdid, filePath);
|
return Utils::asyncRun(Internal::takeSceenshot, simUdid, filePath);
|
||||||
}
|
}
|
||||||
@@ -419,14 +414,14 @@ QString bundleExecutable(const Utils::FilePath &bundlePath)
|
|||||||
return executable;
|
return executable;
|
||||||
}
|
}
|
||||||
|
|
||||||
void startSimulator(QPromise<SimulatorControl::ResponseData> &promise, const QString &simUdid)
|
void startSimulator(QPromise<SimulatorControl::Response> &promise, const QString &simUdid)
|
||||||
{
|
{
|
||||||
SimulatorControl::ResponseData response(simUdid);
|
SimulatorControl::ResponseData response(simUdid);
|
||||||
SimulatorInfo simInfo = deviceInfo(simUdid);
|
SimulatorInfo simInfo = deviceInfo(simUdid);
|
||||||
|
|
||||||
if (!simInfo.available) {
|
if (!simInfo.available) {
|
||||||
promise.addResult(
|
promise.addResult(
|
||||||
response.withError(Tr::tr("Simulator device is not available. (%1)").arg(simUdid)));
|
make_unexpected(Tr::tr("Simulator device is not available. (%1)").arg(simUdid)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Shutting down state checks are for the case when simulator start is called within a short
|
// Shutting down state checks are for the case when simulator start is called within a short
|
||||||
@@ -436,7 +431,7 @@ void startSimulator(QPromise<SimulatorControl::ResponseData> &promise, const QSt
|
|||||||
while (simInfo.isShuttingDown() && !simulatorStartDeadline.hasExpired()) {
|
while (simInfo.isShuttingDown() && !simulatorStartDeadline.hasExpired()) {
|
||||||
// Wait till the simulator shuts down, if doing so.
|
// Wait till the simulator shuts down, if doing so.
|
||||||
if (promise.isCanceled()) {
|
if (promise.isCanceled()) {
|
||||||
promise.addResult(response.withError(Tr::tr("Simulator start was canceled.")));
|
promise.addResult(make_unexpected(Tr::tr("Simulator start was canceled.")));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -446,14 +441,14 @@ void startSimulator(QPromise<SimulatorControl::ResponseData> &promise, const QSt
|
|||||||
|
|
||||||
if (simInfo.isShuttingDown()) {
|
if (simInfo.isShuttingDown()) {
|
||||||
promise.addResult(
|
promise.addResult(
|
||||||
response.withError(Tr::tr("Cannot start Simulator device. Previous instance taking "
|
make_unexpected(Tr::tr("Cannot start Simulator device. Previous instance taking "
|
||||||
"too long to shut down. (%1)")
|
"too long to shut down. (%1)")
|
||||||
.arg(simInfo.toString())));
|
.arg(simInfo.toString())));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!simInfo.isShutdown()) {
|
if (!simInfo.isShutdown()) {
|
||||||
promise.addResult(response.withError(
|
promise.addResult(make_unexpected(
|
||||||
Tr::tr("Cannot start Simulator device. Simulator not in shutdown state. (%1)")
|
Tr::tr("Cannot start Simulator device. Simulator not in shutdown state. (%1)")
|
||||||
.arg(simInfo.toString())));
|
.arg(simInfo.toString())));
|
||||||
return;
|
return;
|
||||||
@@ -462,7 +457,7 @@ void startSimulator(QPromise<SimulatorControl::ResponseData> &promise, const QSt
|
|||||||
expected_str<void> result = launchSimulator(simUdid,
|
expected_str<void> result = launchSimulator(simUdid,
|
||||||
[&promise] { return promise.isCanceled(); });
|
[&promise] { return promise.isCanceled(); });
|
||||||
if (!result) {
|
if (!result) {
|
||||||
promise.addResult(response.withError(result.error()));
|
promise.addResult(make_unexpected(result.error()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -475,24 +470,29 @@ void startSimulator(QPromise<SimulatorControl::ResponseData> &promise, const QSt
|
|||||||
do {
|
do {
|
||||||
info = deviceInfo(simUdid);
|
info = deviceInfo(simUdid);
|
||||||
if (promise.isCanceled()) {
|
if (promise.isCanceled()) {
|
||||||
promise.addResult(response.withError(Tr::tr("Simulator start was canceled.")));
|
promise.addResult(make_unexpected(Tr::tr("Simulator start was canceled.")));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} while (!info.isBooted() && !simulatorStartDeadline.hasExpired());
|
} while (!info.isBooted() && !simulatorStartDeadline.hasExpired());
|
||||||
|
|
||||||
if (info.isBooted())
|
if (!info.isBooted()) {
|
||||||
response.success = true;
|
promise.addResult(make_unexpected(
|
||||||
|
Tr::tr("Cannot start Simulator device. Simulator not in booted state. (%1)")
|
||||||
|
.arg(info.toString())));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
promise.addResult(response.withSuccess());
|
promise.addResult(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
void installApp(QPromise<SimulatorControl::ResponseData> &promise,
|
void installApp(QPromise<SimulatorControl::Response> &promise,
|
||||||
const QString &simUdid, const Utils::FilePath &bundlePath)
|
const QString &simUdid,
|
||||||
|
const Utils::FilePath &bundlePath)
|
||||||
{
|
{
|
||||||
SimulatorControl::ResponseData response(simUdid);
|
SimulatorControl::ResponseData response(simUdid);
|
||||||
|
|
||||||
if (!bundlePath.exists()) {
|
if (!bundlePath.exists()) {
|
||||||
promise.addResult(response.withError(Tr::tr("Bundle path does not exist.")));
|
promise.addResult(make_unexpected(Tr::tr("Bundle path does not exist.")));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -501,12 +501,12 @@ void installApp(QPromise<SimulatorControl::ResponseData> &promise,
|
|||||||
&response.commandOutput,
|
&response.commandOutput,
|
||||||
[&promise] { return promise.isCanceled(); });
|
[&promise] { return promise.isCanceled(); });
|
||||||
if (!result)
|
if (!result)
|
||||||
promise.addResult(response.withError(result.error()));
|
promise.addResult(make_unexpected(result.error()));
|
||||||
else
|
else
|
||||||
promise.addResult(response.withSuccess());
|
promise.addResult(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
void launchApp(QPromise<SimulatorControl::ResponseData> &promise,
|
void launchApp(QPromise<SimulatorControl::Response> &promise,
|
||||||
const QString &simUdid,
|
const QString &simUdid,
|
||||||
const QString &bundleIdentifier,
|
const QString &bundleIdentifier,
|
||||||
bool waitForDebugger,
|
bool waitForDebugger,
|
||||||
@@ -517,7 +517,7 @@ void launchApp(QPromise<SimulatorControl::ResponseData> &promise,
|
|||||||
SimulatorControl::ResponseData response(simUdid);
|
SimulatorControl::ResponseData response(simUdid);
|
||||||
|
|
||||||
if (bundleIdentifier.isEmpty()) {
|
if (bundleIdentifier.isEmpty()) {
|
||||||
promise.addResult(response.withError(Tr::tr("Invalid (empty) bundle identifier.")));
|
promise.addResult(make_unexpected(Tr::tr("Invalid (empty) bundle identifier.")));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -545,19 +545,24 @@ void launchApp(QPromise<SimulatorControl::ResponseData> &promise,
|
|||||||
[&promise] { return promise.isCanceled(); });
|
[&promise] { return promise.isCanceled(); });
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
promise.addResult(response.withError(result.error()));
|
promise.addResult(make_unexpected(result.error()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString pIdStr = stdOutput.trimmed().split(' ').last().trimmed();
|
const QString pIdStr = stdOutput.trimmed().split(' ').last().trimmed();
|
||||||
bool validPid = false;
|
bool validPid = false;
|
||||||
response.pID = pIdStr.toLongLong(&validPid);
|
response.inferiorPid = pIdStr.toLongLong(&validPid);
|
||||||
response.success = validPid;
|
|
||||||
|
|
||||||
promise.addResult(response.withSuccess());
|
if (!validPid) {
|
||||||
|
promise.addResult(
|
||||||
|
make_unexpected(Tr::tr("Failed to convert inferior pid. (%1)").arg(pIdStr)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
promise.addResult(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
void deleteSimulator(QPromise<SimulatorControl::ResponseData> &promise, const QString &simUdid)
|
void deleteSimulator(QPromise<SimulatorControl::Response> &promise, const QString &simUdid)
|
||||||
{
|
{
|
||||||
SimulatorControl::ResponseData response(simUdid);
|
SimulatorControl::ResponseData response(simUdid);
|
||||||
expected_str<void> result = runSimCtlCommand({"delete", simUdid},
|
expected_str<void> result = runSimCtlCommand({"delete", simUdid},
|
||||||
@@ -566,12 +571,12 @@ void deleteSimulator(QPromise<SimulatorControl::ResponseData> &promise, const QS
|
|||||||
[&promise] { return promise.isCanceled(); });
|
[&promise] { return promise.isCanceled(); });
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
promise.addResult(response.withError(result.error()));
|
promise.addResult(make_unexpected(result.error()));
|
||||||
else
|
else
|
||||||
promise.addResult(response.withSuccess());
|
promise.addResult(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
void resetSimulator(QPromise<SimulatorControl::ResponseData> &promise, const QString &simUdid)
|
void resetSimulator(QPromise<SimulatorControl::Response> &promise, const QString &simUdid)
|
||||||
{
|
{
|
||||||
SimulatorControl::ResponseData response(simUdid);
|
SimulatorControl::ResponseData response(simUdid);
|
||||||
expected_str<void> result = runSimCtlCommand({"erase", simUdid},
|
expected_str<void> result = runSimCtlCommand({"erase", simUdid},
|
||||||
@@ -580,12 +585,12 @@ void resetSimulator(QPromise<SimulatorControl::ResponseData> &promise, const QSt
|
|||||||
[&promise] { return promise.isCanceled(); });
|
[&promise] { return promise.isCanceled(); });
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
promise.addResult(response.withError(result.error()));
|
promise.addResult(make_unexpected(result.error()));
|
||||||
else
|
else
|
||||||
promise.addResult(response.withSuccess());
|
promise.addResult(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
void renameSimulator(QPromise<SimulatorControl::ResponseData> &promise,
|
void renameSimulator(QPromise<SimulatorControl::Response> &promise,
|
||||||
const QString &simUdid,
|
const QString &simUdid,
|
||||||
const QString &newName)
|
const QString &newName)
|
||||||
{
|
{
|
||||||
@@ -595,12 +600,12 @@ void renameSimulator(QPromise<SimulatorControl::ResponseData> &promise,
|
|||||||
&response.commandOutput,
|
&response.commandOutput,
|
||||||
[&promise] { return promise.isCanceled(); });
|
[&promise] { return promise.isCanceled(); });
|
||||||
if (!result)
|
if (!result)
|
||||||
promise.addResult(response.withError(result.error()));
|
promise.addResult(make_unexpected(result.error()));
|
||||||
else
|
else
|
||||||
promise.addResult(response.withSuccess());
|
promise.addResult(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
void createSimulator(QPromise<SimulatorControl::ResponseData> &promise,
|
void createSimulator(QPromise<SimulatorControl::Response> &promise,
|
||||||
const QString &name,
|
const QString &name,
|
||||||
const DeviceTypeInfo &deviceType,
|
const DeviceTypeInfo &deviceType,
|
||||||
const RuntimeInfo &runtime)
|
const RuntimeInfo &runtime)
|
||||||
@@ -618,15 +623,17 @@ void createSimulator(QPromise<SimulatorControl::ResponseData> &promise,
|
|||||||
&stdOutput,
|
&stdOutput,
|
||||||
&response.commandOutput,
|
&response.commandOutput,
|
||||||
[&promise] { return promise.isCanceled(); });
|
[&promise] { return promise.isCanceled(); });
|
||||||
response.simUdid = result ? stdOutput.trimmed() : QString();
|
|
||||||
|
if (result)
|
||||||
|
response.simUdid = stdOutput.trimmed();
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
promise.addResult(response.withError(result.error()));
|
promise.addResult(make_unexpected(result.error()));
|
||||||
else
|
else
|
||||||
promise.addResult(response.withSuccess());
|
promise.addResult(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
void takeSceenshot(QPromise<SimulatorControl::ResponseData> &promise,
|
void takeSceenshot(QPromise<SimulatorControl::Response> &promise,
|
||||||
const QString &simUdid,
|
const QString &simUdid,
|
||||||
const QString &filePath)
|
const QString &filePath)
|
||||||
{
|
{
|
||||||
@@ -637,9 +644,9 @@ void takeSceenshot(QPromise<SimulatorControl::ResponseData> &promise,
|
|||||||
[&promise] { return promise.isCanceled(); });
|
[&promise] { return promise.isCanceled(); });
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
promise.addResult(response.withError(result.error()));
|
promise.addResult(make_unexpected(result.error()));
|
||||||
else
|
else
|
||||||
promise.addResult(response.withSuccess());
|
promise.addResult(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString SimulatorInfo::toString() const
|
QString SimulatorInfo::toString() const
|
||||||
|
@@ -54,30 +54,17 @@ class SimulatorControl
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
struct ResponseData {
|
struct ResponseData {
|
||||||
ResponseData(const QString & udid):
|
ResponseData(const QString &udid)
|
||||||
simUdid(udid) { }
|
: simUdid(udid)
|
||||||
|
{}
|
||||||
|
|
||||||
QString simUdid;
|
QString simUdid;
|
||||||
bool success = false;
|
qint64 inferiorPid{-1};
|
||||||
qint64 pID = -1;
|
|
||||||
QString commandOutput;
|
QString commandOutput;
|
||||||
|
|
||||||
ResponseData withError(const QString errorMsg)
|
|
||||||
{
|
|
||||||
ResponseData result = *this;
|
|
||||||
result.commandOutput = errorMsg;
|
|
||||||
result.success = false;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
ResponseData withSuccess()
|
|
||||||
{
|
|
||||||
ResponseData result = std::move(*this);
|
|
||||||
result.success = true;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using Response = Utils::expected_str<ResponseData>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static QList<DeviceTypeInfo> availableDeviceTypes();
|
static QList<DeviceTypeInfo> availableDeviceTypes();
|
||||||
static QFuture<QList<DeviceTypeInfo>> updateDeviceTypes(QObject *context);
|
static QFuture<QList<DeviceTypeInfo>> updateDeviceTypes(QObject *context);
|
||||||
@@ -90,22 +77,21 @@ public:
|
|||||||
static QString bundleExecutable(const Utils::FilePath &bundlePath);
|
static QString bundleExecutable(const Utils::FilePath &bundlePath);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static QFuture<ResponseData> startSimulator(const QString &simUdid);
|
static QFuture<Response> startSimulator(const QString &simUdid);
|
||||||
static QFuture<ResponseData> installApp(const QString &simUdid,
|
static QFuture<Response> installApp(const QString &simUdid, const Utils::FilePath &bundlePath);
|
||||||
const Utils::FilePath &bundlePath);
|
static QFuture<Response> launchApp(const QString &simUdid,
|
||||||
static QFuture<ResponseData> launchApp(const QString &simUdid,
|
const QString &bundleIdentifier,
|
||||||
const QString &bundleIdentifier,
|
bool waitForDebugger,
|
||||||
bool waitForDebugger,
|
const QStringList &extraArgs,
|
||||||
const QStringList &extraArgs,
|
const QString &stdoutPath = QString(),
|
||||||
const QString &stdoutPath = QString(),
|
const QString &stderrPath = QString());
|
||||||
const QString &stderrPath = QString());
|
static QFuture<Response> deleteSimulator(const QString &simUdid);
|
||||||
static QFuture<ResponseData> deleteSimulator(const QString &simUdid);
|
static QFuture<Response> resetSimulator(const QString &simUdid);
|
||||||
static QFuture<ResponseData> resetSimulator(const QString &simUdid);
|
static QFuture<Response> renameSimulator(const QString &simUdid, const QString &newName);
|
||||||
static QFuture<ResponseData> renameSimulator(const QString &simUdid, const QString &newName);
|
static QFuture<Response> createSimulator(const QString &name,
|
||||||
static QFuture<ResponseData> createSimulator(const QString &name,
|
const DeviceTypeInfo &deviceType,
|
||||||
const DeviceTypeInfo &deviceType,
|
const RuntimeInfo &runtime);
|
||||||
const RuntimeInfo &runtime);
|
static QFuture<Response> takeSceenshot(const QString &simUdid, const QString &filePath);
|
||||||
static QFuture<ResponseData> takeSceenshot(const QString &simUdid, const QString &filePath);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Ios::Internal
|
} // Ios::Internal
|
||||||
|
@@ -94,15 +94,15 @@ void SimulatorOperationDialog::addMessage(const QString &message, Utils::OutputF
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorOperationDialog::addMessage(const SimulatorInfo &siminfo,
|
void SimulatorOperationDialog::addMessage(const SimulatorInfo &siminfo,
|
||||||
const SimulatorControl::ResponseData &response,
|
const SimulatorControl::Response &response,
|
||||||
const QString &context)
|
const QString &context)
|
||||||
{
|
{
|
||||||
QTC_CHECK(siminfo.identifier == response.simUdid);
|
if (response) {
|
||||||
if (response.success) {
|
QTC_CHECK(siminfo.identifier == response->simUdid);
|
||||||
addMessage(Tr::tr("%1, %2\nOperation %3 completed successfully.").arg(siminfo.name)
|
addMessage(Tr::tr("%1, %2\nOperation %3 completed successfully.").arg(siminfo.name)
|
||||||
.arg(siminfo.runtimeName).arg(context), Utils::StdOutFormat);
|
.arg(siminfo.runtimeName).arg(context), Utils::StdOutFormat);
|
||||||
} else {
|
} else {
|
||||||
QString erroMsg = response.commandOutput.trimmed();
|
QString erroMsg = response.error();
|
||||||
QString message = Tr::tr("%1, %2\nOperation %3 failed.\nUDID: %4\nError: %5").arg(siminfo.name)
|
QString message = Tr::tr("%1, %2\nOperation %3 failed.\nUDID: %4\nError: %5").arg(siminfo.name)
|
||||||
.arg(siminfo.runtimeName).arg(context).arg(siminfo.identifier)
|
.arg(siminfo.runtimeName).arg(context).arg(siminfo.identifier)
|
||||||
.arg(erroMsg.isEmpty() ? Tr::tr("Unknown") : erroMsg);
|
.arg(erroMsg.isEmpty() ? Tr::tr("Unknown") : erroMsg);
|
||||||
|
@@ -30,7 +30,8 @@ public:
|
|||||||
public:
|
public:
|
||||||
void addFutures(const QList<QFuture<void> > &futureList);
|
void addFutures(const QList<QFuture<void> > &futureList);
|
||||||
void addMessage(const QString &message, Utils::OutputFormat format);
|
void addMessage(const QString &message, Utils::OutputFormat format);
|
||||||
void addMessage(const SimulatorInfo &siminfo, const SimulatorControl::ResponseData &response,
|
void addMessage(const SimulatorInfo &siminfo,
|
||||||
|
const SimulatorControl::Response &response,
|
||||||
const QString &context);
|
const QString &context);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Reference in New Issue
Block a user