Made ModuleLoader async, added dependency check.

main
Teo Mrnjavac 11 years ago
parent 8d4ee1debd
commit 19da31baa4

@ -118,3 +118,10 @@ Calamares::Module::name()
{
return m_name;
}
QStringList
Calamares::Module::requiredModules()
{
return m_requiredModules;
}

@ -45,6 +45,7 @@ public:
static Module* loadFromFile( const QString& path );
QString name();
QStringList requiredModules();
enum Type
{

@ -23,6 +23,7 @@
#include <yaml-cpp/yaml.h>
#include <QDir>
#include <QTimer>
#define MODULE_CONFIG_FILENAME "module.conf"
@ -45,7 +46,14 @@ ModuleLoader::~ModuleLoader()
void
ModuleLoader::exec()
ModuleLoader::start()
{
QTimer::singleShot( 0, this, SLOT( doWork() ) );
}
void
ModuleLoader::doWork()
{
// We start from a list of paths in m_paths. Each of those is a directory that
// might (should) contain Calamares modules of any type/interface.
@ -98,6 +106,37 @@ ModuleLoader::exec()
}
// At this point m_availableModules is filled with whatever was found in the
// search paths.
checkDependencies();
emit done();
}
void
ModuleLoader::checkDependencies()
{
// This goes through the map of available modules, and deletes those whose
// dependencies are not met, if any.
bool somethingWasRemovedBecauseOfUnmetDependencies = false;
forever
{
for ( auto it = m_availableModules.begin();
it != m_availableModules.end(); ++it )
{
foreach ( QString depName, (*it)->requiredModules() )
{
if ( !m_availableModules.contains( depName ) )
{
somethingWasRemovedBecauseOfUnmetDependencies = true;
m_availableModules.erase( it );
break;
}
}
if ( somethingWasRemovedBecauseOfUnmetDependencies )
break;
}
if ( !somethingWasRemovedBecauseOfUnmetDependencies )
break;
}
}
}

@ -37,12 +37,17 @@ public:
explicit ModuleLoader( const QStringList& paths, QObject* parent = 0 );
virtual ~ModuleLoader();
void exec();
void start();
signals:
void done();
private slots:
void doWork();
private:
void checkDependencies();
QMap< QString, Module* > m_availableModules;
QStringList m_paths;

Loading…
Cancel
Save