Skip to content
This repository was archived by the owner on Mar 4, 2023. It is now read-only.

Commit 062c9e0

Browse files
committed
add support for wasm
1 parent bcf65ce commit 062c9e0

File tree

4 files changed

+73
-40
lines changed

4 files changed

+73
-40
lines changed

Sample/App/App.pro

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ QT += quick
22

33
CONFIG += c++14
44

5-
include(../../qpluginfactory.pri)
6-
75
HEADERS += \
86
pluginhelper.h \
97
iplugin.h
@@ -14,3 +12,6 @@ SOURCES += main.cpp \
1412
RESOURCES += qml.qrc
1513

1614
ANDROID_EXTRA_PLUGINS = $$OUT_PWD/../plugins
15+
16+
include(../../qpluginfactory.pri)
17+
!load(qdep):error("qdep required")

qpluginfactory.cpp

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,31 @@ class StaticPluginInfo : public QPluginFactoryBase::PluginInfo
1515

1616
QJsonObject metaData() const override;
1717
QObject *instance() override;
18+
bool isLoaded() const override;
19+
void unload(const QString &key) override;
1820

1921
private:
2022
QStaticPlugin _plugin;
2123
};
2224

25+
#if QT_CONFIG(library)
26+
2327
class DynamicPluginInfo : public QPluginFactoryBase::PluginInfo
2428
{
2529
public:
2630
DynamicPluginInfo(QScopedPointer<QPluginLoader, QScopedPointerDeleteLater> &loader);
2731

2832
QJsonObject metaData() const override;
2933
QObject *instance() override;
30-
31-
QPluginLoader *loader() const;
34+
bool isLoaded() const override;
35+
void unload(const QString &key) override;
3236

3337
private:
3438
QScopedPointer<QPluginLoader, QScopedPointerDeleteLater> _loader;
3539
};
3640

41+
#endif
42+
3743
}
3844

3945

@@ -111,6 +117,8 @@ void QPluginFactoryBase::reloadPlugins()
111117
//find the plugin dir
112118
auto oldKeys = _plugins.keys();
113119

120+
#if QT_CONFIG(library)
121+
114122
QList<QDir> allDirs;
115123
//first: dirs in path
116124
//MAJOR remove
@@ -159,6 +167,8 @@ void QPluginFactoryBase::reloadPlugins()
159167
}
160168
}
161169

170+
#endif
171+
162172
//setup static plugins
163173
for(const auto &info : QPluginLoader::staticPlugins()) {
164174
auto keys = checkMeta(info.metaData(), QString());
@@ -179,30 +189,18 @@ bool QPluginFactoryBase::isLoaded(const QString &key) const
179189
{
180190
QMutexLocker _{&_loaderMutex};
181191
auto info = _plugins.value(key);
182-
if(info) {
183-
auto dynInfo = info.dynamicCast<DynamicPluginInfo>();
184-
if(dynInfo)
185-
return dynInfo->loader()->isLoaded();
186-
else //static plugin
187-
return true;
188-
} else
192+
if(info)
193+
return info->isLoaded();
194+
else
189195
return false;
190196
}
191197

192198
void QPluginFactoryBase::unload(const QString &key)
193199
{
194200
QMutexLocker _{&_loaderMutex};
195201
auto info = _plugins.value(key);
196-
if(info) {
197-
auto dynInfo = info.dynamicCast<DynamicPluginInfo>();
198-
if(dynInfo) {
199-
auto loader = dynInfo->loader();
200-
if(loader->isLoaded()){
201-
if(!loader->unload())
202-
qWarning().noquote() << "Failed to unload plugin for key" << key << "with error:" << loader->errorString();
203-
}
204-
}
205-
}
202+
if(info)
203+
info->unload(key);
206204
}
207205

208206
QJsonArray QPluginFactoryBase::checkMeta(const QJsonObject &metaData, const QString &filename) const
@@ -228,10 +226,12 @@ QJsonArray QPluginFactoryBase::checkMeta(const QJsonObject &metaData, const QStr
228226

229227

230228

229+
#if QT_CONFIG(library)
230+
231231
QPluginLoadException::QPluginLoadException(QPluginLoader *loader) :
232-
QPluginLoadException{QStringLiteral("Failed to load plugin \"%1\" with error: %2")
233-
.arg(loader->fileName(), loader->errorString())
234-
.toUtf8()}
232+
_what{QStringLiteral("Failed to load plugin \"%1\" with error: %2")
233+
.arg(loader->fileName(), loader->errorString())
234+
.toUtf8()}
235235
{}
236236

237237
const char *QPluginLoadException::what() const noexcept
@@ -244,14 +244,12 @@ void QPluginLoadException::raise() const
244244
throw *this;
245245
}
246246

247-
QException *QPluginLoadException::clone() const
247+
QExceptionBase::Base *QPluginLoadException::clone() const
248248
{
249-
return new QPluginLoadException(_what);
249+
return new QPluginLoadException{*this};
250250
}
251251

252-
QPluginLoadException::QPluginLoadException(QByteArray error) :
253-
_what{std::move(error)}
254-
{}
252+
#endif
255253

256254

257255

@@ -269,6 +267,20 @@ QObject *StaticPluginInfo::instance()
269267
return _plugin.instance();
270268
}
271269

