Skip to content

Commit

Permalink
dnfdaemon: Register interface methods for sdbus-cpp-2
Browse files Browse the repository at this point in the history
sdbus-cpp-2 uses different approach to registering methods and signals
on the interface.
  • Loading branch information
m-blaha committed Nov 22, 2024
1 parent 54eea4e commit 2f18a16
Show file tree
Hide file tree
Showing 10 changed files with 474 additions and 4 deletions.
4 changes: 4 additions & 0 deletions dnf5daemon-client/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ void Context::init_session(sdbus::IConnection & connection) {
// open dnf5daemon-server session
auto cfg = static_cast<DaemonCommand *>(get_selected_command())->session_config();
auto session_manager_proxy = sdbus::createProxy(connection, dnfdaemon::DBUS_NAME, dnfdaemon::DBUS_OBJECT_PATH);
#ifndef SDBUS_CPP_VERSION_2
session_manager_proxy->finishRegistration();
#endif

// set up the install root end setopts
std::map<std::string, std::string> empty_options{};
Expand All @@ -63,7 +65,9 @@ void Context::init_session(sdbus::IConnection & connection) {
// register progress bars callbacks
download_cb = std::make_unique<DownloadCB>(*this);
transaction_cb = std::make_unique<TransactionCB>(*this);
#ifndef SDBUS_CPP_VERSION_2
session_proxy->finishRegistration();
#endif
}


Expand Down
15 changes: 15 additions & 0 deletions dnf5daemon-server/services/advisory/advisory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ namespace dnfdaemon {

void Advisory::dbus_register() {
auto dbus_object = session.get_dbus_object();
#ifdef SDBUS_CPP_VERSION_2
dbus_object
->addVTable(sdbus::MethodVTableItem{
sdbus::MethodName{"list"},
sdbus::Signature{"a{sv}"},
{"options"},
sdbus::Signature{"aa{sv}"},
{"advisories"},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Advisory::list, call, session.session_locale);
},
{}})
.forInterface(INTERFACE_ADVISORY);
#else
dbus_object->registerMethod(
INTERFACE_ADVISORY,
"list",
Expand All @@ -41,6 +55,7 @@ void Advisory::dbus_register() {
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Advisory::list, call, session.session_locale);
});
#endif
}

libdnf5::advisory::AdvisoryQuery Advisory::advisory_query_from_options(
Expand Down
62 changes: 62 additions & 0 deletions dnf5daemon-server/services/base/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,67 @@ static const std::unordered_set<std::string> ALLOWED_CACHE_TYPES = {

void Base::dbus_register() {
auto dbus_object = session.get_dbus_object();
#ifdef SDBUS_CPP_VERSION_2
dbus_object
->addVTable(
sdbus::MethodVTableItem{
sdbus::MethodName{"read_all_repos"},
sdbus::Signature{""},
{},
sdbus::Signature{"b"},
{"success"},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(
*this, &Base::read_all_repos, call, session.session_locale);
},
{}},
sdbus::MethodVTableItem{
sdbus::MethodName{"clean"},
sdbus::Signature{"s"},
{"cache_type"},
sdbus::Signature{"bs"},
{"success", "error_msg"},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Base::clean, call, session.session_locale);
},
{}},
sdbus::MethodVTableItem{
sdbus::MethodName{"reset"},
sdbus::Signature{""},
{},
sdbus::Signature{"bs"},
{"success", "error_msg"},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Base::reset, call, session.session_locale);
},
{}},
sdbus::SignalVTableItem{
dnfdaemon::SIGNAL_DOWNLOAD_ADD_NEW,
sdbus::Signature{"ossx"},
{"session_object_path", "download_id", "description", "total_to_download"},
{}},
sdbus::SignalVTableItem{
dnfdaemon::SIGNAL_DOWNLOAD_PROGRESS,
sdbus::Signature{"osxx"},
{"session_object_path", "download_id", "total_to_download", "downloaded"},
{}},
sdbus::SignalVTableItem{
dnfdaemon::SIGNAL_DOWNLOAD_END,
sdbus::Signature{"osus"},
{"session_object_path", "download_id", "transfer_status", "message"},
{}},
sdbus::SignalVTableItem{
dnfdaemon::SIGNAL_DOWNLOAD_MIRROR_FAILURE,
sdbus::Signature{"ossss"},
{"session_object_path", "download_id", "message", "url", "metadata"},
{}},
sdbus::SignalVTableItem{
dnfdaemon::SIGNAL_REPO_KEY_IMPORT_REQUEST,
sdbus::Signature{"osasssx"},
{"session_object_path", "key_id", "user_ids", "key_fingerprint", "key_url", "timestamp"},
{}})
.forInterface(dnfdaemon::INTERFACE_BASE);
#else
dbus_object->registerMethod(
dnfdaemon::INTERFACE_BASE, "read_all_repos", "", {}, "b", {"success"}, [this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Base::read_all_repos, call, session.session_locale);
Expand Down Expand Up @@ -95,6 +156,7 @@ void Base::dbus_register() {
dnfdaemon::SIGNAL_REPO_KEY_IMPORT_REQUEST,
"osasssx",
{"session_object_path", "key_id", "user_ids", "key_fingerprint", "key_url", "timestamp"});
#endif
}

