Skip to content

Commit

Permalink
dnfdaemon: Base.reset() API
Browse files Browse the repository at this point in the history
This call will re-create libdnf5::Base instance stored in the session.
As a result, the goal and transaction are reset as well.
  • Loading branch information
m-blaha authored and jan-kolarik committed Nov 12, 2024
1 parent 3bd3782 commit 7bc0a1c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
12 changes: 12 additions & 0 deletions dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.Base.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
<arg name="error_msg" type="s" direction="out"/>
</method>

<!--
reset:
@success: `true` if the session was successfully resetted, `false` otherwise.
@error_msg: string, contains errors encountered while resetting the session
Completely reset the session.
-->
<method name="reset">
<arg name="success" type="b" direction="out"/>
<arg name="error_msg" type="s" direction="out"/>
</method>

<!--
download_add_new:
@session_object_path: object path of the dnf5daemon session
Expand Down
29 changes: 29 additions & 0 deletions dnf5daemon-server/services/base/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#include <unistd.h>

#include <iostream>
#include <mutex>
#include <string>
#include <thread>
#include <unordered_set>
Expand Down Expand Up @@ -58,6 +59,16 @@ void Base::dbus_register() {
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Base::clean, call, session.session_locale);
});
dbus_object->registerMethod(
dnfdaemon::INTERFACE_BASE,
"reset",
"",
{},
"bs",
{"success", "error_msg"},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Base::reset, call, session.session_locale);
});

dbus_object->registerSignal(
dnfdaemon::INTERFACE_BASE,
Expand Down Expand Up @@ -147,3 +158,21 @@ sdbus::MethodReply Base::clean(sdbus::MethodCall & call) {
reply << error_msg;
return reply;
}

sdbus::MethodReply Base::reset(sdbus::MethodCall & call) {
bool success{true};
std::string error_msg{};

auto & transaction_mutex = session.get_transaction_mutex();
if (!transaction_mutex.try_lock()) {
success = false;
error_msg = "Cannot reset, an rpm transaction is running.";
} else {
std::lock_guard<std::mutex> transaction_lock(transaction_mutex, std::adopt_lock);
session.reset_base();
}
auto reply = call.createReply();
reply << success;
reply << error_msg;
return reply;
}
1 change: 1 addition & 0 deletions dnf5daemon-server/services/base/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Base : public IDbusSessionService {

private:
sdbus::MethodReply clean(sdbus::MethodCall & call);
sdbus::MethodReply reset(sdbus::MethodCall & call);
sdbus::MethodReply read_all_repos(sdbus::MethodCall & call);
};

Expand Down
4 changes: 4 additions & 0 deletions dnf5daemon-server/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,7 @@ void Session::reset_goal() {
transaction.reset(nullptr);
goal->reset();
}

void Session::reset_base() {
setup_base();
}
1 change: 1 addition & 0 deletions dnf5daemon-server/session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class Session {
std::mutex & get_transaction_mutex() { return transaction_mutex; }

void reset_goal();
void reset_base();

private:
void setup_base();
Expand Down

0 comments on commit 7bc0a1c

Please sign in to comment.