FastLED 3.9.15
Loading...
Searching...
No Matches
stream_server.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef FASTLED_HAS_NETWORKING
4
6#include "fl/stl/asio/http/native_server.h" // IWYU pragma: keep
8#include "fl/stl/string.h"
9#include "fl/stl/unique_ptr.h"
10#include "fl/stl/flat_map.h"
11#include "fl/stl/vector.h"
12#include "fl/stl/noexcept.h"
13
14namespace fl {
15namespace net {
16namespace http {
17
23public:
27 HttpStreamServer(u16 port = 8080, u32 heartbeatIntervalMs = 30000);
28
30 ~HttpStreamServer() FL_NOEXCEPT override;
31
32 // Connection Management (override from HttpStreamTransport)
33
36 bool connect() override;
37
39 void disconnect() override;
40
43 bool isConnected() const override;
44
45 // Server-specific methods
46
49 u16 port() const;
50
53 void acceptClients();
54
57 size_t getClientCount() const;
58
61 void disconnectClient(u32 clientId);
62
65 fl::vector<u32> getClientIds() const;
66
67protected:
68 // Abstract methods implementation (from HttpStreamTransport)
69
73 int sendData(fl::span<const u8> data) override;
74
79 int recvData(fl::span<u8> buffer) override;
80
82 void triggerReconnect() override;
83
84private:
86 struct ClientState {
87 u32 clientId;
88 bool httpHeaderReceived;
89 bool httpHeaderSent;
90 HttpRequestParser requestParser;
91 fl::vector<u8> pendingData; // Data waiting to be processed
92 fl::string headerBuffer; // Accumulates partial HTTP header reads
93
94 // Default constructor (required for map operations)
95 ClientState() FL_NOEXCEPT
96 : clientId(0)
97 , httpHeaderReceived(false)
98 , httpHeaderSent(false)
99 , requestParser()
100 , pendingData()
101 {
102 }
103
104 ClientState(u32 id)
105 : clientId(id)
106 , httpHeaderReceived(false)
107 , httpHeaderSent(false)
108 , requestParser()
109 , pendingData()
110 {
111 }
112 };
113
117 bool readHttpRequestHeader(u32 clientId);
118
122 bool sendHttpResponseHeader(u32 clientId);
123
127 bool processClientData(u32 clientId);
128
132 ClientState* getOrCreateClientState(u32 clientId);
133
136 void removeClientState(u32 clientId);
137
139 fl::unique_ptr<NativeHttpServer> mNativeServer;
140
142 u16 mPort;
143
145 fl::flat_map<u32, ClientState> mClientStates;
146
148 fl::vector<u8> mRecvBuffer;
149
151 u32 mLastProcessedClientId;
152};
153
154} // namespace http
155} // namespace net
156} // namespace fl
157
158#endif // FASTLED_HAS_NETWORKING
Base class for HTTP streaming transport Implements RequestSource and ResponseSink for Remote class Ma...
unsigned char u8
Definition stdint.h:131
::fl::net::http::HttpStreamServer HttpStreamServer
Definition rpc.h:18
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT