1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QNATIVEINTERFACE_P_H
5#define QNATIVEINTERFACE_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/private/qglobal_p.h>
19#include <QtCore/qloggingcategory.h>
20
21QT_BEGIN_NAMESPACE
22
23QT_DECLARE_EXPORTED_QT_LOGGING_CATEGORY(lcNativeInterface, Q_CORE_EXPORT)
24
25// Provides a definition for the interface destructor
26#define QT_DEFINE_NATIVE_INTERFACE_2(Namespace, InterfaceClass) \
27 QT_PREPEND_NAMESPACE(Namespace)::InterfaceClass::~InterfaceClass() = default
28
29#define QT_DEFINE_NATIVE_INTERFACE(...) \
30 QT_OVERLOADED_MACRO(QT_DEFINE_NATIVE_INTERFACE, QNativeInterface, __VA_ARGS__)
31#define QT_DEFINE_PRIVATE_NATIVE_INTERFACE(...) \
32 QT_OVERLOADED_MACRO(QT_DEFINE_NATIVE_INTERFACE, QNativeInterface::Private, __VA_ARGS__)
33
34#define QT_NATIVE_INTERFACE_RETURN_IF(NativeInterface, baseType) \
35 { \
36 using QNativeInterface::Private::TypeInfo; \
37 qCDebug(lcNativeInterface, "Comparing requested interface name %s with available %s", \
38 name, TypeInfo<NativeInterface>::name()); \
39 if (qstrcmp(name, TypeInfo<NativeInterface>::name()) == 0) { \
40 qCDebug(lcNativeInterface, \
41 "Match for interface %s. Comparing revisions (requested %d / available %d)", \
42 name, revision, TypeInfo<NativeInterface>::revision()); \
43 if (revision == TypeInfo<NativeInterface>::revision()) { \
44 qCDebug(lcNativeInterface) << "Full match. Returning dynamic cast of" << baseType; \
45 return dynamic_cast<NativeInterface *>(baseType); \
46 } else { \
47 qCWarning(lcNativeInterface, \
48 "Native interface revision mismatch (requested %d / available %d) for " \
49 "interface %s", \
50 revision, TypeInfo<NativeInterface>::revision(), name); \
51 return nullptr; \
52 } \
53 } else { \
54 qCDebug(lcNativeInterface, "No match for requested interface name %s", name); \
55 } \
56 }
57
58QT_END_NAMESPACE
59
60#endif // QNATIVEINTERFACE_P_H
61

source code of qtbase/src/corelib/global/qnativeinterface_p.h