1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Copyright (C) 2018 Intel Corporation. |
5 | ** Contact: https://www.qt.io/licensing/ |
6 | ** |
7 | ** This file is part of the QtCore module of the Qt Toolkit. |
8 | ** |
9 | ** $QT_BEGIN_LICENSE:LGPL$ |
10 | ** Commercial License Usage |
11 | ** Licensees holding valid commercial Qt licenses may use this file in |
12 | ** accordance with the commercial license agreement provided with the |
13 | ** Software or, alternatively, in accordance with the terms contained in |
14 | ** a written agreement between you and The Qt Company. For licensing terms |
15 | ** and conditions see https://www.qt.io/terms-conditions. For further |
16 | ** information use the contact form at https://www.qt.io/contact-us. |
17 | ** |
18 | ** GNU Lesser General Public License Usage |
19 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
20 | ** General Public License version 3 as published by the Free Software |
21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
22 | ** packaging of this file. Please review the following information to |
23 | ** ensure the GNU Lesser General Public License version 3 requirements |
24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
25 | ** |
26 | ** GNU General Public License Usage |
27 | ** Alternatively, this file may be used under the terms of the GNU |
28 | ** General Public License version 2.0 or (at your option) the GNU General |
29 | ** Public license version 3 or any later version approved by the KDE Free |
30 | ** Qt Foundation. The licenses are as published by the Free Software |
31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
32 | ** included in the packaging of this file. Please review the following |
33 | ** information to ensure the GNU General Public License requirements will |
34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
35 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
36 | ** |
37 | ** $QT_END_LICENSE$ |
38 | ** |
39 | ****************************************************************************/ |
40 | |
41 | #ifndef QPLUGIN_H |
42 | #define QPLUGIN_H |
43 | |
44 | #include <QtCore/qobject.h> |
45 | #include <QtCore/qpointer.h> |
46 | #include <QtCore/qjsonobject.h> |
47 | |
48 | QT_BEGIN_NAMESPACE |
49 | |
50 | |
51 | #ifndef Q_EXTERN_C |
52 | # ifdef __cplusplus |
53 | # define Q_EXTERN_C extern "C" |
54 | # else |
55 | # define Q_EXTERN_C extern |
56 | # endif |
57 | #endif |
58 | |
59 | inline constexpr unsigned char qPluginArchRequirements() |
60 | { |
61 | return 0 |
62 | #ifndef QT_NO_DEBUG |
63 | | 1 |
64 | #endif |
65 | #ifdef __AVX2__ |
66 | | 2 |
67 | # ifdef __AVX512F__ |
68 | | 4 |
69 | # endif |
70 | #endif |
71 | ; |
72 | } |
73 | |
74 | typedef QObject *(*QtPluginInstanceFunction)(); |
75 | struct QPluginMetaData |
76 | { |
77 | const uchar *data; |
78 | size_t size; |
79 | }; |
80 | typedef QPluginMetaData (*QtPluginMetaDataFunction)(); |
81 | |
82 | |
83 | struct Q_CORE_EXPORT QStaticPlugin |
84 | { |
85 | public: |
86 | constexpr QStaticPlugin(QtPluginInstanceFunction i, QtPluginMetaDataFunction m) |
87 | : instance(i), rawMetaDataSize(m().size), rawMetaData(m().data) |
88 | {} |
89 | QtPluginInstanceFunction instance; |
90 | QJsonObject metaData() const; |
91 | |
92 | private: |
93 | qsizetype rawMetaDataSize; |
94 | const void *rawMetaData; |
95 | }; |
96 | Q_DECLARE_TYPEINFO(QStaticPlugin, Q_PRIMITIVE_TYPE); |
97 | |
98 | void Q_CORE_EXPORT qRegisterStaticPluginFunction(QStaticPlugin staticPlugin); |
99 | |
100 | #if (defined(Q_OF_ELF) || defined(Q_OS_WIN)) && (defined (Q_CC_GNU) || defined(Q_CC_CLANG)) |
101 | # define QT_PLUGIN_METADATA_SECTION \ |
102 | __attribute__ ((section (".qtmetadata"))) __attribute__((used)) |
103 | #elif defined(Q_OS_MAC) |
104 | // TODO: Implement section parsing on Mac |
105 | # define QT_PLUGIN_METADATA_SECTION \ |
106 | __attribute__ ((section ("__TEXT,qtmetadata"))) __attribute__((used)) |
107 | #elif defined(Q_CC_MSVC) |
108 | // TODO: Implement section parsing for MSVC |
109 | #pragma section(".qtmetadata",read,shared) |
110 | # define QT_PLUGIN_METADATA_SECTION \ |
111 | __declspec(allocate(".qtmetadata")) |
112 | #else |
113 | # define QT_PLUGIN_METADATA_SECTION |
114 | #endif |
115 | |
116 | |
117 | #define Q_IMPORT_PLUGIN(PLUGIN) \ |
118 | extern const QT_PREPEND_NAMESPACE(QStaticPlugin) qt_static_plugin_##PLUGIN(); \ |
119 | class Static##PLUGIN##PluginInstance{ \ |
120 | public: \ |
121 | Static##PLUGIN##PluginInstance() { \ |
122 | qRegisterStaticPluginFunction(qt_static_plugin_##PLUGIN()); \ |
123 | } \ |
124 | }; \ |
125 | static Static##PLUGIN##PluginInstance static##PLUGIN##Instance; |
126 | |
127 | #if defined(QT_PLUGIN_RESOURCE_INIT_FUNCTION) |
128 | # define QT_PLUGIN_RESOURCE_INIT \ |
129 | extern void QT_PLUGIN_RESOURCE_INIT_FUNCTION(); \ |
130 | QT_PLUGIN_RESOURCE_INIT_FUNCTION(); |
131 | #else |
132 | # define QT_PLUGIN_RESOURCE_INIT |
133 | #endif |
134 | |
135 | #define Q_PLUGIN_INSTANCE(IMPLEMENTATION) \ |
136 | { \ |
137 | static QT_PREPEND_NAMESPACE(QPointer)<QT_PREPEND_NAMESPACE(QObject)> _instance; \ |
138 | if (!_instance) { \ |
139 | QT_PLUGIN_RESOURCE_INIT \ |
140 | _instance = new IMPLEMENTATION; \ |
141 | } \ |
142 | return _instance; \ |
143 | } |
144 | |
145 | #if defined(QT_STATICPLUGIN) |
146 | |
147 | # define QT_MOC_EXPORT_PLUGIN(PLUGINCLASS, PLUGINCLASSNAME) \ |
148 | static QT_PREPEND_NAMESPACE(QObject) *qt_plugin_instance_##PLUGINCLASSNAME() \ |
149 | Q_PLUGIN_INSTANCE(PLUGINCLASS) \ |
150 | static QPluginMetaData qt_plugin_query_metadata_##PLUGINCLASSNAME() \ |
151 | { return { qt_pluginMetaData_##PLUGINCLASSNAME, sizeof qt_pluginMetaData_##PLUGINCLASSNAME }; } \ |
152 | const QT_PREPEND_NAMESPACE(QStaticPlugin) qt_static_plugin_##PLUGINCLASSNAME() { \ |
153 | return { qt_plugin_instance_##PLUGINCLASSNAME, qt_plugin_query_metadata_##PLUGINCLASSNAME}; \ |
154 | } |
155 | |
156 | #else |
157 | |
158 | # define QT_MOC_EXPORT_PLUGIN(PLUGINCLASS, PLUGINCLASSNAME) \ |
159 | Q_EXTERN_C Q_DECL_EXPORT \ |
160 | QPluginMetaData qt_plugin_query_metadata() \ |
161 | { return { qt_pluginMetaData_##PLUGINCLASSNAME, sizeof qt_pluginMetaData_##PLUGINCLASSNAME }; } \ |
162 | Q_EXTERN_C Q_DECL_EXPORT QT_PREPEND_NAMESPACE(QObject) *qt_plugin_instance() \ |
163 | Q_PLUGIN_INSTANCE(PLUGINCLASS) |
164 | |
165 | #endif |
166 | |
167 | #define Q_EXPORT_PLUGIN(PLUGIN) \ |
168 | Q_EXPORT_PLUGIN2(PLUGIN, PLUGIN) |
169 | # define Q_EXPORT_PLUGIN2(PLUGIN, PLUGINCLASS) \ |
170 | static_assert(false, "Old plugin system used") |
171 | |
172 | # define Q_EXPORT_STATIC_PLUGIN2(PLUGIN, PLUGINCLASS) \ |
173 | static_assert(false, "Old plugin system used") |
174 | |
175 | |
176 | QT_END_NAMESPACE |
177 | |
178 | #endif // Q_PLUGIN_H |
179 | |