FastLED 3.10.8
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
14#include "fl/stl/noexcept.h"
15
16namespace fl {
17
18// Forward declaration
19class ResponseSend;
20
21namespace detail {
22
23// =============================================================================
24// CallableHolderBase - Type-erased holder for typed callables
25// =============================================================================
26
28 virtual ~CallableHolderBase() FL_NO_EXCEPT = default;
29};
30
31// =============================================================================
32// TypedCallableHolder - Holds a typed callable
33// =============================================================================
34
35template<typename Sig>
40
41// =============================================================================
42// RpcEntry - Registry entry containing method metadata and invokers
43// =============================================================================
44
45struct RpcEntry {
46 const void* mTypeTag = nullptr;
52 fl::RpcMode mMode = fl::RpcMode::SYNC; // Default to synchronous
53
54 // For response-aware async methods (with ResponseSend& parameter)
56 bool mIsResponseAware = false;
57
58#if FL_PLATFORM_HAS_LARGE_MEMORY
59 // For streamed sync methods that write their JSON-RPC result directly.
60 StreamingRpcHandler mStreamingFn;
61 bool mIsStreaming = false;
62#endif
63};
64
65// =============================================================================
66// makeJsonRpcError - Helper to create JSON-RPC error responses
67// =============================================================================
68
69inline json makeJsonRpcError(int code, const fl::string& message, const json& id) FL_NO_EXCEPT {
70 json response = json::object();
71 response.set("jsonrpc", "2.0");
72
73 json error = json::object();
74 error.set("code", code);
75 error.set("message", message);
76 response.set("error", error);
77
78 if (id.has_value()) {
79 response.set("id", id);
80 }
81
82 return response;
83}
84
85} // namespace detail
86} // namespace fl
Helper class for sending responses in async/streaming RPC methods.
void set(const fl::string &key, const json &value) FL_NO_EXCEPT
Definition json.h:866
static json object() FL_NO_EXCEPT
Definition json.h:857
FastLED's Elegant JSON Library: fl::json
json makeJsonRpcError(int code, const fl::string &message, const json &id) FL_NO_EXCEPT
Compile-time linker keep-alive hook for a single fl::Bus.
Definition bus_info.h:57
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
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
fl::function< void(fl::JsonStreamWriter &, const fl::json &, const fl::json &)> StreamingRpcHandler
RpcMode
Definition rpc_mode.h:9
Base definition for an LED controller.
Definition crgb.hpp:179
virtual ~CallableHolderBase() FL_NO_EXCEPT=default
TypedCallableHolder(fl::function< Sig > fn) FL_NO_EXCEPT