添加dlopen失败时错误提示
parent
3706bad621
commit
97798acba5
|
|
@ -20,8 +20,7 @@
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Plugins
|
namespace Plugins {
|
||||||
{
|
|
||||||
PluginManager* PluginManager::_instance = nullptr;
|
PluginManager* PluginManager::_instance = nullptr;
|
||||||
|
|
||||||
PluginManager* PluginManager::getInstance()
|
PluginManager* PluginManager::getInstance()
|
||||||
|
|
@ -39,8 +38,7 @@ namespace Plugins
|
||||||
void PluginManager::releasePlugs()
|
void PluginManager::releasePlugs()
|
||||||
{
|
{
|
||||||
int nplug = _pluginList.size();
|
int nplug = _pluginList.size();
|
||||||
for (int i = 0; i < nplug; ++i)
|
for(int i = 0; i < nplug; ++i) {
|
||||||
{
|
|
||||||
Plugins::PluginBase* p = _pluginList.at(i);
|
Plugins::PluginBase* p = _pluginList.at(i);
|
||||||
bool ok = p->uninstall();
|
bool ok = p->uninstall();
|
||||||
if(!ok)
|
if(!ok)
|
||||||
|
|
@ -58,15 +56,13 @@ namespace Plugins
|
||||||
QStringList plugins = Setting::BusAPI::instance()->getPlugins();
|
QStringList plugins = Setting::BusAPI::instance()->getPlugins();
|
||||||
const QString plugdir = QApplication::applicationDirPath() + "/plugins/";
|
const QString plugdir = QApplication::applicationDirPath() + "/plugins/";
|
||||||
QDir dir(plugdir);
|
QDir dir(plugdir);
|
||||||
if (!dir.exists())
|
if(!dir.exists()) {
|
||||||
{
|
|
||||||
plugins.clear();
|
plugins.clear();
|
||||||
Setting::BusAPI::instance()->setPlugins(plugins);
|
Setting::BusAPI::instance()->setPlugins(plugins);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < plugins.size(); ++i)
|
for(int i = 0; i < plugins.size(); ++i) {
|
||||||
{
|
|
||||||
QString pluginname = plugins.at(i);
|
QString pluginname = plugins.at(i);
|
||||||
bool ok = loadPlugin(pluginname);
|
bool ok = loadPlugin(pluginname);
|
||||||
if(!ok)
|
if(!ok)
|
||||||
|
|
@ -96,11 +92,9 @@ namespace Plugins
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
HMODULE hmodel = LoadLibrary(LPCWSTR(plugpath.utf16()));
|
HMODULE hmodel = LoadLibrary(LPCWSTR(plugpath.utf16()));
|
||||||
if (hmodel)
|
if(hmodel) {
|
||||||
{
|
|
||||||
fun = (Reg)GetProcAddress(hmodel, "Register");
|
fun = (Reg)GetProcAddress(hmodel, "Register");
|
||||||
if (fun)
|
if(fun) {
|
||||||
{
|
|
||||||
fun(_mainWindow, &_pluginList);
|
fun(_mainWindow, &_pluginList);
|
||||||
Plugins::PluginBase* pls = _pluginList.last();
|
Plugins::PluginBase* pls = _pluginList.last();
|
||||||
qDebug() << "Plugin: " << pls->getDescribe();
|
qDebug() << "Plugin: " << pls->getDescribe();
|
||||||
|
|
@ -108,9 +102,7 @@ namespace Plugins
|
||||||
pls->setFileName(pluginname);
|
pls->setFileName(pluginname);
|
||||||
pls->setWinModule(hmodel);
|
pls->setWinModule(hmodel);
|
||||||
pls->reTranslate(lang);
|
pls->reTranslate(lang);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
FreeLibrary(hmodel);
|
FreeLibrary(hmodel);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -123,11 +115,12 @@ namespace Plugins
|
||||||
if(!pluginname.toLower().endsWith(".so"))
|
if(!pluginname.toLower().endsWith(".so"))
|
||||||
return false;
|
return false;
|
||||||
void* pHandle = dlopen(plugpath.toLatin1().data(), RTLD_NOW);
|
void* pHandle = dlopen(plugpath.toLatin1().data(), RTLD_NOW);
|
||||||
if (!pHandle)
|
if(!pHandle) {
|
||||||
|
qDebug() << "dlopen error: " << dlerror();
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
fun = (Reg)dlsym(pHandle, "Register");
|
fun = (Reg)dlsym(pHandle, "Register");
|
||||||
if (fun)
|
if(fun) {
|
||||||
{
|
|
||||||
fun(_mainWindow, &_pluginList);
|
fun(_mainWindow, &_pluginList);
|
||||||
Plugins::PluginBase* pls = _pluginList.last();
|
Plugins::PluginBase* pls = _pluginList.last();
|
||||||
qDebug() << "Plugin: " << pls->getDescribe();
|
qDebug() << "Plugin: " << pls->getDescribe();
|
||||||
|
|
@ -135,9 +128,7 @@ namespace Plugins
|
||||||
pls->setFileName(pluginname);
|
pls->setFileName(pluginname);
|
||||||
pls->setLinuxModule(pHandle);
|
pls->setLinuxModule(pHandle);
|
||||||
pls->reTranslate(lang);
|
pls->reTranslate(lang);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// plugins.removeOne(pluginname);
|
// plugins.removeOne(pluginname);
|
||||||
dlclose(pHandle);
|
dlclose(pHandle);
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -150,8 +141,7 @@ namespace Plugins
|
||||||
void PluginManager::reTranslate(QString lang)
|
void PluginManager::reTranslate(QString lang)
|
||||||
{
|
{
|
||||||
const int n = _pluginList.size();
|
const int n = _pluginList.size();
|
||||||
for (int i = 0; i < n; ++i)
|
for(int i = 0; i < n; ++i) {
|
||||||
{
|
|
||||||
auto p = _pluginList.at(i);
|
auto p = _pluginList.at(i);
|
||||||
p->reTranslate(lang);
|
p->reTranslate(lang);
|
||||||
}
|
}
|
||||||
|
|
@ -159,8 +149,7 @@ namespace Plugins
|
||||||
|
|
||||||
PluginBase* PluginManager::getPluginByDescribe(QString des)
|
PluginBase* PluginManager::getPluginByDescribe(QString des)
|
||||||
{
|
{
|
||||||
for (auto p : _pluginList)
|
for(auto p : _pluginList) {
|
||||||
{
|
|
||||||
if(des.toLower() == p->getDescribe().toLower())
|
if(des.toLower() == p->getDescribe().toLower())
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
@ -175,10 +164,8 @@ namespace Plugins
|
||||||
|
|
||||||
bool PluginManager::releasePlugin(QString name)
|
bool PluginManager::releasePlugin(QString name)
|
||||||
{
|
{
|
||||||
for (auto p : _pluginList)
|
for(auto p : _pluginList) {
|
||||||
{
|
if(name == p->getFileName()) {
|
||||||
if (name == p->getFileName())
|
|
||||||
{
|
|
||||||
bool ok = p->uninstall();
|
bool ok = p->uninstall();
|
||||||
if(!ok)
|
if(!ok)
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -195,8 +182,7 @@ namespace Plugins
|
||||||
{
|
{
|
||||||
QList<PluginBase*> ps;
|
QList<PluginBase*> ps;
|
||||||
|
|
||||||
for (PluginBase *p : _pluginList)
|
for(PluginBase* p : _pluginList) {
|
||||||
{
|
|
||||||
if(p->getType() == t)
|
if(p->getType() == t)
|
||||||
ps.append(p);
|
ps.append(p);
|
||||||
}
|
}
|
||||||
|
|
@ -230,8 +216,7 @@ namespace Plugins
|
||||||
|
|
||||||
bool PluginManager::isFileLoaded(const QString fileName)
|
bool PluginManager::isFileLoaded(const QString fileName)
|
||||||
{
|
{
|
||||||
for (auto p : _pluginList)
|
for(auto p : _pluginList) {
|
||||||
{
|
|
||||||
QString name = p->getFileName();
|
QString name = p->getFileName();
|
||||||
if(name.toLower() == fileName.toLower())
|
if(name.toLower() == fileName.toLower())
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -239,4 +224,4 @@ namespace Plugins
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace Plugins
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue