| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/plugin/qpluginloader.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||
| 2 | - | |||||||
| 3 | - | |||||||
| 4 | QPluginLoader::QPluginLoader(QObject *parent) | - | ||||||
| 5 | : QObject(parent), d(0), did_load(false) | - | ||||||
| 6 | { | - | ||||||
| 7 | } | - | ||||||
| 8 | QPluginLoader::QPluginLoader(const QString &fileName, QObject *parent) | - | ||||||
| 9 | : QObject(parent), d(0), did_load(false) | - | ||||||
| 10 | { | - | ||||||
| 11 | setFileName(fileName); | - | ||||||
| 12 | setLoadHints(QLibrary::PreventUnloadHint); | - | ||||||
| 13 | } | - | ||||||
| 14 | QPluginLoader::~QPluginLoader() | - | ||||||
| 15 | { | - | ||||||
| 16 | if (d) | - | ||||||
| 17 | d->release(); | - | ||||||
| 18 | } | - | ||||||
| 19 | QObject *QPluginLoader::instance() | - | ||||||
| 20 | { | - | ||||||
| 21 | if (!isLoaded() && !load()) | - | ||||||
| 22 | return 0; | - | ||||||
| 23 | if (!d->inst && d->instance) | - | ||||||
| 24 | d->inst = d->instance(); | - | ||||||
| 25 | return d->inst.data(); | - | ||||||
| 26 | } | - | ||||||
| 27 | QJsonObject QPluginLoader::metaData() const | - | ||||||
| 28 | { | - | ||||||
| 29 | if (!d) | - | ||||||
| 30 | return QJsonObject(); | - | ||||||
| 31 | return d->metaData; | - | ||||||
| 32 | } | - | ||||||
| 33 | bool QPluginLoader::load() | - | ||||||
| 34 | { | - | ||||||
| 35 | if (!d || d->fileName.isEmpty()) | - | ||||||
| 36 | return false; | - | ||||||
| 37 | if (did_load) | - | ||||||
| 38 | return d->pHnd && d->instance; | - | ||||||
| 39 | if (!d->isPlugin()) | - | ||||||
| 40 | return false; | - | ||||||
| 41 | did_load = true; | - | ||||||
| 42 | return d->loadPlugin(); | - | ||||||
| 43 | } | - | ||||||
| 44 | bool QPluginLoader::unload() | - | ||||||
| 45 | { | - | ||||||
| 46 | if (did_load) { | - | ||||||
| 47 | did_load = false; | - | ||||||
| 48 | return d->unload(); | - | ||||||
| 49 | } | - | ||||||
| 50 | if (d) | - | ||||||
| 51 | d->errorString = tr("The plugin was not loaded."); | - | ||||||
| 52 | return false; | - | ||||||
| 53 | } | - | ||||||
| 54 | - | |||||||
| 55 | - | |||||||
| 56 | - | |||||||
| 57 | - | |||||||
| 58 | - | |||||||
| 59 | - | |||||||
| 60 | bool QPluginLoader::isLoaded() const | - | ||||||
| 61 | { | - | ||||||
| 62 | return d && d->pHnd && d->instance; | - | ||||||
| 63 | } | - | ||||||
| 64 | - | |||||||
| 65 | - | |||||||
| 66 | static QString locatePlugin(const QString& fileName) | - | ||||||
| 67 | { | - | ||||||
| 68 | const bool isAbsolute = QDir::isAbsolutePath(fileName); | - | ||||||
| 69 | if (isAbsolute
| 3-24 | ||||||
| 70 | QFileInfo fi(fileName); | - | ||||||
| 71 | if (fi.isFile()
| 1-23 | ||||||
| 72 | return executed 23 times by 2 tests: fi.canonicalFilePath();return fi.canonicalFilePath();Executed by:
executed 23 times by 2 tests: return fi.canonicalFilePath();Executed by:
| 23 | ||||||
| 73 | } | - | ||||||
| 74 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||
| 75 | QStringList prefixes = QLibraryPrivate::prefixes_sys(); | - | ||||||
| 76 | prefixes.prepend(QString()); | - | ||||||
| 77 | QStringList suffixes = QLibraryPrivate::suffixes_sys(QString()); | - | ||||||
| 78 | suffixes.prepend(QString()); | - | ||||||
| 79 | - | |||||||
| 80 | - | |||||||
| 81 | const int slash = fileName.lastIndexOf(QLatin1Char('/')); | - | ||||||
| 82 | const QStringRef baseName = fileName.midRef(slash + 1); | - | ||||||
| 83 | const QStringRef basePath = isAbsolute
| 1-3 | ||||||
| 84 | - | |||||||
| 85 | const bool debug = qt_debug_component(); | - | ||||||
| 86 | - | |||||||
| 87 | QStringList paths; | - | ||||||
| 88 | if (isAbsolute
| 1-3 | ||||||
| 89 | paths.append(fileName.left(slash)); | - | ||||||
| 90 | } executed 1 time by 1 test: else {end of blockExecuted by:
| 1 | ||||||
| 91 | paths = QCoreApplication::libraryPaths(); | - | ||||||
| 92 | paths.prepend(([]() -> QString { enum { Size = sizeof(u"" ".")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "." }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())); | - | ||||||
| 93 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||
| 94 | - | |||||||
| 95 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(paths)>::type> _container_((paths)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const QString &path = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||
| for (QForeachContainer<typename QtPrivate::remove_reference<decltype: qAsConst(prefixes)>::type> _container_((prefixes)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)paths)) { | ||||||||
| 96 | for (const QString &prefix = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||
| for (QForeachContainer<typename QtPrivate::remove_reference<decltype: qAsConst(suffixes)>::type> _container_((suffixes)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)prefixes)) { | ||||||||
| 97 | for (const QString &suffix = *_container_.i; _container_.control; _container_.control = 0): qAsConst(suffixes)) { | - | ||||||
| 98 | const QString fn = path + QLatin1Char('/') + basePath + prefix + baseName + suffix; | - | ||||||
| 99 | if (debug
| 0-36 | ||||||
| 100 | QMessageLogger(__FILE__, 309315, __PRETTY_FUNCTION__).debug() << "Trying..." << fn; never executed: QMessageLogger(__FILE__, 315, __PRETTY_FUNCTION__).debug() << "Trying..." << fn; | 0 | ||||||
| 101 | if (QFileInfo(fn).isFile()
| 2-34 | ||||||
| 102 | return executed 2 times by 1 test: fn;return fn;Executed by:
executed 2 times by 1 test: return fn;Executed by:
| 2 | ||||||
| 103 | } executed 34 times by 1 test: end of blockExecuted by:
| 34 | ||||||
| 104 | } executed 16 times by 1 test: end of blockExecuted by:
| 16 | ||||||
| 105 | } executed 7 times by 1 test: end of blockExecuted by:
| 7 | ||||||
| 106 | if (debug
| 0-2 | ||||||
| 107 | QMessageLogger(__FILE__, 316322, __PRETTY_FUNCTION__).debug() << fileName << "not found"; never executed: QMessageLogger(__FILE__, 322, __PRETTY_FUNCTION__).debug() << fileName << "not found"; | 0 | ||||||
| 108 | return executed 2 times by 1 test: QString();return QString();Executed by:
executed 2 times by 1 test: return QString();Executed by:
| 2 | ||||||
| 109 | } | - | ||||||
| 110 | void QPluginLoader::setFileName(const QString &fileName) | - | ||||||
| 111 | { | - | ||||||
| 112 | - | |||||||
| 113 | QLibrary::LoadHints lh = QLibrary::PreventUnloadHint; | - | ||||||
| 114 | if (d) { | - | ||||||
| 115 | lh = d->loadHints(); | - | ||||||
| 116 | d->release(); | - | ||||||
| 117 | d = 0; | - | ||||||
| 118 | did_load = false; | - | ||||||
| 119 | } | - | ||||||
| 120 | - | |||||||
| 121 | const QString fn = locatePlugin(fileName); | - | ||||||
| 122 | - | |||||||
| 123 | d = QLibraryPrivate::findOrCreate(fn, QString(), lh); | - | ||||||
| 124 | if (!fn.isEmpty()) | - | ||||||
| 125 | d->updatePluginState(); | - | ||||||
| 126 | } | - | ||||||
| 127 | - | |||||||
| 128 | QString QPluginLoader::fileName() const | - | ||||||
| 129 | { | - | ||||||
| 130 | if (d) | - | ||||||
| 131 | return d->fileName; | - | ||||||
| 132 | return QString(); | - | ||||||
| 133 | } | - | ||||||
| 134 | - | |||||||
| 135 | - | |||||||
| 136 | - | |||||||
| 137 | - | |||||||
| 138 | - | |||||||
| 139 | - | |||||||
| 140 | QString QPluginLoader::errorString() const | - | ||||||
| 141 | { | - | ||||||
| 142 | return (!d || d->errorString.isEmpty()) ? tr("Unknown error") : d->errorString; | - | ||||||
| 143 | } | - | ||||||
| 144 | void QPluginLoader::setLoadHints(QLibrary::LoadHints loadHints) | - | ||||||
| 145 | { | - | ||||||
| 146 | if (!d) { | - | ||||||
| 147 | d = QLibraryPrivate::findOrCreate(QString()); | - | ||||||
| 148 | d->errorString.clear(); | - | ||||||
| 149 | } | - | ||||||
| 150 | d->setLoadHints(loadHints); | - | ||||||
| 151 | } | - | ||||||
| 152 | - | |||||||
| 153 | QLibrary::LoadHints QPluginLoader::loadHints() const | - | ||||||
| 154 | { | - | ||||||
| 155 | return d ? d->loadHints() : QLibrary::LoadHints(); | - | ||||||
| 156 | } | - | ||||||
| 157 | - | |||||||
| 158 | - | |||||||
| 159 | - | |||||||
| 160 | typedef QVector<QStaticPlugin> StaticPluginList; | - | ||||||
| 161 | namespace { namespace Q_QGS_staticPluginList { typedef StaticPluginList Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized) guard.store(QtGlobalStatic::Destroyed); } }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<StaticPluginList, Q_QGS_staticPluginList::innerFunction, Q_QGS_staticPluginList::guard> staticPluginList; | - | ||||||
| void QPluginLoader::setLoadHints(QLibrary::LoadHints loadHints) | ||||||||
| { | ||||||||
| if (!d) { | ||||||||
| d = QLibraryPrivate::findOrCreate(QString()); | ||||||||
| d->errorString.clear(); | ||||||||
| } | ||||||||
| d->setLoadHints(loadHints); | ||||||||
| } | ||||||||
| QLibrary::LoadHints QPluginLoader::loadHints() const | ||||||||
| { | ||||||||
| return d ? d->loadHints() : QLibrary::LoadHints(); | ||||||||
| }void __attribute__((visibility("default"))) qRegisterStaticPluginFunction(QStaticPlugin plugin) | ||||||||
| 163 | { | - | ||||||
| 164 | staticPluginList()->append(plugin); | - | ||||||
| 165 | } | - | ||||||
| 166 | - | |||||||
| 167 | - | |||||||
| 168 | - | |||||||
| 169 | - | |||||||
| 170 | - | |||||||
| 171 | - | |||||||
| 172 | QObjectList QPluginLoader::staticInstances() | - | ||||||
| 173 | { | - | ||||||
| 174 | QObjectList instances; | - | ||||||
| 175 | const StaticPluginList *plugins = staticPluginList(); | - | ||||||
| 176 | if (plugins) { | - | ||||||
| 177 | const int numPlugins = plugins->size(); | - | ||||||
| 178 | instances.reserve(numPlugins); | - | ||||||
| 179 | for (int i = 0; i < numPlugins; ++i) | - | ||||||
| 180 | instances += plugins->at(i).instance(); | - | ||||||
| 181 | } | - | ||||||
| 182 | return instances; | - | ||||||
| 183 | } | - | ||||||
| 184 | QVector<QStaticPlugin> QPluginLoader::staticPlugins() | - | ||||||
| 185 | { | - | ||||||
| 186 | StaticPluginList *plugins = staticPluginList(); | - | ||||||
| 187 | if (plugins) | - | ||||||
| 188 | return *plugins; | - | ||||||
| 189 | return QVector<QStaticPlugin>(); | - | ||||||
| 190 | } | - | ||||||
| 191 | - | |||||||
| 192 | - | |||||||
| 193 | - | |||||||
| 194 | - | |||||||
| 195 | - | |||||||
| 196 | - | |||||||
| 197 | QJsonObject QStaticPlugin::metaData() const | - | ||||||
| 198 | { | - | ||||||
| 199 | return executed 26 times by 1 test: QLibraryPrivate::fromRawMetaDataqJsonFromRawLibraryMetaData(rawMetaData()).object();return qJsonFromRawLibraryMetaData(rawMetaData()).object();Executed by:
executed 26 times by 1 test: return qJsonFromRawLibraryMetaData(rawMetaData()).object();Executed by:
| 26 | ||||||
| 200 | } | - | ||||||
| 201 | - | |||||||
| 202 | - | |||||||
| Switch to Source code | Preprocessed file |