From bc7778a31d15efa443583fa5092a36dd51abfeb1 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Sun, 8 Sep 2013 23:02:28 +0300 Subject: [PATCH] Utils: Introduce sleep function Use it in Android plugin Change-Id: Id3ae707d5425e99a2e5b993e1ed98dddd73809a9 Reviewed-by: hjk --- src/libs/utils/sleep.cpp | 47 +++++++++++++++++++ src/libs/utils/sleep.h | 41 ++++++++++++++++ src/libs/utils/utils-lib.pri | 2 + src/libs/utils/utils.qbs | 2 + src/plugins/android/android.qbs | 1 + src/plugins/android/android_dependencies.pri | 3 ++ src/plugins/android/androidconfigurations.cpp | 13 ++--- 7 files changed, 99 insertions(+), 10 deletions(-) create mode 100644 src/libs/utils/sleep.cpp create mode 100644 src/libs/utils/sleep.h diff --git a/src/libs/utils/sleep.cpp b/src/libs/utils/sleep.cpp new file mode 100644 index 00000000000..700fdcb671a --- /dev/null +++ b/src/libs/utils/sleep.cpp @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Orgad Shaneh . +** 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 "sleep.h" + +#ifdef Q_OS_WIN +#include +#else +#include +#include +#endif + +void Utils::sleep(int msec) +{ +#ifdef Q_OS_WIN + ::Sleep(msec); +#else + struct timespec ts = { msec / 1000, (msec % 1000) * 1000000 }; + ::nanosleep(&ts, NULL); +#endif +} diff --git a/src/libs/utils/sleep.h b/src/libs/utils/sleep.h new file mode 100644 index 00000000000..c8a592ab95e --- /dev/null +++ b/src/libs/utils/sleep.h @@ -0,0 +1,41 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Orgad Shaneh . +** 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 SLEEP_H +#define SLEEP_H + +#include "utils_global.h" + +namespace Utils { + +void QTCREATOR_UTILS_EXPORT sleep(int msec); + +} + +#endif // SLEEP_H diff --git a/src/libs/utils/utils-lib.pri b/src/libs/utils/utils-lib.pri index 3899a45c194..97833eb8e79 100644 --- a/src/libs/utils/utils-lib.pri +++ b/src/libs/utils/utils-lib.pri @@ -73,6 +73,7 @@ SOURCES += $$PWD/environment.cpp \ $$PWD/portlist.cpp \ $$PWD/tcpportsgatherer.cpp \ $$PWD/appmainwindow.cpp \ + $$PWD/sleep.cpp \ $$PWD/basetreeview.cpp \ $$PWD/qtcassert.cpp \ $$PWD/elfreader.cpp \ @@ -163,6 +164,7 @@ HEADERS += \ $$PWD/portlist.h \ $$PWD/tcpportsgatherer.h \ $$PWD/appmainwindow.h \ + $$PWD/sleep.h \ $$PWD/basetreeview.h \ $$PWD/elfreader.h \ $$PWD/bracematcher.h \ diff --git a/src/libs/utils/utils.qbs b/src/libs/utils/utils.qbs index 2a55db5bbc1..f3b058936f1 100644 --- a/src/libs/utils/utils.qbs +++ b/src/libs/utils/utils.qbs @@ -151,6 +151,8 @@ QtcLibrary { "settingsselector.cpp", "settingsselector.h", "settingsutils.h", + "sleep.cpp", + "sleep.h", "statuslabel.cpp", "statuslabel.h", "stringutils.cpp", diff --git a/src/plugins/android/android.qbs b/src/plugins/android/android.qbs index b9c02f78cc5..8a58a60d950 100644 --- a/src/plugins/android/android.qbs +++ b/src/plugins/android/android.qbs @@ -17,6 +17,7 @@ QtcPlugin { Depends { name: "QtSupport" } Depends { name: "TextEditor" } Depends { name: "AnalyzerBase" } + Depends { name: "Utils" } Depends { name: "Qt"; submodules: ["widgets", "xml", "network"] } property bool enable: false diff --git a/src/plugins/android/android_dependencies.pri b/src/plugins/android/android_dependencies.pri index 4ee3ff5acff..c21226f6f27 100644 --- a/src/plugins/android/android_dependencies.pri +++ b/src/plugins/android/android_dependencies.pri @@ -8,6 +8,9 @@ QTC_PLUGIN_DEPENDS += \ texteditor \ analyzerbase +QTC_LIB_DEPENDS += \ + utils + exists(../../shared/qbs/qbs.pro): \ QTC_PLUGIN_DEPENDS += \ qbsprojectmanager diff --git a/src/plugins/android/androidconfigurations.cpp b/src/plugins/android/androidconfigurations.cpp index aa208129f14..13f4b5dc373 100644 --- a/src/plugins/android/androidconfigurations.cpp +++ b/src/plugins/android/androidconfigurations.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -59,14 +60,6 @@ #include #include -#if defined(_WIN32) -#include -#include -#define sleep(_n) Sleep(1000 * (_n)) -#else -#include -#endif - using namespace ProjectExplorer; using namespace Utils; @@ -618,11 +611,11 @@ QString AndroidConfigurations::waitForAvd(int apiLevel, const QString &cpuAbi) c if (hasFinishedBooting(serialNumber)) return serialNumber; else - sleep(8); + Utils::sleep(8000); } return QString(); } - sleep(8); + Utils::sleep(8000); } return QString(); }