Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qfactoryloader_p.h
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// Copyright (C) 2022 Intel Corporation.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
6#ifndef QFACTORYLOADER_P_H
7#define QFACTORYLOADER_P_H
8
9//
10// W A R N I N G
11// -------------
12//
13// This file is not part of the Qt API. It exists purely as an
14// implementation detail. This header file may change from version to
15// version without notice, or even be removed.
16//
17// We mean it.
18//
19
20#include "QtCore/qglobal.h"
21#ifndef QT_NO_QOBJECT
22
23#include "QtCore/private/qplugin_p.h"
24#include "QtCore/private/qduplicatetracker_p.h"
25#include "QtCore/qcoreapplication.h"
26#include "QtCore/qmap.h"
27#include "QtCore/qmutex.h"
28#include "QtCore/qobject.h"
29#include "QtCore/qplugin.h"
30
31#if QT_CONFIG(library)
32# include "QtCore/private/qlibrary_p.h"
33#endif
34
35QT_BEGIN_NAMESPACE
36
37class QJsonObject;
38class QLibraryPrivate;
39
40class Q_CORE_EXPORT QFactoryLoader
41{
42 Q_DECLARE_TR_FUNCTIONS(QFactoryLoader);
43
44public:
45 explicit QFactoryLoader(const char *iid,
46 const QString &suffix = QString(),
47 Qt::CaseSensitivity = Qt::CaseSensitive);
48
49#if QT_CONFIG(library)
50 ~QFactoryLoader();
51
52 void setLoadHints(QLibrary::LoadHints hints);
53 void update();
54 static void refreshAll();
55
56#if defined(Q_OS_UNIX) && !defined (Q_OS_DARWIN)
57 QLibraryPrivate *library(const QString &key) const;
58#endif // Q_OS_UNIX && !Q_OS_DARWIN
59#endif // QT_CONFIG(library)
60
61 void setExtraSearchPath(const QString &path);
62 QMultiMap<int, QString> keyMap() const;
63 int indexOf(const QString &needle) const;
64
65 using MetaDataList = QList<QPluginParsedMetaData>;
66
67 MetaDataList metaData() const;
69 QObject *instance(int index) const;
70
71private:
72 struct Private {
73 QByteArray iid;
74 mutable QMutex mutex;
75 mutable QList<QtPluginInstanceFunction> usedStaticInstances;
76#if QT_CONFIG(library)
77 QDuplicateTracker<QString> loadedPaths;
78 std::vector<QLibraryPrivate::UniquePtr> libraries;
79 mutable QList<bool> loadedLibraries;
80 std::map<QString, QLibraryPrivate*> keyMap;
81 QString suffix;
82 QString extraSearchPath;
83 Qt::CaseSensitivity cs;
84 QLibrary::LoadHints loadHints;
85 void updateSinglePath(const QString &pluginDir);
86#endif
87
88 // for compat when we d was a pointer
89 auto operator->() { return this; }
90 auto operator->() const { return this; }
91 } d;
92
93 inline QObject *instanceHelper_locked(int index) const;
94};
95
96template <class PluginInterface, class FactoryInterface, typename ...Args>
97PluginInterface *qLoadPlugin(const QFactoryLoader *loader, const QString &key, Args &&...args)
98{
99 const int index = loader->indexOf(key);
100 if (index != -1) {
101 QObject *factoryObject = loader->instance(index);
102 if (FactoryInterface *factory = qobject_cast<FactoryInterface *>(factoryObject))
103 if (PluginInterface *result = factory->create(key, std::forward<Args>(args)...))
104 return result;
105 }
106 return nullptr;
107}
108
109template <class PluginInterface, class FactoryInterface, typename Arg>
110Q_DECL_DEPRECATED PluginInterface *qLoadPlugin1(const QFactoryLoader *loader, const QString &key, Arg &&arg)
111{ return qLoadPlugin<PluginInterface, FactoryInterface>(loader, key, std::forward<Arg>(arg)); }
112
113QT_END_NAMESPACE
114
115#endif // QT_NO_QOBJECT
116
117#endif // QFACTORYLOADER_P_H
void setExtraSearchPath(const QString &path)
int indexOf(const QString &needle) const
QMultiMap< int, QString > keyMap() const
MetaDataList metaData() const
QList< QCborArray > metaDataKeys() const
QObject * instance(int index) const
Combined button and popup list for selecting options.
Q_TRACE_POINT(qtcore, QFactoryLoader_update, const QString &fileName)
static bool isIidMatch(QByteArrayView raw, QLatin1StringView iid)
static IterationResult iterateInPluginMetaData(QByteArrayView raw, F &&f)
PluginInterface * qLoadPlugin(const QFactoryLoader *loader, const QString &key, Args &&...args)