nspkg / engine / retrieval.v
43 lines · 37 sloc · 1.04 KB · c01b0795d1db56c7bce2539b2c46b110637fdc1a
Raw
1// retrieval event boundaries follow pacman be_sync.c and dload.c.
2// SPDX-License-Identifier: GPL-2.0-or-later
3module engine
4
5pub enum RetrievalEventKind {
6 database_missing
7 db_retrieve_start
8 db_retrieve_done
9 db_retrieve_failed
10 pkg_retrieve_start
11 pkg_retrieve_done
12 pkg_retrieve_failed
13}
14
15pub struct RetrievalEvent {
16pub:
17 kind RetrievalEventKind
18 database string
19 packages int
20 total_size i64
21}
22
23pub type RetrievalCallback = fn (voidptr, RetrievalEvent)
24
25pub fn (mut handle Handle) set_retrieval_callback(callback RetrievalCallback, context voidptr) ! {
26 handle.check()!
27 handle.retrieval_callback = callback
28 handle.retrieval_context = context
29}
30
31fn (handle &Handle) retrieval_event(event RetrievalEvent) {
32 if voidptr(handle.retrieval_callback) != unsafe { nil } {
33 handle.retrieval_callback(handle.retrieval_context, event)
34 }
35}
36
37fn (mut handle Handle) begin_retrieval() ! {
38 handle.check()!
39 if handle.retrieval_active || handle.download_active {
40 return handle.fail(.trans_not_null, 'retrieval is active')
41 }
42 handle.retrieval_active = true
43}
44