FastLED 3.9.15
Loading...
Searching...
No Matches

◆ bindAsync()

void fl::Rpc::bindAsync ( const char * name,
fl::function< void(ResponseSend &, const json &)> fn,
fl::RpcMode mode = fl::RpcMode::ASYNC )

Bind async method with ResponseSend& parameter (for ASYNC/ASYNC_STREAM modes) Signature: void(ResponseSend&, const json&) The ResponseSend& parameter is automatically injected with request ID and response sink The json& parameter contains the raw JSON params from the request.

EXAMPLE: rpc.bindAsync("longTask", [](ResponseSend& send, const json& params) { // ACK already sent automatically // Do work... send.send(json::object().set("value", 42)); // Send result });

Definition at line 32 of file rpc.cpp.hpp.

34 {
35 fl::string key(name);
36
37 detail::RpcEntry entry;
38 entry.mTypeTag = detail::TypeTag<void(const json&)>::id();
39 entry.mMode = mode;
40 entry.mIsResponseAware = true;
41 entry.mResponseAwareFn = fl::move(fn);
42
43#if FL_PLATFORM_HAS_LARGE_MEMORY
44 // Create schema generator for void(json) signature (params not decomposed).
45 // Gated on Low-memory per FastLED #3081 / #3079 (rpc.discover unreachable).
46 entry.mSchemaGenerator = fl::make_shared<detail::TypedSchemaGenerator<void(const json&)>>();
47#endif
48 entry.mDescription = "";
49 entry.mTags = {};
50
51 // Create a placeholder invoker (actual invocation handled in handle())
52 struct PlaceholderInvoker : public detail::ErasedInvoker {
53 fl::tuple<TypeConversionResult, json> invoke(const json&) override {
54 // Should not be called - handle() will call mResponseAwareFn directly
55 return fl::make_tuple(TypeConversionResult::success(), json(nullptr));
56 }
57 };
58 entry.mInvoker = fl::make_shared<PlaceholderInvoker>();
59
60 mRegistry[key] = fl::move(entry);
61}
fl::unordered_map< fl::string, detail::RpcEntry > mRegistry
Definition rpc.h:387
constexpr remove_reference< T >::type && move(T &&t) FL_NOEXCEPT
Definition s16x16x4.h:28
shared_ptr< T > make_shared(Args &&... args) FL_NOEXCEPT
Definition shared_ptr.h:414
tuple< typename fl::decay< Ts >::type... > make_tuple(Ts &&... args) FL_NOEXCEPT
Definition tuple.h:104
auto invoke(F &&f, T1 &&t1, Args &&... args) FL_NOEXCEPT -> enable_if_t< is_member_function_pointer< typename remove_reference< F >::type >::value &&!detail::use_pointer_syntax< T1 >::value, decltype((fl::forward< T1 >(t1).*f)(fl::forward< Args >(args)...))>
Definition functional.h:43

References fl::invoke(), fl::make_shared(), fl::make_tuple(), fl::detail::RpcEntry::mDescription, fl::detail::RpcEntry::mInvoker, fl::detail::RpcEntry::mIsResponseAware, fl::detail::RpcEntry::mMode, fl::fl::move(), mRegistry, fl::detail::RpcEntry::mResponseAwareFn, fl::detail::RpcEntry::mSchemaGenerator, fl::detail::RpcEntry::mTags, fl::detail::RpcEntry::mTypeTag, and fl::TypeConversionResult::success().

+ Here is the call graph for this function: