cpp-msgpack-rpc
0.2.0
An RPC library implementing MessagePack RPC.
Loading...
Searching...
No Matches
wrapping_executor.cpp
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
#include <exception>
21
#include <functional>
22
#include <memory>
23
#include <utility>
24
25
#include "
msgpack_rpc/executors/asio_context_type.h
"
26
#include "
msgpack_rpc/executors/i_async_executor.h
"
27
#include "
msgpack_rpc/executors/i_executor.h
"
28
#include "
msgpack_rpc/executors/operation_type.h
"
29
#include "
msgpack_rpc/executors/wrap_executor.h
"
30
31
namespace
msgpack_rpc::executors
{
32
39
class
WrappingExecutor
final :
public
IAsyncExecutor {
40
public
:
46
explicit
WrappingExecutor
(std::shared_ptr<IExecutor> executor)
47
:
executor_
(
std
::move(executor)) {}
48
50
AsioContextType
&
context
(
OperationType
type)
noexcept
override
{
51
return
executor_
->context(type);
52
}
53
55
void
start
()
override
{
56
// No operation.
57
}
58
60
void
stop
()
override
{
61
// No operation.
62
}
63
65
[[nodiscard]] std::exception_ptr
last_exception
()
override
{
66
return
nullptr
;
67
}
68
70
void
on_exception
(
71
std::function<
void
(std::exception_ptr)> exception_callback)
override
{
72
// No operation.
73
(void)exception_callback;
74
}
75
77
[[nodiscard]]
bool
is_running
()
override
{
return
true
; }
78
79
private
:
81
std::shared_ptr<IExecutor>
executor_
;
82
};
83
84
std::shared_ptr<IAsyncExecutor>
wrap_executor
(
85
std::shared_ptr<IExecutor> executor) {
86
return
std::make_shared<WrappingExecutor>(std::move(executor));
87
}
88
89
}
// namespace msgpack_rpc::executors
asio_context_type.h
Definition of AsioContextType class.
msgpack_rpc::executors::WrappingExecutor::is_running
bool is_running() override
Check whether this executor is running.
Definition
wrapping_executor.cpp:77
msgpack_rpc::executors::WrappingExecutor::last_exception
std::exception_ptr last_exception() override
Get the last exception thrown in asynchronous tasks.
Definition
wrapping_executor.cpp:65
msgpack_rpc::executors::WrappingExecutor::stop
void stop() override
Stops operation.
Definition
wrapping_executor.cpp:60
msgpack_rpc::executors::WrappingExecutor::on_exception
void on_exception(std::function< void(std::exception_ptr)> exception_callback) override
Register a function called when an exception is thrown in asynchronous tasks.
Definition
wrapping_executor.cpp:70
msgpack_rpc::executors::WrappingExecutor::start
void start() override
Start internal event loops to process asynchronous tasks.
Definition
wrapping_executor.cpp:55
msgpack_rpc::executors::WrappingExecutor::WrappingExecutor
WrappingExecutor(std::shared_ptr< IExecutor > executor)
Constructor.
Definition
wrapping_executor.cpp:46
msgpack_rpc::executors::WrappingExecutor::executor_
std::shared_ptr< IExecutor > executor_
Executor.
Definition
wrapping_executor.cpp:81
msgpack_rpc::executors::WrappingExecutor::context
AsioContextType & context(OperationType type) noexcept override
Get the context in asio library.
Definition
wrapping_executor.cpp:50
i_async_executor.h
Definition of IAsyncExecutor class.
i_executor.h
Definition of IExecutor class.
msgpack_rpc::executors
Namespace of executors to process asynchronous tasks.
Definition
asio_context_type.h:24
msgpack_rpc::executors::OperationType
OperationType
Enumeration of types of operations.
Definition
operation_type.h:29
msgpack_rpc::executors::wrap_executor
std::shared_ptr< IAsyncExecutor > wrap_executor(std::shared_ptr< IExecutor > executor)
Create a wrapper of an existing executor.
Definition
wrapping_executor.cpp:84
msgpack_rpc::executors::AsioContextType
asio::io_context AsioContextType
Type of context in asio library.
Definition
asio_context_type.h:29
std
STL namespace.
operation_type.h
Definition of OperationType enumeration.
wrap_executor.h
Declaration of wrap_executor function.
src
msgpack_rpc
executors
wrapping_executor.cpp
Generated on
for cpp-msgpack-rpc by
1.14.0