cpp-msgpack-rpc 0.2.0
An RPC library implementing MessagePack RPC.
Loading...
Searching...
No Matches
received_message_processor.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 <utility>
24#include <variant>
25
32
34
39public:
46 ReceivedMessageProcessor(std::shared_ptr<logging::Logger> logger,
47 std::shared_ptr<CallList> call_list)
48 : logger_(std::move(logger)), call_list_(std::move(call_list)) {}
49
55 void operator()(const messages::ParsedMessage& message) {
56 const auto* response = std::get_if<messages::ParsedResponse>(&message);
57 if (response == nullptr) {
58 MSGPACK_RPC_WARN(logger_, "Received an invalid message.");
59 return;
60 }
61 if (response->result().is_success()) {
62 MSGPACK_RPC_DEBUG(logger_, "Received successful response (id: {})",
63 response->id());
64 } else {
65 MSGPACK_RPC_DEBUG(logger_, "Received error response (id: {}): {}",
66 response->id(),
67 util::format_msgpack_object(response->result().object()));
68 }
69 call_list_->handle(*response);
70 }
71
72private:
74 std::shared_ptr<logging::Logger> logger_;
75
77 std::shared_ptr<CallList> call_list_;
78};
79
80} // namespace msgpack_rpc::clients::impl
Definition of CallList class.
Definition of CallResult class.
void operator()(const messages::ParsedMessage &message)
Process a received message.
ReceivedMessageProcessor(std::shared_ptr< logging::Logger > logger, std::shared_ptr< CallList > call_list)
Constructor.
Definition of format_msgpack_object function.
Definition of Logger class.
#define MSGPACK_RPC_DEBUG(LOGGER_PTR,...)
Write a debug log.
Definition logger.h:186
#define MSGPACK_RPC_WARN(LOGGER_PTR,...)
Write a warning log.
Definition logger.h:210
Namespace of internal implementations.
std::variant< ParsedRequest, ParsedResponse, ParsedNotification > ParsedMessage
Type of parsed messages.
impl::FmtMsgpackObjectProxy format_msgpack_object(const msgpack::object &object)
Format an object in msgpack library using fmt library.
STL namespace.
Definition of ParsedMessage type.
Definition of ParsedResponse class.