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 co_return;
135 }
136
137 if constexpr (std::is_same_v<ErrorType, std::monostate>) {
138 co_await handler_(typed_params);
139 } else {
140 auto result = co_await handler_(typed_params);
141 if (!result) {
142 // Error ignored - notification handlers don't propagate errors
143 }
144 }
145 }

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