From ee834a7abb346bf8fd6c8cdd397d2ffaa8435423 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Aug 2020 22:08:34 +0200 Subject: [PATCH] [libcalamares] Define interface for Module descriptor - add fields -- all const, all bogus -- to the descriptor, introduce a stub method to load the descriptor from YAML data (e.g. read from module.desc) - lighten the type-naming in Module a little, with usings --- src/libcalamares/modulesystem/Descriptor.cpp | 14 ++++++ src/libcalamares/modulesystem/Descriptor.h | 52 +++++++++++++++++++- src/libcalamares/modulesystem/Module.h | 7 ++- 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/src/libcalamares/modulesystem/Descriptor.cpp b/src/libcalamares/modulesystem/Descriptor.cpp index c8a3c3118..6927e74a6 100644 --- a/src/libcalamares/modulesystem/Descriptor.cpp +++ b/src/libcalamares/modulesystem/Descriptor.cpp @@ -7,6 +7,8 @@ #include "Descriptor.h" +#include "utils/Logger.h" + namespace Calamares { namespace ModuleSystem @@ -44,5 +46,17 @@ interfaceNames() return table; } +Descriptor::Descriptor() {} + +Descriptor +Descriptor::fromDescriptorData( const QVariantMap& moduleDesc ) +{ + Descriptor d; + + cDebug() << moduleDesc; + + return d; +} + } // namespace ModuleSystem } // namespace Calamares diff --git a/src/libcalamares/modulesystem/Descriptor.h b/src/libcalamares/modulesystem/Descriptor.h index 1d1a24b8b..a1a04472e 100644 --- a/src/libcalamares/modulesystem/Descriptor.h +++ b/src/libcalamares/modulesystem/Descriptor.h @@ -61,17 +61,65 @@ const NamedEnumTable< Interface >& interfaceNames(); * to create a more strongly-typed Module Descriptor that carries * only the necessary information and no variants. */ -// using Descriptor = QVariantMap; - class Descriptor { public: + ///@brief an invalid, and empty, descriptor Descriptor(); + /** @brief Fills a descriptor from the loaded (YAML) data. + * + */ + static Descriptor fromDescriptorData( const QVariantMap& moduleDesc ); + bool isValid() const { return false; } QString name() const { return QString(); } + Type type() const { return Type::Job; } + Interface interface() const { return Interface::QtPlugin; } + bool isEmergency() const { return false; } + bool hasConfig() const { return true; } + + /// @brief The directory where the module.desc lives + QString directory() const { return m_directory; } + void setDirectory( const QString& d ) { m_directory = d; } + + QStringList requiredModules() const { return QStringList {}; } + + /** @section C++ Modules + * + * The C++ modules are the most general, and are loaded as + * a shared library after which a suitable factory creates + * objects from them. + */ + + /// @brief Short path to the shared-library; no extension. + QString load() const { return QString(); } + + /** @section Process Job modules + * + * Process Jobs are somewhat deprecated in favor of shellprocess + * and contextualprocess jobs, since those handle multiple configuration + * much more gracefully. + * + * Process Jobs execute one command. + */ + /// @brief The command to execute; passed to the shell + QString command() const { return QString(); } + /// @brief Timeout in seconds + int timeout() const { return 30; } + /// @brief Run command in chroot? + bool chroot() const { return false; } + + /** @section Python Job modules + * + * Python job modules have one specific script to load and run. + */ + QString script() const { return QString(); } + +private: + QString m_directory; }; } // namespace ModuleSystem diff --git a/src/libcalamares/modulesystem/Module.h b/src/libcalamares/modulesystem/Module.h index a9492c21c..e9719d756 100644 --- a/src/libcalamares/modulesystem/Module.h +++ b/src/libcalamares/modulesystem/Module.h @@ -51,6 +51,9 @@ Module* moduleFromDescriptor( const ModuleSystem::Descriptor& moduleDescriptor, class DLLEXPORT Module { public: + using Type = ModuleSystem::Type; + using Interface = ModuleSystem::Interface; + virtual ~Module(); /** @@ -132,13 +135,13 @@ public: * @brief type returns the Type of this module object. * @return the type enum value. */ - virtual ModuleSystem::Type type() const = 0; + virtual Type type() const = 0; /** * @brief interface the Interface used by this module. * @return the interface enum value. */ - virtual ModuleSystem::Interface interface() const = 0; + virtual Interface interface() const = 0; /** * @brief Check the requirements of this module.