plugin/qfactoryloader.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6static QList<QFactoryLoader *> *qt_factory_loaders() { static QGlobalStatic<QList<QFactoryLoader *> > thisGlobalStatic = { { (0) }, false }; if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { QList<QFactoryLoader *> *x = new QList<QFactoryLoader *>; if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) delete x; else static QGlobalStaticDeleter<QList<QFactoryLoader *> > cleanup(thisGlobalStatic); } return thisGlobalStatic.pointer.load(); }
never executed: delete x;
executed: return thisGlobalStatic.pointer.load();
Execution Count:1089
partially evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:23
evaluated: !thisGlobalStatic.pointer.load()
TRUEFALSE
yes
Evaluation Count:23
yes
Evaluation Count:1066
partially evaluated: !thisGlobalStatic.destroyed
TRUEFALSE
yes
Evaluation Count:23
no
Evaluation Count:0
0-1089
7 -
8static QMutex *qt_factoryloader_mutex() { static QGlobalStatic<QMutex > thisGlobalStatic = { { (0) }, false }; if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { QMutex *x = new QMutex (QMutex::Recursive); if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) delete x; else static QGlobalStaticDeleter<QMutex > cleanup(thisGlobalStatic); } return thisGlobalStatic.pointer.load(); }
never executed: delete x;
executed: return thisGlobalStatic.pointer.load();
Execution Count:1089
partially evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:23
evaluated: !thisGlobalStatic.pointer.load()
TRUEFALSE
yes
Evaluation Count:23
yes
Evaluation Count:1066
partially evaluated: !thisGlobalStatic.destroyed
TRUEFALSE
yes
Evaluation Count:23
no
Evaluation Count:0
0-1089
9 -
10class QFactoryLoaderPrivate : public QObjectPrivate -
11{ -
12 inline QFactoryLoader* q_func() { return static_cast<QFactoryLoader *>(q_ptr); } inline const QFactoryLoader* q_func() const { return static_cast<const QFactoryLoader *>(q_ptr); } friend class QFactoryLoader; -
13public: -
14 QFactoryLoaderPrivate(){} -
15 ~QFactoryLoaderPrivate(); -
16 mutable QMutex mutex; -
17 QByteArray iid; -
18 QList<QLibraryPrivate*> libraryList; -
19 QMap<QString,QLibraryPrivate*> keyMap; -
20 QStringList keyList; -
21 QString suffix; -
22 Qt::CaseSensitivity cs; -
23 QStringList loadedPaths; -
24 -
25 void unloadPath(const QString &path); -
26}; -
27 -
28QFactoryLoaderPrivate::~QFactoryLoaderPrivate() -
29{ -
30 for (int i = 0; i < libraryList.count(); ++i) {
evaluated: i < libraryList.count()
TRUEFALSE
yes
Evaluation Count:1918
yes
Evaluation Count:979
979-1918
31 QLibraryPrivate *library = libraryList.at(i); -
32 library->unload(); -
33 library->release(); -
34 }
executed: }
Execution Count:1918
1918
35}
executed: }
Execution Count:979
979
36 -
37QFactoryLoader::QFactoryLoader(const char *iid, -
38 const QString &suffix, -
39 Qt::CaseSensitivity cs) -
40 : QObject(*new QFactoryLoaderPrivate) -
41{ -
42 moveToThread(QCoreApplicationPrivate::mainThread()); -
43 QFactoryLoaderPrivate * const d = d_func(); -
44 d->iid = iid; -
45 d->cs = cs; -
46 d->suffix = suffix; -
47 -
48 -
49 QMutexLocker locker(qt_factoryloader_mutex()); -
50 update(); -
51 qt_factory_loaders()->append(this); -
52}
executed: }
Execution Count:104
104
53 -
54 -
55 -
56void QFactoryLoader::update() -
57{ -
58 -
59 QFactoryLoaderPrivate * const d = d_func(); -
60 QStringList paths = QCoreApplication::libraryPaths(); -
61 for (int i = 0; i < paths.count(); ++i) {
evaluated: i < paths.count()
TRUEFALSE
yes
Evaluation Count:248
yes
Evaluation Count:128
128-248
62 const QString &pluginDir = paths.at(i); -
63 -
64 if (d->loadedPaths.contains(pluginDir))
evaluated: d->loadedPaths.contains(pluginDir)
TRUEFALSE
yes
Evaluation Count:30
yes
Evaluation Count:218
30-218
65 continue;
executed: continue;
Execution Count:30
30
66 d->loadedPaths << pluginDir; -
67 -
68 QString path = pluginDir + d->suffix; -
69 if (!QDir(path).exists(QLatin1String(".")))
evaluated: !QDir(path).exists(QLatin1String("."))
TRUEFALSE
yes
Evaluation Count:139
yes
Evaluation Count:79
79-139
70 continue;
executed: continue;
Execution Count:139
139
71 -
72 QStringList plugins = QDir(path).entryList(QDir::Files); -
73 QLibraryPrivate *library = 0; -
74 for (int j = 0; j < plugins.count(); ++j) {
evaluated: j < plugins.count()
TRUEFALSE
yes
Evaluation Count:498
yes
Evaluation Count:79
79-498
75 QString fileName = QDir::cleanPath(path + QLatin1Char('/') + plugins.at(j)); -
76 if (qt_debug_component()) {
partially evaluated: qt_debug_component()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:498
0-498
77 QMessageLogger("plugin/qfactoryloader.cpp", 154, __PRETTY_FUNCTION__).debug() << "QFactoryLoader::QFactoryLoader() looking at" << fileName; -
78 }
never executed: }
0
79 library = QLibraryPrivate::findOrCreate(QFileInfo(fileName).canonicalFilePath()); -
80 if (!library->isPlugin()) {
evaluated: !library->isPlugin()
TRUEFALSE
yes
Evaluation Count:249
yes
Evaluation Count:249
249
81 if (qt_debug_component()) {
partially evaluated: qt_debug_component()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:249
0-249
82 QMessageLogger("plugin/qfactoryloader.cpp", 159, __PRETTY_FUNCTION__).debug() << library->errorString; -
83 QMessageLogger("plugin/qfactoryloader.cpp", 160, __PRETTY_FUNCTION__).debug() << " not a plugin"; -
84 }
never executed: }
0
85 library->release(); -
86 continue;
executed: continue;
Execution Count:249
249
87 } -
88 -
89 QStringList keys; -
90 bool metaDataOk = false; -
91 -
92 QString iid = library->metaData.value(QLatin1String("IID")).toString(); -
93 if (iid == QLatin1String(d->iid.constData(), d->iid.size())) {
evaluated: iid == QLatin1String(d->iid.constData(), d->iid.size())
TRUEFALSE
yes
Evaluation Count:247
yes
Evaluation Count:2
2-247
94 QJsonObject object = library->metaData.value(QLatin1String("MetaData")).toObject(); -
95 metaDataOk = true; -
96 -
97 QJsonArray k = object.value(QLatin1String("Keys")).toArray(); -
98 for (int i = 0; i < k.size(); ++i) {
evaluated: i < k.size()
TRUEFALSE
yes
Evaluation Count:366
yes
Evaluation Count:247
247-366
99 QString s = k.at(i).toString(); -
100 keys += s; -
101 }
executed: }
Execution Count:366
366
102 }
executed: }
Execution Count:247
247
103 if (qt_debug_component())
partially evaluated: qt_debug_component()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:249
0-249
104 QMessageLogger("plugin/qfactoryloader.cpp", 181, __PRETTY_FUNCTION__).debug() << "Got keys from plugin meta data" << keys;
never executed: QMessageLogger("plugin/qfactoryloader.cpp", 181, __PRETTY_FUNCTION__).debug() << "Got keys from plugin meta data" << keys;
0
105 -
106 -
107 if (!metaDataOk) {
evaluated: !metaDataOk
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:247
2-247
108 library->release(); -
109 continue;
executed: continue;
Execution Count:2
2
110 } -
111 -
112 d->libraryList += library; -
113 for (int k = 0; k < keys.count(); ++k) {
evaluated: k < keys.count()
TRUEFALSE
yes
Evaluation Count:366
yes
Evaluation Count:247
247-366
114 -
115 -
116 -
117 -
118 QString key = keys.at(k); -
119 if (!d->cs)
evaluated: !d->cs
TRUEFALSE
yes
Evaluation Count:31
yes
Evaluation Count:335
31-335
120 key = key.toLower();
executed: key = key.toLower();
Execution Count:31
31
121 QLibraryPrivate *previous = d->keyMap.value(key); -
122 int prev_qt_version = 0; -
123 if (previous) {
partially evaluated: previous
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:366
0-366
124 prev_qt_version = (int)previous->metaData.value(QLatin1String("version")).toDouble(); -
125 }
never executed: }
0
126 int qt_version = (int)library->metaData.value(QLatin1String("version")).toDouble(); -
127 if (!previous || (prev_qt_version > 0x050002 && qt_version <= 0x050002)) {
partially evaluated: !previous
TRUEFALSE
yes
Evaluation Count:366
no
Evaluation Count:0
never evaluated: prev_qt_version > 0x050002
never evaluated: qt_version <= 0x050002
0-366
128 d->keyMap[key] = library; -
129 d->keyList += keys.at(k); -
130 }
executed: }
Execution Count:366
366
131 }
executed: }
Execution Count:366
366
132 }
executed: }
Execution Count:247
247
133 }
executed: }
Execution Count:79
79
134 -
135 -
136 -
137 -
138 -
139 -
140 -
141}
executed: }
Execution Count:128
128
142 -
143QFactoryLoader::~QFactoryLoader() -
144{ -
145 QMutexLocker locker(qt_factoryloader_mutex()); -
146 qt_factory_loaders()->removeAll(this); -
147}
executed: }
Execution Count:979
979
148 -
149QList<QJsonObject> QFactoryLoader::metaData() const -
150{ -
151 const QFactoryLoaderPrivate * const d = d_func(); -
152 QMutexLocker locker(&d->mutex); -
153 QList<QJsonObject> metaData; -
154 for (int i = 0; i < d->libraryList.size(); ++i)
evaluated: i < d->libraryList.size()
TRUEFALSE
yes
Evaluation Count:11129
yes
Evaluation Count:6231
6231-11129
155 metaData.append(d->libraryList.at(i)->metaData);
executed: metaData.append(d->libraryList.at(i)->metaData);
Execution Count:11129
11129
156 -
157 QVector<QStaticPlugin> staticPlugins = QLibraryPrivate::staticPlugins(); -
158 for (int i = 0; i < staticPlugins.count(); ++i) {
evaluated: i < staticPlugins.count()
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:6231
8-6231
159 const char *rawMetaData = staticPlugins.at(i).metaData(); -
160 QJsonObject object = QLibraryPrivate::fromRawMetaData(rawMetaData).object(); -
161 if (object.value(QLatin1String("IID")) != QLatin1String(d->iid.constData(), d->iid.size()))
evaluated: object.value(QLatin1String("IID")) != QLatin1String(d->iid.constData(), d->iid.size())
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:2
2-6
162 continue;
executed: continue;
Execution Count:6
6
163 -
164 metaData.append(object); -
165 }
executed: }
Execution Count:2
2
166 return metaData;
executed: return metaData;
Execution Count:6231
6231
167} -
168 -
169QObject *QFactoryLoader::instance(int index) const -
170{ -
171 const QFactoryLoaderPrivate * const d = d_func(); -
172 if (index < 0)
partially evaluated: index < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10534
0-10534
173 return 0;
never executed: return 0;
0
174 -
175 if (index < d->libraryList.size()) {
evaluated: index < d->libraryList.size()
TRUEFALSE
yes
Evaluation Count:8745
yes
Evaluation Count:1789
1789-8745
176 QLibraryPrivate *library = d->libraryList.at(index); -
177 if (library->instance || library->loadPlugin()) {
evaluated: library->instance
TRUEFALSE
yes
Evaluation Count:8587
yes
Evaluation Count:158
partially evaluated: library->loadPlugin()
TRUEFALSE
yes
Evaluation Count:158
no
Evaluation Count:0
0-8587
178 if (!library->inst)
evaluated: !library->inst
TRUEFALSE
yes
Evaluation Count:158
yes
Evaluation Count:8587
158-8587
179 library->inst = library->instance();
executed: library->inst = library->instance();
Execution Count:158
158
180 QObject *obj = library->inst.data(); -
181 if (obj) {
partially evaluated: obj
TRUEFALSE
yes
Evaluation Count:8745
no
Evaluation Count:0
0-8745
182 if (!obj->parent())
partially evaluated: !obj->parent()
TRUEFALSE
yes
Evaluation Count:8745
no
Evaluation Count:0
0-8745
183 obj->moveToThread(QCoreApplicationPrivate::mainThread());
executed: obj->moveToThread(QCoreApplicationPrivate::mainThread());
Execution Count:8745
8745
184 return obj;
executed: return obj;
Execution Count:8745
8745
185 } -
186 }
never executed: }
0
187 return 0;
never executed: return 0;
0
188 } -
189 -
190 index -= d->libraryList.size(); -
191 QVector<QStaticPlugin> staticPlugins = QLibraryPrivate::staticPlugins(); -
192 for (int i = 0; i < staticPlugins.count(); ++i) {
evaluated: i < staticPlugins.count()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1788
1-1788
193 const char *rawMetaData = staticPlugins.at(i).metaData(); -
194 QJsonObject object = QLibraryPrivate::fromRawMetaData(rawMetaData).object(); -
195 if (object.value(QLatin1String("IID")) != QLatin1String(d->iid.constData(), d->iid.size()))
partially evaluated: object.value(QLatin1String("IID")) != QLatin1String(d->iid.constData(), d->iid.size())
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
196 continue;
never executed: continue;
0
197 -
198 if (index == 0)
partially evaluated: index == 0
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
199 return staticPlugins.at(i).instance();
executed: return staticPlugins.at(i).instance();
Execution Count:1
1
200 --index; -
201 }
never executed: }
0
202 -
203 return 0;
executed: return 0;
Execution Count:1788
1788
204} -
205 -
206 -
207QLibraryPrivate *QFactoryLoader::library(const QString &key) const -
208{ -
209 const QFactoryLoaderPrivate * const d = d_func(); -
210 return d->keyMap.value(d->cs ? key : key.toLower());
never executed: return d->keyMap.value(d->cs ? key : key.toLower());
0
211} -
212 -
213 -
214void QFactoryLoader::refreshAll() -
215{ -
216 QMutexLocker locker(qt_factoryloader_mutex()); -
217 QList<QFactoryLoader *> *loaders = qt_factory_loaders(); -
218 for (QList<QFactoryLoader *>::const_iterator it = loaders->constBegin(); -
219 it != loaders->constEnd(); ++it) {
evaluated: it != loaders->constEnd()
TRUEFALSE
yes
Evaluation Count:24
yes
Evaluation Count:6
6-24
220 (*it)->update(); -
221 }
executed: }
Execution Count:24
24
222}
executed: }
Execution Count:6
6
223 -
224QMultiMap<int, QString> QFactoryLoader::keyMap() const -
225{ -
226 QMultiMap<int, QString> result; -
227 const QString metaDataKey = QString::fromUtf8("" "MetaData" "", sizeof("MetaData") - 1); -
228 const QString keysKey = QString::fromUtf8("" "Keys" "", sizeof("Keys") - 1); -
229 const QList<QJsonObject> metaDataList = metaData(); -
230 for (int i = 0; i < metaDataList.size(); ++i) {
evaluated: i < metaDataList.size()
TRUEFALSE
yes
Evaluation Count:9157
yes
Evaluation Count:3154
3154-9157
231 const QJsonObject metaData = metaDataList.at(i).value(metaDataKey).toObject(); -
232 const QJsonArray keys = metaData.value(keysKey).toArray(); -
233 const int keyCount = keys.size(); -
234 for (int k = 0; k < keyCount; ++k)
evaluated: k < keyCount
TRUEFALSE
yes
Evaluation Count:12177
yes
Evaluation Count:9157
9157-12177
235 result.insert(i, keys.at(k).toString());
executed: result.insert(i, keys.at(k).toString());
Execution Count:12177
12177
236 }
executed: }
Execution Count:9157
9157
237 return result;
executed: return result;
Execution Count:3154
3154
238} -
239 -
240int QFactoryLoader::indexOf(const QString &needle) const -
241{ -
242 const QString metaDataKey = QString::fromUtf8("" "MetaData" "", sizeof("MetaData") - 1); -
243 const QString keysKey = QString::fromUtf8("" "Keys" "", sizeof("Keys") - 1); -
244 const QList<QJsonObject> metaDataList = metaData(); -
245 for (int i = 0; i < metaDataList.size(); ++i) {
evaluated: i < metaDataList.size()
TRUEFALSE
yes
Evaluation Count:1685
yes
Evaluation Count:2468
1685-2468
246 const QJsonObject metaData = metaDataList.at(i).value(metaDataKey).toObject(); -
247 const QJsonArray keys = metaData.value(keysKey).toArray(); -
248 const int keyCount = keys.size(); -
249 for (int k = 0; k < keyCount; ++k) {
evaluated: k < keyCount
TRUEFALSE
yes
Evaluation Count:9331
yes
Evaluation Count:1076
1076-9331
250 if (!keys.at(k).toString().compare(needle, Qt::CaseInsensitive))
evaluated: !keys.at(k).toString().compare(needle, Qt::CaseInsensitive)
TRUEFALSE
yes
Evaluation Count:609
yes
Evaluation Count:8722
609-8722
251 return i;
executed: return i;
Execution Count:609
609
252 }
executed: }
Execution Count:8722
8722
253 }
executed: }
Execution Count:1076
1076
254 return -1;
executed: return -1;
Execution Count:2468
2468
255} -
256 -
257 -
258 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial