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
30
31namespace msgpack_rpc::executors {
32
39class WrappingExecutor final : public IAsyncExecutor {
40public:
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
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
79private:
81 std::shared_ptr<IExecutor> executor_;
82};
83
84std::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
Definition of AsioContextType class.
bool is_running() override
Check whether this executor is running.
std::exception_ptr last_exception() override
Get the last exception thrown in asynchronous tasks.
void stop() override
Stops operation.
void on_exception(std::function< void(std::exception_ptr)> exception_callback) override
Register a function called when an exception is thrown in asynchronous tasks.
void start() override
Start internal event loops to process asynchronous tasks.
WrappingExecutor(std::shared_ptr< IExecutor > executor)
Constructor.
std::shared_ptr< IExecutor > executor_
Executor.
AsioContextType & context(OperationType type) noexcept override
Get the context in asio library.
Definition of IAsyncExecutor class.
Definition of IExecutor class.
Namespace of executors to process asynchronous tasks.
OperationType
Enumeration of types of operations.
std::shared_ptr< IAsyncExecutor > wrap_executor(std::shared_ptr< IExecutor > executor)
Create a wrapper of an existing executor.
asio::io_context AsioContextType
Type of context in asio library.
STL namespace.
Definition of OperationType enumeration.
Declaration of wrap_executor function.