sdbus::MethodReply Base::read_all_repos(sdbus::MethodCall & call) {
Expand Down
23 changes: 22 additions & 1 deletion dnf5daemon-server/services/comps/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,31 @@ dnfdaemon::KeyValueMap group_to_map(libdnf5::comps::Group & libdnf_group, const

void Group::dbus_register() {
auto dbus_object = session.get_dbus_object();
#ifdef SDBUS_CPP_VERSION_2
dbus_object
->addVTable(sdbus::MethodVTableItem{
sdbus::MethodName{"list"},
sdbus::Signature{"a{sv}"},
{"options"},
sdbus::Signature{"aa{sv}"},
{"groups"},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Group::list, call, session.session_locale);
},
{}})
.forInterface(dnfdaemon::INTERFACE_GROUP);
#else
dbus_object->registerMethod(
dnfdaemon::INTERFACE_GROUP, "list", "a{sv}", "aa{sv}", [this](sdbus::MethodCall call) -> void {
dnfdaemon::INTERFACE_GROUP,
"list",
"a{sv}",
{"options"},
"aa{sv}",
{"groups"},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Group::list, call, session.session_locale);
});
#endif
}

sdbus::MethodReply Group::list(sdbus::MethodCall & call) {
Expand Down
62 changes: 60 additions & 2 deletions dnf5daemon-server/services/goal/goal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,65 @@ static std::string dbus_transaction_item_type_to_string(dnfdaemon::DbusTransacti

void Goal::dbus_register() {
auto dbus_object = session.get_dbus_object();
// TODO(mblaha) Adjust resolve method to accommodate also groups, environments,
// and modules as part of the transaction
#ifdef SDBUS_CPP_VERSION_2
dbus_object
->addVTable(
sdbus::MethodVTableItem{
sdbus::MethodName{"resolve"},
sdbus::Signature{"a{sv}"},
{"options"},
sdbus::Signature{"a(sssa{sv}a{sv})u"},
{"transaction_items", "result"},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Goal::resolve, call, session.session_locale);
},
{}},
sdbus::MethodVTableItem{
sdbus::MethodName{"get_transaction_problems_string"},
{},
{},
sdbus::Signature{"as"},
{"problems"},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(
*this, &Goal::get_transaction_problems_string, call, session.session_locale);
},
{}},
sdbus::MethodVTableItem{
sdbus::MethodName{"get_transaction_problems"},
{},
{},
sdbus::Signature{"aa{sv}"},
{"problems"},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(
*this, &Goal::get_transaction_problems, call, session.session_locale);
},
{}},
sdbus::MethodVTableItem{
sdbus::MethodName{"do_transaction"},
sdbus::Signature{"a{sv}"},
{"options"},
{},
{},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(
*this, &Goal::do_transaction, call, session.session_locale);
},
{}},
sdbus::MethodVTableItem{
sdbus::MethodName{"cancel"},
sdbus::Signature{""},
{},
sdbus::Signature{"bs"},
{"success", "error_msg"},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(
*this, &Goal::cancel, call, session.session_locale);
},
{}})
.forInterface(dnfdaemon::INTERFACE_GOAL);
#else
dbus_object->registerMethod(
dnfdaemon::INTERFACE_GOAL,
"resolve",
Expand Down Expand Up @@ -118,6 +175,7 @@ void Goal::dbus_register() {
dnfdaemon::INTERFACE_GOAL, "reset", "", {}, "", {}, [this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Goal::reset, call, session.session_locale);
});
#endif
}