270+
bool StaticPluginInfo::isLoaded() const
271+
{
272+
return true;
273+
}
274+
275+
void StaticPluginInfo::unload(const QString &key)
276+
{
277+
Q_UNUSED(key)
278+
}
279+
280+
281+
282+
#if QT_CONFIG(library)
283+
272284
DynamicPluginInfo::DynamicPluginInfo(QScopedPointer<QPluginLoader, QScopedPointerDeleteLater> &loader)
273285
{
274286
_loader.swap(loader);
@@ -286,7 +298,17 @@ QObject *DynamicPluginInfo::instance()
286298
return _loader->instance();
287299
}
288300

289-
QPluginLoader *DynamicPluginInfo::loader() const
301+
bool DynamicPluginInfo::isLoaded() const
290302
{
291-
return _loader.data();
303+
return _loader->isLoaded();
292304
}
305+
306+
void DynamicPluginInfo::unload(const QString &key)
307+
{
308+
if(_loader->isLoaded()){
309+
if(!_loader->unload())
310+
qWarning().noquote() << "Failed to unload plugin for key" << key << "with error:" << _loader->errorString();
311+
}
312+
}
313+
314+
#endif

qpluginfactory.h

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,33 @@
44
#include <QtCore/QDir>
55
#include <QtCore/QObject>
66
#include <QtCore/QPluginLoader>
7-
#include <QtCore/QException>
87
#include <QtCore/QMutex>
98

10-
#ifdef QT_NO_DEBUG
11-
#define Q_PLUGIN_FACTORY_IS_DEBUG false
12-
#else
13-
#define Q_PLUGIN_FACTORY_IS_DEBUG true
14-
#endif
9+
#include <qexceptionbase.h>
1510

16-
class Q_PLUGIN_FACTORY_EXPORT QPluginLoadException : public QException
11+
#if QT_CONFIG(library)
12+
class Q_PLUGIN_FACTORY_EXPORT QPluginLoadException : public QExceptionBase
1713
{
1814
public:
1915
QPluginLoadException(QPluginLoader *loader);
2016

2117
const char *what() const noexcept override;
2218
void raise() const override;
23-
QException *clone() const override;
19+
Base *clone() const override;
2420

2521
private:
26-
QPluginLoadException(QByteArray error);
2722
const QByteArray _what;
2823
};
24+
#else
25+
//dummy class
26+
class Q_PLUGIN_FACTORY_EXPORT QPluginLoadException : public QExceptionBase {};
27+
#endif
28+
29+
#ifdef QT_NO_DEBUG
30+
#define Q_PLUGIN_FACTORY_IS_DEBUG false
31+
#else
32+
#define Q_PLUGIN_FACTORY_IS_DEBUG true
33+
#endif
2934

3035
class Q_PLUGIN_FACTORY_EXPORT QPluginFactoryBase : public QObject
3136
{
@@ -42,6 +47,9 @@ class Q_PLUGIN_FACTORY_EXPORT QPluginFactoryBase : public QObject
4247
virtual inline ~PluginInfo() = default;
4348
virtual QJsonObject metaData() const = 0;
4449
virtual QObject *instance() = 0;
50+
51+
virtual bool isLoaded() const = 0;
52+
virtual void unload(const QString &key) = 0;
4553
};
4654

4755
QPluginFactoryBase(QString pluginType, QObject *parent = nullptr, bool isDebugBuild = Q_PLUGIN_FACTORY_IS_DEBUG);

qpluginfactory.pri

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ HEADERS += \
66
SOURCES += \
77
$$PWD/qpluginfactory.cpp
88

9+
QDEP_DEPENDS += Skycoder42/QExceptionBase
10+
911
QDEP_PACKAGE_EXPORTS += Q_PLUGIN_FACTORY_EXPORT
1012
!qdep_build: DEFINES += "Q_PLUGIN_FACTORY_EXPORT="

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy