cpp-msgpack-rpc
0.2.0
An RPC library implementing MessagePack RPC.
Toggle main menu visibility
Loading...
Searching...
No Matches
call.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 <chrono>
23
#include <memory>
24
#include <utility>
25
26
#include "
msgpack_rpc/clients/impl/call_future_impl.h
"
27
#include "
msgpack_rpc/clients/impl/call_promise.h.h
"
28
#include "
msgpack_rpc/common/status.h
"
29
#include "
msgpack_rpc/executors/i_executor.h
"
30
#include "
msgpack_rpc/executors/operation_type.h
"
31
#include "
msgpack_rpc/executors/timer.h
"
32
#include "
msgpack_rpc/messages/call_result.h
"
33
34
namespace
msgpack_rpc::clients::impl
{
35
39
class
Call
{
40
public
:
47
Call
(
const
std::shared_ptr<executors::IExecutor>& executor,
48
std::chrono::steady_clock::time_point deadline)
49
:
promise_
(deadline),
50
timeout_timer_
(executor,
executors
::OperationType::CALLBACK) {}
51
59
template
<
typename
OnTimeout>
60
void
set_timeout
(std::chrono::steady_clock::time_point deadline,
61
OnTimeout&& on_timeout) {
62
timeout_timer_
.
async_sleep_until
(
63
deadline, std::forward<OnTimeout>(on_timeout));
64
}
65
71
[[nodiscard]] std::shared_ptr<CallFutureImpl>
future
() const noexcept {
72
return
promise_
.
future
();
73
}
74
80
void
set
(
const
messages::CallResult
& result) {
promise_
.
set
(result); }
81
87
void
set
(
const
Status
& error) {
promise_
.
set
(error); }
88
89
private
:
91
CallPromise
promise_
;
92
94
executors::Timer
timeout_timer_
;
95
};
96
97
}
// namespace msgpack_rpc::clients::impl
call_future_impl.h
Definition of CallFutureImpl class.
call_promise.h.h
Definition of CallPromise class.
call_result.h
Definition of CallResult class.
msgpack_rpc::clients::impl::CallPromise
Class to set results of RPCs.
Definition
call_promise.h.h:35
msgpack_rpc::clients::impl::CallPromise::set
void set(messages::CallResult result)
Set a result.
Definition
call_promise.h.h:50
msgpack_rpc::clients::impl::CallPromise::future
std::shared_ptr< CallFutureImpl > future() const noexcept
Get the future.
Definition
call_promise.h.h:64
msgpack_rpc::clients::impl::Call::set_timeout
void set_timeout(std::chrono::steady_clock::time_point deadline, OnTimeout &&on_timeout)
Set timeout.
Definition
call.h:60
msgpack_rpc::clients::impl::Call::future
std::shared_ptr< CallFutureImpl > future() const noexcept
Get the future object to set and get the result of this RPC.
Definition
call.h:71
msgpack_rpc::clients::impl::Call::promise_
CallPromise promise_
Object to set the result of this RPC.
Definition
call.h:91
msgpack_rpc::clients::impl::Call::Call
Call(const std::shared_ptr< executors::IExecutor > &executor, std::chrono::steady_clock::time_point deadline)
Constructor.
Definition
call.h:47
msgpack_rpc::clients::impl::Call::set
void set(const messages::CallResult &result)
Set the result.
Definition
call.h:80
msgpack_rpc::clients::impl::Call::set
void set(const Status &error)
Set an error.
Definition
call.h:87
msgpack_rpc::clients::impl::Call::timeout_timer_
executors::Timer timeout_timer_
Timer of timeout.
Definition
call.h:94
msgpack_rpc::Status
Class of statuses.
Definition
status.h:34
msgpack_rpc::executors::Timer
Class of timers to call functions later.
Definition
timer.h:37
msgpack_rpc::executors::Timer::async_sleep_until
void async_sleep_until(std::chrono::steady_clock::time_point time, Function &&function)
Asynchronously sleep until a time point.
Definition
timer.h:56
msgpack_rpc::messages::CallResult
Class of results of methods.
Definition
call_result.h:35
i_executor.h
Definition of IExecutor class.
msgpack_rpc::clients::impl
Namespace of internal implementations.
Definition
i_call_future_impl.h:26
msgpack_rpc::executors
Namespace of executors to process asynchronous tasks.
Definition
asio_context_type.h:24
operation_type.h
Definition of OperationType enumeration.
status.h
Definition of Status class.
timer.h
Definition of Timer class.
src
msgpack_rpc
clients
impl
call.h
Generated on
for cpp-msgpack-rpc by
1.18.0