repoindex/alpm/manager.h

186 lines
4.9 KiB
C++

#ifndef ALPM_MANAGER_H
#define ALPM_MANAGER_H
#include "upgradelookup.h"
#include "alpmpackage.h"
#include <alpm.h>
#include <QNetworkAccessManager>
#include <QJsonObject>
#include <QJsonArray>
#include <QMutex>
#include <map>
#include <memory>
namespace PackageManagement {
class Config;
class UserRepository;
class AlpmDataBase;
class Manager
{
public:
explicit Manager(const Config &config);
Manager(const Manager &other) = delete;
Manager(Manager &&other) = delete;
Manager &operator =(const Manager &other) = delete;
~Manager();
// configuration, signature level, etc
const Config &config() const;
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();
void unregisterSyncDataBases();
const UserRepository *userRepository() const;
UserRepository *userRepository();
// package lookup
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;
// JSON serialization, handling JSON requests
const QJsonObject basicRepoInfo(const Repository *packageSource) const;
const QJsonArray &basicRepoInfo() const;
const QJsonArray packageInfo(const QJsonObject &pkgSelection, bool full = true) const;
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;
QNetworkAccessManager m_networkAccessManager;
std::unique_ptr<UserRepository> m_userRepo;
std::unique_ptr<AlpmDataBase> m_localDb;
std::map<QString, std::unique_ptr<AlpmDataBase> > m_syncDbs;
mutable QJsonArray m_basicRepoInfo;
mutable QMutex m_basicRepoInfoMutex;
mutable QJsonArray m_groupInfo;
mutable QMutex m_groupInfoMutex;
};
/*!
* \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;
}
/*!
* \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.
*/
inline bool Manager::isPackageIgnored(const AlpmPackage *package) const
{
return alpm_pkg_should_ignore(m_handle, const_cast<alpm_pkg_t *>(package->ptr()));
}
/*!
* \brief Returns the Pacman cache directory.
* \remarks This is read from the Pacman configuration.
*/
inline const QString &Manager::pacmanCacheDir() const
{
return m_pacmanCacheDir;
}
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
{
return m_localDb.get();
}
/*!
* \brief Returns the local data base.
*/
inline AlpmDataBase *Manager::localDataBase()
{
return m_localDb.get();
}
}
#endif // ALPM_MANAGER_H