Skip to content

Instantly share code, notes, and snippets.

@julian-klode
Last active May 19, 2025 19:19
Show Gist options
  • Save julian-klode/90af6c8bb2b4197c62ad9f603830b5d2 to your computer and use it in GitHub Desktop.
Save julian-klode/90af6c8bb2b4197c62ad9f603830b5d2 to your computer and use it in GitHub Desktop.
/*
* APT daemon - Listing packages
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <memory>
#include <optional>
#include <string>
#include <variant>
#include <vector>
namespace APT::Service::Info
{
struct Origin
{
std::optional<std::string> archive;
std::optional<std::string> codename;
std::optional<std::string> version;
std::optional<std::string> origin;
std::optional<std::string> label;
std::optional<std::string> site;
};
struct Version
{
// \brief A numeric identifier for the version in the cache
int id;
// \brief A Debian version
std::string version;
// \brief The architecture of the version. In contrast to the package architecture, this may also be "all".
std::string architecture;
/// \brief The priority of the version, including the priority of origins
int pin;
/// \brief The prefered version of the package.
bool candidate;
/// \brief The version of the package selected for isntall
bool selected;
/// \brief The currently installed version
bool installed;
std::vector<Origin> origins;
};
struct Package
{
int id;
std::string name;
std::string architecture;
std::string mode;
bool automatic;
bool garbage;
bool essential;
bool reinstall;
std::vector<Version> versions;
};
} // namespace APT::Service::Info
namespace APT::Service::Request
{
struct PackageSpec
{
std::string name;
std::optional<std::string> architecture;
std::optional<std::string> version;
};
struct PatternSpec
{
std::string pattern;
};
struct RegexSpec
{
std::string regex;
};
struct FnmatchSpec
{
std::string fnmatch;
};
using Spec = std::variant<PackageSpec, PatternSpec, RegexSpec, FnmatchSpec>;
}; // namespace APT::Service::Request
namespace APT::Service
{
class Service final
{
struct Private;
std::unique_ptr<Private> d;
Service();
auto ListPackages(std::vector<Request::Spec> specs) -> std::optional<std::vector<Info::Package>>;
auto ListVersions(std::vector<Request::Spec> specs) -> std::optional<std::vector<Info::Version>>;
auto SearchPackages(std::vector<Request::Spec> specs) -> std::optional<std::vector<Info::Package>>;
};
} // namespace APT::Service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment