repoindex/alpm/manager.h

186 lines
4.9 KiB
C
Raw Normal View History

2015-08-10 22:46:01 +02:00
#ifndef ALPM_MANAGER_H
#define ALPM_MANAGER_H
2015-09-04 14:37:01 +02:00
#include "upgradelookup.h"
#include "alpmpackage.h"
2015-08-10 22:46:01 +02:00
#include <alpm.h>
#include <QNetworkAccessManager>
#include <QJsonObject>
2015-08-10 22:46:01 +02:00
#include <QJsonArray>
#include <QMutex>
2015-08-10 22:46:01 +02:00
#include <map>
2015-09-04 14:37:01 +02:00
#include <memory>
2015-08-10 22:46:01 +02:00
namespace PackageManagement {
class Config;
2015-09-04 14:37:01 +02:00
class UserRepository;
class AlpmDataBase;
2015-08-10 22:46:01 +02:00
class Manager
2015-08-10 22:46:01 +02:00
{
public:
explicit Manager(const Config &config);
2015-08-10 22:46:01 +02:00
Manager(const Manager &other) = delete;
Manager(Manager &&other) = delete;
Manager &operator =(const Manager &other) = delete;
~Manager();
// configuration, signature level, etc
const Config &config() const;
2015-08-10 22:46:01 +02:00
int sigLevel() const;
void setSigLevel(int sigLevel);
int localFileSigLevel() const;
void setLocalFileSigLevel(int sigLevel);
const QString &pacmanCacheDir() const;
static int parseSigLevel(const std::string &sigLevelStr = std::string());
static int parseUsage(const std::string &usageStr);
void applyPacmanConfig();
void applyRepoIndexConfig();
2015-08-10 22:46:01 +02:00
void unregisterSyncDataBases();
2015-09-04 14:37:01 +02:00
const UserRepository *userRepository() const;
UserRepository *userRepository();
2015-08-10 22:46:01 +02:00
// package lookup
2015-09-04 14:37:01 +02:00
AlpmPackage *packageFromDataBase(const QString &dbName, const QString &pkgName);
const AlpmPackage *packageFromDataBase(const QString &dbName, const QString &pkgName) const;
AlpmPackage *packageFromSyncDataBases(const QString &pkgName);
const AlpmPackage *packageFromSyncDataBases(const QString &pkgName) const;
std::unique_ptr<AlpmOwnershipPackage> packageFromFile(const char *fileName, bool verifyIntegrity = false);
bool isPackageIgnored(const AlpmPackage *package) const;
void setInstallReason(AlpmPackage *package, alpm_pkgreason_t reason);
// data base lookup
const AlpmDataBase *localDataBase() const;
AlpmDataBase *localDataBase();
const std::map<QString, std::unique_ptr<AlpmDataBase> > &syncDataBases() const;
const AlpmDataBase *dataBaseByName(const QString &dbName) const;
AlpmDataBase *dataBaseByName(const QString &dbName);
const Repository *repositoryByName(const QString &name) const;
Repository *repositoryByName(const QString &name);
const UpgradeLookupResults checkForUpgrades(AlpmDataBase *db) const;
2015-08-10 22:46:01 +02:00
// JSON serialization, handling JSON requests
2015-09-04 14:37:01 +02:00
const QJsonObject basicRepoInfo(const Repository *packageSource) const;
2015-08-10 22:46:01 +02:00
const QJsonArray &basicRepoInfo() const;
2015-09-04 14:37:01 +02:00
const QJsonArray packageInfo(const QJsonObject &pkgSelection, bool full = true) const;
2015-08-10 22:46:01 +02:00
const QJsonArray &groupInfo() const;
private:
void cleanup();
const Config &m_config;
alpm_handle_t *m_handle;
int m_sigLevel;
int m_localFileSigLevel;
QString m_pacmanCacheDir;
2015-08-10 22:46:01 +02:00
QNetworkAccessManager m_networkAccessManager;
2015-09-04 14:37:01 +02:00
std::unique_ptr<UserRepository> m_userRepo;
std::unique_ptr<AlpmDataBase> m_localDb;
std::map<QString, std::unique_ptr<AlpmDataBase> > m_syncDbs;
2015-08-10 22:46:01 +02:00
mutable QJsonArray m_basicRepoInfo;
mutable QMutex m_basicRepoInfoMutex;
2015-08-10 22:46:01 +02:00
mutable QJsonArray m_groupInfo;
mutable QMutex m_groupInfoMutex;
2015-08-10 22:46:01 +02:00
};
/*!
* \brief Returns the configuration of the manager.
* \remarks The configuration has been specified when constructing the manager.
*/
inline const Config &Manager::config() const
{
return m_config;
}
2015-08-10 22:46:01 +02:00
/*!
* \brief Returns the signature level.
*
* The signature level is read from the pacman config
* when parsePacmanConfig() is called or can be set
* manually using setSigLevel().
*/
inline int Manager::sigLevel() const
{
return m_sigLevel;
}
/*!
* \brief Sets the signature level.
*/
inline void Manager::setSigLevel(int sigLevel)
{
m_sigLevel = sigLevel;
}
/*!
* \brief Returns the signature level used when opening local files.
*
* The signature level is read from the pacman config
* when parsePacmanConfig() is called or can be set
* manually using setSigLevel().
*/
inline int Manager::localFileSigLevel() const
{
return m_localFileSigLevel;
}
/*!
* \brief Sets the signature level used when opening local files.
*/
inline void Manager::setLocalFileSigLevel(int sigLevel)
{
m_localFileSigLevel = sigLevel;
}
/*!
* \brief Returns whether the specified \a package is ignored.
*/
2015-09-04 14:37:01 +02:00
inline bool Manager::isPackageIgnored(const AlpmPackage *package) const
2015-08-10 22:46:01 +02:00
{
2015-09-04 14:37:01 +02:00
return alpm_pkg_should_ignore(m_handle, const_cast<alpm_pkg_t *>(package->ptr()));
2015-08-10 22:46:01 +02:00
}
/*!
* \brief Returns the Pacman cache directory.
2015-08-10 22:46:01 +02:00
* \remarks This is read from the Pacman configuration.
*/
inline const QString &Manager::pacmanCacheDir() const
{
return m_pacmanCacheDir;
}
2015-09-04 14:37:01 +02:00
inline const UserRepository *Manager::userRepository() const
{
return m_userRepo.get();
}
inline UserRepository *Manager::userRepository()
{
return m_userRepo.get();
}
/*!
* \brief Returns the local data base.
*/
inline const AlpmDataBase *Manager::localDataBase() const
{
2015-09-04 14:37:01 +02:00
return m_localDb.get();
}
2015-09-04 14:37:01 +02:00
/*!
* \brief Returns the local data base.
*/
inline AlpmDataBase *Manager::localDataBase()
2015-08-10 22:46:01 +02:00
{
2015-09-04 14:37:01 +02:00
return m_localDb.get();
2015-08-10 22:46:01 +02:00
}
}
#endif // ALPM_MANAGER_H