1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtCore module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
45 #include <QtCore/qobject.h>
46 #include <QtCore/qpointer.h>
55 # define Q_EXTERN_C extern "C"
57 # define Q_EXTERN_C extern
61 typedef QObject *(*QtPluginInstanceFunction)();
62 typedef const char *(*QtPluginMetaDataFunction)();
66 QtPluginInstanceFunction instance;
67 QtPluginMetaDataFunction metaData;
70 void Q_CORE_EXPORT qRegisterStaticPluginFunction(QStaticPlugin staticPlugin);
72 #if defined (Q_OF_ELF) && (defined (Q_CC_GNU) || defined(Q_CC_CLANG))
73 # define QT_PLUGIN_METADATA_SECTION \
74 __attribute__ ((section (".qtmetadata"))) __attribute__((used))
75 #elif defined(Q_OS_MAC)
76 // TODO: Implement section parsing on Mac
77 # define QT_PLUGIN_METADATA_SECTION \
78 __attribute__ ((section ("__TEXT,qtmetadata"))) __attribute__((used))
79 #elif defined(Q_CC_MSVC)
80 // TODO: Implement section parsing for MSVC
81 #pragma section(".qtmetadata",read,shared)
82 # define QT_PLUGIN_METADATA_SECTION \
83 __declspec(allocate(".qtmetadata"))
85 # define QT_PLUGIN_VERIFICATION_SECTION
86 # define QT_PLUGIN_METADATA_SECTION
90 #define Q_IMPORT_PLUGIN(PLUGIN) \
91 extern const QT_PREPEND_NAMESPACE(QStaticPlugin) qt_static_plugin_##PLUGIN(); \
92 class Static##PLUGIN##PluginInstance{ \
94 Static##PLUGIN##PluginInstance() { \
95 qRegisterStaticPluginFunction(qt_static_plugin_##PLUGIN()); \
98 static Static##PLUGIN##PluginInstance static##PLUGIN##Instance;
100 #define Q_PLUGIN_INSTANCE(IMPLEMENTATION) \
102 static QT_PREPEND_NAMESPACE(QPointer)<QT_PREPEND_NAMESPACE(QObject)> _instance; \
104 _instance = new IMPLEMENTATION; \
108 #if defined(QT_STATICPLUGIN)
110 # define QT_MOC_EXPORT_PLUGIN(PLUGINCLASS) \
111 static QT_PREPEND_NAMESPACE(QObject) *qt_plugin_instance() \
112 Q_PLUGIN_INSTANCE(PLUGINCLASS) \
113 static const char *qt_plugin_query_metadata() { return (const char *)qt_pluginMetaData; } \
114 const QT_PREPEND_NAMESPACE(QStaticPlugin) qt_static_plugin_##PLUGINCLASS() { \
115 QT_PREPEND_NAMESPACE(QStaticPlugin) plugin = { qt_plugin_instance, qt_plugin_query_metadata }; \
121 # define QT_MOC_EXPORT_PLUGIN(PLUGINCLASS) \
122 Q_EXTERN_C Q_DECL_EXPORT \
123 const char *qt_plugin_query_metadata() \
124 { return (const char *)qt_pluginMetaData; } \
125 Q_EXTERN_C Q_DECL_EXPORT QT_PREPEND_NAMESPACE(QObject) *qt_plugin_instance() \
126 Q_PLUGIN_INSTANCE(PLUGINCLASS)
131 #define Q_EXPORT_PLUGIN(PLUGIN) \
132 Q_EXPORT_PLUGIN2(PLUGIN, PLUGIN)
133 # define Q_EXPORT_PLUGIN2(PLUGIN, PLUGINCLASS) \
134 Q_STATIC_ASSERT_X(false, "Old plugin system used")
136 # define Q_EXPORT_STATIC_PLUGIN2(PLUGIN, PLUGINCLASS) \
137 Q_STATIC_ASSERT_X(false, "Old plugin system used")