Skip to content

Commit

Permalink
dnfdaemon: Replace check_pending() with get_status()
Browse files Browse the repository at this point in the history
Replace check_pending() method of the Offline interface with richer
get_status() method. The new method returns two values:
- boolean whether there is a dnf5 offline transaction scheduled for the
  next reboot
- a string->variant dictionary with the status of the dnf5 offline
  transaction
  • Loading branch information
m-blaha committed Jul 10, 2024
1 parent 95f589a commit 9c2e215
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
8 changes: 5 additions & 3 deletions dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.Offline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
-->
<interface name="org.rpm.dnf.v0.Offline">
<!--
check_pending:
get_status:
@pending: boolean, true if there is a pending offline transaction
@transaction_status: the status of the current offline dnf5 transaction
Check whether there is an offline transaction configured for the next reboot initiated by dnf5.
Check whether there is an offline transaction configured for the next reboot initiated by dnf5 and return its status.
-->
<method name="check_pending">
<method name="get_status">
<arg name="pending" type="b" direction="out" />
<arg name="transaction_status" type="a{sv}" direction="out" />
</method>


Expand Down
28 changes: 23 additions & 5 deletions dnf5daemon-server/services/offline/offline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ void Offline::dbus_register() {
});
dbus_object->registerMethod(
dnfdaemon::INTERFACE_OFFLINE,
"check_pending",
"get_status",
{},
{},
"b",
{"pending"},
"ba{sv}",
{"is_pending", "transaction_status"},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Offline::check_pending, call, session.session_locale);
session.get_threads_manager().handle_method(*this, &Offline::get_status, call, session.session_locale);
});
dbus_object->registerMethod(
dnfdaemon::INTERFACE_OFFLINE,
Expand All @@ -95,9 +95,27 @@ void Offline::dbus_register() {
});
}

sdbus::MethodReply Offline::check_pending(sdbus::MethodCall & call) {
sdbus::MethodReply Offline::get_status(sdbus::MethodCall & call) {
dnfdaemon::KeyValueMap transaction_state;

const std::filesystem::path state_path{get_datadir() / libdnf5::offline::TRANSACTION_STATE_FILENAME};
// try load the offline transaction state
libdnf5::offline::OfflineTransactionState state{state_path};
if (!state.get_read_exception()) {
const auto & state_data = state.get_data();
transaction_state["status"] = state_data.get_status();
transaction_state["cachedir"] = state_data.get_cachedir();
transaction_state["target_releasever"] = state_data.get_target_releasever();
transaction_state["system_releasever"] = state_data.get_system_releasever();
transaction_state["verb"] = state_data.get_verb();
transaction_state["cmd_line"] = state_data.get_cmd_line();
transaction_state["poweroff_after"] = state_data.get_poweroff_after();
transaction_state["module_platform_id"] = state_data.get_module_platform_id();
}

auto reply = call.createReply();
reply << (offline_transaction_scheduled() == Scheduled::SCHEDULED);
reply << transaction_state;
return reply;
}

Expand Down
2 changes: 1 addition & 1 deletion dnf5daemon-server/services/offline/offline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class Offline : public IDbusSessionService {

private:
sdbus::MethodReply cancel(sdbus::MethodCall & call);
sdbus::MethodReply check_pending(sdbus::MethodCall & call);
sdbus::MethodReply clean(sdbus::MethodCall & call);
sdbus::MethodReply get_status(sdbus::MethodCall & call);
sdbus::MethodReply set_finish_action(sdbus::MethodCall & call);

enum class Scheduled { NOT_SCHEDULED, ANOTHER_TOOL, SCHEDULED };
Expand Down

0 comments on commit 9c2e215

Please sign in to comment.