FastLED 3.10.9
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 368 of file rpc.h.

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