StelModuleMgr.cpp   StelModuleMgr.cpp 
skipping to change at line 33 skipping to change at line 33
#include <QPluginLoader> #include <QPluginLoader>
#include <QSettings> #include <QSettings>
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelModule.hpp" #include "StelModule.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelPluginInterface.hpp" #include "StelPluginInterface.hpp"
#include "StelIniParser.hpp" #include "StelIniParser.hpp"
StelModuleMgr::StelModuleMgr() StelModuleMgr::StelModuleMgr() : callingListsToRegenerate(true), pluginDesc riptorListLoaded(false)
{ {
// Initialize empty call lists for each possible actions // Initialize empty call lists for each possible actions
callOrders[StelModule::ActionDraw]=QList<StelModule*>(); callOrders[StelModule::ActionDraw]=QList<StelModule*>();
callOrders[StelModule::ActionUpdate]=QList<StelModule*>(); callOrders[StelModule::ActionUpdate]=QList<StelModule*>();
callOrders[StelModule::ActionHandleMouseClicks]=QList<StelModule*>() ; callOrders[StelModule::ActionHandleMouseClicks]=QList<StelModule*>() ;
callOrders[StelModule::ActionHandleMouseMoves]=QList<StelModule*>(); callOrders[StelModule::ActionHandleMouseMoves]=QList<StelModule*>();
callOrders[StelModule::ActionHandleKeys]=QList<StelModule*>(); callOrders[StelModule::ActionHandleKeys]=QList<StelModule*>();
callingListsToRegenerate = false;
} }
StelModuleMgr::~StelModuleMgr() StelModuleMgr::~StelModuleMgr()
{ {
} }
// Regenerate calling lists if necessary // Regenerate calling lists if necessary
void StelModuleMgr::update() void StelModuleMgr::update()
{ {
if (callingListsToRegenerate) if (callingListsToRegenerate)
skipping to change at line 89 skipping to change at line 88
StelModule* m = getModule(moduleID); StelModule* m = getModule(moduleID);
if (!m) if (!m)
{ {
qWarning() << "Module \"" << moduleID << "\" is not loaded." ; qWarning() << "Module \"" << moduleID << "\" is not loaded." ;
return; return;
} }
modules.remove(moduleID); modules.remove(moduleID);
m->setParent(NULL); m->setParent(NULL);
callingListsToRegenerate = true; callingListsToRegenerate = true;
if (alsoDelete) if (alsoDelete)
{
m->deinit();
m->deleteLater(); m->deleteLater();
}
} }
/************************************************************************* /*************************************************************************
Get the corresponding module or NULL if can't find it. Get the corresponding module or NULL if can't find it.
*************************************************************************/ *************************************************************************/
StelModule* StelModuleMgr::getModule(const QString& moduleID) StelModule* StelModuleMgr::getModule(const QString& moduleID, bool noWarnin g)
{ {
QMap<QString, StelModule*>::const_iterator iter = modules.find(modul eID); QMap<QString, StelModule*>::const_iterator iter = modules.find(modul eID);
if (iter==modules.end()) if (iter==modules.end())
{ {
qWarning() << "Warning can't find module called " << moduleI if (noWarning==false)
D << "."; qWarning() << "Warning can't find module called " <<
moduleID << ".";
return NULL; return NULL;
} }
return iter.value(); return iter.value();
} }
/************************************************************************* /*************************************************************************
Load an external plugin Load an external plugin
*************************************************************************/ *************************************************************************/
StelModule* StelModuleMgr::loadPlugin(const QString& moduleID) StelModule* StelModuleMgr::loadPlugin(const QString& moduleID)
{ {
QString moduleFullPath = "modules/" + moduleID + "/lib" + moduleID; foreach (const PluginDescriptor& desc, getPluginsList())
#ifdef WIN32
moduleFullPath += ".dll";
#else
#ifdef MACOSX
moduleFullPath += ".dylib";
#else
moduleFullPath += ".so";
#endif
#endif
try
{
moduleFullPath = StelApp::getInstance().getFileMgr().findFil
e(moduleFullPath, StelFileMgr::File);
}
catch (std::runtime_error& e)
{
qWarning() << "ERROR while locating plugin path: " << e.what
();
}
QPluginLoader loader(moduleFullPath);
if (!loader.load())
{
qWarning() << "Couldn't load the dynamic library: " << modul
eFullPath << ": " << loader.errorString();
qWarning() << "Plugin " << moduleID << " will not be loaded.
";
return NULL;
}
QObject* obj = loader.instance();
if (!obj)
{ {
qWarning() << "Couldn't open the dynamic library: " << modul if (desc.info.id==moduleID)
eFullPath << ": " << loader.errorString(); {
qWarning() << "Plugin " << moduleID << " will not be open."; Q_ASSERT(desc.pluginInterface);
return NULL; StelModule* sMod = desc.pluginInterface->getStelModu
le();
qDebug() << "Loaded plugin " << moduleID << ".";
pluginDescriptorList[moduleID].loaded=true;
return sMod;
}
} }
qWarning() << "Can't find plugin called " << moduleID;
StelPluginInterface* plugInt = qobject_cast<StelPluginInterface *>(o return NULL;
bj);
StelModule* sMod = plugInt->getStelModule();
qDebug() << "Loaded plugin " << moduleID << ".";
return sMod;
} }
struct StelModuleOrderComparator struct StelModuleOrderComparator
{ {
StelModuleOrderComparator(StelModule::StelModuleActionName aaction) : action(aaction) {;} StelModuleOrderComparator(StelModule::StelModuleActionName aaction) : action(aaction) {;}
bool operator()(StelModule* x, StelModule* y) {return x->getCallOrde r(action)<y->getCallOrder(action);} bool operator()(StelModule* x, StelModule* y) {return x->getCallOrde r(action)<y->getCallOrder(action);}
private: private:
StelModule::StelModuleActionName action; StelModule::StelModuleActionName action;
}; };
// Unload all plugins // Unload all plugins
void StelModuleMgr::unloadAllPlugins() void StelModuleMgr::unloadAllPlugins()
{ {
QListIterator<PluginDescriptor> i(getPluginsList()); QListIterator<PluginDescriptor> i(getPluginsList());
i.toBack(); i.toBack();
while (i.hasPrevious()) while (i.hasPrevious())
{ {
const PluginDescriptor& d = i.previous(); const PluginDescriptor& d = i.previous();
if (d.loadAtStartup==false) if (d.loaded==false)
continue; continue;
unloadModule(d.key, true); unloadModule(d.info.id, true);
qDebug() << "Unloaded plugin " << d.key << "."; qDebug() << "Unloaded plugin " << d.info.id << ".";
}
}
void StelModuleMgr::setPluginLoadAtStartup(const QString& key, bool b)
{
QSettings* conf = StelApp::getInstance().getSettings();
conf->setValue("plugins_load_at_startup/"+key, b);
if (pluginDescriptorList.contains(key))
{
pluginDescriptorList[key].loadAtStartup=b;
} }
} }
/************************************************************************* /*************************************************************************
Generate properly sorted calling lists for each action (e,g, draw, update) Generate properly sorted calling lists for each action (e,g, draw, update)
according to modules orders dependencies according to modules orders dependencies
*************************************************************************/ *************************************************************************/
void StelModuleMgr::generateCallingLists() void StelModuleMgr::generateCallingLists()
{ {
QMap<StelModule::StelModuleActionName, QList<StelModule*> >::iterato r mc; QMap<StelModule::StelModuleActionName, QList<StelModule*> >::iterato r mc;
skipping to change at line 201 skipping to change at line 188
} }
qSort(mc.value().begin(), mc.value().end(), StelModuleOrderC omparator(mc.key())); qSort(mc.value().begin(), mc.value().end(), StelModuleOrderC omparator(mc.key()));
} }
} }
/************************************************************************* /*************************************************************************
Return the list of all the external module found in the modules/ directori es Return the list of all the external module found in the modules/ directori es
*************************************************************************/ *************************************************************************/
QList<StelModuleMgr::PluginDescriptor> StelModuleMgr::getPluginsList() QList<StelModuleMgr::PluginDescriptor> StelModuleMgr::getPluginsList()
{ {
QList<StelModuleMgr::PluginDescriptor> result; if (pluginDescriptorListLoaded)
QSet<QString> moduleDirs; {
return pluginDescriptorList.values();
}
StelFileMgr& fileMan(StelApp::getInstance().getFileMgr()); // First list all static plugins.
// If a dynamic plugin with the same ID exists, it will take precede
nce on the static one.
foreach (QObject *plugin, QPluginLoader::staticInstances())
{
StelPluginInterface* pluginInterface = qobject_cast<StelPlug
inInterface*>(plugin);
if (pluginInterface)
{
StelModuleMgr::PluginDescriptor mDesc;
mDesc.info = pluginInterface->getPluginInfo();
mDesc.pluginInterface = pluginInterface;
pluginDescriptorList.insert(mDesc.info.id, mDesc);
}
}
// Then list dynamic libraries from the modules/ directory
QSet<QString> moduleDirs;
try try
{ {
moduleDirs = fileMan.listContents("modules",StelFileMgr::Dir ectory); moduleDirs = StelFileMgr::listContents("modules",StelFileMgr ::Directory);
} }
catch(std::runtime_error& e) catch(std::runtime_error& e)
{ {
qWarning() << "ERROR while trying list list modules:" << e.w hat(); qWarning() << "ERROR while trying list list modules:" << e.w hat();
} }
for (QSet<QString>::iterator dir=moduleDirs.begin(); dir!=moduleDirs .end(); dir++) foreach (QString dir, moduleDirs)
{ {
QString moduleFullPath = QString("modules/") + dir + "/lib"
+ dir;
#ifdef Q_OS_WIN
moduleFullPath += ".dll";
#else
#ifdef Q_OS_MAC
moduleFullPath += ".dylib";
#else
moduleFullPath += ".so";
#endif
#endif
try try
{ {
StelModuleMgr::PluginDescriptor mDesc; moduleFullPath = StelFileMgr::findFile(moduleFullPat
QSettings pd(fileMan.findFile("modules/" + *dir + "/ h, StelFileMgr::File);
module.ini"), StelIniFormat);
mDesc.key = *dir;
mDesc.name = pd.value("module/name").toString();
mDesc.author = pd.value("module/author").toString();
mDesc.contact = pd.value("module/contact").toString(
);
mDesc.description = pd.value("module/description").t
oString();
mDesc.loadAtStartup = pd.value("module/load_at_start
up").toBool();
result.push_back(mDesc);
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
qWarning() << "WARNING: unable to successfully read continue;
module.ini file from plugin " << *dir; }
QPluginLoader loader(moduleFullPath);
if (!loader.load())
{
qWarning() << "Couldn't load the dynamic library: "
<< moduleFullPath << ": " << loader.errorString();
qWarning() << "Plugin " << dir << " will not be load
ed.";
continue;
}
QObject* obj = loader.instance();
if (!obj)
{
qWarning() << "Couldn't open the dynamic library: "
<< moduleFullPath << ": " << loader.errorString();
qWarning() << "Plugin " << dir << " will not be open
.";
continue;
}
StelPluginInterface* pluginInterface = qobject_cast<StelPlug
inInterface *>(obj);
if (pluginInterface)
{
StelModuleMgr::PluginDescriptor mDesc;
mDesc.info = pluginInterface->getPluginInfo();
mDesc.pluginInterface = pluginInterface;
pluginDescriptorList.insert(mDesc.info.id, mDesc);
} }
} }
return result; // Load for each plugin if it should be loaded at startup
QSettings* conf = StelApp::getInstance().getSettings();
for (QMap<QString, StelModuleMgr::PluginDescriptor>::Iterator iter=p
luginDescriptorList.begin();iter!=pluginDescriptorList.end();++iter)
{
if (!conf->contains("plugins_load_at_startup/"+iter.key()))
conf->setValue("plugins_load_at_startup/"+iter.key()
, false);
iter->loadAtStartup = conf->value("plugins_load_at_startup/"
+iter.key()).toBool();
}
pluginDescriptorListLoaded = true;
return pluginDescriptorList.values();
} }
 End of changes. 20 change blocks. 
72 lines changed or deleted 114 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/