@geastack/host 0.1.14 → 0.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,9 +7,11 @@
7
7
 
8
8
  namespace gea::host {
9
9
 
10
- using GeolocationCoordinates = gea::framework::geolocation::GeolocationCoordinates;
10
+ using GeolocationCoordinates =
11
+ gea::framework::geolocation::GeolocationCoordinates;
11
12
  using GeolocationPosition = gea::framework::geolocation::GeolocationPosition;
12
- using GeolocationPositionError = gea::framework::geolocation::GeolocationPositionError;
13
+ using GeolocationPositionError =
14
+ gea::framework::geolocation::GeolocationPositionError;
13
15
  using GeolocationOptions = gea::framework::geolocation::GeolocationOptions;
14
16
 
15
17
  class AccelerometerValueProperty {
@@ -17,15 +19,12 @@ public:
17
19
  using Getter = double (*)();
18
20
 
19
21
  constexpr AccelerometerValueProperty() = default;
20
- explicit constexpr AccelerometerValueProperty(Getter getter) : getter_(getter) {}
22
+ explicit constexpr AccelerometerValueProperty(Getter getter)
23
+ : getter_(getter) {}
21
24
 
22
- double operator()() const {
23
- return getter_ ? getter_() : 0.0;
24
- }
25
+ double operator()() const { return getter_ ? getter_() : 0.0; }
25
26
 
26
- operator double() const {
27
- return (*this)();
28
- }
27
+ operator double() const { return (*this)(); }
29
28
 
30
29
  private:
31
30
  Getter getter_ = nullptr;
@@ -39,9 +38,12 @@ public:
39
38
  x(gea::framework::sensors::AccelerometerBackend::accelerationX),
40
39
  y(gea::framework::sensors::AccelerometerBackend::accelerationY),
41
40
  z(gea::framework::sensors::AccelerometerBackend::accelerationZ),
42
- accelerationX(gea::framework::sensors::AccelerometerBackend::accelerationX),
43
- accelerationY(gea::framework::sensors::AccelerometerBackend::accelerationY),
44
- accelerationZ(gea::framework::sensors::AccelerometerBackend::accelerationZ),
41
+ accelerationX(
42
+ gea::framework::sensors::AccelerometerBackend::accelerationX),
43
+ accelerationY(
44
+ gea::framework::sensors::AccelerometerBackend::accelerationY),
45
+ accelerationZ(
46
+ gea::framework::sensors::AccelerometerBackend::accelerationZ),
45
47
  gyroscopeX(gea::framework::sensors::AccelerometerBackend::gyroscopeX),
46
48
  gyroscopeY(gea::framework::sensors::AccelerometerBackend::gyroscopeY),
47
49
  gyroscopeZ(gea::framework::sensors::AccelerometerBackend::gyroscopeZ) {}
@@ -49,7 +51,9 @@ public:
49
51
  void start() const { gea::framework::sensors::AccelerometerBackend::init(); }
50
52
  void init() const { gea::framework::sensors::AccelerometerBackend::init(); }
51
53
  void close() const { gea::framework::sensors::AccelerometerBackend::close(); }
52
- void calibrateBias() const { gea::framework::sensors::AccelerometerBackend::calibrateBias(); }
54
+ void calibrateBias() const {
55
+ gea::framework::sensors::AccelerometerBackend::calibrateBias();
56
+ }
53
57
 
54
58
  AccelerometerValueProperty tiltX;
55
59
  AccelerometerValueProperty tiltY;
@@ -72,9 +76,15 @@ inline constexpr const AccelerometerFacade &imu = Accelerometer;
72
76
  class WiFiNetwork {
73
77
  public:
74
78
  explicit WiFiNetwork(double index) : index_(index) {}
75
- std::string ssid() const { return gea::framework::network::WifiBackend::scanSsidAt(index_); }
76
- double rssi() const { return gea::framework::network::WifiBackend::scanRssiAt(index_); }
77
- bool secured() const { return gea::framework::network::WifiBackend::scanSecuredAt(index_); }
79
+ std::string ssid() const {
80
+ return gea::framework::network::WifiBackend::scanSsidAt(index_);
81
+ }
82
+ double rssi() const {
83
+ return gea::framework::network::WifiBackend::scanRssiAt(index_);
84
+ }
85
+ bool secured() const {
86
+ return gea::framework::network::WifiBackend::scanSecuredAt(index_);
87
+ }
78
88
 
79
89
  private:
80
90
  double index_ = 0.0;
@@ -83,18 +93,53 @@ private:
83
93
  class WiFi {
84
94
  public:
85
95
  const WiFi &operator()() const { return *this; }
86
- bool enabled() const { return gea::framework::network::WifiBackend::enabled(); }
87
- void setEnabled(bool enabled) const { gea::framework::network::WifiBackend::setEnabled(enabled); }
88
- bool connected() const { return gea::framework::network::WifiBackend::connected(); }
89
- std::string ssid() const { return gea::framework::network::WifiBackend::ssid(); }
96
+ bool enabled() const {
97
+ return gea::framework::network::WifiBackend::enabled();
98
+ }
99
+ void setEnabled(bool enabled) const {
100
+ gea::framework::network::WifiBackend::setEnabled(enabled);
101
+ }
102
+ bool connected() const {
103
+ return gea::framework::network::WifiBackend::connected();
104
+ }
105
+ std::string ssid() const {
106
+ return gea::framework::network::WifiBackend::ssid();
107
+ }
90
108
  std::string ip() const { return gea::framework::network::WifiBackend::ip(); }
91
- std::string mac() const { return gea::framework::network::WifiBackend::mac(); }
109
+ std::string mac() const {
110
+ return gea::framework::network::WifiBackend::mac();
111
+ }
92
112
  double rssi() const { return gea::framework::network::WifiBackend::rssi(); }
93
- void configure(const std::string &ssid, const std::string &password) const { gea::framework::network::WifiBackend::configure(ssid, password); }
94
- bool waitForConnection(double timeoutMs) const { return gea::framework::network::WifiBackend::waitForConnection(timeoutMs); }
113
+ void configure(const std::string &ssid, const std::string &password) const {
114
+ gea::framework::network::WifiBackend::configure(ssid, password);
115
+ }
116
+ bool startAccessPoint(const std::string &ssid,
117
+ const std::string &password = {}) const {
118
+ return gea::framework::network::WifiBackend::startAccessPoint(ssid,
119
+ password);
120
+ }
121
+ void stopAccessPoint() const {
122
+ gea::framework::network::WifiBackend::stopAccessPoint();
123
+ }
124
+ std::string accessPointMac() const {
125
+ return gea::framework::network::WifiBackend::accessPointMac();
126
+ }
127
+ bool startCaptivePortal() const {
128
+ return gea::framework::network::WifiBackend::startCaptivePortal();
129
+ }
130
+ void stopCaptivePortal() const {
131
+ gea::framework::network::WifiBackend::stopCaptivePortal();
132
+ }
133
+ bool waitForConnection(double timeoutMs) const {
134
+ return gea::framework::network::WifiBackend::waitForConnection(timeoutMs);
135
+ }
95
136
  void startScan() const { gea::framework::network::WifiBackend::startScan(); }
96
- bool scanning() const { return gea::framework::network::WifiBackend::scanning(); }
97
- double scanCount() const { return gea::framework::network::WifiBackend::scanCount(); }
137
+ bool scanning() const {
138
+ return gea::framework::network::WifiBackend::scanning();
139
+ }
140
+ double scanCount() const {
141
+ return gea::framework::network::WifiBackend::scanCount();
142
+ }
98
143
  WiFiNetwork network(double index) const { return WiFiNetwork(index); }
99
144
  std::string scanSsidAt(double index) const { return network(index).ssid(); }
100
145
  double scanRssiAt(double index) const { return network(index).rssi(); }
@@ -103,17 +148,24 @@ public:
103
148
 
104
149
  class BluetoothKeyboard {
105
150
  public:
106
- void tap(double hid_code) const { gea::framework::bluetooth::HidBackend::keyTap(hid_code); }
107
- void down(double modifier, double hid_code) const { gea::framework::bluetooth::HidBackend::keyDown(modifier, hid_code); }
151
+ void tap(double hid_code) const {
152
+ gea::framework::bluetooth::HidBackend::keyTap(hid_code);
153
+ }
154
+ void down(double modifier, double hid_code) const {
155
+ gea::framework::bluetooth::HidBackend::keyDown(modifier, hid_code);
156
+ }
108
157
  void up() const { gea::framework::bluetooth::HidBackend::keyUp(); }
109
158
  };
110
159
 
111
160
  class BluetoothMouse {
112
161
  public:
113
- void move(double dx, double dy, double buttons = 0.0, double wheel = 0.0) const {
162
+ void move(double dx, double dy, double buttons = 0.0,
163
+ double wheel = 0.0) const {
114
164
  gea::framework::bluetooth::HidBackend::mouseMove(dx, dy, buttons, wheel);
115
165
  }
116
- void click(double button) const { gea::framework::bluetooth::HidBackend::mouseClick(button); }
166
+ void click(double button) const {
167
+ gea::framework::bluetooth::HidBackend::mouseClick(button);
168
+ }
117
169
  };
118
170
 
119
171
  class BluetoothMidi {
@@ -123,17 +175,35 @@ public:
123
175
  // advertised). send() transmits one already-framed BLE-MIDI packet — the
124
176
  // TS side owns the header/timestamp framing.
125
177
  void enable() const { gea::framework::bluetooth::HidBackend::midiEnable(); }
126
- bool bound() const { return gea::framework::bluetooth::HidBackend::midiBound(); }
127
- void send(const std::vector<double> &bytes) const { gea::framework::bluetooth::HidBackend::midiSend(bytes); }
178
+ bool bound() const {
179
+ return gea::framework::bluetooth::HidBackend::midiBound();
180
+ }
181
+ void send(const std::vector<double> &bytes) const {
182
+ gea::framework::bluetooth::HidBackend::midiSend(bytes);
183
+ }
128
184
  // Central role: scan for BLE-MIDI peripherals and connect as a GATT client.
129
185
  // Scan results use the WiFi-scan polling idiom (startScan / scanCount / *At).
130
- void startScan() const { gea::framework::bluetooth::HidBackend::midiStartScan(); }
131
- void stopScan() const { gea::framework::bluetooth::HidBackend::midiStopScan(); }
132
- bool scanning() const { return gea::framework::bluetooth::HidBackend::midiScanning(); }
133
- double scanCount() const { return gea::framework::bluetooth::HidBackend::midiScanCount(); }
134
- std::string scanNameAt(double index) const { return gea::framework::bluetooth::HidBackend::midiScanNameAt(index); }
135
- void connect(double index) const { gea::framework::bluetooth::HidBackend::midiConnect(index); }
136
- void disconnect() const { gea::framework::bluetooth::HidBackend::midiDisconnect(); }
186
+ void startScan() const {
187
+ gea::framework::bluetooth::HidBackend::midiStartScan();
188
+ }
189
+ void stopScan() const {
190
+ gea::framework::bluetooth::HidBackend::midiStopScan();
191
+ }
192
+ bool scanning() const {
193
+ return gea::framework::bluetooth::HidBackend::midiScanning();
194
+ }
195
+ double scanCount() const {
196
+ return gea::framework::bluetooth::HidBackend::midiScanCount();
197
+ }
198
+ std::string scanNameAt(double index) const {
199
+ return gea::framework::bluetooth::HidBackend::midiScanNameAt(index);
200
+ }
201
+ void connect(double index) const {
202
+ gea::framework::bluetooth::HidBackend::midiConnect(index);
203
+ }
204
+ void disconnect() const {
205
+ gea::framework::bluetooth::HidBackend::midiDisconnect();
206
+ }
137
207
  };
138
208
 
139
209
  class BluetoothHidHost {
@@ -143,21 +213,46 @@ public:
143
213
  // polling idiom as MIDI; raw input reports queue driver-side until the
144
214
  // app drains them (reportCount / reportIdAt / reportLenAt / reportByteAt
145
215
  // / clearReports) and decodes the peripheral's report format itself.
146
- void startScan() const { gea::framework::bluetooth::HidBackend::hidHostStartScan(); }
147
- void stopScan() const { gea::framework::bluetooth::HidBackend::hidHostStopScan(); }
148
- bool scanning() const { return gea::framework::bluetooth::HidBackend::hidHostScanning(); }
149
- double scanCount() const { return gea::framework::bluetooth::HidBackend::hidHostScanCount(); }
150
- std::string scanNameAt(double index) const { return gea::framework::bluetooth::HidBackend::hidHostScanNameAt(index); }
151
- void connect(double index) const { gea::framework::bluetooth::HidBackend::hidHostConnect(index); }
152
- void disconnect() const { gea::framework::bluetooth::HidBackend::hidHostDisconnect(); }
153
- bool bound() const { return gea::framework::bluetooth::HidBackend::hidHostBound(); }
154
- double reportCount() const { return gea::framework::bluetooth::HidBackend::hidHostReportCount(); }
155
- double reportIdAt(double index) const { return gea::framework::bluetooth::HidBackend::hidHostReportIdAt(index); }
156
- double reportLenAt(double index) const { return gea::framework::bluetooth::HidBackend::hidHostReportLenAt(index); }
216
+ void startScan() const {
217
+ gea::framework::bluetooth::HidBackend::hidHostStartScan();
218
+ }
219
+ void stopScan() const {
220
+ gea::framework::bluetooth::HidBackend::hidHostStopScan();
221
+ }
222
+ bool scanning() const {
223
+ return gea::framework::bluetooth::HidBackend::hidHostScanning();
224
+ }
225
+ double scanCount() const {
226
+ return gea::framework::bluetooth::HidBackend::hidHostScanCount();
227
+ }
228
+ std::string scanNameAt(double index) const {
229
+ return gea::framework::bluetooth::HidBackend::hidHostScanNameAt(index);
230
+ }
231
+ void connect(double index) const {
232
+ gea::framework::bluetooth::HidBackend::hidHostConnect(index);
233
+ }
234
+ void disconnect() const {
235
+ gea::framework::bluetooth::HidBackend::hidHostDisconnect();
236
+ }
237
+ bool bound() const {
238
+ return gea::framework::bluetooth::HidBackend::hidHostBound();
239
+ }
240
+ double reportCount() const {
241
+ return gea::framework::bluetooth::HidBackend::hidHostReportCount();
242
+ }
243
+ double reportIdAt(double index) const {
244
+ return gea::framework::bluetooth::HidBackend::hidHostReportIdAt(index);
245
+ }
246
+ double reportLenAt(double index) const {
247
+ return gea::framework::bluetooth::HidBackend::hidHostReportLenAt(index);
248
+ }
157
249
  double reportByteAt(double index, double byteIndex) const {
158
- return gea::framework::bluetooth::HidBackend::hidHostReportByteAt(index, byteIndex);
250
+ return gea::framework::bluetooth::HidBackend::hidHostReportByteAt(
251
+ index, byteIndex);
252
+ }
253
+ void clearReports() const {
254
+ gea::framework::bluetooth::HidBackend::hidHostClearReports();
159
255
  }
160
- void clearReports() const { gea::framework::bluetooth::HidBackend::hidHostClearReports(); }
161
256
  };
162
257
 
163
258
  class BluetoothConnections {
@@ -166,9 +261,15 @@ public:
166
261
  // central peer (desktop using us as keyboard/mouse), 1 = MIDI central
167
262
  // peer (DAW), 2 = HID peripheral we host (macro pad), 3 = BLE-MIDI
168
263
  // peripheral we drive (pedal/WIDI adapter).
169
- double count() const { return gea::framework::bluetooth::HidBackend::connectionCount(); }
170
- double kindAt(double index) const { return gea::framework::bluetooth::HidBackend::connectionKindAt(index); }
171
- std::string nameAt(double index) const { return gea::framework::bluetooth::HidBackend::connectionNameAt(index); }
264
+ double count() const {
265
+ return gea::framework::bluetooth::HidBackend::connectionCount();
266
+ }
267
+ double kindAt(double index) const {
268
+ return gea::framework::bluetooth::HidBackend::connectionKindAt(index);
269
+ }
270
+ std::string nameAt(double index) const {
271
+ return gea::framework::bluetooth::HidBackend::connectionNameAt(index);
272
+ }
172
273
  };
173
274
 
174
275
  class BluetoothConfig {
@@ -180,15 +281,32 @@ public:
180
281
  // polls pendingLength() each frame; on a committed inbound blob it drains
181
282
  // pendingByteAt()/consumePending() and re-serializes via setDocument().
182
283
  // The pairing trio drives the on-device pairing overlay.
183
- void setDocument(const std::vector<double> &bytes) const { gea::framework::bluetooth::HidBackend::configSetDocument(bytes); }
184
- double pendingLength() const { return gea::framework::bluetooth::HidBackend::configPendingLength(); }
185
- double pendingByteAt(double index) const { return gea::framework::bluetooth::HidBackend::configPendingByteAt(index); }
186
- void consumePending() const { gea::framework::bluetooth::HidBackend::configConsumePending(); }
187
- bool pairing() const { return gea::framework::bluetooth::HidBackend::configPairing(); }
188
- std::string pairCode() const { return gea::framework::bluetooth::HidBackend::configPairCode(); }
189
- void dismissPairing() const { gea::framework::bluetooth::HidBackend::configDismissPairing(); }
190
- // Device -> portal activity push (see BluetoothConfig::pushActivity in the TS API).
191
- void pushActivity(double index) const { gea::framework::bluetooth::HidBackend::configPushActivity(index); }
284
+ void setDocument(const std::vector<double> &bytes) const {
285
+ gea::framework::bluetooth::HidBackend::configSetDocument(bytes);
286
+ }
287
+ double pendingLength() const {
288
+ return gea::framework::bluetooth::HidBackend::configPendingLength();
289
+ }
290
+ double pendingByteAt(double index) const {
291
+ return gea::framework::bluetooth::HidBackend::configPendingByteAt(index);
292
+ }
293
+ void consumePending() const {
294
+ gea::framework::bluetooth::HidBackend::configConsumePending();
295
+ }
296
+ bool pairing() const {
297
+ return gea::framework::bluetooth::HidBackend::configPairing();
298
+ }
299
+ std::string pairCode() const {
300
+ return gea::framework::bluetooth::HidBackend::configPairCode();
301
+ }
302
+ void dismissPairing() const {
303
+ gea::framework::bluetooth::HidBackend::configDismissPairing();
304
+ }
305
+ // Device -> portal activity push (see BluetoothConfig::pushActivity in the TS
306
+ // API).
307
+ void pushActivity(double index) const {
308
+ gea::framework::bluetooth::HidBackend::configPushActivity(index);
309
+ }
192
310
  };
193
311
 
194
312
  class Bluetooth {
@@ -201,52 +319,82 @@ public:
201
319
  BluetoothConfig config;
202
320
 
203
321
  const Bluetooth &operator()() const { return *this; }
204
- bool enabled() const { return gea::framework::bluetooth::HidBackend::enabled(); }
205
- void setEnabled(bool enabled) const { gea::framework::bluetooth::HidBackend::setEnabled(enabled); }
206
- void init(const std::string &device_name, double appearance = 0.0, const std::string &mac_address = std::string()) const {
207
- gea::framework::bluetooth::HidBackend::init(device_name, appearance, mac_address);
208
- }
209
- void startAdvertising() const { gea::framework::bluetooth::HidBackend::startAdvertising(); }
210
- void stopAdvertising() const { gea::framework::bluetooth::HidBackend::stopAdvertising(); }
211
- bool connected() const { return gea::framework::bluetooth::HidBackend::connected(); }
322
+ bool enabled() const {
323
+ return gea::framework::bluetooth::HidBackend::enabled();
324
+ }
325
+ void setEnabled(bool enabled) const {
326
+ gea::framework::bluetooth::HidBackend::setEnabled(enabled);
327
+ }
328
+ void init(const std::string &device_name, double appearance = 0.0,
329
+ const std::string &mac_address = std::string()) const {
330
+ gea::framework::bluetooth::HidBackend::init(device_name, appearance,
331
+ mac_address);
332
+ }
333
+ void startAdvertising() const {
334
+ gea::framework::bluetooth::HidBackend::startAdvertising();
335
+ }
336
+ void stopAdvertising() const {
337
+ gea::framework::bluetooth::HidBackend::stopAdvertising();
338
+ }
339
+ bool connected() const {
340
+ return gea::framework::bluetooth::HidBackend::connected();
341
+ }
212
342
  bool bound() const { return gea::framework::bluetooth::HidBackend::bound(); }
213
- double batteryLevel() const { return gea::framework::bluetooth::HidBackend::batteryLevel(); }
214
- std::string mac() const { return gea::framework::bluetooth::HidBackend::mac(); }
215
- std::string deviceName() const { return gea::framework::bluetooth::HidBackend::deviceName(); }
343
+ double batteryLevel() const {
344
+ return gea::framework::bluetooth::HidBackend::batteryLevel();
345
+ }
346
+ std::string mac() const {
347
+ return gea::framework::bluetooth::HidBackend::mac();
348
+ }
349
+ std::string deviceName() const {
350
+ return gea::framework::bluetooth::HidBackend::deviceName();
351
+ }
216
352
  };
217
353
 
218
354
  class Geolocation {
219
355
  public:
220
356
  const Geolocation &operator()() const { return *this; }
221
357
 
222
- bool hasFix() const { return gea::framework::geolocation::GeolocationBackend::hasFix(); }
223
- GeolocationPosition currentPosition() const { return gea::framework::geolocation::GeolocationBackend::currentPosition(); }
358
+ bool hasFix() const {
359
+ return gea::framework::geolocation::GeolocationBackend::hasFix();
360
+ }
361
+ GeolocationPosition currentPosition() const {
362
+ return gea::framework::geolocation::GeolocationBackend::currentPosition();
363
+ }
224
364
  GeolocationCoordinates coords() const { return currentPosition().coords; }
225
- double latitude() const { return gea::framework::geolocation::GeolocationBackend::latitude(); }
226
- double longitude() const { return gea::framework::geolocation::GeolocationBackend::longitude(); }
227
- double accuracy() const { return gea::framework::geolocation::GeolocationBackend::accuracy(); }
365
+ double latitude() const {
366
+ return gea::framework::geolocation::GeolocationBackend::latitude();
367
+ }
368
+ double longitude() const {
369
+ return gea::framework::geolocation::GeolocationBackend::longitude();
370
+ }
371
+ double accuracy() const {
372
+ return gea::framework::geolocation::GeolocationBackend::accuracy();
373
+ }
228
374
 
229
- template <typename Success>
230
- void getCurrentPosition(Success success) const {
375
+ template <typename Success> void getCurrentPosition(Success success) const {
231
376
  auto position = currentPosition();
232
- if (position.hasFix) success(position);
377
+ if (position.hasFix)
378
+ success(position);
233
379
  }
234
380
 
235
381
  template <typename Success, typename Error>
236
382
  void getCurrentPosition(Success success, Error error) const {
237
383
  auto position = currentPosition();
238
- if (position.hasFix) success(position);
239
- else error(GeolocationPositionError{2.0, "Position unavailable"});
384
+ if (position.hasFix)
385
+ success(position);
386
+ else
387
+ error(GeolocationPositionError{2.0, "Position unavailable"});
240
388
  }
241
389
 
242
390
  template <typename Success, typename Error, typename Options>
243
- void getCurrentPosition(Success success, Error error, const Options &options) const {
391
+ void getCurrentPosition(Success success, Error error,
392
+ const Options &options) const {
244
393
  (void)options;
245
394
  getCurrentPosition(success, error);
246
395
  }
247
396
 
248
- template <typename Success>
249
- double watchPosition(Success success) const {
397
+ template <typename Success> double watchPosition(Success success) const {
250
398
  getCurrentPosition(success);
251
399
  return 1.0;
252
400
  }
@@ -258,7 +406,8 @@ public:
258
406
  }
259
407
 
260
408
  template <typename Success, typename Error, typename Options>
261
- double watchPosition(Success success, Error error, const Options &options) const {
409
+ double watchPosition(Success success, Error error,
410
+ const Options &options) const {
262
411
  (void)options;
263
412
  getCurrentPosition(success, error);
264
413
  return 1.0;
@@ -280,4 +429,4 @@ public:
280
429
 
281
430
  inline constexpr Navigator navigator{};
282
431
 
283
- } // namespace gea::host
432
+ } // namespace gea::host
@@ -2,6 +2,7 @@
2
2
  #pragma once
3
3
 
4
4
  #include "services/storage_service.h"
5
+ #include "platform/internal_stack.h"
5
6
 
6
7
  #include <cstdint>
7
8
  #include <cstring>
@@ -21,11 +22,10 @@ namespace gea::host {
21
22
  // setItem / removeItem / clear / key / length is a pure in-memory operation —
22
23
  // safe from ANY task, at any time (a store constructor, init(), tick(), or an
23
24
  // event handler). A mutation only flips a dirty flag; the actual flash write is
24
- // deferred to flushPending(), which the runtime calls once per frame from the
25
- // main frame task (gea_main, whose stack is in internal RAM). SPI flash — which
26
- // momentarily disables the flash cache and would fault a PSRAM-stack task — is
27
- // therefore only ever touched from that one safe task. load() likewise runs
28
- // once at boot from the frame task.
25
+ // deferred to flushPending(), which the runtime calls once per frame. Flash
26
+ // writes run on the shared internal-stack worker when the runtime stack is in
27
+ // PSRAM, so a cache-disabled flash operation cannot invalidate its own stack.
28
+ // load() runs during boot on the internal bring-up stack.
29
29
  //
30
30
  // Persistence is delegated to gea::framework::services::StorageService, which
31
31
  // stores the whole set as one opaque blob (an NVS blob on esp32, RAM elsewhere),
@@ -86,7 +86,10 @@ struct StorageFacade {
86
86
  // from the main frame task — the only context that is allowed to touch flash.
87
87
  void flushPending() {
88
88
  if (!dirty_) return;
89
- gea::framework::services::StorageService::saveKv(serialize());
89
+ const auto blob = serialize();
90
+ gea::platform::onInternalStack([&] {
91
+ gea::framework::services::StorageService::saveKv(blob);
92
+ });
90
93
  dirty_ = false;
91
94
  }
92
95
 
@@ -6,11 +6,8 @@
6
6
 
7
7
  namespace gea::host {
8
8
 
9
- #if defined(GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT) && GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT
10
- using AnimationFrameTimestamp = float;
11
- #else
12
- using AnimationFrameTimestamp = double;
13
- #endif
9
+ // Application::frame supplies integer milliseconds on every native target.
10
+ using AnimationFrameTimestamp = int;
14
11
 
15
12
  using AnimationFrameCallback = std::function<void(AnimationFrameTimestamp)>;
16
13
  using TimerCallback = std::function<void()>;
@@ -4,7 +4,9 @@
4
4
  #include <cstdint>
5
5
  #include <functional>
6
6
  #include <memory>
7
+ #include <stdexcept>
7
8
  #include <string>
9
+ #include <type_traits>
8
10
  #include <unordered_map>
9
11
  #include <utility>
10
12
  #include <vector>
@@ -95,16 +97,54 @@ struct CallbackTable {
95
97
 
96
98
  std::unordered_map<NativeWebSocketHandle, CallbackTable> &callbackTable();
97
99
 
98
- NativeWebSocketHandle create_handle(const std::string &url, const std::string &protocols = {});
100
+ NativeWebSocketHandle create_handle(const std::string &url, const std::string &protocols = {},
101
+ const std::string &headers = {});
102
+ // Typed records and arrays may be native values or identity-preserving Refs.
103
+ template <typename T>
104
+ decltype(auto) connectionValue(const T &value) {
105
+ if constexpr (requires { value.operator->(); }) return *value;
106
+ else return (value);
107
+ }
108
+ template <typename Options>
109
+ NativeWebSocketHandle create_handle(const std::string &url, const std::string &protocols,
110
+ const Options &options) {
111
+ std::string headers;
112
+ const auto &entries = connectionValue(connectionValue(options).headers);
113
+ for (std::size_t i = 0; i < entries.size(); ++i) {
114
+ const auto &header = connectionValue(entries.at(i));
115
+ if (header.name.empty() || header.name.find_first_not_of(
116
+ "!#$%&'*+-.^_`|~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") != std::string::npos ||
117
+ header.value.find_first_of("\r\n") != std::string::npos ||
118
+ header.value.find('\0') != std::string::npos) {
119
+ throw std::invalid_argument("Invalid WebSocket connection header");
120
+ }
121
+ headers += header.name + ": " + header.value + "\r\n";
122
+ }
123
+ return create_handle(url, protocols, headers);
124
+ }
99
125
  template <typename Protocols>
126
+ requires (!std::is_convertible_v<Protocols, std::string>)
100
127
  NativeWebSocketHandle create_handle(const std::string &url, const Protocols &protocols) {
101
128
  std::string joined;
102
- for (std::size_t i = 0; i < protocols.size(); ++i) {
129
+ const auto &entries = connectionValue(protocols);
130
+ for (std::size_t i = 0; i < entries.size(); ++i) {
103
131
  if (i) joined += ",";
104
- joined += protocols.at(i);
132
+ joined += entries.at(i);
105
133
  }
106
134
  return create_handle(url, joined);
107
135
  }
136
+ template <typename Protocols, typename Options>
137
+ requires (!std::is_convertible_v<Protocols, std::string>)
138
+ NativeWebSocketHandle create_handle(const std::string &url, const Protocols &protocols,
139
+ const Options &options) {
140
+ std::string joined;
141
+ const auto &entries = connectionValue(protocols);
142
+ for (std::size_t i = 0; i < entries.size(); ++i) {
143
+ if (i) joined += ",";
144
+ joined += entries.at(i);
145
+ }
146
+ return create_handle(url, joined, options);
147
+ }
108
148
  void destroy_handle(NativeWebSocketHandle handle);
109
149
 
110
150
  // Native streaming sources run on the socket's sender, never on the UI loop.
@@ -0,0 +1,89 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #pragma once
3
+
4
+ #include <exception>
5
+ #include <functional>
6
+ #include <mutex>
7
+ #include <stdexcept>
8
+
9
+ #ifdef ESP_PLATFORM
10
+ #include "esp_memory_utils.h"
11
+ #include "freertos/FreeRTOS.h"
12
+ #include "freertos/idf_additions.h"
13
+ #include "freertos/semphr.h"
14
+ #include "freertos/task.h"
15
+ #endif
16
+
17
+ namespace gea::platform {
18
+
19
+ // Flash-backed VFS and radio configuration can disable caches. Run these
20
+ // operations on an internal stack when a compiled application uses PSRAM.
21
+ inline void onInternalStack(const std::function<void()> &action, unsigned stackBytes = 6144) {
22
+ #ifdef ESP_PLATFORM
23
+ int marker;
24
+ if (esp_ptr_external_ram(&marker)) {
25
+ static std::mutex mutex;
26
+ std::lock_guard<std::mutex> lock(mutex);
27
+
28
+ struct Worker {
29
+ SemaphoreHandle_t ready = nullptr;
30
+ SemaphoreHandle_t done = nullptr;
31
+ const std::function<void()> *action = nullptr;
32
+ std::exception_ptr error;
33
+ TaskHandle_t task = nullptr;
34
+ };
35
+
36
+ static Worker worker;
37
+ if (stackBytes > 10240) {
38
+ throw std::runtime_error("Internal-stack action exceeds worker capacity");
39
+ }
40
+ if (!worker.task) {
41
+ worker.ready = xSemaphoreCreateBinary();
42
+ worker.done = xSemaphoreCreateBinary();
43
+ if (!worker.ready || !worker.done) {
44
+ if (worker.ready) {
45
+ vSemaphoreDelete(worker.ready);
46
+ }
47
+ if (worker.done) {
48
+ vSemaphoreDelete(worker.done);
49
+ }
50
+ worker.ready = worker.done = nullptr;
51
+ throw std::runtime_error("Internal-stack semaphore allocation failed");
52
+ }
53
+ const auto run = [](void *argument) {
54
+ auto &worker = *static_cast<Worker *>(argument);
55
+ for (;;) {
56
+ xSemaphoreTake(worker.ready, portMAX_DELAY);
57
+ try {
58
+ (*worker.action)();
59
+ } catch (...) {
60
+ worker.error = std::current_exception();
61
+ }
62
+ worker.action = nullptr;
63
+ xSemaphoreGive(worker.done);
64
+ }
65
+ };
66
+ if (xTaskCreateWithCaps(run, "gea_internal", 10240, &worker, 5, &worker.task,
67
+ MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT) != pdPASS) {
68
+ vSemaphoreDelete(worker.ready);
69
+ vSemaphoreDelete(worker.done);
70
+ worker.ready = worker.done = nullptr;
71
+ throw std::runtime_error("Internal-stack worker allocation failed");
72
+ }
73
+ }
74
+ worker.error = {};
75
+ worker.action = &action;
76
+ xSemaphoreGive(worker.ready);
77
+ xSemaphoreTake(worker.done, portMAX_DELAY);
78
+ if (worker.error) {
79
+ std::rethrow_exception(worker.error);
80
+ }
81
+ return;
82
+ }
83
+ #else
84
+ (void)stackBytes;
85
+ #endif
86
+ action();
87
+ }
88
+
89
+ } // namespace gea::platform