From 7b6dc202a982344bb914717560fe4cfb6f450fd0 Mon Sep 17 00:00:00 2001 From: Marek Blaha Date: Fri, 16 Feb 2024 09:09:02 +0100 Subject: [PATCH] dnf5daemon: Signals to wrap rpm transaction execution Use the new callbacks before_begin / after_complete to signal clients about overall transaction progress. --- dnf5daemon-server/callbacks.cpp | 18 ++++++++++++++++++ dnf5daemon-server/callbacks.hpp | 4 ++++ dnf5daemon-server/dbus.hpp | 2 ++ 3 files changed, 24 insertions(+) diff --git a/dnf5daemon-server/callbacks.cpp b/dnf5daemon-server/callbacks.cpp index c9c7d06eb..7b27833a6 100644 --- a/dnf5daemon-server/callbacks.cpp +++ b/dnf5daemon-server/callbacks.cpp @@ -125,6 +125,24 @@ sdbus::Signal DbusTransactionCB::create_signal_pkg( } +void DbusTransactionCB::before_begin(uint64_t total) { + try { + auto signal = create_signal(dnfdaemon::INTERFACE_RPM, dnfdaemon::SIGNAL_TRANSACTION_BEFORE_BEGIN); + signal << total; + dbus_object->emitSignal(signal); + } catch (...) { + } +} + +void DbusTransactionCB::after_complete(bool success) { + try { + auto signal = create_signal(dnfdaemon::INTERFACE_RPM, dnfdaemon::SIGNAL_TRANSACTION_AFTER_COMPLETE); + signal << success; + dbus_object->emitSignal(signal); + } catch (...) { + } +} + void DbusTransactionCB::install_start(const libdnf5::rpm::TransactionItem & item, uint64_t total) { try { dnfdaemon::RpmTransactionItemActions action; diff --git a/dnf5daemon-server/callbacks.hpp b/dnf5daemon-server/callbacks.hpp index ea7dcc1fa..373c6fa3d 100644 --- a/dnf5daemon-server/callbacks.hpp +++ b/dnf5daemon-server/callbacks.hpp @@ -93,6 +93,10 @@ class DbusTransactionCB : public libdnf5::rpm::TransactionCallbacks, public Dbus 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; diff --git a/dnf5daemon-server/dbus.hpp b/dnf5daemon-server/dbus.hpp index 4c514b6e1..ae1ff18ba 100644 --- a/dnf5daemon-server/dbus.hpp +++ b/dnf5daemon-server/dbus.hpp @@ -70,6 +70,8 @@ const char * const SIGNAL_DOWNLOAD_MIRROR_FAILURE = "download_mirror_failure"; const char * const SIGNAL_REPO_KEY_IMPORT_REQUEST = "repo_key_import_request"; +const char * const SIGNAL_TRANSACTION_BEFORE_BEGIN = "transaction_before_begin"; +const char * const SIGNAL_TRANSACTION_AFTER_COMPLETE = "transaction_after_complete"; const char * const SIGNAL_TRANSACTION_TRANSACTION_START = "transaction_transaction_start"; const char * const SIGNAL_TRANSACTION_TRANSACTION_PROGRESS = "transaction_transaction_progress"; const char * const SIGNAL_TRANSACTION_TRANSACTION_STOP = "transaction_transaction_stop";