refactor: use new tr_variant API in rpcimpl (#6456)

* refactor: tr_rpc_request_exec_json takes a std::function callback

* refactor: tr_rpc_request_exec_json callback takes a tr_variant&&

* refactor: use new tr_variant API in rpcimpl.cc

* refactor: tr_rpc_request_exec_json() now takes a const& to the request

* fixup! refactor: use new tr_variant API in rpcimpl.cc

* chore: rename function to tr_rpc_request_exec()

* chore: remove unused DetailsDialog::Impl::build_torrent_ids_variant_list()

* refactor: minor copyediting in rpcimpl.cc getTorrents()

* refactor: split handler methods between sync, async

* refactor: remove unused args_out param from AsyncHandlers

* chore: fix new readability-inconsistent-declaration-parameter-name warning
This commit is contained in:
Charles Kerr
2024-01-02 22:14:43 -06:00
committed by GitHub
parent 10d047005a
commit 22cde5d4b9
10 changed files with 777 additions and 1056 deletions

View File

@@ -83,7 +83,7 @@ public:
void add_torrent(Glib::RefPtr<Torrent> const& torrent, bool do_notify);
bool add_from_url(Glib::ustring const& url);
void send_rpc_request(tr_variant const* request, int64_t tag, std::function<void(tr_variant&)> const& response_func);
void send_rpc_request(tr_variant const& request, int64_t tag, std::function<void(tr_variant&)> const& response_func);
void commit_prefs_change(tr_quark key);
@@ -967,7 +967,7 @@ void Session::start_now(tr_torrent_id_t id)
auto* args = tr_variantDictAddDict(&top, TR_KEY_arguments, 1);
auto* ids = tr_variantDictAddList(args, TR_KEY_ids, 1);
tr_variantListAddInt(ids, id);
exec(&top);
exec(top);
}
void Session::Impl::update()
@@ -1186,19 +1186,16 @@ bool core_read_rpc_response_idle(tr_variant& response)
return false;
}
void core_read_rpc_response(tr_session* /*session*/, tr_variant* response, gpointer /*user_data*/)
void core_read_rpc_response(tr_session* /*session*/, tr_variant&& response)
{
auto owned_response = std::make_shared<tr_variant>();
*owned_response.get() = false;
std::swap(*owned_response, *response);
auto owned_response = std::make_shared<tr_variant>(std::move(response));
Glib::signal_idle().connect([owned_response]() mutable { return core_read_rpc_response_idle(*owned_response); });
}
} // namespace
void Session::Impl::send_rpc_request(
tr_variant const* request,
tr_variant const& request,
int64_t tag,
std::function<void(tr_variant&)> const& response_func)
{
@@ -1216,7 +1213,7 @@ void Session::Impl::send_rpc_request(
gtr_message(fmt::format("request: [{}]", tr_variantToStr(request, TR_VARIANT_FMT_JSON_LEAN)));
#endif
tr_rpc_request_exec_json(session_, request, core_read_rpc_response, nullptr);
tr_rpc_request_exec(session_, request, core_read_rpc_response);
}
}
@@ -1234,7 +1231,7 @@ void Session::port_test()
tr_variantDictAddStrView(&request, TR_KEY_method, "port-test");
tr_variantDictAddInt(&request, TR_KEY_tag, tag);
impl_->send_rpc_request(
&request,
request,
tag,
[this](auto& response)
{
@@ -1265,7 +1262,7 @@ void Session::blocklist_update()
tr_variantDictAddStrView(&request, TR_KEY_method, "blocklist-update");
tr_variantDictAddInt(&request, TR_KEY_tag, tag);
impl_->send_rpc_request(
&request,
request,
tag,
[this](auto& response)
{
@@ -1291,7 +1288,7 @@ void Session::blocklist_update()
****
***/
void Session::exec(tr_variant const* request)
void Session::exec(tr_variant const& request)
{
auto const tag = nextTag;
++nextTag;