foxygit / Torlinkc Log in
commits tags

/include/torlinkc/engine/types.hpp · 1.91 KB

raw
#pragma once

#include <cstdint>
#include <optional>
#include <string>

namespace torlinkc {

// "queued" = waiting for a free download slot (see DownloadQueue's maxDownloads).
// Unlike "paused" (an explicit user action) a queued item is started
// automatically as soon as a slot frees.
enum class DownloadStatus { Downloading, Queued, Paused, Completed, Failed };

enum class SeedStatus { Seeding, Paused, Missing };

// Named asymmetrically to downloadStatusFromString/seedStatusFromString
// (rather than an overloaded "toString") on purpose: a bare "toString" in an
// app namespace is exactly the name test frameworks like doctest use as an
// ADL extension point, and a non-template exact-match overload there wins
// over the framework's own generic template -- which silently breaks
// CHECK(a == b) stringification for these enums with no useful diagnostic.
std::string downloadStatusToString(DownloadStatus s);
std::string seedStatusToString(SeedStatus s);
std::optional<DownloadStatus> downloadStatusFromString(const std::string& s);
std::optional<SeedStatus> seedStatusFromString(const std::string& s);

struct QueueItem {
  std::string id;
  std::string name;
  std::string source;  // empty = none, mirrors TS's optional SourceId
  std::string magnet;
  std::string dir;
  DownloadStatus status = DownloadStatus::Downloading;
  int progress = 0;  // 0..100, matches the TS field (rounded percent)
  std::int64_t totalBytes = 0;
  std::int64_t downloadedBytes = 0;
  int speed = 0;
  int peers = 0;
  std::optional<double> eta;  // seconds
  std::optional<int> files;
  std::optional<std::string> error;
  std::int64_t addedAt = 0;  // unix ms
};

struct SeedItem {
  std::string id;
  std::string name;
  std::string source;
  std::string magnet;
  std::string dir;
  std::int64_t sizeBytes = 0;
  SeedStatus status = SeedStatus::Seeding;
  int uploadSpeed = 0;
  std::int64_t uploaded = 0;
  int peers = 0;
};

}  // namespace torlinkc