FastLED 3.9.15
Loading...
Searching...
No Matches
fl::Remote Class Reference

Detailed Description

JSON-RPC server with scheduling support.

Extends Server with JSON-RPC method dispatch and time-based scheduling. Supports immediate and scheduled execution via "timestamp" field in requests.

Architecture:

  • Server: JSON-RPC I/O coordination (pull/push)
  • Rpc: Method registry and JSON-RPC execution
  • RpcScheduler: Time-based task execution
  • Remote: Coordinator that combines all three

Usage: Remote remote(requestSource, responseSink); remote.bind("setLed", [](int i, int r, int g, int b) { leds[i] = CRGB(r,g,b); }); remote.update(millis()); // pull + tick + push

Definition at line 40 of file remote.h.

#include <remote.h>

+ Inheritance diagram for fl::Remote:
+ Collaboration diagram for fl::Remote:

Classes

struct  AsyncRequest
 

Public Types

using ClearFlags = fl::RemoteClearFlags
 
template<typename Callable>
using Config = typename fl::Rpc::Config<Callable>
 Configuration for method registration (forwards to Rpc::Config)
 
using MethodInfo = fl::MethodInfo
 
using ParamInfo = fl::ParamInfo
 
using RpcResult = fl::RpcResult
 
- Public Types inherited from fl::Server
using RequestHandler = fl::function<fl::json(const fl::json&)>
 
using RequestSource = fl::function<fl::optional<fl::json>()>
 
using ResponseSink = fl::function<void(const fl::json&)>
 

Public Member Functions

 Remote (const Remote &) FL_NOEXCEPT=delete
 
 Remote (Remote &&) FL_NOEXCEPT=delete
 
 Remote (RequestSource source, ResponseSink sink)
 Construct with I/O callbacks.
 
template<typename Callable>
void bind (const char *name, Callable fn, fl::RpcMode mode=fl::RpcMode::SYNC)
 Register method by name, function, and optional mode (default SYNC)
 
template<typename Callable>
void bind (const Config< Callable > &config)
 Register method with config (name, function, optional metadata)
 
void bindAsync (const char *name, fl::function< void(fl::ResponseSend &, const fl::json &)> fn, fl::RpcMode mode=fl::RpcMode::ASYNC)
 Register async method with ResponseSend& parameter (for ASYNC/ASYNC_STREAM modes) Signature: void(ResponseSend&, const json&) The ResponseSend& parameter provides send(), sendUpdate(), sendFinal() methods.
 
void clear (ClearFlags flags)
 Clear state (bitwise OR of ClearFlags)
 
fl::size count () const
 Get number of registered methods.
 
template<class Sig>
fl::BindResult< Sig > get (const char *name) const
 Get bound method by name for direct C++ invocation.
 
bool has (const fl::string &name) const
 Check if method is registered.
 
fl::vector< MethodInfomethods () const
 Get method information for all registered methods.
 
Remoteoperator= (const Remote &) FL_NOEXCEPT=delete
 
Remoteoperator= (Remote &&) FL_NOEXCEPT=delete
 
size_t pendingCount () const
 Get number of pending scheduled calls.
 
fl::json processRpc (const fl::json &request)
 Process JSON-RPC request (with optional "timestamp" field for scheduling) Returns JSON-RPC response: {"result": ...} or {"error": {...}}.
 
void reportError (const fl::json &data)
 Send an error notification with structured data Format: {"jsonrpc":"2.0","method":"__error","params":<data>}.
 
void reportError (const fl::string &message)
 Send an error notification to the remote peer.
 
fl::json schema () const
 Returns flat schema document Format: {"schema": [["methodName", "returnType", [["param1", "type1"], ...]], ...]}.
 
void sendAsyncResponse (const char *method, const fl::json &result)
 Send async response for a previously-called async method The request ID is automatically retrieved from internal storage.
 
void sendStreamFinal (const char *method, const fl::json &result)
 Send final stream response for a streaming async method (ASYNC_STREAM mode) The request ID is automatically retrieved from internal storage and method is removed.
 
void sendStreamUpdate (const char *method, const fl::json &update)
 Send stream update for a streaming async method (ASYNC_STREAM mode) The request ID is automatically retrieved from internal storage.
 
size_t tick (u32 currentTimeMs)
 Process scheduled calls (call regularly)
 
bool unbind (const fl::string &name)
 Unregister method by name.
 
size_t update (u32 currentTimeMs)
 Main update: pull + tick + push (overrides Server::update)
 
- Public Member Functions inherited from fl::Server
 Server () FL_NOEXCEPT
 Default constructor.
 
 Server (const Server &) FL_NOEXCEPT=delete
 
 Server (RequestSource source, ResponseSink sink)
 Construct with I/O callbacks.
 
 Server (Server &&) FL_NOEXCEPT=default
 
virtual ~Server () FL_NOEXCEPT=default
 
Serveroperator= (const Server &) FL_NOEXCEPT=delete
 
Serveroperator= (Server &&) FL_NOEXCEPT=default
 
size_t pull ()
 Pull requests from source, process, queue responses.
 
size_t push ()
 Push queued responses to sink.
 
void setRequestHandler (RequestHandler handler)
 Set request handler.
 
void setRequestSource (RequestSource source)
 Set request source callback.
 
void setResponseSink (ResponseSink sink)
 Set response sink callback.
 
size_t update ()
 Main update: pull + push.
 

Protected Member Functions

void recordResult (const fl::string &funcName, const fl::json &result, u32 scheduledAt, u32 receivedAt, u32 executedAt, bool wasScheduled)
 
void scheduleFunction (u32 timestamp, u32 receivedAt, const fl::json &jsonRpcRequest)
 

Protected Attributes

fl::unordered_map< fl::string, AsyncRequestmAsyncRequests
 
fl::vector< RpcResultmResults
 
fl::Rpc mRpc
 
fl::net::RpcScheduler mScheduler
 
- Protected Attributes inherited from fl::Server
fl::vector< fl::jsonmOutgoingQueue
 
RequestHandler mRequestHandler
 
RequestSource mRequestSource
 
ResponseSink mResponseSink
 

The documentation for this class was generated from the following files: