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