|
FastLED 3.10.8
|
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:
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
#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_NO_EXCEPT=delete | |
| Remote (Remote &&) FL_NO_EXCEPT=delete | |
| Remote (RequestSource source, ResponseSink sink) FL_NO_EXCEPT | |
| Construct with I/O callbacks. | |
| Remote (RequestSource source, ResponseSink sink, ResponseStreamSink streamSink) FL_NO_EXCEPT | |
| Construct with I/O callbacks, including streamed response output. | |
| template<typename Callable> | |
| void | bind (const char *name, Callable fn, fl::RpcMode mode=fl::RpcMode::SYNC) FL_NO_EXCEPT |
| Register method by name, function, and optional mode (default SYNC) | |
| template<typename Callable> | |
| void | bind (const Config< Callable > &config) FL_NO_EXCEPT |
| 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) FL_NO_EXCEPT |
| 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 | bindStreaming (const char *name, fl::StreamingRpcHandler fn) FL_NO_EXCEPT |
| Register method that streams its JSON-RPC result directly to the transport. | |
| void | clear (ClearFlags flags) FL_NO_EXCEPT |
| Clear state (bitwise OR of ClearFlags) | |
| fl::size | count () const FL_NO_EXCEPT |
| Get number of registered methods. | |
| template<class Sig> | |
| fl::BindResult< Sig > | get (const char *name) const FL_NO_EXCEPT |
| Get bound method by name for direct C++ invocation. | |
| bool | has (const fl::string &name) const FL_NO_EXCEPT |
| Check if method is registered. | |
| fl::vector< MethodInfo > | methods () const FL_NO_EXCEPT |
| Get method information for all registered methods. | |
| Remote & | operator= (const Remote &) FL_NO_EXCEPT=delete |
| Remote & | operator= (Remote &&) FL_NO_EXCEPT=delete |
| size_t | pendingCount () const FL_NO_EXCEPT |
| Get number of pending scheduled calls. | |
| fl::json | processRpc (const fl::json &request) FL_NO_EXCEPT |
| Process JSON-RPC request (with optional "timestamp" field for scheduling) Returns JSON-RPC response: {"result": ...} or {"error": {...}}. | |
| void | reportError (const fl::json &data) FL_NO_EXCEPT |
| Send an error notification with structured data Format: {"jsonrpc":"2.0","method":"__error","params":<data>}. | |
| void | reportError (const fl::string &message) FL_NO_EXCEPT |
| Send an error notification to the remote peer. | |
| fl::json | schema () const FL_NO_EXCEPT |
| Returns flat schema document Format: {"schema": [["methodName", "returnType", [["param1", "type1"], ...]], ...]}. | |
| void | sendAsyncResponse (const char *method, const fl::json &result) FL_NO_EXCEPT |
| 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) FL_NO_EXCEPT |
| 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) FL_NO_EXCEPT |
| 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) FL_NO_EXCEPT |
| Process scheduled calls (call regularly) | |
| bool | unbind (const fl::string &name) FL_NO_EXCEPT |
| Unregister method by name. | |
| size_t | update (u32 currentTimeMs) FL_NO_EXCEPT |
| Main update: pull + tick + push (overrides Server::update) | |
Public Member Functions inherited from fl::Server | |
| Server () FL_NO_EXCEPT | |
| Default constructor. | |
| Server (const Server &) FL_NO_EXCEPT=delete | |
| Server (RequestSource source, ResponseSink sink) FL_NO_EXCEPT | |
| Construct with I/O callbacks. | |
| Server (Server &&) FL_NO_EXCEPT=default | |
| virtual | ~Server () FL_NO_EXCEPT=default |
| Server & | operator= (const Server &) FL_NO_EXCEPT=delete |
| Server & | operator= (Server &&) FL_NO_EXCEPT=default |
| size_t | pull () FL_NO_EXCEPT |
| Pull requests from source, process, queue responses. | |
| size_t | push () FL_NO_EXCEPT |
| Push queued responses to sink. | |
| void | setRequestHandler (RequestHandler handler) FL_NO_EXCEPT |
| Set request handler. | |
| void | setRequestSource (RequestSource source) FL_NO_EXCEPT |
| Set request source callback. | |
| void | setResponseSink (ResponseSink sink) FL_NO_EXCEPT |
| Set response sink callback. | |
| void | setResponseStreamSink (ResponseStreamSink sink) FL_NO_EXCEPT |
| Set streaming response sink callback. | |
| size_t | update () FL_NO_EXCEPT |
| Main update: pull + push. | |
Protected Attributes | |
| fl::Rpc | mRpc |
Protected Attributes inherited from fl::Server | |
| fl::vector< fl::json > | mOutgoingQueue |
| RequestHandler | mRequestHandler |
| RequestSource | mRequestSource |
| ResponseSink | mResponseSink |