FastLED 3.9.15
Loading...
Searching...
No Matches
rpc_invokers.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/stl/json.h"
4#include "fl/stl/tuple.h"
5#include "fl/stl/function.h"
6#include "fl/stl/vector.h"
10#include "fl/stl/noexcept.h"
11
12namespace fl {
13namespace detail {
14
15// =============================================================================
16// TypeTag - Unique identifier for signatures at runtime
17// =============================================================================
18
19template<typename Sig>
20struct TypeTag {
21 static const void* id() {
22 static const char tag = 0;
23 return &tag;
24 }
25};
26
27// =============================================================================
28// ErasedInvoker - Type-erased interface for JSON transport invocation
29// =============================================================================
30
32public:
33 virtual ~ErasedInvoker() FL_NOEXCEPT = default;
35};
36
37// =============================================================================
38// ErasedSchemaGenerator - Type-erased interface for schema generation
39// =============================================================================
40
42public:
44 virtual void setParamNames(const fl::vector<fl::string>& names) = 0;
45
46 // Flat tuple format: [["name", "type"], ...] optimized for low-memory devices
47 virtual json params() const = 0;
48 virtual const char* resultTypeName() const = 0;
49};
50
51// =============================================================================
52// TypedSchemaGenerator - Generates schema for a specific signature
53// =============================================================================
54
55template<typename Sig>
57public:
58 void setParamNames(const fl::vector<fl::string>& names) override {
59 mParamNames = names;
60 }
61
62 // Flat tuple format: [["name", "type"], ...] optimized for low-memory devices
63 json params() const override {
65 }
66
67 const char* resultTypeName() const override {
69 }
70
71private:
73};
74
75// =============================================================================
76// TypedInvoker - Invokes typed functions via JSON transport
77// =============================================================================
78
79template<typename Sig>
81
82// Specialization for non-void return types
83template<typename R, typename... Args>
84class TypedInvoker<R(Args...)> : public ErasedInvoker {
85public:
86 TypedInvoker(fl::function<R(Args...)> fn) : mBinding(fn) {}
87
89 return mBinding.invokeWithReturn(args);
90 }
91
92private:
94};
95
96// Specialization for void return type
97template<typename... Args>
98class TypedInvoker<void(Args...)> : public ErasedInvoker {
99public:
100 TypedInvoker(fl::function<void(Args...)> fn) : mBinding(fn) {}
101
106
107private:
108 TypedRpcBinding<void(Args...)> mBinding;
109};
110
111} // namespace detail
112} // namespace fl
virtual fl::tuple< TypeConversionResult, json > invoke(const json &args)=0
virtual ~ErasedInvoker() FL_NOEXCEPT=default
virtual const char * resultTypeName() const =0
virtual json params() const =0
virtual void setParamNames(const fl::vector< fl::string > &names)=0
virtual ~ErasedSchemaGenerator() FL_NOEXCEPT=default
TypedRpcBinding< R(Args...)> mBinding
TypedInvoker(fl::function< R(Args...)> fn)
fl::tuple< TypeConversionResult, json > invoke(const json &args) override
fl::tuple< TypeConversionResult, json > invoke(const json &args) override
TypedInvoker(fl::function< void(Args...)> fn)
TypedRpcBinding< void(Args...)> mBinding
void setParamNames(const fl::vector< fl::string > &names) override
const char * resultTypeName() const override
fl::vector< fl::string > mParamNames
json params() const override
FastLED's Elegant JSON Library: fl::json
Compile-time linker keep-alive hook for a single fl::Bus.
Definition bus_traits.h:48
tuple< typename fl::decay< Ts >::type... > make_tuple(Ts &&... args) FL_NOEXCEPT
Definition tuple.h:104
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31
Base definition for an LED controller.
Definition crgb.hpp:179
corkscrew_args args
Definition old.h:149
#define FL_NOEXCEPT
static const void * id()