JSON-RPC 2.0
JSON-RPC 2.0 Modern C++ Library
Loading...
Searching...
No Matches
jsonrpc::endpoint::TypedNotificationHandler< ParamsType, ErrorType > Class Template Reference

#include <typed_handlers.hpp>

Collaboration diagram for jsonrpc::endpoint::TypedNotificationHandler< ParamsType, ErrorType >:

Public Member Functions

 TypedNotificationHandler (SimpleHandler handler)
 
 TypedNotificationHandler (ExpectedHandler handler)
 
auto operator() (std::optional< nlohmann::json > params) -> asio::awaitable< void >
 

Detailed Description

template<typename ParamsType, typename ErrorType = std::monostate>
requires (FromJson<ParamsType> && HasMessageMethod<ErrorType>)
class jsonrpc::endpoint::TypedNotificationHandler< ParamsType, ErrorType >

Definition at line 103 of file typed_handlers.hpp.

Constructor & Destructor Documentation

◆ TypedNotificationHandler() [1/2]

template<typename ParamsType , typename ErrorType = std::monostate>
jsonrpc::endpoint::TypedNotificationHandler< ParamsType, ErrorType >::TypedNotificationHandler ( SimpleHandler handler)
inlineexplicit

Definition at line 116 of file typed_handlers.hpp.

118 : handler_(std::move(handler)) {
119 }

◆ TypedNotificationHandler() [2/2]

template<typename ParamsType , typename ErrorType = std::monostate>
jsonrpc::endpoint::TypedNotificationHandler< ParamsType, ErrorType >::TypedNotificationHandler ( ExpectedHandler handler)
inlineexplicit

Definition at line 121 of file typed_handlers.hpp.

123 : handler_(std::move(handler)) {
124 }

Member Function Documentation

◆ operator()()

template<typename ParamsType , typename ErrorType = std::monostate>
auto jsonrpc::endpoint::TypedNotificationHandler< ParamsType, ErrorType >::operator() ( std::optional< nlohmann::json > params) -> asio::awaitable<void>
inline

Definition at line 126 of file typed_handlers.hpp.

127 {
128 ParamsType typed_params{};
129 try {
130 if (params.has_value()) {
131 typed_params = params.value().get<ParamsType>();
132 }
133 } catch (const nlohmann::json::exception& ex) {
134 spdlog::error("Failed to parse parameters: {}", ex.what());
135 co_return;
136 }
137
138 if constexpr (std::is_same_v<ErrorType, std::monostate>) {
139 co_await handler_(typed_params);
140 } else {
141 auto result = co_await handler_(typed_params);
142 if (!result) {
143 spdlog::warn(
144 "TypedNotificationHandler ignored error: {}",
145 result.error().Message());
146 }
147 }
148 }

The documentation for this class was generated from the following file: