cpp-msgpack-rpc 0.2.0
An RPC library implementing MessagePack RPC.
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
31
32namespace msgpack_rpc::clients {
33
39class Client {
40public:
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>
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
123private:
125 std::shared_ptr<impl::IClientImpl> impl_;
126};
127
128} // namespace msgpack_rpc::clients
Definition of CallFuture class.
Class of future object to wait for asynchronous RPCs.
Definition call_future.h:40
std::shared_ptr< impl::IClientImpl > impl_
Object of the internal implementation.
Definition client.h:125
std::shared_ptr< executors::IExecutor > executor()
Get the executor.
Definition client.h:119
CallFuture< std::decay_t< Result > > async_call(messages::MethodNameView method_name, const Parameters &... parameters)
Asynchronously call a method.
Definition client.h:70
Client(std::shared_ptr< impl::IClientImpl > impl)
Constructor.
Definition client.h:49
std::decay_t< Result > call(messages::MethodNameView method_name, const Parameters &... parameters)
Synchronously call a method.
Definition client.h:89
void stop()
Stop processing of this client.
Definition client.h:58
void notify(messages::MethodNameView method_name, const Parameters &... parameters)
Notify to a method.
Definition client.h:105
Definition of IClientImpl class.
Definition of IExecutor class.
Definition of MethodNameView class.
Namespace of internal implementations.
ParametersSerializer< Parameters... > make_parameters_serializer(const Parameters &... parameters)
Create ParametersSerializer object.
Namespace of clients.
Definition call_future.h:30
STL namespace.
Definition of ParametersSerializer class.