ESPectre SDK 2.8.0-280-gac7af68
Wi-Fi CSI motion sensing for ESP32 firmware
Loading...
Searching...
No Matches
direct_websocket_service.h
Go to the documentation of this file.
1/*
2 * ESPectre - Direct WebSocket Service Boundary
3 *
4 * Transport boundary for the local, versioned Direct WebSocket endpoint.
5 *
6 * Author: Francesco Pace <francesco.pace@gmail.com>
7 * SPDX-License-Identifier: GPL-3.0-only
8 * Commercial licensing available under separate agreement; see LICENSING.md.
9 */
10#pragma once
11
12#include <cstddef>
13#include <cstdint>
14#include <functional>
15#include <string>
16#include <vector>
17
19
20namespace espectre {
21
23 std::vector<std::string> allowed_origins;
24 uint16_t port{80U};
25 size_t max_clients{2U};
30};
31
45
46/** Local WebSocket endpoint used by the Native frontend after Wi-Fi is ready. */
48 public:
49 using RequestHandler = std::function<std::string(const DirectWebSocketRequest &request)>;
50 using ClientCountCallback = std::function<void(size_t client_count)>;
51
52 virtual ~IDirectWebSocketService() = default;
53
54 /** Configure and start the endpoint. Safe to call again after shutdown. */
55 virtual bool setup(const DirectWebSocketServiceConfig &config,
56 RequestHandler request_handler,
57 ClientCountCallback client_count_callback) = 0;
58 /** Pump deferred receive, dispatch, and send work from the frontend task. */
59 virtual void loop() = 0;
60 /** Stop accepting clients, close sockets, and release queued messages. */
61 virtual void shutdown() = 0;
62 virtual bool running() const = 0;
63 virtual size_t client_count() const = 0;
64
65 /**
66 * Queue a normalized event for every connected client.
67 *
68 * Telemetry events may replace an older queued event with the same name.
69 * State transitions and command responses must never be replaced by
70 * telemetry. Returns false when no client can accept the event.
71 */
72 virtual bool publish_event(const std::string &event_name,
73 const std::string &data_json,
74 bool replaceable_telemetry) = 0;
76};
77
78} // namespace espectre
Local WebSocket endpoint used by the Native frontend after Wi-Fi is ready.
virtual void shutdown()=0
Stop accepting clients, close sockets, and release queued messages.
virtual size_t client_count() const =0
virtual ~IDirectWebSocketService()=default
virtual bool setup(const DirectWebSocketServiceConfig &config, RequestHandler request_handler, ClientCountCallback client_count_callback)=0
Configure and start the endpoint.
virtual void loop()=0
Pump deferred receive, dispatch, and send work from the frontend task.
std::function< std::string(const DirectWebSocketRequest &request)> RequestHandler
virtual bool publish_event(const std::string &event_name, const std::string &data_json, bool replaceable_telemetry)=0
Queue a normalized event for every connected client.
virtual DirectWebSocketServiceDiagnostics diagnostics() const =0
virtual bool running() const =0
std::function< void(size_t client_count)> ClientCountCallback