Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
ipc
libmultiprocess
include
mp
type-interface.h
Go to the documentation of this file.
1
// Copyright (c) The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#ifndef MP_PROXY_TYPE_INTERFACE_H
6
#define MP_PROXY_TYPE_INTERFACE_H
7
8
#include <
mp/util.h
>
9
10
namespace
mp
{
11
template
<
typename
Interface,
typename
Impl>
12
kj::Own<typename Interface::Server>
MakeProxyServer
(
InvokeContext
& context, std::shared_ptr<Impl> impl)
13
{
14
return
kj::heap<ProxyServer<Interface>>(std::move(impl), context.
connection
);
15
}
16
17
template
<
typename
Interface,
typename
Impl>
18
kj::Own<typename Interface::Server>
CustomMakeProxyServer
(
InvokeContext
& context, std::shared_ptr<Impl>&& impl)
19
{
20
return
MakeProxyServer<Interface, Impl>
(context, std::move(impl));
21
}
22
23
template
<
typename
Impl,
typename
Value,
typename
Output>
24
void
CustomBuildField
(
TypeList
<std::unique_ptr<Impl>>,
25
Priority<1>
,
26
InvokeContext
& invoke_context,
27
Value&& value,
28
Output&& output,
29
typename
Decay
<
decltype
(output.get())>::Calls* enable =
nullptr
)
30
{
31
if
(value) {
32
using
Interface =
typename
decltype
(output.get())::Calls;
33
output.set(
CustomMakeProxyServer<Interface, Impl>
(invoke_context, std::shared_ptr<Impl>(value.release())));
34
}
35
}
36
37
template
<
typename
Impl,
typename
Value,
typename
Output>
38
void
CustomBuildField
(
TypeList
<std::shared_ptr<Impl>>,
39
Priority<2>
,
40
InvokeContext
& invoke_context,
41
Value&& value,
42
Output&& output,
43
typename
Decay
<
decltype
(output.get())>::Calls* enable =
nullptr
)
44
{
45
if
(value) {
46
using
Interface =
typename
decltype
(output.get())::Calls;
47
output.set(
CustomMakeProxyServer<Interface, Impl>
(invoke_context, std::forward<Value>(value)));
48
}
49
}
50
51
template
<
typename
Impl,
typename
Output>
52
void
CustomBuildField
(
TypeList<Impl&>
,
53
Priority<1>
,
54
InvokeContext
& invoke_context,
55
Impl& value,
56
Output&& output,
57
typename
decltype
(output.get())::Calls* enable =
nullptr
)
58
{
59
// Disable deleter so proxy server object doesn't attempt to delete the
60
// wrapped implementation when the proxy client is destroyed or
61
// disconnected.
62
using
Interface =
typename
decltype
(output.get())::Calls;
63
output.set(
CustomMakeProxyServer<Interface, Impl>
(invoke_context, std::shared_ptr<Impl>(&value, [](Impl*){})));
64
}
65
66
template
<
typename
Interface,
typename
Impl>
67
std::unique_ptr<Impl>
MakeProxyClient
(
InvokeContext
& context,
typename
Interface::Client&& client)
68
{
69
return
std::make_unique<ProxyClient<Interface>>(
70
std::move(client), &context.
connection
,
/* destroy_connection= */
false
);
71
}
72
73
template
<
typename
Interface,
typename
Impl>
74
std::unique_ptr<Impl>
CustomMakeProxyClient
(
InvokeContext
& context,
typename
Interface::Client&& client)
75
{
76
return
MakeProxyClient<Interface, Impl>
(context, kj::mv(client));
77
}
78
79
template
<
typename
LocalType,
typename
Input,
typename
ReadDest>
80
decltype
(
auto
)
CustomReadField
(
TypeList
<std::unique_ptr<LocalType>>,
81
Priority<1>
,
82
InvokeContext
& invoke_context,
83
Input&& input,
84
ReadDest&& read_dest,
85
typename
Decay
<
decltype
(input.get())>::Calls* enable =
nullptr
)
86
{
87
using
Interface =
typename
Decay
<
decltype
(input.get())>::Calls;
88
if
(
CustomHasField
(
TypeList<LocalType>
(), invoke_context, input)) {
89
return
read_dest.construct(
90
CustomMakeProxyClient<Interface, LocalType>
(invoke_context, std::move(input.get())));
91
}
92
return
read_dest.construct();
93
}
94
95
template
<
typename
LocalType,
typename
Input,
typename
ReadDest>
96
decltype
(
auto
)
CustomReadField
(
TypeList
<std::shared_ptr<LocalType>>,
97
Priority<1>
,
98
InvokeContext
& invoke_context,
99
Input&& input,
100
ReadDest&& read_dest,
101
typename
Decay
<
decltype
(input.get())>::Calls* enable =
nullptr
)
102
{
103
using
Interface =
typename
Decay
<
decltype
(input.get())>::Calls;
104
if
(
CustomHasField
(
TypeList<LocalType>
(), invoke_context, input)) {
105
return
read_dest.construct(
106
CustomMakeProxyClient<Interface, LocalType>
(invoke_context, std::move(input.get())));
107
}
108
return
read_dest.construct();
109
}
110
}
// namespace mp
111
112
#endif
// MP_PROXY_TYPE_INTERFACE_H
util.h
mp
Functions to serialize / deserialize common bitcoin types.
Definition
common-types.h:57
mp::CustomMakeProxyClient
std::unique_ptr< Impl > CustomMakeProxyClient(InvokeContext &context, typename Interface::Client &&client)
Definition
type-interface.h:74
mp::MakeProxyServer
kj::Own< typename Interface::Server > MakeProxyServer(InvokeContext &context, std::shared_ptr< Impl > impl)
Definition
type-interface.h:12
mp::CustomHasField
bool CustomHasField(TypeList< LocalTypes... >, InvokeContext &invoke_context, const Input &input)
Definition
proxy-types.h:207
mp::Decay
std::decay_t< T > Decay
Type helper abbreviating std::decay.
Definition
util.h:86
mp::CustomReadField
decltype(auto) CustomReadField(TypeList< LocalType >, Priority< 1 >, InvokeContext &invoke_context, Input &&input, ReadDest &&read_dest)
Definition
common-types.h:83
mp::CustomMakeProxyServer
kj::Own< typename Interface::Server > CustomMakeProxyServer(InvokeContext &context, std::shared_ptr< Impl > &&impl)
Definition
type-interface.h:18
mp::MakeProxyClient
std::unique_ptr< Impl > MakeProxyClient(InvokeContext &context, typename Interface::Client &&client)
Definition
type-interface.h:67
mp::CustomBuildField
void CustomBuildField(TypeList< LocalType >, Priority< 1 >, InvokeContext &invoke_context, Value &&value, Output &&output)
Definition
common-types.h:63
mp::InvokeContext
Definition
proxy-io.h:30
mp::InvokeContext::connection
Connection & connection
Definition
proxy-io.h:31
mp::Priority
Definition
util.h:109
mp::TypeList
Generic utility functions used by capnp code.
Definition
util.h:33
Generated on
for Bitcoin Core by
1.17.0