diff options
Diffstat (limited to 'src/corelib/kernel/qfunctions_winrt.h')
-rw-r--r-- | src/corelib/kernel/qfunctions_winrt.h | 130 |
1 files changed, 110 insertions, 20 deletions
diff --git a/src/corelib/kernel/qfunctions_winrt.h b/src/corelib/kernel/qfunctions_winrt.h index fa2b2e12ff..04ebda5cfe 100644 --- a/src/corelib/kernel/qfunctions_winrt.h +++ b/src/corelib/kernel/qfunctions_winrt.h @@ -1,40 +1,32 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the QtCore module of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL$ +** $QT_BEGIN_LICENSE:LGPL21$ ** 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 +** 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. +** 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. ** ** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -44,7 +36,11 @@ #include <QtCore/qglobal.h> -#ifdef Q_OS_WINRT +#ifdef Q_OS_WIN + +#include <QtCore/QThread> +#include <QtCore/QAbstractEventDispatcher> +#include <QtCore/qt_windows.h> QT_BEGIN_NAMESPACE @@ -53,6 +49,8 @@ QT_BEGIN_NAMESPACE QT_END_NAMESPACE +#ifdef Q_OS_WINRT + // Environment ------------------------------------------------------ errno_t qt_winrt_getenv_s(size_t*, char*, size_t, const char*); errno_t qt_winrt__putenv_s(const char*, const char*); @@ -119,4 +117,96 @@ generate_inline_return_func0(tzset, void) generate_inline_return_func0(_tzset, void) #endif // Q_OS_WINRT + +// Convenience macros for handling HRESULT values +#define RETURN_IF_FAILED(msg, ret) \ + if (FAILED(hr)) { \ + qErrnoWarning(hr, msg); \ + ret; \ + } + +#define RETURN_HR_IF_FAILED(msg) RETURN_IF_FAILED(msg, return hr) +#define RETURN_OK_IF_FAILED(msg) RETURN_IF_FAILED(msg, return S_OK) +#define RETURN_FALSE_IF_FAILED(msg) RETURN_IF_FAILED(msg, return false) +#define RETURN_VOID_IF_FAILED(msg) RETURN_IF_FAILED(msg, return) + +#define Q_ASSERT_SUCCEEDED(hr) \ + Q_ASSERT_X(SUCCEEDED(hr), Q_FUNC_INFO, qPrintable(qt_error_string(hr))); + + +namespace Microsoft { namespace WRL { template <typename T> class ComPtr; } } + +namespace QWinRTFunctions { + +// Synchronization methods +enum AwaitStyle +{ + YieldThread = 0, + ProcessThreadEvents = 1, + ProcessMainThreadEvents = 2 +}; + +template <typename T> +static inline HRESULT _await_impl(const Microsoft::WRL::ComPtr<T> &asyncOp, AwaitStyle awaitStyle) +{ + Microsoft::WRL::ComPtr<IAsyncInfo> asyncInfo; + HRESULT hr = asyncOp.As(&asyncInfo); + if (FAILED(hr)) + return hr; + + AsyncStatus status; + switch (awaitStyle) { + case ProcessMainThreadEvents: + while (SUCCEEDED(hr = asyncInfo->get_Status(&status)) && status == Started) + QCoreApplication::processEvents(); + break; + case ProcessThreadEvents: + if (QAbstractEventDispatcher *dispatcher = QThread::currentThread()->eventDispatcher()) { + while (SUCCEEDED(hr = asyncInfo->get_Status(&status)) && status == Started) + dispatcher->processEvents(QEventLoop::AllEvents); + break; + } + // fall through + default: + case YieldThread: + while (SUCCEEDED(hr = asyncInfo->get_Status(&status)) && status == Started) + QThread::yieldCurrentThread(); + break; + } + + if (FAILED(hr) || status != Completed) { + HRESULT ec; + hr = asyncInfo->get_ErrorCode(&ec); + if (FAILED(hr)) + return hr; + return ec; + } + + return hr; +} + +template <typename T> +static inline HRESULT await(const Microsoft::WRL::ComPtr<T> &asyncOp, AwaitStyle awaitStyle = YieldThread) +{ + HRESULT hr = _await_impl(asyncOp, awaitStyle); + if (FAILED(hr)) + return hr; + + return asyncOp->GetResults(); +} + +template <typename T, typename U> +static inline HRESULT await(const Microsoft::WRL::ComPtr<T> &asyncOp, U *results, AwaitStyle awaitStyle = YieldThread) +{ + HRESULT hr = _await_impl(asyncOp, awaitStyle); + if (FAILED(hr)) + return hr; + + return asyncOp->GetResults(results); +} + +} // QWinRTFunctions + +#endif // Q_OS_WIN + #endif // QFUNCTIONS_WINRT_H |