FastLED 3.9.15
Loading...
Searching...
No Matches
rpc_registry.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/stl/json.h"
4#include "fl/stl/stdint.h" // IWYU pragma: keep
5#include "fl/stl/string.h"
6#include "fl/stl/vector.h"
7#include "fl/stl/function.h"
8#include "fl/stl/shared_ptr.h"
9#include "fl/stl/unordered_map.h" // IWYU pragma: keep
10#include "fl/remote/rpc/rpc_invokers.h" // IWYU pragma: keep
12#include "fl/stl/noexcept.h"
13
14namespace fl {
15
16// Forward declaration
17class ResponseSend;
18
19namespace detail {
20
21// =============================================================================
22// CallableHolderBase - Type-erased holder for typed callables
23// =============================================================================
24
26 virtual ~CallableHolderBase() FL_NOEXCEPT = default;
27};
28
29// =============================================================================
30// TypedCallableHolder - Holds a typed callable
31// =============================================================================
32
33template<typename Sig>
38
39// =============================================================================
40// RpcEntry - Registry entry containing method metadata and invokers
41// =============================================================================
42
56
57// =============================================================================
58// makeJsonRpcError - Helper to create JSON-RPC error responses
59// =============================================================================
60
61inline json makeJsonRpcError(int code, const fl::string& message, const json& id) {
62 json response = json::object();
63 response.set("jsonrpc", "2.0");
64
65 json error = json::object();
66 error.set("code", code);
67 error.set("message", message);
68 response.set("error", error);
69
70 if (id.has_value()) {
71 response.set("id", id);
72 }
73
74 return response;
75}
76
77} // namespace detail
78} // namespace fl
Helper class for sending responses in async/streaming RPC methods.
void set(const fl::string &key, const json &value) FL_NOEXCEPT
Definition json.h:701
static json object() FL_NOEXCEPT
Definition json.h:692
FastLED's Elegant JSON Library: fl::json
json makeJsonRpcError(int code, const fl::string &message, const json &id)
Compile-time linker keep-alive hook for a single fl::Bus.
Definition bus_traits.h:48
fl::shared_ptr< ErasedInvoker > mInvoker
fl::function< void(ResponseSend &, const json &)> mResponseAwareFn
fl::shared_ptr< ErasedSchemaGenerator > mSchemaGenerator
fl::shared_ptr< CallableHolderBase > mTypedCallable
fl::string mDescription
fl::vector< fl::string > mTags
const void * mTypeTag
RpcMode
Definition rpc_mode.h:9
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT
virtual ~CallableHolderBase() FL_NOEXCEPT=default
TypedCallableHolder(fl::function< Sig > fn)