61bd2933ab56f968420d98dbea8be3e1d4e60537
[profile/ivi/qtbase.git] / src / corelib / plugin / qplugin.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QPLUGIN_H
43 #define QPLUGIN_H
44
45 #include <QtCore/qobject.h>
46 #include <QtCore/qpointer.h>
47
48 QT_BEGIN_HEADER
49
50 QT_BEGIN_NAMESPACE
51
52
53 #ifndef Q_EXTERN_C
54 #  ifdef __cplusplus
55 #    define Q_EXTERN_C extern "C"
56 #  else
57 #    define Q_EXTERN_C extern
58 #  endif
59 #endif
60
61 typedef QObject *(*QtPluginInstanceFunction)();
62 typedef const char *(*QtPluginMetaDataFunction)();
63
64 struct QStaticPlugin
65 {
66     QtPluginInstanceFunction instance;
67     QtPluginMetaDataFunction metaData;
68 };
69
70 void Q_CORE_EXPORT qRegisterStaticPluginFunction(QStaticPlugin staticPlugin);
71
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"))
84 #else
85 #  define QT_PLUGIN_VERIFICATION_SECTION
86 #  define QT_PLUGIN_METADATA_SECTION
87 #endif
88
89
90 #define Q_IMPORT_PLUGIN(PLUGIN) \
91         extern const QT_PREPEND_NAMESPACE(QStaticPlugin) qt_static_plugin_##PLUGIN(); \
92         class Static##PLUGIN##PluginInstance{ \
93         public: \
94                 Static##PLUGIN##PluginInstance() { \
95                     qRegisterStaticPluginFunction(qt_static_plugin_##PLUGIN()); \
96                 } \
97         }; \
98        static Static##PLUGIN##PluginInstance static##PLUGIN##Instance;
99
100 #define Q_PLUGIN_INSTANCE(IMPLEMENTATION) \
101         { \
102             static QT_PREPEND_NAMESPACE(QPointer)<QT_PREPEND_NAMESPACE(QObject)> _instance; \
103             if (!_instance)      \
104                 _instance = new IMPLEMENTATION; \
105             return _instance; \
106         }
107
108 #if defined(QT_STATICPLUGIN)
109
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 }; \
116         return plugin; \
117     }
118
119 #else
120
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)
127
128 #endif
129
130
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")
135
136 #  define Q_EXPORT_STATIC_PLUGIN2(PLUGIN, PLUGINCLASS) \
137     Q_STATIC_ASSERT_X(false, "Old plugin system used")
138
139
140 QT_END_NAMESPACE
141
142 QT_END_HEADER
143
144 #endif // Q_PLUGIN_H