-
Notifications
You must be signed in to change notification settings - Fork 90
/
callbacks.hpp
154 lines (116 loc) · 5.41 KB
/
callbacks.hpp
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
Copyright Contributors to the libdnf project.
This file is part of libdnf: https://github.com/rpm-software-management/libdnf/
Libdnf is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
Libdnf is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with libdnf. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef DNF5DAEMON_SERVER_CALLBACKS_HPP
#define DNF5DAEMON_SERVER_CALLBACKS_HPP
#include <libdnf5/repo/download_callbacks.hpp>
#include <libdnf5/repo/package_downloader.hpp>
#include <libdnf5/repo/repo_callbacks.hpp>
#include <libdnf5/rpm/rpm_signature.hpp>
#include <libdnf5/rpm/transaction_callbacks.hpp>
#include <sdbus-c++/sdbus-c++.h>
#include <chrono>
#include <string>
class Session;
namespace dnf5daemon {
struct DownloadUserData {
std::string download_id{};
};
class DbusCallback {
public:
explicit DbusCallback(Session & session);
virtual ~DbusCallback() = default;
protected:
static std::chrono::time_point<std::chrono::steady_clock> prev_print_time;
Session & session;
sdbus::IObject * dbus_object;
virtual sdbus::Signal create_signal(std::string interface, std::string signal_name);
static bool is_time_to_print() {
auto now = std::chrono::steady_clock::now();
auto delta = now - prev_print_time;
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(delta).count();
if (ms > 400) {
prev_print_time = now;
return true;
}
return false;
}
};
class DownloadCB : public DbusCallback, public libdnf5::repo::DownloadCallbacks {
public:
DownloadCB(Session & session) : DbusCallback(session), libdnf5::repo::DownloadCallbacks() {}
void * add_new_download(void * user_data, const char * description, double total_to_download) override;
int progress(void * user_cb_data, double total_to_download, double downloaded) override;
int end(void * user_cb_data, TransferStatus status, const char * msg) override;
int mirror_failure(void * user_cb_data, const char * msg, const char * url, const char * metadata) override;
private:
sdbus::Signal create_signal_download(const std::string & signal_name, void * user_data);
};
class KeyImportRepoCB : public DbusCallback, public libdnf5::repo::RepoCallbacks {
public:
KeyImportRepoCB(Session & session) : DbusCallback(session) {}
bool repokey_import(const libdnf5::rpm::KeyInfo & key_info) override;
};
class DbusTransactionCB : public libdnf5::rpm::TransactionCallbacks, public DbusCallback {
public:
explicit DbusTransactionCB(Session & session) : DbusCallback(session) {}
virtual ~DbusTransactionCB() = default;
// overall transaction progress
void before_begin(uint64_t total) override;
void after_complete(bool success) override;
// transaction preparation
void transaction_start(uint64_t total) override;
void transaction_progress(uint64_t amount, uint64_t total) override;
void transaction_stop(uint64_t total) override;
// install a package
void install_start(const libdnf5::rpm::TransactionItem & item, uint64_t) override;
void install_progress(const libdnf5::rpm::TransactionItem & item, uint64_t amount, uint64_t total) override;
void install_stop(const libdnf5::rpm::TransactionItem & item, uint64_t amount, uint64_t total) override;
// uninstall a package (the same messages as for install are used)
void uninstall_start(const libdnf5::rpm::TransactionItem & item, uint64_t total) override {
install_start(item, total);
}
void uninstall_progress(const libdnf5::rpm::TransactionItem & item, uint64_t amount, uint64_t total) override {
install_progress(item, amount, total);
}
void uninstall_stop(const libdnf5::rpm::TransactionItem & item, uint64_t amount, uint64_t total) override {
install_stop(item, amount, total);
}
void script_start(
const libdnf5::rpm::TransactionItem * item,
libdnf5::rpm::Nevra nevra,
libdnf5::rpm::TransactionCallbacks::ScriptType type) override;
void script_stop(
const libdnf5::rpm::TransactionItem * item,
libdnf5::rpm::Nevra nevra,
libdnf5::rpm::TransactionCallbacks::ScriptType type,
uint64_t return_code) override;
void script_error(
const libdnf5::rpm::TransactionItem * item,
libdnf5::rpm::Nevra nevra,
libdnf5::rpm::TransactionCallbacks::ScriptType type,
uint64_t return_code) override;
void elem_progress(const libdnf5::rpm::TransactionItem & item, uint64_t amount, uint64_t total) override;
void verify_start(uint64_t total) override;
void verify_progress(uint64_t amount, uint64_t total) override;
void verify_stop(uint64_t total) override;
void unpack_error(const libdnf5::rpm::TransactionItem & item) override;
void cpio_error(const libdnf5::rpm::TransactionItem & /*item*/) override{};
// whole rpm transaction is finished
void finish();
private:
sdbus::Signal create_signal_pkg(std::string interface, std::string signal_name, const std::string & nevra);
};
} // namespace dnf5daemon
#endif