[libcalamares] Add KPMCore manager
- This handles cleaning up KPMCore on exit
This commit is contained in:
parent
8eb04a082e
commit
7adbc8cda6
@ -117,6 +117,7 @@ if ( KPMcore_FOUND )
|
|||||||
include_directories( ${KPMCORE_INCLUDE_DIR} )
|
include_directories( ${KPMCORE_INCLUDE_DIR} )
|
||||||
list( APPEND libSources
|
list( APPEND libSources
|
||||||
partition/FileSystem.cpp
|
partition/FileSystem.cpp
|
||||||
|
partition/KPMManager.cpp
|
||||||
partition/PartitionIterator.cpp
|
partition/PartitionIterator.cpp
|
||||||
partition/PartitionQuery.cpp
|
partition/PartitionQuery.cpp
|
||||||
)
|
)
|
||||||
|
104
src/libcalamares/partition/KPMManager.cpp
Normal file
104
src/libcalamares/partition/KPMManager.cpp
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
/* === This file is part of Calamares - <https://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 "KPMManager.h"
|
||||||
|
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
|
#include <kpmcore/backend/corebackendmanager.h>
|
||||||
|
#if defined( WITH_KPMCORE4API )
|
||||||
|
#include <kpmcore/util/externalcommand.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
|
||||||
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
namespace Partition
|
||||||
|
{
|
||||||
|
class InternalManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
InternalManager();
|
||||||
|
~InternalManager();
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool s_kpm_loaded = false;
|
||||||
|
static bool s_loaded = false;
|
||||||
|
static std::shared_ptr< InternalManager > s_backend;
|
||||||
|
|
||||||
|
|
||||||
|
InternalManager::InternalManager()
|
||||||
|
{
|
||||||
|
Q_ASSERT( !s_loaded );
|
||||||
|
s_loaded = true;
|
||||||
|
s_backend.reset( this );
|
||||||
|
|
||||||
|
cDebug() << "KPMCore backend starting ..";
|
||||||
|
if ( !s_kpm_loaded )
|
||||||
|
{
|
||||||
|
QByteArray backendName = qgetenv( "KPMCORE_BACKEND" );
|
||||||
|
if ( !CoreBackendManager::self()->load( backendName.isEmpty() ? CoreBackendManager::defaultBackendName()
|
||||||
|
: backendName ) )
|
||||||
|
{
|
||||||
|
cWarning() << "Failed to load backend plugin" << backendName;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s_kpm_loaded = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
InternalManager::~InternalManager()
|
||||||
|
{
|
||||||
|
cDebug() << "Cleaning up KPMCore backend ..";
|
||||||
|
|
||||||
|
s_loaded = false;
|
||||||
|
|
||||||
|
#if defined( WITH_KPMCORE4API )
|
||||||
|
auto backend_p = CoreBackendManager::self()->backend();
|
||||||
|
if ( backend_p )
|
||||||
|
{
|
||||||
|
ExternalCommand::stopHelper();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr< InternalManager >
|
||||||
|
getInternal()
|
||||||
|
{
|
||||||
|
|
||||||
|
if ( !s_loaded )
|
||||||
|
{
|
||||||
|
return std::make_shared< InternalManager >();
|
||||||
|
}
|
||||||
|
return s_backend;
|
||||||
|
}
|
||||||
|
|
||||||
|
KPMManager::KPMManager()
|
||||||
|
: m_d( getInternal() )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
KPMManager::~KPMManager() {}
|
||||||
|
|
||||||
|
} // namespace Partition
|
||||||
|
} // namespace CalamaresUtils
|
58
src/libcalamares/partition/KPMManager.h
Normal file
58
src/libcalamares/partition/KPMManager.h
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/* === This file is part of Calamares - <https://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 PARTITION_KPMMANAGER_H
|
||||||
|
#define PARTITION_KPMMANAGER_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
class CoreBackend;
|
||||||
|
|
||||||
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
namespace Partition
|
||||||
|
{
|
||||||
|
/// @brief Handle to KPMCore
|
||||||
|
class InternalManager;
|
||||||
|
|
||||||
|
/** @brief KPMCore loader and cleanup
|
||||||
|
*
|
||||||
|
* A Calamares plugin that uses KPMCore should hold an object of
|
||||||
|
* this class; its only responsibility is to load KPMCore
|
||||||
|
* and to cleanly unload it on destruction (with KPMCore 4,
|
||||||
|
* also to shutdown the privileged helper application).
|
||||||
|
*
|
||||||
|
* It loads the default plugin ("parted" with KPMCore 3, "sfdisk"
|
||||||
|
* with KPMCore 4), but this can be overridden by setting the
|
||||||
|
* environment variable KPMCORE_BACKEND. Setting it to
|
||||||
|
* "dummy" will load the dummy plugin instead.
|
||||||
|
*/
|
||||||
|
class KPMManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
KPMManager();
|
||||||
|
~KPMManager();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr< InternalManager > m_d;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Partition
|
||||||
|
} // namespace CalamaresUtils
|
||||||
|
|
||||||
|
#endif // PARTITION_KPMMANAGER_H
|
Loading…
Reference in New Issue
Block a user