File: progress.h

package info (click to toggle)
rust-rust-apt 0.7.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 524 kB
  • sloc: cpp: 773; makefile: 8
file content (123 lines) | stat: -rw-r--r-- 3,162 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#pragma once
#include <apt-pkg/acquire-item.h>
#include <apt-pkg/install-progress.h>
#include <apt-pkg/progress.h>
#include "rust/cxx.h"

struct Worker;

/// Classes for pkgAcquireStatus usage.
class DynAcquireProgress {
   public:
	DynAcquireProgress(DynAcquireProgress&&) noexcept;
	~DynAcquireProgress() noexcept;
	using IsRelocatable = std::true_type;

	int pulse_interval() const noexcept;
	void hit(u_int32_t id, std::string description) const noexcept;
	void fetch(u_int32_t id, std::string description, u_int64_t file_size) const noexcept;
	void fail(u_int32_t id, std::string description, u_int32_t status, std::string error_text)
		const noexcept;
	void pulse(
		rust::vec<Worker> workers,
		double percent,
		u_int64_t total_bytes,
		u_int64_t current_bytes,
		u_int64_t current_cps
	) const noexcept;
	void done() const noexcept;
	void start() const noexcept;
	void stop(
		u_int64_t fetched_bytes,
		u_int64_t elapsed_time,
		u_int64_t current_cps,
		bool pending_errors
	) const noexcept;
};

class AcqTextStatus : public pkgAcquireStatus {
	unsigned long ID;
	/// Callback to the rust struct
	DynAcquireProgress& callback;

	void clearLastLine();
	void AssignItemID(pkgAcquire::ItemDesc& Itm);

   public:
	virtual bool ReleaseInfoChanges(
		metaIndex const* const LastRelease,
		metaIndex const* const CurrentRelease,
		std::vector<ReleaseInfoChange>&& Changes
	);
	virtual bool MediaChange(std::string Media, std::string Drive);
	virtual void IMSHit(pkgAcquire::ItemDesc& Itm);
	virtual void Fetch(pkgAcquire::ItemDesc& Itm);
	virtual void Done(pkgAcquire::ItemDesc& Itm);
	virtual void Fail(pkgAcquire::ItemDesc& Itm);
	virtual void Start();
	virtual void Stop();

	bool Pulse(pkgAcquire* Owner);

	AcqTextStatus(DynAcquireProgress& callback);
};

/// Classes for OpProgress usage.
class DynOperationProgress {
   public:
	void op_update(std::string operation, float percent);
	void op_done();
};

class OpProgressWrapper : public OpProgress {
	/// Callback to the rust struct
	DynOperationProgress& callback;

   public:
	void Update();
	void Done();

	OpProgressWrapper(DynOperationProgress& callback);
};

/// Classes for InstallProgress usage.
class DynInstallProgress {
   public:
	/// This is supposed to return a bool, but I have zero clue when that'd be needed in practice.
	/// TODO: StatusChanged returns a bool sometimes in the C++ lib, though I'm not sure if it ever
	/// happens in practice.
	void inst_status_changed(
		std::string pkgname,
		u_int64_t steps_done,
		u_int64_t total_steps,
		std::string action
	);
	void inst_error(
		std::string pkgname,
		u_int64_t steps_done,
		u_int64_t total_steps,
		std::string error
	);
};

class PackageManagerWrapper : public APT::Progress::PackageManagerFancy {
	// class PackageManagerWrapper {
	/// Callback to the rust struct
	DynInstallProgress& callback;

   public:
	virtual bool StatusChanged(
		std::string pkgname,
		unsigned int steps_done,
		unsigned int total_steps,
		std::string action
	);
	virtual void Error(
		std::string pkgname,
		unsigned int steps_done,
		unsigned int total_steps,
		std::string error
	);

	PackageManagerWrapper(DynInstallProgress& callback);
};