[libcalamaresui] Refactor Requirements-Checking

- Move the actual checking into a separate object with some lifecycle-
   management signals.
 - Right now this is still single-threaded and blocking, so no net gain.
This commit is contained in:
Adriaan de Groot 2019-02-20 05:48:15 -05:00
parent bbb9ff0cbf
commit c678cd80b4
5 changed files with 158 additions and 25 deletions

View File

@ -6,6 +6,7 @@ set( calamaresui_SOURCES
modulesystem/ModuleManager.cpp modulesystem/ModuleManager.cpp
modulesystem/ProcessJobModule.cpp modulesystem/ProcessJobModule.cpp
modulesystem/Requirement.cpp modulesystem/Requirement.cpp
modulesystem/RequirementsChecker.cpp
modulesystem/ViewModule.cpp modulesystem/ViewModule.cpp
utils/CalamaresUtilsGui.cpp utils/CalamaresUtilsGui.cpp

View File

@ -21,11 +21,13 @@
#include "ExecutionViewStep.h" #include "ExecutionViewStep.h"
#include "Module.h" #include "Module.h"
#include "utils/Logger.h" #include "RequirementsChecker.h"
#include "utils/YamlUtils.h"
#include "Settings.h" #include "Settings.h"
#include "ViewManager.h" #include "ViewManager.h"
#include "utils/Logger.h"
#include "utils/YamlUtils.h"
#include <yaml-cpp/yaml.h> #include <yaml-cpp/yaml.h>
#include <QApplication> #include <QApplication>
@ -306,32 +308,21 @@ void
ModuleManager::checkRequirements() ModuleManager::checkRequirements()
{ {
cDebug() << "Checking module requirements .."; cDebug() << "Checking module requirements ..";
QTimer::singleShot( 0, this, [ this ]()
QVector< Module* > modules( m_loadedModulesByInstanceKey.count() );
int count = 0;
for (const auto& module : m_loadedModulesByInstanceKey )
{ {
bool acceptable = true; modules[count++] = module;
}
for (const auto& module : m_loadedModulesByInstanceKey ) RequirementsChecker *rq = new RequirementsChecker( modules, this );
{ connect( rq, &RequirementsChecker::requirementsResult, this, &ModuleManager::requirementsResult );
RequirementsList l = module->checkRequirements(); connect( rq, &RequirementsChecker::requirementsComplete, this, &ModuleManager::requirementsComplete );
if ( l.length() > 0 ) connect( rq, &RequirementsChecker::done, rq, &RequirementsChecker::deleteLater );
{ connect( rq, &RequirementsChecker::requirementsProgress, this, &ModuleManager::requirementsProgress );
cDebug() << " .." << module->name() << "has" << l.length() << "requirements";
emit requirementsResult( l );
}
int count = 0;
for (const auto& r : l)
{
if ( r.mandatory && !r.satisfied )
{
cDebug() << " .. requirement" << count << r.name << "is not satisfied.";
acceptable = false;
}
++count;
}
}
emit requirementsComplete( acceptable ); QTimer::singleShot( 0, rq, &RequirementsChecker::run );
} );
} }
QStringList QStringList

View File

@ -93,8 +93,10 @@ signals:
void initDone(); void initDone();
void modulesLoaded(); /// All of the modules were loaded successfully void modulesLoaded(); /// All of the modules were loaded successfully
void modulesFailed( QStringList ); /// .. or not void modulesFailed( QStringList ); /// .. or not
// Below, see RequirementsChecker documentation
void requirementsComplete( bool ); void requirementsComplete( bool );
void requirementsResult( RequirementsList& ); void requirementsResult( RequirementsList& );
void requirementsProgress( const QString& );
private slots: private slots:
void doInit(); void doInit();

View File

@ -0,0 +1,73 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2019, Adriaan de Groot <groot@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#include "RequirementsChecker.h"
#include "Module.h"
#include "Requirement.h"
#include "utils/Logger.h"
#include <QTimer>
namespace Calamares
{
RequirementsChecker::RequirementsChecker( QVector< Module* > modules, QObject* parent )
: QObject( parent )
, m_modules( std::move( modules ) )
{
}
RequirementsChecker::~RequirementsChecker()
{
}
void
RequirementsChecker::run()
{
bool acceptable = true;
for (const auto& module : m_modules )
{
RequirementsList l = module->checkRequirements();
if ( l.length() > 0 )
{
cDebug() << " .." << module->name() << "has" << l.length() << "requirements";
emit requirementsResult( l );
}
int count = 0;
for (const auto& r : l)
{
if ( r.mandatory && !r.satisfied )
{
cDebug() << " .. requirement" << count << r.name << "is not satisfied.";
acceptable = false;
}
++count;
}
}
emit requirementsComplete( acceptable );
QTimer::singleShot(0, this, &RequirementsChecker::done );
}
}

View File

@ -0,0 +1,66 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2019, Adriaan de Groot <groot@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CALAMARES_REQUIREMENTSCHECKER_H
#define CALAMARES_REQUIREMENTSCHECKER_H
#include <QObject>
#include <QVector>
#include "Requirement.h"
namespace Calamares
{
class Module;
/** @brief A manager-class that checks all the module requirements
*
* Asynchronously checks the requirements for each module, and
* emits progress signals as appropriate.
*/
class RequirementsChecker : public QObject
{
Q_OBJECT
public:
RequirementsChecker( QVector< Module* > modules, QObject* parent = nullptr );
virtual ~RequirementsChecker() override;
public slots:
void run();
signals:
/// @brief Human-readable progress message
void requirementsProgress( const QString& );
/// @brief Requirements from a single module
void requirementsResult( RequirementsList& );
/** @brief When all requirements are collected
*
* The argument indicates if all mandatory requirements are satisfied.
*/
void requirementsComplete( bool );
/// @brief Emitted after requirementsComplete
void done();
private:
QVector< Module* > m_modules;
} ;
}
#endif