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
23namespace QtPrivate {
24Q_DECLARE_EXPORTED_LOGGING_CATEGORY(lcNativeInterface, Q_CORE_EXPORT)
25}
26
27// Provides a definition for the interface destructor
28#define QT_DEFINE_NATIVE_INTERFACE_2(Namespace, InterfaceClass) \
29 QT_PREPEND_NAMESPACE(Namespace)::InterfaceClass::~InterfaceClass() = default
30
31#define QT_DEFINE_NATIVE_INTERFACE(...) \
32 QT_OVERLOADED_MACRO(QT_DEFINE_NATIVE_INTERFACE, QNativeInterface, __VA_ARGS__)
33#define QT_DEFINE_PRIVATE_NATIVE_INTERFACE(...) \
34 QT_OVERLOADED_MACRO(QT_DEFINE_NATIVE_INTERFACE, QNativeInterface::Private, __VA_ARGS__)
35
36#define QT_NATIVE_INTERFACE_RETURN_IF(NativeInterface, baseType) \
37 { \
38 using QtPrivate::lcNativeInterface; \
39 using QNativeInterface::Private::TypeInfo; \
40 qCDebug(lcNativeInterface, "Comparing requested interface name %s with available %s", \
41 name, TypeInfo<NativeInterface>::name()); \
42 if (qstrcmp(name, TypeInfo<NativeInterface>::name()) == 0) { \
43 qCDebug(lcNativeInterface, \
44 "Match for interface %s. Comparing revisions (requested %d / available %d)", \
45 name, revision, TypeInfo<NativeInterface>::revision()); \
46 if (revision == TypeInfo<NativeInterface>::revision()) { \
47 qCDebug(lcNativeInterface) << "Full match. Returning dynamic cast of" << baseType; \
48 return dynamic_cast<NativeInterface *>(baseType); \
49 } else { \
50 qCWarning(lcNativeInterface, \
51 "Native interface revision mismatch (requested %d / available %d) for " \
52 "interface %s", \
53 revision, TypeInfo<NativeInterface>::revision(), name); \
54 return nullptr; \
55 } \
56 } else { \
57 qCDebug(lcNativeInterface, "No match for requested interface name %s", name); \
58 } \
59 }
60
61QT_END_NAMESPACE
62
63#endif // QNATIVEINTERFACE_P_H
64

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