cpp-msgpack-rpc
0.2.0
An RPC library implementing MessagePack RPC.
Toggle main menu visibility
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
26
#include "
msgpack_rpc/clients/impl/call_list.h
"
27
#include "
msgpack_rpc/logging/logger.h
"
28
#include "
msgpack_rpc/messages/call_result.h
"
29
#include "
msgpack_rpc/messages/parsed_message.h
"
30
#include "
msgpack_rpc/messages/parsed_response.h
"
31
#include "
msgpack_rpc/util/format_msgpack_object.h
"
32
33
namespace
msgpack_rpc::clients::impl
{
34
38
class
ReceivedMessageProcessor
{
39
public
:
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
72
private
:
74
std::shared_ptr<logging::Logger>
logger_
;
75
77
std::shared_ptr<CallList>
call_list_
;
78
};
79
80
}
// namespace msgpack_rpc::clients::impl
call_list.h
Definition of CallList class.
call_result.h
Definition of CallResult class.
msgpack_rpc::clients::impl::ReceivedMessageProcessor::operator()
void operator()(const messages::ParsedMessage &message)
Process a received message.
Definition
received_message_processor.h:55
msgpack_rpc::clients::impl::ReceivedMessageProcessor::ReceivedMessageProcessor
ReceivedMessageProcessor(std::shared_ptr< logging::Logger > logger, std::shared_ptr< CallList > call_list)
Constructor.
Definition
received_message_processor.h:46
msgpack_rpc::clients::impl::ReceivedMessageProcessor::call_list_
std::shared_ptr< CallList > call_list_
List of RPCs.
Definition
received_message_processor.h:77
msgpack_rpc::clients::impl::ReceivedMessageProcessor::logger_
std::shared_ptr< logging::Logger > logger_
Logger.
Definition
received_message_processor.h:74
format_msgpack_object.h
Definition of format_msgpack_object function.
logger.h
Definition of Logger class.
MSGPACK_RPC_DEBUG
#define MSGPACK_RPC_DEBUG(LOGGER_PTR,...)
Write a debug log.
Definition
logger.h:186
MSGPACK_RPC_WARN
#define MSGPACK_RPC_WARN(LOGGER_PTR,...)
Write a warning log.
Definition
logger.h:210
msgpack_rpc::clients::impl
Namespace of internal implementations.
Definition
i_call_future_impl.h:26
msgpack_rpc::messages::ParsedMessage
std::variant< ParsedRequest, ParsedResponse, ParsedNotification > ParsedMessage
Type of parsed messages.
Definition
parsed_message.h:33
msgpack_rpc::util::format_msgpack_object
impl::FmtMsgpackObjectProxy format_msgpack_object(const msgpack::object &object)
Format an object in msgpack library using fmt library.
Definition
format_msgpack_object.cpp:50
std
STL namespace.
parsed_message.h
Definition of ParsedMessage type.
parsed_response.h
Definition of ParsedResponse class.
src
msgpack_rpc
clients
impl
received_message_processor.h
Generated on
for cpp-msgpack-rpc by
1.18.0