ESPectre SDK
2.8.0-280-gac7af68
Wi-Fi CSI motion sensing for ESP32 firmware
Toggle main menu visibility
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
18
#include "
direct_websocket_protocol.h
"
19
20
namespace
espectre
{
21
22
struct
DirectWebSocketServiceConfig
{
23
std::vector<std::string>
allowed_origins
;
24
uint16_t
port
{80U};
25
size_t
max_clients
{2U};
26
size_t
outbound_queue_depth
{8U};
27
uint16_t
max_mutations_per_minute
{60U};
28
bool
allow_missing_origin
{
false
};
29
bool
allow_http_loopback_origins
{
false
};
30
};
31
32
struct
DirectWebSocketServiceDiagnostics
{
33
size_t
client_limit
{0U};
34
size_t
queue_capacity
{0U};
35
uint32_t
accepted_connections
{0U};
36
uint32_t
rejected_connections
{0U};
37
uint32_t
malformed_frames
{0U};
38
uint32_t
oversized_frames
{0U};
39
uint32_t
rate_limited_requests
{0U};
40
uint32_t
dropped_telemetry_events
{0U};
41
uint32_t
send_failures
{0U};
42
uint32_t
slow_client_disconnects
{0U};
43
size_t
queued_messages
{0U};
44
};
45
46
/** Local WebSocket endpoint used by the Native frontend after Wi-Fi is ready. */
47
class
IDirectWebSocketService
{
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;
75
virtual
DirectWebSocketServiceDiagnostics
diagnostics
()
const
= 0;
76
};
77
78
}
// namespace espectre
espectre::IDirectWebSocketService
Local WebSocket endpoint used by the Native frontend after Wi-Fi is ready.
Definition
direct_websocket_service.h:47
espectre::IDirectWebSocketService::shutdown
virtual void shutdown()=0
Stop accepting clients, close sockets, and release queued messages.
espectre::IDirectWebSocketService::client_count
virtual size_t client_count() const =0
espectre::IDirectWebSocketService::~IDirectWebSocketService
virtual ~IDirectWebSocketService()=default
espectre::IDirectWebSocketService::setup
virtual bool setup(const DirectWebSocketServiceConfig &config, RequestHandler request_handler, ClientCountCallback client_count_callback)=0
Configure and start the endpoint.
espectre::IDirectWebSocketService::loop
virtual void loop()=0
Pump deferred receive, dispatch, and send work from the frontend task.
espectre::IDirectWebSocketService::RequestHandler
std::function< std::string(const DirectWebSocketRequest &request)> RequestHandler
Definition
direct_websocket_service.h:49
espectre::IDirectWebSocketService::publish_event
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.
espectre::IDirectWebSocketService::diagnostics
virtual DirectWebSocketServiceDiagnostics diagnostics() const =0
espectre::IDirectWebSocketService::running
virtual bool running() const =0
espectre::IDirectWebSocketService::ClientCountCallback
std::function< void(size_t client_count)> ClientCountCallback
Definition
direct_websocket_service.h:50
direct_websocket_protocol.h
espectre
Definition
espectre_sdk_version.h:62
espectre::DirectWebSocketRequest
Definition
direct_websocket_protocol.h:27
espectre::DirectWebSocketServiceConfig
Definition
direct_websocket_service.h:22
espectre::DirectWebSocketServiceConfig::max_mutations_per_minute
uint16_t max_mutations_per_minute
Definition
direct_websocket_service.h:27
espectre::DirectWebSocketServiceConfig::max_clients
size_t max_clients
Definition
direct_websocket_service.h:25
espectre::DirectWebSocketServiceConfig::allow_http_loopback_origins
bool allow_http_loopback_origins
Definition
direct_websocket_service.h:29
espectre::DirectWebSocketServiceConfig::port
uint16_t port
Definition
direct_websocket_service.h:24
espectre::DirectWebSocketServiceConfig::outbound_queue_depth
size_t outbound_queue_depth
Definition
direct_websocket_service.h:26
espectre::DirectWebSocketServiceConfig::allow_missing_origin
bool allow_missing_origin
Definition
direct_websocket_service.h:28
espectre::DirectWebSocketServiceConfig::allowed_origins
std::vector< std::string > allowed_origins
Definition
direct_websocket_service.h:23
espectre::DirectWebSocketServiceDiagnostics
Definition
direct_websocket_service.h:32
espectre::DirectWebSocketServiceDiagnostics::accepted_connections
uint32_t accepted_connections
Definition
direct_websocket_service.h:35
espectre::DirectWebSocketServiceDiagnostics::rejected_connections
uint32_t rejected_connections
Definition
direct_websocket_service.h:36
espectre::DirectWebSocketServiceDiagnostics::oversized_frames
uint32_t oversized_frames
Definition
direct_websocket_service.h:38
espectre::DirectWebSocketServiceDiagnostics::slow_client_disconnects
uint32_t slow_client_disconnects
Definition
direct_websocket_service.h:42
espectre::DirectWebSocketServiceDiagnostics::send_failures
uint32_t send_failures
Definition
direct_websocket_service.h:41
espectre::DirectWebSocketServiceDiagnostics::client_limit
size_t client_limit
Definition
direct_websocket_service.h:33
espectre::DirectWebSocketServiceDiagnostics::dropped_telemetry_events
uint32_t dropped_telemetry_events
Definition
direct_websocket_service.h:40
espectre::DirectWebSocketServiceDiagnostics::rate_limited_requests
uint32_t rate_limited_requests
Definition
direct_websocket_service.h:39
espectre::DirectWebSocketServiceDiagnostics::malformed_frames
uint32_t malformed_frames
Definition
direct_websocket_service.h:37
espectre::DirectWebSocketServiceDiagnostics::queue_capacity
size_t queue_capacity
Definition
direct_websocket_service.h:34
espectre::DirectWebSocketServiceDiagnostics::queued_messages
size_t queued_messages
Definition
direct_websocket_service.h:43
src
cpp
runtime
direct_websocket_service.h
Generated by
1.17.0