sdbus::MethodReply Goal::resolve(sdbus::MethodCall & call) {
Expand Down
48 changes: 48 additions & 0 deletions dnf5daemon-server/services/offline/offline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,53 @@ Offline::Scheduled Offline::offline_transaction_scheduled() {

void Offline::dbus_register() {
auto dbus_object = session.get_dbus_object();
#ifdef SDBUS_CPP_VERSION_2
dbus_object
->addVTable(
sdbus::MethodVTableItem{
sdbus::MethodName{"cancel"},
{},
{},
sdbus::Signature{"bs"},
{"success", "error_msg"},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Offline::cancel, call, session.session_locale);
},
{}},
sdbus::MethodVTableItem{
sdbus::MethodName{"get_status"},
{},
{},
sdbus::Signature{"ba{sv}"},
{"is_pending", "transaction_status"},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(
*this, &Offline::get_status, call, session.session_locale);
},
{}},
sdbus::MethodVTableItem{
sdbus::MethodName{"clean"},
{},
{},
sdbus::Signature{"bs"},
{"success", "error_msg"},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Offline::clean, call, session.session_locale);
},
{}},
sdbus::MethodVTableItem{
sdbus::MethodName{"set_finish_action"},
sdbus::Signature{"s"},
{"action"},
sdbus::Signature{"bs"},
{"success", "error_msg"},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(
*this, &Offline::set_finish_action, call, session.session_locale);
},
{}})
.forInterface(dnfdaemon::INTERFACE_OFFLINE);
#else
dbus_object->registerMethod(
dnfdaemon::INTERFACE_OFFLINE,
"cancel",
Expand Down Expand Up @@ -93,6 +140,7 @@ void Offline::dbus_register() {
session.get_threads_manager().handle_method(
*this, &Offline::set_finish_action, call, session.session_locale);
});
#endif
}

sdbus::MethodReply Offline::get_status(sdbus::MethodCall & call) {
Expand Down
47 changes: 47 additions & 0 deletions dnf5daemon-server/services/repo/repo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,52 @@ bool keyval_repo_compare(const dnfdaemon::KeyValueMap & first, const dnfdaemon::

void Repo::dbus_register() {
auto dbus_object = session.get_dbus_object();

#ifdef SDBUS_CPP_VERSION_2
dbus_object
->addVTable(
sdbus::MethodVTableItem{
sdbus::MethodName{"list"},
sdbus::Signature{"a{sv}"},
{"options"},
sdbus::Signature{"aa{sv}"},
{"repositories"},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Repo::list, call, session.session_locale);
},
{}},
sdbus::MethodVTableItem{
sdbus::MethodName{"confirm_key"},
sdbus::Signature{"sb"},
{"key_id", "confirmed"},
sdbus::Signature{""},
{},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Repo::confirm_key, call);
},
{}},
sdbus::MethodVTableItem{
sdbus::MethodName{"enable"},
sdbus::Signature{"as"},
{"repo_ids"},
sdbus::Signature{""},
{},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Repo::enable, call, session.session_locale);
},
{}},
sdbus::MethodVTableItem{
sdbus::MethodName{"disable"},
sdbus::Signature{"as"},
{"repo_ids"},
sdbus::Signature{""},
{},
[this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Repo::disable, call, session.session_locale);
},
{}})
.forInterface(dnfdaemon::INTERFACE_REPO);
#else
dbus_object->registerMethod(
dnfdaemon::INTERFACE_REPO,
"list",
Expand Down Expand Up @@ -290,6 +336,7 @@ void Repo::dbus_register() {
dnfdaemon::INTERFACE_REPO, "disable", "as", {"repo_ids"}, "", {}, [this](sdbus::MethodCall call) -> void {
session.get_threads_manager().handle_method(*this, &Repo::disable, call, session.session_locale);
});
#endif
}

sdbus::MethodReply Repo::confirm_key(sdbus::MethodCall & call) {
Expand Down
Loading

0 comments on commit 2f18a16

Please sign in to comment.