FastLED 3.10.8
Loading...
Searching...
No Matches

◆ registerMethod()

template<class Sig>
bool fl::Rpc::registerMethod ( const char * name,
RpcFn< Sig > fn,
const fl::vector< fl::string > & paramNames,
const fl::string & description,
const fl::vector< fl::string > & tags,
fl::RpcMode mode = fl::RpcMode::SYNC )
inline

Definition at line 357 of file rpc.h.

361 {
362 fl::string key(name);
363 auto it = mRegistry.find(key);
364 if (it != mRegistry.end()) {
365 if (it->second.mTypeTag != detail::TypeTag<Sig>::id()) {
366 return false;
367 }
368 }
369
370 detail::RpcEntry entry;
371 entry.mTypeTag = detail::TypeTag<Sig>::id();
372 // Per-Sig dispatch fork (FastLED #3246). Low-memory targets pay only
373 // a ~50-150 B trampoline per signature via RuntimeRpcBinding instead
374 // of the ~2.1 KB TypedRpcBinding<Sig>::invokeWithReturn instantiation.
375 // Large-memory targets keep the existing fast inline-dispatch path.
376#if FL_PLATFORM_HAS_LARGE_MEMORY
377 entry.mInvoker = fl::make_shared<detail::TypedInvoker<Sig>>(fn);
378#else
379 entry.mInvoker = detail::makeRuntimeRpcBinding(fn);
380#endif
381 entry.mTypedCallable = fl::make_shared<detail::TypedCallableHolder<Sig>>(fn);
382#if FL_PLATFORM_HAS_LARGE_MEMORY
383 // Schema generator construction gated on Low-memory targets per
384 // FastLED #3081 / #3079. The schema generator is only consumed by
385 // `rpc.discover` (also gated). Skipping it on Low-memory drops
386 // `TypedSchemaGenerator<Sig>::params()` (~800 B per signature).
387 entry.mSchemaGenerator = fl::make_shared<detail::TypedSchemaGenerator<Sig>>();
388#endif
389 entry.mDescription = description;
390 entry.mTags = tags;
391 entry.mMode = mode;
392
393#if FL_PLATFORM_HAS_LARGE_MEMORY
394 if (!paramNames.empty()) {
395 entry.mSchemaGenerator->setParamNames(paramNames);
396 }
397#else
398 (void)paramNames;
399#endif
400
401 mRegistry[key] = fl::move(entry);
402 return true;
403 }
fl::UIDescription description("Demo of the Animatrix effects. @author of fx is StefanPetrick")
fl::unordered_map< fl::string, detail::RpcEntry > mRegistry
Definition rpc.h:406
fl::vector< fl::string > tags() const FL_NO_EXCEPT
Returns list of unique tags used across all methods.
Definition rpc.cpp.hpp:324
bool empty() const FL_NO_EXCEPT
constexpr remove_reference< T >::type && move(T &&t) FL_NO_EXCEPT
Definition move.h:30
shared_ptr< T > make_shared(Args &&... args) FL_NO_EXCEPT
Definition shared_ptr.h:423
fl::shared_ptr< RuntimeRpcBinding > makeRuntimeRpcBinding(fl::function< R(Args...)> fn) FL_NO_EXCEPT
static const void * id() FL_NO_EXCEPT

References description, fl::FL_NO_EXCEPT, fl::detail::TypeTag< Sig >::id(), fl::adl_barrier::make_shared(), fl::detail::makeRuntimeRpcBinding(), fl::detail::RpcEntry::mDescription, fl::detail::RpcEntry::mInvoker, fl::detail::RpcEntry::mMode, fl::adl_barrier::move(), mRegistry, fl::detail::RpcEntry::mSchemaGenerator, fl::detail::RpcEntry::mTags, fl::detail::RpcEntry::mTypedCallable, fl::detail::RpcEntry::mTypeTag, registerMethod(), fl::SYNC, and tags().

Referenced by bind(), and registerMethod().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: