23 FL_DBG(
"Unregistered RPC function: " << name);
38 FL_WARN(
"No pending async request for method: " << method);
47 response.set(
"jsonrpc",
"2.0");
49 response.set(
"result",
result);
54 FL_DBG(
"Sent async response for " << method <<
" (id=" <<
requestId <<
")");
62 FL_WARN(
"No pending async request for method: " << method);
71 response.set(
"jsonrpc",
"2.0");
76 response.set(
"result", resultObj);
81 FL_DBG(
"Sent stream update for " << method <<
" (id=" <<
requestId <<
")");
89 FL_WARN(
"No pending async request for method: " << method);
98 response.set(
"jsonrpc",
"2.0");
103 resultObj.
set(
"stop",
true);
104 response.set(
"result", resultObj);
109 FL_DBG(
"Sent stream final for " << method <<
" (id=" <<
requestId <<
")");
117 params.
set(
"message", message);
126 notification.
set(
"jsonrpc",
"2.0");
127 notification.
set(
"method",
"__error");
128 notification.
set(
"params", data);
137 if (request.
contains(
"timestamp") && request[
"timestamp"].
is_int()) {
138 timestamp =
static_cast<u32
>(request[
"timestamp"].
as_int().
value());
144 if (timestamp == 0) {
158 if (response.contains(
"__async") && response[
"__async"].as_bool().value_or(
false)) {
162 nullResponse.
set(
"__skip",
true);
173 if (response.contains(
"result") && request.
contains(
"method")) {
175 recordResult(funcName, response[
"result"], 0, receivedAt, receivedAt,
false);
182 FL_DBG(
"RPC: Scheduled function - result will be pushed after execution");
187 response.set(
"id", request[
"id"]);
189 response.set(
"result",
fl::json(
nullptr));
190 response.set(
"scheduled",
true);
197 fl::json requestCopy = jsonRpcRequest;
201 mScheduler.schedule(timestamp, [
this, requestCopy, timestamp, receivedAt, funcName]() {
208 if (response.contains(
"result") && requestCopy.
contains(
"method")) {
209 recordResult(funcName, response[
"result"], timestamp, receivedAt, executedAt,
true);
213 FL_DBG(
"Scheduled RPC: " << funcName <<
" at " << timestamp);
217 mResults.push_back({funcName,
result, scheduledAt, receivedAt, executedAt, wasScheduled});
237 if ((flags & ClearFlags::Results) != ClearFlags::None) {
239 FL_DBG(
"Cleared RPC results");
241 if ((flags & ClearFlags::Scheduled) != ClearFlags::None) {
243 FL_DBG(
"Cleared scheduled RPC calls");
245 if ((flags & ClearFlags::Functions) != ClearFlags::None) {
247 FL_DBG(
"Cleared registered RPC functions");
274 size_t executed =
tick(currentTimeMs);
279 response.set(
"result", r.result);
286 return processed + executed + sent;
303 for (fl::size i = 0; i < jsonMethods.
size(); i++) {
321 for (fl::size j = 0; j < params.
size(); j++) {
FastLED chrono implementation - duration types for time measurements.
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 automat...
void recordResult(const fl::string &funcName, const fl::json &result, u32 scheduledAt, u32 receivedAt, u32 executedAt, bool wasScheduled)
size_t tick(u32 currentTimeMs)
Process scheduled calls (call regularly)
size_t update(u32 currentTimeMs)
Main update: pull + tick + push (overrides Server::update)
fl::net::RpcScheduler mScheduler
bool has(const fl::string &name) const
Check if method is registered.
void scheduleFunction(u32 timestamp, u32 receivedAt, const fl::json &jsonRpcRequest)
size_t pendingCount() const
Get number of pending scheduled calls.
fl::MethodInfo MethodInfo
fl::unordered_map< fl::string, AsyncRequest > mAsyncRequests
fl::RemoteClearFlags ClearFlags
fl::vector< MethodInfo > methods() const
Get method information for all registered methods.
void reportError(const fl::string &message)
Send an error notification to the remote peer.
void sendAsyncResponse(const char *method, const fl::json &result)
Send async response for a previously-called async method The request ID is automatically retrieved fr...
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 r...
fl::vector< RpcResult > mResults
bool unbind(const fl::string &name)
Unregister method by name.
void clear(ClearFlags flags)
Clear state (bitwise OR of ClearFlags)
fl::json processRpc(const fl::json &request)
Process JSON-RPC request (with optional "timestamp" field for scheduling) Returns JSON-RPC response: ...
Remote(RequestSource source, ResponseSink sink)
Construct with I/O callbacks.
size_t push()
Push queued responses to sink.
size_t update()
Main update: pull + push.
fl::vector< fl::json > mOutgoingQueue
size_t pull()
Pull requests from source, process, queue responses.
fl::function< fl::optional< fl::json >()> RequestSource
void setRequestHandler(RequestHandler handler)
Set request handler.
Server() FL_NOEXCEPT
Default constructor.
fl::function< void(const fl::json &)> ResponseSink
ResponseSink mResponseSink
const char * c_str() const FL_NOEXCEPT
fl::optional< i64 > as_int() const FL_NOEXCEPT
bool is_array() const FL_NOEXCEPT
bool is_int() const FL_NOEXCEPT
size_t size() const FL_NOEXCEPT
bool contains(size_t idx) const FL_NOEXCEPT
fl::optional< fl::string > as_string() const FL_NOEXCEPT
void set(const fl::string &key, const json &value) FL_NOEXCEPT
static json object() FL_NOEXCEPT
FastLED's Elegant JSON Library: fl::json
Centralized logging categories for FastLED hardware interfaces and subsystems.
constexpr remove_reference< T >::type && move(T &&t) FL_NOEXCEPT
constexpr remove_reference< T >::type && move(T &&t) FL_NOEXCEPT
constexpr int type_rank< T >::value
fl::u32 millis()
Universal millisecond timer - returns milliseconds since system startup.
expected< T, E > result
Alias for expected (Rust-style naming)
Base definition for an LED controller.
fl::vector< ParamInfo > params
fl::vector< fl::string > tags