Made ModuleLoader async, added dependency check.
This commit is contained in:
parent
8d4ee1debd
commit
19da31baa4
@ -118,3 +118,10 @@ Calamares::Module::name()
|
|||||||
{
|
{
|
||||||
return m_name;
|
return m_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QStringList
|
||||||
|
Calamares::Module::requiredModules()
|
||||||
|
{
|
||||||
|
return m_requiredModules;
|
||||||
|
}
|
||||||
|
@ -45,6 +45,7 @@ public:
|
|||||||
static Module* loadFromFile( const QString& path );
|
static Module* loadFromFile( const QString& path );
|
||||||
|
|
||||||
QString name();
|
QString name();
|
||||||
|
QStringList requiredModules();
|
||||||
|
|
||||||
enum Type
|
enum Type
|
||||||
{
|
{
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <yaml-cpp/yaml.h>
|
#include <yaml-cpp/yaml.h>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#define MODULE_CONFIG_FILENAME "module.conf"
|
#define MODULE_CONFIG_FILENAME "module.conf"
|
||||||
|
|
||||||
@ -45,7 +46,14 @@ ModuleLoader::~ModuleLoader()
|
|||||||
|
|
||||||
|
|
||||||
void
|
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
|
// 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.
|
// 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
|
// At this point m_availableModules is filled with whatever was found in the
|
||||||
// search paths.
|
// 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 );
|
explicit ModuleLoader( const QStringList& paths, QObject* parent = 0 );
|
||||||
virtual ~ModuleLoader();
|
virtual ~ModuleLoader();
|
||||||
|
|
||||||
void exec();
|
void start();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void done();
|
void done();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void doWork();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void checkDependencies();
|
||||||
|
|
||||||
QMap< QString, Module* > m_availableModules;
|
QMap< QString, Module* > m_availableModules;
|
||||||
|
|
||||||
QStringList m_paths;
|
QStringList m_paths;
|
||||||
|
Loading…
Reference in New Issue
Block a user