Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qlibrary_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// Copyright (C) 2021 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
5#ifndef QLIBRARY_P_H
6#define QLIBRARY_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of the QLibrary class. This header file may change from
14// version to version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include "QtCore/qlibrary.h"
20
21#include "QtCore/private/qfactoryloader_p.h"
22#include "QtCore/qloggingcategory.h"
23#include "QtCore/qmutex.h"
24#include "QtCore/qplugin.h"
25#include "QtCore/qpointer.h"
26#include "QtCore/qstringlist.h"
27#ifdef Q_OS_WIN
28# include "QtCore/qt_windows.h"
29#endif
30
31#include <memory>
32
34
36
37Q_DECLARE_LOGGING_CATEGORY(qt_lcDebugPlugins)
38
40{
43#if defined(Q_OF_MACH_O)
44 bool isEncrypted = false;
45#endif
46};
47
48class QLibraryStore;
50{
51public:
52#ifdef Q_OS_WIN
53 using Handle = HINSTANCE;
54#else
55 using Handle = void *;
56#endif
58
59 struct Deleter {
60 // QLibraryPrivate::release() is not, yet, and cannot easily be made, noexcept:
61 void operator()(QLibraryPrivate *p) const { p->release(); }
62 };
63 using UniquePtr = std::unique_ptr<QLibraryPrivate, Deleter>;
64
67
68 bool load();
69 QtPluginInstanceFunction loadPlugin(); // loads and resolves instance
70 bool unload(UnloadFlag flag = UnloadSys);
71 void release();
72 QFunctionPointer resolve(const char *);
73
74 QLibrary::LoadHints loadHints() const
75 { return QLibrary::LoadHints(loadHintsInt.loadRelaxed()); }
76 void setLoadHints(QLibrary::LoadHints lh);
78
79 static QLibraryPrivate *findOrCreate(const QString &fileName, const QString &version = QString(),
80 QLibrary::LoadHints loadHints = { });
83
84 QAtomicPointer<std::remove_pointer<QtPluginInstanceFunction>::type> instanceFactory;
85 QAtomicPointer<std::remove_pointer<Handle>::type> pHnd;
86
87 // the mutex protects the fields below
89 QPointer<QObject> inst; // used by QFactoryLoader
93
94 void updatePluginState();
95 bool isPlugin();
96
97private:
98 explicit QLibraryPrivate(const QString &canonicalFileName, const QString &version, QLibrary::LoadHints loadHints);
100 void mergeLoadHints(QLibrary::LoadHints loadHints);
101
102 bool load_sys();
103 bool unload_sys();
104 QFunctionPointer resolve_sys(const char *);
105
106 QAtomicInt loadHintsInt;
107
109 QAtomicInt libraryRefCount;
111 QAtomicInt libraryUnloadCount;
112
113 enum { IsAPlugin, IsNotAPlugin, MightBeAPlugin } pluginState;
114 friend class QLibraryStore;
115};
116
118
119#endif // QLIBRARY_P_H
\inmodule QtCore
Definition qatomic.h:112
T loadRelaxed() const noexcept
QString errorString
Definition qlibrary_p.h:91
bool unload(UnloadFlag flag=UnloadSys)
Definition qlibrary.cpp:554
QString qualifiedFileName
Definition qlibrary_p.h:92
QtPluginInstanceFunction loadPlugin()
Definition qlibrary.cpp:581
QAtomicPointer< std::remove_pointer< Handle >::type > pHnd
Definition qlibrary_p.h:85
static QStringList suffixes_sys(const QString &fullVersion)
void setLoadHints(QLibrary::LoadHints lh)
Definition qlibrary.cpp:485
const QString fileName
Definition qlibrary_p.h:65
const QString fullVersion
Definition qlibrary_p.h:66
void updatePluginState()
Definition qlibrary.cpp:720
QAtomicPointer< std::remove_pointer< QtPluginInstanceFunction >::type > instanceFactory
Definition qlibrary_p.h:84
static QStringList prefixes_sys()
QPluginParsedMetaData metaData
Definition qlibrary_p.h:90
QFunctionPointer resolve(const char *)
Definition qlibrary.cpp:478
QPointer< QObject > inst
Definition qlibrary_p.h:89
std::unique_ptr< QLibraryPrivate, Deleter > UniquePtr
Definition qlibrary_p.h:63
QObject * pluginInstance()
Definition qlibrary.cpp:499
static QLibraryPrivate * findOrCreate(const QString &fileName, const QString &version=QString(), QLibrary::LoadHints loadHints={ })
Definition qlibrary.cpp:459
QLibrary::LoadHints loadHints() const
Definition qlibrary_p.h:74
\inmodule QtCore
Definition qmutex.h:281
\inmodule QtCore
Definition qobject.h:103
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Combined button and popup list for selecting options.
#define Q_DECLARE_LOGGING_CATEGORY(name)
static bool isEncrypted(const my_mach_header *header)
GLfloat GLfloat p
[1]
QObject *(* QtPluginInstanceFunction)()
Definition qplugin.h:36
#define QT_REQUIRE_CONFIG(feature)
ptrdiff_t qsizetype
Definition qtypes.h:165
void operator()(QLibraryPrivate *p) const
Definition qlibrary_p.h:61