| 1 | // retrieval event boundaries follow pacman be_sync.c and dload.c. |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | module engine |
| 4 | |
| 5 | pub 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 | |
| 15 | pub struct RetrievalEvent { |
| 16 | pub: |
| 17 | kind RetrievalEventKind |
| 18 | database string |
| 19 | packages int |
| 20 | total_size i64 |
| 21 | } |
| 22 | |
| 23 | pub type RetrievalCallback = fn (voidptr, RetrievalEvent) |
| 24 | |
| 25 | pub 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 | |
| 31 | fn (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 | |
| 37 | fn (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 | |