49template <
typename Signature,
typename Function,
typename =
void>
59template <
typename Function,
typename Result,
typename... Parameters>
61 std::enable_if_t<!std::is_same_v<Result, void>>>
62 final :
public IMethod {
72 template <
typename InputFunction>
74 std::shared_ptr<logging::Logger> logger)
100 request.
parameters().
as<std::decay_t<Parameters>...>()));
115 notification.
parameters().
as<std::decay_t<Parameters>...>());
118 "Method {} threw an exception with a custom object: {}",
name_,
120 }
catch (
const std::exception& e) {
136 template <
typename ParameterTuple>
140 function_, std::forward<ParameterTuple>(parameter_tuple));
143 "Method {} threw an exception with a custom object: {}",
name_,
146 }
catch (
const std::exception& e) {
169template <
typename Function,
typename... Parameters>
180 template <
typename InputFunction>
182 std::shared_ptr<logging::Logger> logger)
206 request.
parameters().
as<std::decay_t<Parameters>...>());
209 "Method {} threw an exception with a custom object: {}",
name_,
213 }
catch (
const std::exception& e) {
220 request.
id(), msgpack::type::nil_t());
231 notification.
parameters().
as<std::decay_t<Parameters>...>());
234 "Method {} threw an exception with a custom object: {}",
name_,
236 }
catch (
const std::exception& e) {
263template <
typename Signature,
typename Function>
264[[nodiscard]]
inline std::unique_ptr<FunctionalMethod<Signature, Function>>
268 std::shared_ptr<logging::Logger> logger) {
269 return std::make_unique<
271 std::move(name), std::forward<Function>(function), std::move(logger));
static SerializedMessage serialize_error_response(MessageID request_id, const T &error)
Serialize an error response.
static SerializedMessage serialize_successful_response(MessageID request_id, const T &result)
Serialize a successful response.
Class of parsed notification.
const ParsedParameters & parameters() const noexcept
Get the parameters.
std::tuple< Parameters... > as() const
Get parameters as given types.
Class of parsed requests.
const ParsedParameters & parameters() const noexcept
Get the parameters.
MessageID id() const noexcept
Get the message ID.
Class of serialized message data.
decltype(auto) invoke_with_tuple(ParameterTuple &¶meter_tuple)
Invoke the function with a tuple of parameters.
messages::MethodNameView name() const noexcept override
Get the method name.
std::shared_ptr< logging::Logger > logger_
Logger.
messages::MethodName name_
Method name.
std::decay_t< Function > function_
Function.
void notify(const messages::ParsedNotification ¬ification) override
Notify this method.
messages::SerializedMessage call(const messages::ParsedRequest &request) override
Call this method.
FunctionalMethod(messages::MethodName name, InputFunction &&function, std::shared_ptr< logging::Logger > logger)
Constructor.
void notify(const messages::ParsedNotification ¬ification) override
Notify this method.
messages::MethodName name_
Method name.
std::decay_t< Function > function_
Function.
FunctionalMethod(messages::MethodNameView name, InputFunction &&function, std::shared_ptr< logging::Logger > logger)
Constructor.
messages::MethodNameView name() const noexcept override
Get the method name.
messages::SerializedMessage call(const messages::ParsedRequest &request) override
Call this method.
std::shared_ptr< logging::Logger > logger_
Logger.
Class of methods implemented by function objects.
Class of exceptions in methods.
const msgpack::object & object() const noexcept
Get the object in msgpack library.
const char * what() const noexcept override
Get the message of this exception.
Definition of IMethod class.
Definition of Logger class.
#define MSGPACK_RPC_DEBUG(LOGGER_PTR,...)
Write a debug log.
Definition of MessageSerializer class.
Definition of MethodException class.
Definition of MethodName class.
Definition of MethodNameView class.
Namespace of methods in MessagePack-RPC.
std::unique_ptr< FunctionalMethod< Signature, Function > > create_functional_method(messages::MethodName name, Function &&function, std::shared_ptr< logging::Logger > logger)
Create a method implemented by a function object.
impl::FmtMsgpackObjectProxy format_msgpack_object(const msgpack::object &object)
Format an object in msgpack library using fmt library.
Definition of ParsedNotification class.
Definition of ParsedRequest class.
Definition of SerializedMessage class.