cpp-msgpack-rpc
0.2.0
An RPC library implementing MessagePack RPC.
Toggle main menu visibility
Loading...
Searching...
No Matches
client.h
Go to the documentation of this file.
1
/*
2
* Copyright 2023 MusicScience37 (Kenta Kabashima)
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
20
#pragma once
21
22
#include <memory>
23
#include <type_traits>
24
#include <utility>
25
26
#include "
msgpack_rpc/clients/call_future.h
"
27
#include "
msgpack_rpc/clients/impl/i_client_impl.h
"
28
#include "
msgpack_rpc/clients/impl/parameters_serializer.h
"
29
#include "
msgpack_rpc/executors/i_executor.h
"
30
#include "
msgpack_rpc/messages/method_name_view.h
"
31
32
namespace
msgpack_rpc::clients
{
33
39
class
Client
{
40
public
:
49
explicit
Client
(std::shared_ptr<impl::IClientImpl>
impl
)
50
:
impl_
(
std
::move(
impl
)) {}
51
58
void
stop
() {
impl_
->stop(); }
59
69
template
<
typename
Result,
typename
... Parameters>
70
[[nodiscard]]
CallFuture<std::decay_t<Result>
>
async_call
(
71
messages::MethodNameView
method_name,
const
Parameters&... parameters) {
72
return
CallFuture<std::decay_t<Result>
>{
impl_
->async_call(
73
method_name,
impl::make_parameters_serializer
(parameters...))};
74
}
75
88
template
<
typename
Result,
typename
... Parameters>
89
std::decay_t<Result>
call
(
90
messages::MethodNameView
method_name,
const
Parameters&... parameters) {
91
return
async_call<Result>
(method_name, parameters...).get_result();
92
}
93
104
template
<
typename
... Parameters>
105
void
notify
(
106
messages::MethodNameView
method_name,
const
Parameters&... parameters) {
107
impl_
->notify(
108
method_name,
impl::make_parameters_serializer
(parameters...));
109
}
110
119
[[nodiscard]] std::shared_ptr<executors::IExecutor>
executor
() {
120
return
impl_
->executor();
121
}
122
123
private
:
125
std::shared_ptr<impl::IClientImpl>
impl_
;
126
};
127
128
}
// namespace msgpack_rpc::clients
call_future.h
Definition of CallFuture class.
msgpack_rpc::clients::CallFuture
Class of future object to wait for asynchronous RPCs.
Definition
call_future.h:40
msgpack_rpc::clients::Client::impl_
std::shared_ptr< impl::IClientImpl > impl_
Object of the internal implementation.
Definition
client.h:125
msgpack_rpc::clients::Client::executor
std::shared_ptr< executors::IExecutor > executor()
Get the executor.
Definition
client.h:119
msgpack_rpc::clients::Client::async_call
CallFuture< std::decay_t< Result > > async_call(messages::MethodNameView method_name, const Parameters &... parameters)
Asynchronously call a method.
Definition
client.h:70
msgpack_rpc::clients::Client::Client
Client(std::shared_ptr< impl::IClientImpl > impl)
Constructor.
Definition
client.h:49
msgpack_rpc::clients::Client::call
std::decay_t< Result > call(messages::MethodNameView method_name, const Parameters &... parameters)
Synchronously call a method.
Definition
client.h:89
msgpack_rpc::clients::Client::stop
void stop()
Stop processing of this client.
Definition
client.h:58
msgpack_rpc::clients::Client::notify
void notify(messages::MethodNameView method_name, const Parameters &... parameters)
Notify to a method.
Definition
client.h:105
msgpack_rpc::messages::MethodNameView
Class of method names.
Definition
method_name_view.h:39
i_client_impl.h
Definition of IClientImpl class.
i_executor.h
Definition of IExecutor class.
method_name_view.h
Definition of MethodNameView class.
msgpack_rpc::clients::impl
Namespace of internal implementations.
Definition
i_call_future_impl.h:26
msgpack_rpc::clients::impl::make_parameters_serializer
ParametersSerializer< Parameters... > make_parameters_serializer(const Parameters &... parameters)
Create ParametersSerializer object.
Definition
parameters_serializer.h:176
msgpack_rpc::clients
Namespace of clients.
Definition
call_future.h:30
std
STL namespace.
parameters_serializer.h
Definition of ParametersSerializer class.
include
msgpack_rpc
clients
client.h
Generated on
for cpp-msgpack-rpc by
1.18.0