mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 23:29:12 +01:00
27c7e8e5a581 Merge chaincodelabs/libmultiprocess#172: refactor: fix warnings from clang-tidy-20 and bitcoin-tidy 2fe87d016be4 Merge chaincodelabs/libmultiprocess#173: doc: Fix error string typo 57a65b854664 clang-tidy: Suppress bitcoin-nontrivial-threadlocal error 0d8012f656fe Merge chaincodelabs/libmultiprocess#165: clang-tidy: fix warnings introduced in version 19 3a96cdc18f2d clang-tidy: Fix bugprone-move-forwarding-reference error c1e8c1a02864 clang-tidy: Fix bugprone-move-forwarding-reference errors aa19285303ff use ranges transform a78137ca73b8 make member function const ca3226ec8ab7 replace custom tuple unpacking code with `std::apply` 949fe85fc91f replace SFINAE trick with `if constexpr` 44ee4b40b89a doc: Fix error string typo git-subtree-dir: src/ipc/libmultiprocess git-subtree-split: 27c7e8e5a581b3c41330e758951251ef11807b11
113 lines
3.9 KiB
C++
113 lines
3.9 KiB
C++
// Copyright (c) 2025 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#ifndef MP_PROXY_TYPE_INTERFACE_H
|
|
#define MP_PROXY_TYPE_INTERFACE_H
|
|
|
|
#include <mp/util.h>
|
|
|
|
namespace mp {
|
|
template <typename Interface, typename Impl>
|
|
kj::Own<typename Interface::Server> MakeProxyServer(InvokeContext& context, std::shared_ptr<Impl> impl)
|
|
{
|
|
return kj::heap<ProxyServer<Interface>>(std::move(impl), context.connection);
|
|
}
|
|
|
|
template <typename Interface, typename Impl>
|
|
kj::Own<typename Interface::Server> CustomMakeProxyServer(InvokeContext& context, std::shared_ptr<Impl>&& impl)
|
|
{
|
|
return MakeProxyServer<Interface, Impl>(context, std::move(impl));
|
|
}
|
|
|
|
template <typename Impl, typename Value, typename Output>
|
|
void CustomBuildField(TypeList<std::unique_ptr<Impl>>,
|
|
Priority<1>,
|
|
InvokeContext& invoke_context,
|
|
Value&& value,
|
|
Output&& output,
|
|
typename Decay<decltype(output.get())>::Calls* enable = nullptr)
|
|
{
|
|
if (value) {
|
|
using Interface = typename decltype(output.get())::Calls;
|
|
output.set(CustomMakeProxyServer<Interface, Impl>(invoke_context, std::shared_ptr<Impl>(value.release())));
|
|
}
|
|
}
|
|
|
|
template <typename Impl, typename Value, typename Output>
|
|
void CustomBuildField(TypeList<std::shared_ptr<Impl>>,
|
|
Priority<2>,
|
|
InvokeContext& invoke_context,
|
|
Value&& value,
|
|
Output&& output,
|
|
typename Decay<decltype(output.get())>::Calls* enable = nullptr)
|
|
{
|
|
if (value) {
|
|
using Interface = typename decltype(output.get())::Calls;
|
|
output.set(CustomMakeProxyServer<Interface, Impl>(invoke_context, std::forward<Value>(value)));
|
|
}
|
|
}
|
|
|
|
template <typename Impl, typename Output>
|
|
void CustomBuildField(TypeList<Impl&>,
|
|
Priority<1>,
|
|
InvokeContext& invoke_context,
|
|
Impl& value,
|
|
Output&& output,
|
|
typename decltype(output.get())::Calls* enable = nullptr)
|
|
{
|
|
// Disable deleter so proxy server object doesn't attempt to delete the
|
|
// wrapped implementation when the proxy client is destroyed or
|
|
// disconnected.
|
|
using Interface = typename decltype(output.get())::Calls;
|
|
output.set(CustomMakeProxyServer<Interface, Impl>(invoke_context, std::shared_ptr<Impl>(&value, [](Impl*){})));
|
|
}
|
|
|
|
template <typename Interface, typename Impl>
|
|
std::unique_ptr<Impl> MakeProxyClient(InvokeContext& context, typename Interface::Client&& client)
|
|
{
|
|
return std::make_unique<ProxyClient<Interface>>(
|
|
std::move(client), &context.connection, /* destroy_connection= */ false);
|
|
}
|
|
|
|
template <typename Interface, typename Impl>
|
|
std::unique_ptr<Impl> CustomMakeProxyClient(InvokeContext& context, typename Interface::Client&& client)
|
|
{
|
|
return MakeProxyClient<Interface, Impl>(context, kj::mv(client));
|
|
}
|
|
|
|
template <typename LocalType, typename Input, typename ReadDest>
|
|
decltype(auto) CustomReadField(TypeList<std::unique_ptr<LocalType>>,
|
|
Priority<1>,
|
|
InvokeContext& invoke_context,
|
|
Input&& input,
|
|
ReadDest&& read_dest,
|
|
typename Decay<decltype(input.get())>::Calls* enable = nullptr)
|
|
{
|
|
using Interface = typename Decay<decltype(input.get())>::Calls;
|
|
if (input.has()) {
|
|
return read_dest.construct(
|
|
CustomMakeProxyClient<Interface, LocalType>(invoke_context, std::move(input.get())));
|
|
}
|
|
return read_dest.construct();
|
|
}
|
|
|
|
template <typename LocalType, typename Input, typename ReadDest>
|
|
decltype(auto) CustomReadField(TypeList<std::shared_ptr<LocalType>>,
|
|
Priority<1>,
|
|
InvokeContext& invoke_context,
|
|
Input&& input,
|
|
ReadDest&& read_dest,
|
|
typename Decay<decltype(input.get())>::Calls* enable = nullptr)
|
|
{
|
|
using Interface = typename Decay<decltype(input.get())>::Calls;
|
|
if (input.has()) {
|
|
return read_dest.construct(
|
|
CustomMakeProxyClient<Interface, LocalType>(invoke_context, std::move(input.get())));
|
|
}
|
|
return read_dest.construct();
|
|
}
|
|
} // namespace mp
|
|
|
|
#endif // MP_PROXY_TYPE_INTERFACE_H
|