Add support for C++/Qt batch job plugins
These job plugins work similarly to view modules, with the following differences: * These jobs need to link only libcalamares, not libcalamaresui. For this reason, PluginFactory was moved from libcalamaresui to libcalamares. (It depends only on QtCore.) * Instead of deriving from ViewModule, derive from CppJob (which is a subclass of Job). * Like process and Python jobs, a job plugin is a single job, whereas a ViewModule can generate a whole list of jobs. The CppJob and CppJobModule classes are new. In Module::fromDescriptor, the combination type=job, intf=qtplugin is now supported and mapped to CppJobModule.
This commit is contained in:
parent
19e41a3c71
commit
206a89e06c
@ -11,6 +11,7 @@ configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/../calamares/CalamaresVersion.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/CalamaresVersion.h )
|
||||
|
||||
set( libSources
|
||||
CppJob.cpp
|
||||
GlobalStorage.cpp
|
||||
Job.cpp
|
||||
JobQueue.cpp
|
||||
@ -24,6 +25,7 @@ set( libSources
|
||||
utils/CalamaresUtils.cpp
|
||||
utils/CalamaresUtilsSystem.cpp
|
||||
utils/Logger.cpp
|
||||
utils/PluginFactory.cpp
|
||||
utils/Retranslator.cpp
|
||||
)
|
||||
|
||||
|
45
src/libcalamares/CppJob.cpp
Normal file
45
src/libcalamares/CppJob.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
||||
* Copyright 2016, Kevin Kofler <kevin.kofler@chello.at>
|
||||
*
|
||||
* 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 "CppJob.h"
|
||||
|
||||
namespace Calamares
|
||||
{
|
||||
|
||||
CppJob::CppJob( QObject* parent )
|
||||
: Job( parent )
|
||||
{}
|
||||
|
||||
|
||||
CppJob::~CppJob()
|
||||
{}
|
||||
|
||||
|
||||
void
|
||||
CppJob::setModuleInstanceKey( const QString& instanceKey )
|
||||
{
|
||||
m_instanceKey = instanceKey;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CppJob::setConfigurationMap( const QVariantMap& configurationMap )
|
||||
{}
|
||||
|
||||
}
|
51
src/libcalamares/CppJob.h
Normal file
51
src/libcalamares/CppJob.h
Normal file
@ -0,0 +1,51 @@
|
||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
||||
* Copyright 2016, Kevin Kofler <kevin.kofler@chello.at>
|
||||
*
|
||||
* 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_CPPJOB_H
|
||||
#define CALAMARES_CPPJOB_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QVariant>
|
||||
|
||||
#include "DllMacro.h"
|
||||
#include "Typedefs.h"
|
||||
#include "Job.h"
|
||||
|
||||
namespace Calamares
|
||||
{
|
||||
|
||||
class DLLEXPORT CppJob : public Job
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CppJob( QObject* parent = nullptr );
|
||||
virtual ~CppJob();
|
||||
|
||||
void setModuleInstanceKey( const QString& instanceKey );
|
||||
QString moduleInstanceKey() const { return m_instanceKey; }
|
||||
|
||||
virtual void setConfigurationMap( const QVariantMap& configurationMap );
|
||||
|
||||
protected:
|
||||
QString m_instanceKey;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // CALAMARES_CPPJOB_H
|
@ -23,7 +23,7 @@
|
||||
#ifndef CALAMARESPLUGINFACTORY_H
|
||||
#define CALAMARESPLUGINFACTORY_H
|
||||
|
||||
#include "UiDllMacro.h"
|
||||
#include "DllMacro.h"
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QVariant>
|
||||
@ -196,7 +196,7 @@ namespace Calamares
|
||||
* \author Matthias Kretz <kretz@kde.org>
|
||||
* \author Bernhard Loos <nhuh.put@web.de>
|
||||
*/
|
||||
class UIDLLEXPORT PluginFactory : public QObject
|
||||
class DLLEXPORT PluginFactory : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DECLARE_PRIVATE(PluginFactory)
|
@ -1,6 +1,7 @@
|
||||
set( CALAMARESUI_LIBRARY_TARGET calamaresui )
|
||||
|
||||
list( APPEND ${CALAMARESUI_LIBRARY_TARGET}_SOURCES
|
||||
modulesystem/CppJobModule.cpp
|
||||
modulesystem/Module.cpp
|
||||
modulesystem/ModuleManager.cpp
|
||||
modulesystem/ProcessJobModule.cpp
|
||||
@ -14,8 +15,6 @@ list( APPEND ${CALAMARESUI_LIBRARY_TARGET}_SOURCES
|
||||
utils/qjsonmodel.cpp
|
||||
utils/qjsonitem.cpp
|
||||
|
||||
utils/PluginFactory.cpp
|
||||
|
||||
viewpages/AbstractPage.cpp
|
||||
viewpages/ViewStep.cpp
|
||||
|
||||
|
128
src/libcalamaresui/modulesystem/CppJobModule.cpp
Normal file
128
src/libcalamaresui/modulesystem/CppJobModule.cpp
Normal file
@ -0,0 +1,128 @@
|
||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
||||
* Copyright 2016, Kevin Kofler <kevin.kofler@chello.at>
|
||||
*
|
||||
* 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 "CppJobModule.h"
|
||||
|
||||
#include "utils/PluginFactory.h"
|
||||
#include "utils/Logger.h"
|
||||
#include "CppJob.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QPluginLoader>
|
||||
|
||||
namespace Calamares {
|
||||
|
||||
|
||||
Module::Type
|
||||
CppJobModule::type() const
|
||||
{
|
||||
return Job;
|
||||
}
|
||||
|
||||
|
||||
Module::Interface
|
||||
CppJobModule::interface() const
|
||||
{
|
||||
return QtPlugin;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CppJobModule::loadSelf()
|
||||
{
|
||||
if ( m_loader )
|
||||
{
|
||||
PluginFactory* pf = qobject_cast< PluginFactory* >( m_loader->instance() );
|
||||
if ( !pf )
|
||||
{
|
||||
cDebug() << Q_FUNC_INFO << m_loader->errorString();
|
||||
return;
|
||||
}
|
||||
|
||||
CppJob *cppJob = pf->create< Calamares::CppJob >();
|
||||
if ( !cppJob )
|
||||
{
|
||||
cDebug() << Q_FUNC_INFO << m_loader->errorString();
|
||||
return;
|
||||
}
|
||||
// cDebug() << "CppJobModule loading self for instance" << instanceKey()
|
||||
// << "\nCppJobModule at address" << this
|
||||
// << "\nCalamares::PluginFactory at address" << pf
|
||||
// << "\nCppJob at address" << cppJob;
|
||||
|
||||
cppJob->setModuleInstanceKey( instanceKey() );
|
||||
cppJob->setConfigurationMap( m_configurationMap );
|
||||
m_job = Calamares::job_ptr( static_cast< Calamares::Job * >( cppJob ) );
|
||||
m_loaded = true;
|
||||
cDebug() << "CppJobModule" << instanceKey() << "loading complete.";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QList< job_ptr >
|
||||
CppJobModule::jobs() const
|
||||
{
|
||||
return QList< job_ptr >() << m_job;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CppJobModule::initFrom( const QVariantMap& moduleDescriptor )
|
||||
{
|
||||
Module::initFrom( moduleDescriptor );
|
||||
QDir directory( location() );
|
||||
QString load;
|
||||
if ( !moduleDescriptor.value( "load" ).toString().isEmpty() )
|
||||
{
|
||||
load = moduleDescriptor.value( "load" ).toString();
|
||||
load = directory.absoluteFilePath( load );
|
||||
}
|
||||
// If a load path is not specified, we look for a plugin to load in the directory.
|
||||
if ( load.isEmpty() || !QLibrary::isLibrary( load ) )
|
||||
{
|
||||
const QStringList ls = directory.entryList( QStringList{ "*.so" } );
|
||||
if ( !ls.isEmpty() )
|
||||
{
|
||||
for ( QString entry : ls )
|
||||
{
|
||||
entry = directory.absoluteFilePath( entry );
|
||||
if ( QLibrary::isLibrary( entry ) )
|
||||
{
|
||||
load = entry;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_loader = new QPluginLoader( load );
|
||||
}
|
||||
|
||||
CppJobModule::CppJobModule()
|
||||
: Module()
|
||||
, m_loader( nullptr )
|
||||
{
|
||||
}
|
||||
|
||||
CppJobModule::~CppJobModule()
|
||||
{
|
||||
delete m_loader;
|
||||
}
|
||||
|
||||
} // namespace Calamares
|
53
src/libcalamaresui/modulesystem/CppJobModule.h
Normal file
53
src/libcalamaresui/modulesystem/CppJobModule.h
Normal file
@ -0,0 +1,53 @@
|
||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
||||
* Copyright 2016, Kevin Kofler <kevin.kofler@chello.at>
|
||||
*
|
||||
* 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_CPPJOBMODULE_H
|
||||
#define CALAMARES_CPPJOBMODULE_H
|
||||
|
||||
#include "UiDllMacro.h"
|
||||
#include "Module.h"
|
||||
|
||||
class QPluginLoader;
|
||||
|
||||
namespace Calamares {
|
||||
|
||||
class UIDLLEXPORT CppJobModule : public Module
|
||||
{
|
||||
public:
|
||||
Type type() const override;
|
||||
Interface interface() const override;
|
||||
|
||||
void loadSelf() override;
|
||||
QList< job_ptr > jobs() const override;
|
||||
|
||||
protected:
|
||||
void initFrom( const QVariantMap& moduleDescriptor ) override;
|
||||
|
||||
private:
|
||||
friend class Module; //so only the superclass can instantiate
|
||||
explicit CppJobModule();
|
||||
virtual ~CppJobModule();
|
||||
|
||||
QPluginLoader* m_loader;
|
||||
job_ptr m_job;
|
||||
};
|
||||
|
||||
} // namespace Calamares
|
||||
|
||||
#endif // CALAMARES_CPPJOBMODULE_H
|
@ -19,6 +19,7 @@
|
||||
#include "Module.h"
|
||||
|
||||
#include "ProcessJobModule.h"
|
||||
#include "CppJobModule.h"
|
||||
#include "ViewModule.h"
|
||||
#include "utils/CalamaresUtils.h"
|
||||
#include "utils/YamlUtils.h"
|
||||
@ -76,7 +77,11 @@ Module::fromDescriptor( const QVariantMap& moduleDescriptor,
|
||||
}
|
||||
else if ( typeString == "job" )
|
||||
{
|
||||
if ( intfString == "process" )
|
||||
if ( intfString == "qtplugin" )
|
||||
{
|
||||
m = new CppJobModule();
|
||||
}
|
||||
else if ( intfString == "process" )
|
||||
{
|
||||
m = new ProcessJobModule();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user