Skip to content

Commit 74d1503

Browse files
committed
feat: 支持加载插件指针
(cherry picked from commit ce457ab)
1 parent cc5f34f commit 74d1503

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

QCloudMusicApi/apihelper.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,18 @@ bool ApiHelper::loadPlugin(const QString& fileName)
158158
return false;
159159
}
160160

161+
bool ApiHelper::loadPlugin(QCloudMusicApiPlugin *plugin)
162+
{
163+
ApiPluginImpl* pluginImpl = new ApiPluginImpl();
164+
if (plugin) {
165+
pluginImpl->loader = new QPluginLoader(this);
166+
pluginImpl->plugin = plugin;
167+
m_pluginImpls.push_back(pluginImpl);
168+
return true;
169+
}
170+
return false;
171+
}
172+
161173
bool ApiHelper::unloadPlugin(const QString& fileName)
162174
{
163175
auto result = false;
@@ -175,3 +187,21 @@ bool ApiHelper::unloadPlugin(const QString& fileName)
175187
}
176188
return result;
177189
}
190+
191+
bool ApiHelper::unloadPlugin(QCloudMusicApiPlugin *plugin)
192+
{
193+
auto result = false;
194+
for (auto i = 0; i < m_pluginImpls.size(); i++) {
195+
auto pluginImpl = m_pluginImpls[i];
196+
if (pluginImpl->plugin == plugin) {
197+
m_pluginImpls.removeAt(i);
198+
pluginImpl->loader->deleteLater();
199+
result = pluginImpl->loader->unload();
200+
if (!result) {
201+
DEBUG << pluginImpl->loader->errorString();
202+
}
203+
break;
204+
}
205+
}
206+
return result;
207+
}

QCloudMusicApi/apihelper.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <QObject>
77

88
class ApiPluginImpl;
9+
class QCloudMusicApiPlugin;
910

1011
/**
1112
* @class ApiHelper
@@ -64,13 +65,27 @@ class QCLOUDMUSICAPI_EXPORT ApiHelper : public NeteaseCloudMusicApi
6465
*/
6566
Q_INVOKABLE bool loadPlugin(const QString& fileName);
6667

68+
/**
69+
* @brief 加载插件
70+
* @param plugin 插件指针
71+
* @return 加载结果
72+
*/
73+
Q_INVOKABLE bool loadPlugin(QCloudMusicApiPlugin* plugin);
74+
6775
/**
6876
* @brief 卸载插件
6977
* @param fileName 插件路径
7078
* @return 卸载结果
7179
*/
7280
Q_INVOKABLE bool unloadPlugin(const QString& fileName);
7381

82+
/**
83+
* @brief 卸载插件
84+
* @param plugin 插件指针
85+
* @return 卸载结果
86+
*/
87+
Q_INVOKABLE bool unloadPlugin(QCloudMusicApiPlugin* plugin);
88+
7489
public:
7590
DEFINE_VALUE(QString, proxy, "")
7691
DEFINE_VALUE(QString, realIP, "")

0 commit comments

Comments
 (0)