Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
ipc
libmultiprocess
include
mp
type-function.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_FUNCTION_H
6
#define MP_PROXY_TYPE_FUNCTION_H
7
8
#include <
mp/util.h
>
9
10
namespace
mp
{
12
template
<
typename
Result
,
typename
... Args>
13
class
ProxyCallbackImpl
final :
public
ProxyCallback
<std::function<Result(Args...)>>
14
{
15
using
Fn
= std::function<Result(Args...)>;
16
Fn
m_fn
;
17
18
public
:
19
ProxyCallbackImpl
(
Fn
fn) :
m_fn
(
std
::move(fn)) {}
20
Result
call
(Args&&...
args
)
override
{
return
m_fn
(std::forward<Args>(
args
)...); }
21
};
22
23
template
<
typename
Value,
typename
FnR,
typename
... FnParams,
typename
Output>
24
void
CustomBuildField
(
TypeList
<std::function<FnR(FnParams...)>>,
25
Priority<1>
,
26
InvokeContext
& invoke_context,
27
Value&& value,
28
Output&& output)
29
{
30
if
(value) {
31
using
Interface =
typename
decltype
(output.get())::Calls;
32
using
Callback =
ProxyCallbackImpl
<FnR, FnParams...>;
33
output.set(kj::heap<
ProxyServer<Interface>
>(
34
std::make_shared<Callback>(std::forward<Value>(value)), invoke_context.
connection
));
35
}
36
}
37
38
// ProxyCallFn class is needed because c++11 doesn't support auto lambda parameters.
39
// It's equivalent c++14: [invoke_context](auto&& params) {
40
// invoke_context->call(std::forward<decltype(params)>(params)...)
41
template
<
typename
InvokeContext>
42
struct
ProxyCallFn
43
{
44
InvokeContext
m_proxy
;
45
46
template
<
typename
... CallParams>
47
decltype
(
auto
)
operator
()(CallParams&&... params) {
return
this->m_proxy->call(std::forward<CallParams>(params)...); }
48
};
49
50
template
<
typename
FnR,
typename
... FnParams,
typename
Input,
typename
ReadDest>
51
decltype
(
auto
)
CustomReadField
(
TypeList
<std::function<FnR(FnParams...)>> types,
52
Priority<1>
,
53
InvokeContext
& invoke_context,
54
Input&& input,
55
ReadDest&& read_dest)
56
{
57
if
(
CustomHasField
(types, invoke_context, input)) {
58
using
Interface =
typename
Decay
<
decltype
(input.get())>::Calls;
59
auto
client = std::make_shared<ProxyClient<Interface>>(
60
input.get(), &invoke_context.
connection
,
/* destroy_connection= */
false
);
61
return
read_dest.construct(
ProxyCallFn
<
decltype
(client)>{std::move(client)});
62
}
63
return
read_dest.construct();
64
};
65
}
// namespace mp
66
67
#endif
// MP_PROXY_TYPE_FUNCTION_H
args
ArgsManager & args
Definition
bitcoind.cpp:277
mp::ProxyCallback
Wrapper around std::function for passing std::function objects between client and servers.
Definition
proxy.h:326
mp::ProxyCallbackImpl
Adapter to convert ProxyCallback object call to function object call.
Definition
type-function.h:14
mp::ProxyCallbackImpl::m_fn
Fn m_fn
Definition
type-function.h:16
mp::ProxyCallbackImpl::call
Result call(Args &&... args) override
Definition
type-function.h:20
mp::ProxyCallbackImpl::Fn
std::function< Result(Args...)> Fn
Definition
type-function.h:15
mp::ProxyCallbackImpl::ProxyCallbackImpl
ProxyCallbackImpl(Fn fn)
Definition
type-function.h:19
util.h
mp
Functions to serialize / deserialize common bitcoin types.
Definition
common-types.h:57
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::CustomBuildField
void CustomBuildField(TypeList< LocalType >, Priority< 1 >, InvokeContext &invoke_context, Value &&value, Output &&output)
Definition
common-types.h:63
std
Definition
common.h:29
wallet::feebumper::Result
Result
Definition
feebumper.h:24
mp::InvokeContext
Definition
proxy-io.h:30
mp::InvokeContext::connection
Connection & connection
Definition
proxy-io.h:31
mp::Priority
Definition
util.h:109
mp::ProxyCallFn
Definition
type-function.h:43
mp::ProxyCallFn::m_proxy
InvokeContext m_proxy
Definition
type-function.h:44
mp::ProxyServer
Definition
proxy.h:28
mp::TypeList
Generic utility functions used by capnp code.
Definition
util.h:33
Generated on
for Bitcoin Core by
1.17.0