From 2f18a1659b63cbb17544f7b1d6cbe96ddb6f5d57 Mon Sep 17 00:00:00 2001 From: Marek Blaha Date: Fri, 7 Jun 2024 14:16:57 +0200 Subject: [PATCH] dnfdaemon: Register interface methods for sdbus-cpp-2 sdbus-cpp-2 uses different approach to registering methods and signals on the interface. --- dnf5daemon-client/context.cpp | 4 + .../services/advisory/advisory.cpp | 15 ++ dnf5daemon-server/services/base/base.cpp | 62 ++++++ dnf5daemon-server/services/comps/group.cpp | 23 ++- dnf5daemon-server/services/goal/goal.cpp | 62 +++++- .../services/offline/offline.cpp | 48 +++++ dnf5daemon-server/services/repo/repo.cpp | 47 +++++ dnf5daemon-server/services/rpm/rpm.cpp | 178 ++++++++++++++++++ dnf5daemon-server/session.cpp | 6 + dnf5daemon-server/session_manager.cpp | 33 +++- 10 files changed, 474 insertions(+), 4 deletions(-) diff --git a/dnf5daemon-client/context.cpp b/dnf5daemon-client/context.cpp index bcfd1bfa6..f2bb40cad 100644 --- a/dnf5daemon-client/context.cpp +++ b/dnf5daemon-client/context.cpp @@ -37,7 +37,9 @@ void Context::init_session(sdbus::IConnection & connection) { // open dnf5daemon-server session auto cfg = static_cast(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 empty_options{}; @@ -63,7 +65,9 @@ void Context::init_session(sdbus::IConnection & connection) { // register progress bars callbacks download_cb = std::make_unique(*this); transaction_cb = std::make_unique(*this); +#ifndef SDBUS_CPP_VERSION_2 session_proxy->finishRegistration(); +#endif } diff --git a/dnf5daemon-server/services/advisory/advisory.cpp b/dnf5daemon-server/services/advisory/advisory.cpp index 65e7e217f..454340264 100644 --- a/dnf5daemon-server/services/advisory/advisory.cpp +++ b/dnf5daemon-server/services/advisory/advisory.cpp @@ -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", @@ -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( diff --git a/dnf5daemon-server/services/base/base.cpp b/dnf5daemon-server/services/base/base.cpp index d1a356504..301c1c411 100644 --- a/dnf5daemon-server/services/base/base.cpp +++ b/dnf5daemon-server/services/base/base.cpp @@ -45,6 +45,67 @@ static const std::unordered_set 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); @@ -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) { diff --git a/dnf5daemon-server/services/comps/group.cpp b/dnf5daemon-server/services/comps/group.cpp index 178c44065..3164cac51 100644 --- a/dnf5daemon-server/services/comps/group.cpp +++ b/dnf5daemon-server/services/comps/group.cpp @@ -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) { diff --git a/dnf5daemon-server/services/goal/goal.cpp b/dnf5daemon-server/services/goal/goal.cpp index 27cc93db5..493f717a2 100644 --- a/dnf5daemon-server/services/goal/goal.cpp +++ b/dnf5daemon-server/services/goal/goal.cpp @@ -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", @@ -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) { diff --git a/dnf5daemon-server/services/offline/offline.cpp b/dnf5daemon-server/services/offline/offline.cpp index c9ff03fc6..48968f867 100644 --- a/dnf5daemon-server/services/offline/offline.cpp +++ b/dnf5daemon-server/services/offline/offline.cpp @@ -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", @@ -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) { diff --git a/dnf5daemon-server/services/repo/repo.cpp b/dnf5daemon-server/services/repo/repo.cpp index 521a93a3f..cee863916 100644 --- a/dnf5daemon-server/services/repo/repo.cpp +++ b/dnf5daemon-server/services/repo/repo.cpp @@ -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", @@ -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) { diff --git a/dnf5daemon-server/services/rpm/rpm.cpp b/dnf5daemon-server/services/rpm/rpm.cpp index 83cf253e5..aa8f5393a 100644 --- a/dnf5daemon-server/services/rpm/rpm.cpp +++ b/dnf5daemon-server/services/rpm/rpm.cpp @@ -33,6 +33,183 @@ along with libdnf. If not, see . void Rpm::dbus_register() { auto dbus_object = session.get_dbus_object(); +#ifdef SDBUS_CPP_VERSION_2 + dbus_object + ->addVTable( + sdbus::MethodVTableItem{ + sdbus::MethodName{"distro_sync"}, + sdbus::Signature{"asa{sv}"}, + {"pkg_specs", "options"}, + {}, + {}, + [this](sdbus::MethodCall call) -> void { + session.get_threads_manager().handle_method(*this, &Rpm::distro_sync, call, session.session_locale); + }, + {}}, + sdbus::MethodVTableItem{ + sdbus::MethodName{"downgrade"}, + sdbus::Signature{"asa{sv}"}, + {"pkg_specs", "options"}, + {}, + {}, + [this](sdbus::MethodCall call) -> void { + session.get_threads_manager().handle_method(*this, &Rpm::downgrade, call, session.session_locale); + }, + {}}, + sdbus::MethodVTableItem{ + sdbus::MethodName{"list"}, + sdbus::Signature{"a{sv}"}, + {"options"}, + sdbus::Signature{"aa{sv}"}, + {"packages"}, + [this](sdbus::MethodCall call) -> void { + session.get_threads_manager().handle_method(*this, &Rpm::list, call, session.session_locale); + }, + {}}, + sdbus::MethodVTableItem{ + sdbus::MethodName{"list_fd"}, + sdbus::Signature{"a{sv}h"}, + {"options", "file_descriptor"}, + sdbus::Signature{"s"}, + {"transfer_id"}, + [this](sdbus::MethodCall call) -> void { + session.get_threads_manager().handle_method_fd(*this, &Rpm::list_fd, call, session.session_locale); + }, + {}}, + sdbus::MethodVTableItem{ + sdbus::MethodName{"install"}, + sdbus::Signature{"asa{sv}"}, + {"pkg_specs", "options"}, + {}, + {}, + [this](sdbus::MethodCall call) -> void { + session.get_threads_manager().handle_method(*this, &Rpm::install, call, session.session_locale); + }, + {}}, + sdbus::MethodVTableItem{ + sdbus::MethodName{"upgrade"}, + sdbus::Signature{"asa{sv}"}, + {"pkg_specs", "options"}, + {}, + {}, + [this](sdbus::MethodCall call) -> void { + session.get_threads_manager().handle_method(*this, &Rpm::upgrade, call, session.session_locale); + }, + {}}, + sdbus::MethodVTableItem{ + sdbus::MethodName{"reinstall"}, + sdbus::Signature{"asa{sv}"}, + {"pkg_specs", "options"}, + {}, + {}, + [this](sdbus::MethodCall call) -> void { + session.get_threads_manager().handle_method(*this, &Rpm::reinstall, call, session.session_locale); + }, + {}}, + sdbus::MethodVTableItem{ + sdbus::MethodName{"remove"}, + sdbus::Signature{"asa{sv}"}, + {"pkg_specs", "options"}, + {}, + {}, + [this](sdbus::MethodCall call) -> void { + session.get_threads_manager().handle_method(*this, &Rpm::remove, call, session.session_locale); + }, + {}}, + sdbus::MethodVTableItem{ + sdbus::MethodName{"system_upgrade"}, + sdbus::Signature{"a{sv}"}, + {"options"}, + {}, + {}, + [this](sdbus::MethodCall call) -> void { + session.get_threads_manager().handle_method( + *this, &Rpm::system_upgrade, call, session.session_locale); + }, + {}}, + + sdbus::SignalVTableItem{ + dnfdaemon::SIGNAL_TRANSACTION_BEFORE_BEGIN, + sdbus::Signature{"ot"}, + {"session_object_path", "total"}, + {}}, + sdbus::SignalVTableItem{ + dnfdaemon::SIGNAL_TRANSACTION_AFTER_COMPLETE, + sdbus::Signature{"ob"}, + {"session_object_path", "success"}, + {}}, + sdbus::SignalVTableItem{ + dnfdaemon::SIGNAL_TRANSACTION_ELEM_PROGRESS, + sdbus::Signature{"ostt"}, + {"session_object_path", "nevra", "processed", "total"}, + {}}, + sdbus::SignalVTableItem{ + dnfdaemon::SIGNAL_TRANSACTION_ACTION_START, + sdbus::Signature{"osut"}, + {"session_object_path", "nevra", "action", "total"}, + {}}, + sdbus::SignalVTableItem{ + dnfdaemon::SIGNAL_TRANSACTION_ACTION_PROGRESS, + sdbus::Signature{"ostt"}, + {"session_object_path", "nevra", "processed", "total"}, + {}}, + sdbus::SignalVTableItem{ + dnfdaemon::SIGNAL_TRANSACTION_ACTION_STOP, + sdbus::Signature{"ost"}, + {"session_object_path", "nevra", "total"}, + {}}, + sdbus::SignalVTableItem{ + dnfdaemon::SIGNAL_TRANSACTION_SCRIPT_START, + sdbus::Signature{"osu"}, + {"session_object_path", "nevra", "scriptlet_type"}, + {}}, + sdbus::SignalVTableItem{ + dnfdaemon::SIGNAL_TRANSACTION_SCRIPT_STOP, + sdbus::Signature{"osut"}, + {"session_object_path", "nevra", "scriptlet_type", "return_code"}, + {}}, + sdbus::SignalVTableItem{ + dnfdaemon::SIGNAL_TRANSACTION_SCRIPT_ERROR, + sdbus::Signature{"osut"}, + {"session_object_path", "nevra", "scriptlet_type", "return_code"}, + {}}, + sdbus::SignalVTableItem{ + dnfdaemon::SIGNAL_TRANSACTION_VERIFY_START, + sdbus::Signature{"ot"}, + {"session_object_path", "total"}, + {}}, + sdbus::SignalVTableItem{ + dnfdaemon::SIGNAL_TRANSACTION_VERIFY_PROGRESS, + sdbus::Signature{"ott"}, + {"session_object_path", "processed", "total"}, + {}}, + sdbus::SignalVTableItem{ + dnfdaemon::SIGNAL_TRANSACTION_VERIFY_STOP, + sdbus::Signature{"ot"}, + {"session_object_path", "total"}, + {}}, + sdbus::SignalVTableItem{ + dnfdaemon::SIGNAL_TRANSACTION_TRANSACTION_START, + sdbus::Signature{"ot"}, + {"session_object_path", "total"}, + {}}, + sdbus::SignalVTableItem{ + dnfdaemon::SIGNAL_TRANSACTION_TRANSACTION_PROGRESS, + sdbus::Signature{"ott"}, + {"session_object_path", "processed", "total"}, + {}}, + sdbus::SignalVTableItem{ + dnfdaemon::SIGNAL_TRANSACTION_TRANSACTION_STOP, + sdbus::Signature{"ot"}, + {"session_object_path", "total"}, + {}}, + sdbus::SignalVTableItem{ + dnfdaemon::SIGNAL_TRANSACTION_UNPACK_ERROR, + sdbus::Signature{"os"}, + {"session_object_path", "nevra"}, + {}}) + .forInterface(dnfdaemon::INTERFACE_RPM); +#else dbus_object->registerMethod( dnfdaemon::INTERFACE_RPM, "distro_sync", @@ -192,6 +369,7 @@ void Rpm::dbus_register() { {"session_object_path", "total"}); dbus_object->registerSignal( dnfdaemon::INTERFACE_RPM, dnfdaemon::SIGNAL_TRANSACTION_UNPACK_ERROR, "os", {"session_object_path", "nevra"}); +#endif } std::vector get_filter_patterns(dnfdaemon::KeyValueMap options, const std::string & option) { diff --git a/dnf5daemon-server/session.cpp b/dnf5daemon-server/session.cpp index 2ff8ffea5..ad677c384 100644 --- a/dnf5daemon-server/session.cpp +++ b/dnf5daemon-server/session.cpp @@ -159,7 +159,10 @@ Session::Session( for (auto & s : services) { s->dbus_register(); } + +#ifndef SDBUS_CPP_VERSION_2 dbus_object->finishRegistration(); +#endif } Session::~Session() { @@ -268,7 +271,10 @@ bool Session::check_authorization( const sdbus::ObjectPath object_path{"/org/freedesktop/PolicyKit1/Authority"}; const SDBUS_INTERFACE_NAME_TYPE interface_name{"org.freedesktop.PolicyKit1.Authority"}; auto polkit_proxy = sdbus::createProxy(connection, destination_name, object_path); + +#ifndef SDBUS_CPP_VERSION_2 polkit_proxy->finishRegistration(); +#endif // call CheckAuthorization method sdbus::Struct> auth_result; diff --git a/dnf5daemon-server/session_manager.cpp b/dnf5daemon-server/session_manager.cpp index 8ea9d2c8e..e6494199d 100644 --- a/dnf5daemon-server/session_manager.cpp +++ b/dnf5daemon-server/session_manager.cpp @@ -47,6 +47,31 @@ SessionManager::~SessionManager() { void SessionManager::dbus_register() { dbus_object = sdbus::createObject(*connection, dnfdaemon::DBUS_OBJECT_PATH); +#ifdef SDBUS_CPP_VERSION_2 + dbus_object + ->addVTable( + sdbus::MethodVTableItem{ + sdbus::MethodName{"open_session"}, + sdbus::Signature{"a{sv}"}, + {"options"}, + sdbus::Signature{"o"}, + {"session_object_path"}, + [this](sdbus::MethodCall call) -> void { + threads_manager.handle_method(*this, &SessionManager::open_session, call); + }, + {}}, + sdbus::MethodVTableItem{ + sdbus::MethodName{"close_session"}, + sdbus::Signature{"o"}, + {"session_object_path"}, + sdbus::Signature{"b"}, + {"success"}, + [this](sdbus::MethodCall call) -> void { + threads_manager.handle_method(*this, &SessionManager::close_session, call); + }, + {}}) + .forInterface(dnfdaemon::INTERFACE_SESSION_MANAGER); +#else dbus_object->registerMethod( dnfdaemon::INTERFACE_SESSION_MANAGER, "open_session", @@ -69,14 +94,20 @@ void SessionManager::dbus_register() { }); dbus_object->finishRegistration(); +#endif + // register signal handler for NameOwnerChanged name_changed_proxy = sdbus::createProxy( *connection, SDBUS_SERVICE_NAME_TYPE{"org.freedesktop.DBus"}, sdbus::ObjectPath{"/org/freedesktop/DBus"}); name_changed_proxy->registerSignalHandler( - "org.freedesktop.DBus", "NameOwnerChanged", [this](sdbus::Signal signal) -> void { + SDBUS_INTERFACE_NAME_TYPE{"org.freedesktop.DBus"}, + SDBUS_SIGNAL_NAME_TYPE{"NameOwnerChanged"}, + [this](sdbus::Signal signal) -> void { threads_manager.handle_signal(*this, &SessionManager::on_name_owner_changed, signal); }); +#ifndef SDBUS_CPP_VERSION_2 name_changed_proxy->finishRegistration(); +#endif }