@dittolive/ditto 4.8.2 → 4.9.0-alpha.1
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.
- package/DittoReactNative.podspec +0 -2
- package/README.md +2 -2
- package/node/ditto.cjs.js +952 -532
- package/node/ditto.darwin-arm64.node +0 -0
- package/node/ditto.darwin-x64.node +0 -0
- package/node/ditto.linux-arm.node +0 -0
- package/node/ditto.linux-arm64.node +0 -0
- package/node/ditto.linux-x64.node +0 -0
- package/node/ditto.win32-x64.node +0 -0
- package/package.json +3 -3
- package/react-native/android/CMakeLists.txt +8 -10
- package/react-native/android/build.gradle +5 -5
- package/react-native/android/dittoffi/src/attachment_observer_interfaces.cpp +1 -0
- package/react-native/android/dittoffi/src/attachment_observer_interfaces.h +75 -0
- package/react-native/android/dittoffi/src/connection_request.cpp +1 -0
- package/react-native/android/dittoffi/src/connection_request.h +56 -0
- package/react-native/android/dittoffi/src/crash_reporter.cpp +1 -0
- package/react-native/android/dittoffi/src/crash_reporter.h +40 -0
- package/react-native/android/dittoffi/src/dittoffi_java.i +42 -0
- package/react-native/android/dittoffi/src/dittomesh_java.i +16 -0
- package/react-native/android/dittoffi/src/dittostore_java.i +430 -0
- package/react-native/android/dittoffi/src/live_query_java_interfaces.cpp +1 -0
- package/react-native/android/dittoffi/src/live_query_java_interfaces.h +64 -0
- package/react-native/android/dittoffi/src/logger_cb.cpp +3 -0
- package/react-native/android/dittoffi/src/logger_cb.h +47 -0
- package/react-native/android/dittoffi/src/logger_export.cpp +1 -0
- package/react-native/android/dittoffi/src/logger_export.h +37 -0
- package/react-native/android/dittoffi/src/mesh_java_interfaces.cpp +1 -0
- package/react-native/android/dittoffi/src/mesh_java_interfaces.h +664 -0
- package/react-native/android/dittoffi/src/presence.cpp +1 -0
- package/react-native/android/dittoffi/src/presence.h +82 -0
- package/react-native/android/dittoffi/src/retainable.cpp +1 -0
- package/react-native/android/dittoffi/src/retainable.h +47 -0
- package/react-native/android/dittoffi/src/store_observer.cpp +1 -0
- package/react-native/android/dittoffi/src/store_observer.h +57 -0
- package/react-native/android/src/main/java/com/dittolive/rnsdk/DittoRNSDKModule.java +1 -1
- package/react-native/cpp/include/Authentication.h +1 -0
- package/react-native/cpp/include/Logger.h +1 -0
- package/react-native/cpp/src/Authentication.cpp +25 -0
- package/react-native/cpp/src/Logger.cpp +50 -6
- package/react-native/cpp/src/main.cpp +2 -0
- package/react-native/ditto.es6.js +1 -1
- package/types/ditto.d.ts +3010 -2763
- package/web/ditto.es6.js +1 -1
- package/web/ditto.umd.js +1 -1
- package/web/ditto.wasm +0 -0
- package/react-native/dittoffi/dittoffi.h +0 -4872
- /package/react-native/{dittoffi → android/dittoffi/src}/ifaddrs.cpp +0 -0
- /package/react-native/{dittoffi → android/dittoffi/src}/ifaddrs.h +0 -0
|
@@ -0,0 +1,664 @@
|
|
|
1
|
+
extern "C" {
|
|
2
|
+
#include "dittoffi.h"
|
|
3
|
+
}
|
|
4
|
+
#include "retainable.h"
|
|
5
|
+
#include <atomic>
|
|
6
|
+
#include <cassert>
|
|
7
|
+
#include <memory>
|
|
8
|
+
#include <string>
|
|
9
|
+
|
|
10
|
+
#ifdef SWIG
|
|
11
|
+
%feature("director", assumeoverride=1) WifiAwareRust;
|
|
12
|
+
%apply(char *STRING, size_t LENGTH) { (const char data[], size_t len) }; // byte[] instead of String
|
|
13
|
+
#endif
|
|
14
|
+
class WifiAwareRust : public Retainable {
|
|
15
|
+
public:
|
|
16
|
+
virtual ~WifiAwareRust() {}
|
|
17
|
+
|
|
18
|
+
virtual void clientStartSearching(const char *hashed_app_name,
|
|
19
|
+
const char *local_announce) = 0;
|
|
20
|
+
virtual void clientStopSearching() = 0;
|
|
21
|
+
virtual void clientCreateNetwork(const char *announce) = 0;
|
|
22
|
+
virtual void clientUpdatePeer(const char *announce, ConnectState_t state) = 0;
|
|
23
|
+
|
|
24
|
+
virtual void serverStartAdvertising(const char *announce,
|
|
25
|
+
const char *hashed_app_name,
|
|
26
|
+
uint16_t service_port) = 0;
|
|
27
|
+
virtual void serverStopAdvertising() = 0;
|
|
28
|
+
virtual void serverUpdatePeer(const char *announce, ConnectState_t state) = 0;
|
|
29
|
+
virtual void
|
|
30
|
+
updateParameterU64(dittoffi_wifi_aware_system_parameter_u64 parameter,
|
|
31
|
+
uint64_t value) = 0;
|
|
32
|
+
|
|
33
|
+
static void invokeClientStartSearching(void *ctx, const char *hashed_app_name,
|
|
34
|
+
const char *local_announce) {
|
|
35
|
+
auto inst = static_cast<WifiAwareRust *>(ctx);
|
|
36
|
+
return inst->clientStartSearching(hashed_app_name, local_announce);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static void invokeClientStopSearching(void *ctx) {
|
|
40
|
+
auto inst = static_cast<WifiAwareRust *>(ctx);
|
|
41
|
+
return inst->clientStopSearching();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static void invokeClientCreateNetwork(void *ctx, const char *announce) {
|
|
45
|
+
auto inst = static_cast<WifiAwareRust *>(ctx);
|
|
46
|
+
return inst->clientCreateNetwork(announce);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static void invokeClientUpdatePeer(void *ctx, const char *announce,
|
|
50
|
+
ConnectState_t state) {
|
|
51
|
+
auto inst = static_cast<WifiAwareRust *>(ctx);
|
|
52
|
+
return inst->clientUpdatePeer(announce, state);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static void invokeServerStartAdvertising(void *ctx, const char *announce,
|
|
56
|
+
const char *hashed_app_name,
|
|
57
|
+
uint16_t service_port) {
|
|
58
|
+
auto inst = static_cast<WifiAwareRust *>(ctx);
|
|
59
|
+
return inst->serverStartAdvertising(announce, hashed_app_name,
|
|
60
|
+
service_port);
|
|
61
|
+
}
|
|
62
|
+
static void invokeServerStopAdvertising(void *ctx) {
|
|
63
|
+
auto inst = static_cast<WifiAwareRust *>(ctx);
|
|
64
|
+
return inst->serverStopAdvertising();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static void invokeServerUpdatePeer(void *ctx, const char *announce,
|
|
68
|
+
ConnectState_t state) {
|
|
69
|
+
auto inst = static_cast<WifiAwareRust *>(ctx);
|
|
70
|
+
return inst->serverUpdatePeer(announce, state);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static void
|
|
74
|
+
invokeUpdateParameterU64(void *ctx,
|
|
75
|
+
dittoffi_wifi_aware_system_parameter_u64 parameter,
|
|
76
|
+
uint64_t value) {
|
|
77
|
+
auto inst = static_cast<WifiAwareRust *>(ctx);
|
|
78
|
+
return inst->updateParameterU64(parameter, value);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
virtual void addWifiAwareClientTransport(struct CDitto *ditto) {
|
|
82
|
+
WifiAwareClientCallbacks_t cb = {
|
|
83
|
+
.start_searching = WifiAwareRust::invokeClientStartSearching,
|
|
84
|
+
.stop_searching = WifiAwareRust::invokeClientStopSearching,
|
|
85
|
+
.create_network = WifiAwareRust::invokeClientCreateNetwork,
|
|
86
|
+
.update_peer = WifiAwareRust::invokeClientUpdatePeer,
|
|
87
|
+
};
|
|
88
|
+
auto handle = ditto_add_wifi_aware_client_transport(
|
|
89
|
+
ditto, cb, this, WifiAwareRust::invokeRetain,
|
|
90
|
+
WifiAwareRust::invokeRelease);
|
|
91
|
+
atomic_store(
|
|
92
|
+
&clientHandle,
|
|
93
|
+
std::shared_ptr<TransportHandle_WifiAwareClientPlatformEvent_t>(
|
|
94
|
+
handle, [](TransportHandle_WifiAwareClientPlatformEvent_t *h) {
|
|
95
|
+
ditto_wifi_aware_client_free_handle(h);
|
|
96
|
+
}));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
virtual void removeWifiAwareClientTransport() {
|
|
100
|
+
atomic_store(
|
|
101
|
+
&clientHandle,
|
|
102
|
+
std::shared_ptr<TransportHandle_WifiAwareClientPlatformEvent_t>());
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
virtual void addWifiAwareServerAdvertiser(struct CDitto *ditto) {
|
|
106
|
+
WifiAwareServerCallbacks_t cb = {
|
|
107
|
+
.start_advertising = WifiAwareRust::invokeServerStartAdvertising,
|
|
108
|
+
.stop_advertising = WifiAwareRust::invokeServerStopAdvertising,
|
|
109
|
+
.update_peer = WifiAwareRust::invokeServerUpdatePeer,
|
|
110
|
+
.update_parameter_u64 = WifiAwareRust::invokeUpdateParameterU64,
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
auto handle = ditto_add_wifi_aware_server_advertiser(
|
|
114
|
+
ditto, cb, this, WifiAwareRust::invokeRetain,
|
|
115
|
+
WifiAwareRust::invokeRelease);
|
|
116
|
+
atomic_store(
|
|
117
|
+
&serverHandle,
|
|
118
|
+
std::shared_ptr<TransportHandle_WifiAwareServerPlatformEvent_t>(
|
|
119
|
+
handle, [](TransportHandle_WifiAwareServerPlatformEvent_t *h) {
|
|
120
|
+
ditto_wifi_aware_server_free_handle(h);
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
virtual void removeWifiAwareServerAdvertiser() {
|
|
125
|
+
atomic_store(
|
|
126
|
+
&serverHandle,
|
|
127
|
+
std::shared_ptr<TransportHandle_WifiAwareServerPlatformEvent_t>());
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
virtual void clientPeerAppeared(const char *announce) {
|
|
131
|
+
auto handle = atomic_load(&clientHandle);
|
|
132
|
+
if (handle) {
|
|
133
|
+
ditto_wifi_aware_client_peer_appeared(handle.get(), announce);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
virtual void clientPeerDisappeared(const char *announce) {
|
|
137
|
+
auto handle = atomic_load(&clientHandle);
|
|
138
|
+
if (handle) {
|
|
139
|
+
ditto_wifi_aware_client_peer_disappeared(handle.get(), announce);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
virtual void clientScanningStateChanged(OnlineState_t state,
|
|
143
|
+
TransportCondition_t result) {
|
|
144
|
+
auto handle = atomic_load(&clientHandle);
|
|
145
|
+
if (handle) {
|
|
146
|
+
ditto_wifi_aware_client_scanning_state_changed(handle.get(), state,
|
|
147
|
+
result);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
virtual void clientNetworkDidCreate(const char *announce,
|
|
151
|
+
const char *hostname, uint16_t port) {
|
|
152
|
+
auto handle = atomic_load(&clientHandle);
|
|
153
|
+
if (handle) {
|
|
154
|
+
ditto_wifi_aware_client_network_did_create(handle.get(), announce,
|
|
155
|
+
hostname, port);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
virtual void clientNetworkDidNotCreate(const char *announce) {
|
|
159
|
+
auto handle = atomic_load(&clientHandle);
|
|
160
|
+
if (handle) {
|
|
161
|
+
ditto_wifi_aware_client_peer_did_not_connect(handle.get(), announce);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
virtual void serverAdvertisingStateChanged(OnlineState_t state,
|
|
166
|
+
TransportCondition_t result) {
|
|
167
|
+
auto handle = atomic_load(&serverHandle);
|
|
168
|
+
if (handle) {
|
|
169
|
+
ditto_wifi_aware_server_advertising_state_changed(handle.get(), state,
|
|
170
|
+
result);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
std::shared_ptr<TransportHandle_WifiAwareClientPlatformEvent_t> clientHandle;
|
|
175
|
+
std::shared_ptr<TransportHandle_WifiAwareServerPlatformEvent_t> serverHandle;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
#ifdef SWIG
|
|
179
|
+
%feature("director", assumeoverride=1) BluetoothLeRadioRust;
|
|
180
|
+
%apply(char *STRING, size_t LENGTH) { (const char peripheralUuid[], size_t uuidLen) }; // byte[] instead of String
|
|
181
|
+
%apply(char *STRING, size_t LENGTH) { (const char centralUuid[], size_t uuidLen) }; // need one per param name for SWIG
|
|
182
|
+
%apply(char *STRING, size_t LENGTH) { (const char uuid[], size_t uuidLen) };
|
|
183
|
+
%apply(char *STRING, size_t LENGTH) { (const char serviceUuid[], size_t uuidLen) };
|
|
184
|
+
%apply(char *STRING, size_t LENGTH) { (const char characteristicUuid[], size_t uuidLen) };
|
|
185
|
+
%apply(char *STRING, size_t LENGTH) { (const char manufacturerData[], size_t manufacturerDataLen) };
|
|
186
|
+
// It is implied that UUID buffers are 16 bytes in length - insert an extra size_t for this Java array conversion
|
|
187
|
+
%apply(char *STRING, size_t LENGTH) { (const char data[], size_t len) }; // byte[] instead of String
|
|
188
|
+
#endif
|
|
189
|
+
class BluetoothLeRadioRust : public Retainable {
|
|
190
|
+
public:
|
|
191
|
+
virtual ~BluetoothLeRadioRust() {}
|
|
192
|
+
virtual void connectPeripheral(const char peripheralUuid[],
|
|
193
|
+
size_t uuidLen) = 0;
|
|
194
|
+
virtual void disconnectPeripheral(const char peripheralUuid[],
|
|
195
|
+
size_t uuidLen) = 0;
|
|
196
|
+
virtual OnlineState_t getAdvertisingState() { return ONLINE_STATE_OFFLINE; }
|
|
197
|
+
virtual OnlineState_t getScanningState() { return ONLINE_STATE_OFFLINE; }
|
|
198
|
+
virtual SendResult_t notifyToCentral(BleDataType_t sendType,
|
|
199
|
+
const char centralUuid[], size_t uuidLen,
|
|
200
|
+
const char data[], size_t len) = 0;
|
|
201
|
+
virtual void startAdvertising(const char serviceUuid[], size_t uuidLen,
|
|
202
|
+
char *localName) = 0;
|
|
203
|
+
virtual void startScanning(const char serviceUuid[], size_t uuidLen,
|
|
204
|
+
char *announce) = 0;
|
|
205
|
+
virtual void stopAdvertising() = 0;
|
|
206
|
+
virtual void stopScanning() = 0;
|
|
207
|
+
virtual SendResult_t writeToPeripheral(BleDataType_t sendType,
|
|
208
|
+
const char peripheralUuid[],
|
|
209
|
+
size_t uuidLen, const char data[],
|
|
210
|
+
size_t len) = 0;
|
|
211
|
+
virtual bool appIsInForeground() = 0;
|
|
212
|
+
virtual int readL2capFromPeripheral(const char peripheralUuid[],
|
|
213
|
+
size_t uuidLen,
|
|
214
|
+
slice_mut_uint8_t data) = 0;
|
|
215
|
+
virtual int sendL2capToPeripheral(const char peripheralUuid[], size_t uuidLen,
|
|
216
|
+
const char data[], size_t len) = 0;
|
|
217
|
+
virtual int readL2capFromCentral(const char centralUuid[], size_t uuidLen,
|
|
218
|
+
slice_mut_uint8_t data) = 0;
|
|
219
|
+
virtual int sendL2capToCentral(const char centralUuid[], size_t uuidLen,
|
|
220
|
+
const char data[], size_t len) = 0;
|
|
221
|
+
|
|
222
|
+
static void invokeConnectPeripheral(void *ctx,
|
|
223
|
+
uint8_16_array_t const *peripheral_uuid) {
|
|
224
|
+
auto inst = static_cast<BluetoothLeRadioRust *>(ctx);
|
|
225
|
+
return inst->connectPeripheral((const char *)peripheral_uuid, (size_t)16);
|
|
226
|
+
}
|
|
227
|
+
static void
|
|
228
|
+
invokeDisconnectPeripheral(void *ctx,
|
|
229
|
+
uint8_16_array_t const *peripheral_uuid) {
|
|
230
|
+
auto inst = static_cast<BluetoothLeRadioRust *>(ctx);
|
|
231
|
+
return inst->disconnectPeripheral((const char *)peripheral_uuid,
|
|
232
|
+
(size_t)16);
|
|
233
|
+
}
|
|
234
|
+
static OnlineState_t invokeGetAdvertisingState(void *ctx) {
|
|
235
|
+
auto inst = static_cast<BluetoothLeRadioRust *>(ctx);
|
|
236
|
+
return inst->getAdvertisingState();
|
|
237
|
+
}
|
|
238
|
+
static OnlineState_t invokeGetScanningState(void *ctx) {
|
|
239
|
+
auto inst = static_cast<BluetoothLeRadioRust *>(ctx);
|
|
240
|
+
return inst->getScanningState();
|
|
241
|
+
}
|
|
242
|
+
static SendResult_t
|
|
243
|
+
invokeNotifyToCentral(void *ctx, BleDataType_t sendType,
|
|
244
|
+
uint8_16_array_t const *central_uuid,
|
|
245
|
+
slice_ref_uint8_t data) {
|
|
246
|
+
auto inst = static_cast<BluetoothLeRadioRust *>(ctx);
|
|
247
|
+
return inst->notifyToCentral(sendType, (char const *)central_uuid, 16,
|
|
248
|
+
(char const *)data.ptr, data.len);
|
|
249
|
+
}
|
|
250
|
+
static void invokeStartAdvertising(void *ctx,
|
|
251
|
+
uint8_16_array_t const *service_uuid,
|
|
252
|
+
slice_ref_uint8_t local_name) {
|
|
253
|
+
auto inst = static_cast<BluetoothLeRadioRust *>(ctx);
|
|
254
|
+
char *local_name_str =
|
|
255
|
+
strndup((char const *)local_name.ptr, local_name.len);
|
|
256
|
+
inst->startAdvertising((const char *)service_uuid, 16, local_name_str);
|
|
257
|
+
free(local_name_str);
|
|
258
|
+
}
|
|
259
|
+
static void invokeStartScanning(void *ctx,
|
|
260
|
+
uint8_16_array_t const *service_uuid,
|
|
261
|
+
slice_ref_uint8_t announce) {
|
|
262
|
+
auto inst = static_cast<BluetoothLeRadioRust *>(ctx);
|
|
263
|
+
char *announce_str = strndup((char const *)announce.ptr, announce.len);
|
|
264
|
+
inst->startScanning((const char *)service_uuid, 16, announce_str);
|
|
265
|
+
free(announce_str);
|
|
266
|
+
}
|
|
267
|
+
static void invokeStopAdvertising(void *ctx) {
|
|
268
|
+
auto inst = static_cast<BluetoothLeRadioRust *>(ctx);
|
|
269
|
+
inst->stopAdvertising();
|
|
270
|
+
}
|
|
271
|
+
static void invokeStopScanning(void *ctx) {
|
|
272
|
+
auto inst = static_cast<BluetoothLeRadioRust *>(ctx);
|
|
273
|
+
inst->stopScanning();
|
|
274
|
+
}
|
|
275
|
+
static SendResult_t
|
|
276
|
+
invokeWriteToPeripheral(void *ctx, BleDataType_t sendType,
|
|
277
|
+
uint8_16_array_t const *peripheral_uuid,
|
|
278
|
+
slice_ref_uint8_t data) {
|
|
279
|
+
auto inst = static_cast<BluetoothLeRadioRust *>(ctx);
|
|
280
|
+
return inst->writeToPeripheral(sendType, (const char *)peripheral_uuid, 16,
|
|
281
|
+
(const char *)data.ptr, data.len);
|
|
282
|
+
}
|
|
283
|
+
static bool invokeAppIsInForeground(void *ctx) {
|
|
284
|
+
auto inst = static_cast<BluetoothLeRadioRust *>(ctx);
|
|
285
|
+
return inst->appIsInForeground();
|
|
286
|
+
}
|
|
287
|
+
static int
|
|
288
|
+
invokeReadL2capFromPeripheral(void *ctx,
|
|
289
|
+
uint8_16_array_t const *peripheral_uuid,
|
|
290
|
+
slice_mut_uint8_t data) {
|
|
291
|
+
auto inst = static_cast<BluetoothLeRadioRust *>(ctx);
|
|
292
|
+
return inst->readL2capFromPeripheral((const char *)peripheral_uuid, 16,
|
|
293
|
+
data);
|
|
294
|
+
}
|
|
295
|
+
static int
|
|
296
|
+
invokeSendL2capToPeripheral(void *ctx,
|
|
297
|
+
uint8_16_array_t const *peripheral_uuid,
|
|
298
|
+
slice_ref_uint8_t data) {
|
|
299
|
+
auto inst = static_cast<BluetoothLeRadioRust *>(ctx);
|
|
300
|
+
return inst->sendL2capToPeripheral((const char *)peripheral_uuid, 16,
|
|
301
|
+
(char const *)data.ptr, data.len);
|
|
302
|
+
}
|
|
303
|
+
static int invokeReadL2capFromCentral(void *ctx,
|
|
304
|
+
uint8_16_array_t const *central_uuid,
|
|
305
|
+
slice_mut_uint8_t data) {
|
|
306
|
+
auto inst = static_cast<BluetoothLeRadioRust *>(ctx);
|
|
307
|
+
return inst->readL2capFromCentral((const char *)central_uuid, 16, data);
|
|
308
|
+
}
|
|
309
|
+
static int invokeSendL2capToCentral(void *ctx,
|
|
310
|
+
uint8_16_array_t const *central_uuid,
|
|
311
|
+
slice_ref_uint8_t data) {
|
|
312
|
+
auto inst = static_cast<BluetoothLeRadioRust *>(ctx);
|
|
313
|
+
return inst->sendL2capToCentral((const char *)central_uuid, 16,
|
|
314
|
+
(char const *)data.ptr, data.len);
|
|
315
|
+
}
|
|
316
|
+
virtual void addBleClientTransport(struct CDitto *ditto) {
|
|
317
|
+
BleClientCallbacks_t cb = {
|
|
318
|
+
.start_scanning = BluetoothLeRadioRust::invokeStartScanning,
|
|
319
|
+
.stop_scanning = BluetoothLeRadioRust::invokeStopScanning,
|
|
320
|
+
.scanning_state = BluetoothLeRadioRust::invokeGetScanningState,
|
|
321
|
+
.connect_peripheral = BluetoothLeRadioRust::invokeConnectPeripheral,
|
|
322
|
+
.disconnect_peripheral =
|
|
323
|
+
BluetoothLeRadioRust::invokeDisconnectPeripheral,
|
|
324
|
+
.write_to_peripheral = BluetoothLeRadioRust::invokeWriteToPeripheral,
|
|
325
|
+
.app_is_in_foreground = BluetoothLeRadioRust::invokeAppIsInForeground,
|
|
326
|
+
.read_l2cap_from_peripheral =
|
|
327
|
+
BluetoothLeRadioRust::invokeReadL2capFromPeripheral,
|
|
328
|
+
.send_l2cap_to_peripheral =
|
|
329
|
+
BluetoothLeRadioRust::invokeSendL2capToPeripheral};
|
|
330
|
+
auto handle = ditto_add_ble_client_transport(
|
|
331
|
+
ditto, cb, this, BluetoothLeRadioRust::invokeRetain,
|
|
332
|
+
BluetoothLeRadioRust::invokeRelease);
|
|
333
|
+
atomic_store(&clientHandle,
|
|
334
|
+
std::shared_ptr<TransportHandle_BleClientPlatformEvent_t>(
|
|
335
|
+
handle, [](TransportHandle_BleClientPlatformEvent_t *h) {
|
|
336
|
+
// We own this pointer
|
|
337
|
+
// When nobody is using it any more we will free it via
|
|
338
|
+
// Rust
|
|
339
|
+
ble_client_free_handle(h);
|
|
340
|
+
}));
|
|
341
|
+
}
|
|
342
|
+
virtual void addBleServerTransport(struct CDitto *ditto) {
|
|
343
|
+
BleServerCallbacks_t cb = {
|
|
344
|
+
.start_advertising = BluetoothLeRadioRust::invokeStartAdvertising,
|
|
345
|
+
.stop_advertising = BluetoothLeRadioRust::invokeStopAdvertising,
|
|
346
|
+
.advertising_state = BluetoothLeRadioRust::invokeGetAdvertisingState,
|
|
347
|
+
.notify_to_central = BluetoothLeRadioRust::invokeNotifyToCentral,
|
|
348
|
+
.app_is_in_foreground = BluetoothLeRadioRust::invokeAppIsInForeground,
|
|
349
|
+
.read_l2cap_from_central =
|
|
350
|
+
BluetoothLeRadioRust::invokeReadL2capFromCentral,
|
|
351
|
+
.send_l2cap_to_central =
|
|
352
|
+
BluetoothLeRadioRust::invokeSendL2capToCentral};
|
|
353
|
+
auto handle = ditto_add_ble_server_transport(
|
|
354
|
+
ditto, cb, this, BluetoothLeRadioRust::invokeRetain,
|
|
355
|
+
BluetoothLeRadioRust::invokeRelease);
|
|
356
|
+
atomic_store(&serverHandle,
|
|
357
|
+
std::shared_ptr<TransportHandle_BleServerPlatformEvent_t>(
|
|
358
|
+
handle, [](TransportHandle_BleServerPlatformEvent_t *h) {
|
|
359
|
+
ble_server_free_handle(h);
|
|
360
|
+
}));
|
|
361
|
+
}
|
|
362
|
+
virtual void dropBleClientTransport() {
|
|
363
|
+
// This is how we break the circular ownership when it is time to shut down
|
|
364
|
+
// the transport
|
|
365
|
+
atomic_store(&clientHandle,
|
|
366
|
+
std::shared_ptr<TransportHandle_BleClientPlatformEvent_t>());
|
|
367
|
+
}
|
|
368
|
+
virtual void dropBleServerTransport() {
|
|
369
|
+
atomic_store(&serverHandle,
|
|
370
|
+
std::shared_ptr<TransportHandle_BleServerPlatformEvent_t>());
|
|
371
|
+
}
|
|
372
|
+
virtual void advertisementHeard(const char peripheralUuid[], size_t uuidLen,
|
|
373
|
+
const char manufacturerData[],
|
|
374
|
+
size_t manufacturerDataLen,
|
|
375
|
+
bool manufacturerDataIncludesId, char *name,
|
|
376
|
+
float rssi) {
|
|
377
|
+
auto handle = atomic_load(&clientHandle);
|
|
378
|
+
if (handle) {
|
|
379
|
+
ditto_transports_ble_advertisement_heard(
|
|
380
|
+
handle.get(), (uint8_16_array_t const *)peripheralUuid,
|
|
381
|
+
slice_ref_uint8_t{
|
|
382
|
+
.ptr = (uint8_t const *)manufacturerData,
|
|
383
|
+
.len = manufacturerDataLen,
|
|
384
|
+
},
|
|
385
|
+
manufacturerDataIncludesId,
|
|
386
|
+
slice_ref_uint8_t{
|
|
387
|
+
.ptr = (uint8_t const *)name,
|
|
388
|
+
.len = name ? strlen(name) : 0,
|
|
389
|
+
},
|
|
390
|
+
rssi);
|
|
391
|
+
}
|
|
392
|
+
(void)uuidLen;
|
|
393
|
+
}
|
|
394
|
+
virtual void connectionStateChanged(const char peripheralUuid[],
|
|
395
|
+
size_t uuidLen, ConnectState_t state,
|
|
396
|
+
bool l2cap_available, int mtu) {
|
|
397
|
+
auto handle = atomic_load(&clientHandle);
|
|
398
|
+
assert(uuidLen == 16);
|
|
399
|
+
if (handle) {
|
|
400
|
+
ble_connection_state_changed(handle.get(),
|
|
401
|
+
(uint8_16_array_t const *)peripheralUuid,
|
|
402
|
+
state, l2cap_available ? 1 : 0, mtu);
|
|
403
|
+
}
|
|
404
|
+
(void)uuidLen;
|
|
405
|
+
}
|
|
406
|
+
virtual void peripheralMtuUpdated(const char uuid[], size_t uuidLen,
|
|
407
|
+
int mtu) {
|
|
408
|
+
auto handle = atomic_load(&clientHandle);
|
|
409
|
+
assert(uuidLen == 16);
|
|
410
|
+
if (handle) {
|
|
411
|
+
ble_peripheral_mtu_updated(handle.get(), (uint8_16_array_t const *)uuid,
|
|
412
|
+
mtu);
|
|
413
|
+
}
|
|
414
|
+
(void)uuidLen;
|
|
415
|
+
}
|
|
416
|
+
virtual void receivedFromPeripheral(const char peripheralUuid[],
|
|
417
|
+
size_t uuidLen, BleDataType_t dataType,
|
|
418
|
+
const char data[], size_t len) {
|
|
419
|
+
auto handle = atomic_load(&clientHandle);
|
|
420
|
+
assert(uuidLen == 16);
|
|
421
|
+
if (handle) {
|
|
422
|
+
ble_received_from_peripheral(
|
|
423
|
+
handle.get(), (uint8_16_array_t const *)peripheralUuid, dataType,
|
|
424
|
+
(slice_ref_uint8_t){
|
|
425
|
+
.ptr = (uint8_t const *)data,
|
|
426
|
+
.len = len,
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
(void)uuidLen;
|
|
430
|
+
}
|
|
431
|
+
virtual void scanningStateChanged(OnlineState_t state,
|
|
432
|
+
TransportCondition_t result) {
|
|
433
|
+
auto handle = atomic_load(&clientHandle);
|
|
434
|
+
if (handle) {
|
|
435
|
+
ble_scanning_state_changed(handle.get(), state, result);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
virtual void peripheralReadyToSend(const char uuid[], size_t uuidLen) {
|
|
439
|
+
auto handle = atomic_load(&clientHandle);
|
|
440
|
+
assert(uuidLen == 16);
|
|
441
|
+
if (handle) {
|
|
442
|
+
ble_peripheral_ready_to_send(handle.get(),
|
|
443
|
+
(uint8_16_array_t const *)uuid);
|
|
444
|
+
}
|
|
445
|
+
(void)uuidLen;
|
|
446
|
+
}
|
|
447
|
+
virtual void peripheralL2capReadyToSend(const char uuid[], size_t uuidLen) {
|
|
448
|
+
assert(uuidLen == 16);
|
|
449
|
+
auto handle = atomic_load(&clientHandle);
|
|
450
|
+
if (handle) {
|
|
451
|
+
ble_peripheral_l2cap_ready_to_send(handle.get(),
|
|
452
|
+
(uint8_16_array_t const *)uuid);
|
|
453
|
+
}
|
|
454
|
+
(void)uuidLen;
|
|
455
|
+
}
|
|
456
|
+
virtual void peripheralL2capDataAvailable(const char uuid[], size_t uuidLen) {
|
|
457
|
+
assert(uuidLen == 16);
|
|
458
|
+
auto handle = atomic_load(&clientHandle);
|
|
459
|
+
if (handle) {
|
|
460
|
+
ble_peripheral_l2cap_data_available(handle.get(),
|
|
461
|
+
(uint8_16_array_t const *)uuid);
|
|
462
|
+
}
|
|
463
|
+
(void)uuidLen;
|
|
464
|
+
}
|
|
465
|
+
virtual void advertisingStateChanged(OnlineState_t state,
|
|
466
|
+
TransportCondition_t result) {
|
|
467
|
+
auto handle = atomic_load(&serverHandle);
|
|
468
|
+
if (handle) {
|
|
469
|
+
ble_advertising_state_changed(handle.get(), state, result);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
virtual void centralMtuUpdated(const char uuid[], size_t uuidLen, int mtu) {
|
|
473
|
+
auto handle = atomic_load(&serverHandle);
|
|
474
|
+
assert(uuidLen == 16);
|
|
475
|
+
if (handle) {
|
|
476
|
+
ble_central_mtu_updated(handle.get(), (uint8_16_array_t const *)uuid,
|
|
477
|
+
mtu);
|
|
478
|
+
}
|
|
479
|
+
(void)uuidLen;
|
|
480
|
+
}
|
|
481
|
+
virtual void receivedFromCentral(const char centralUuid[], size_t uuidLen,
|
|
482
|
+
BleDataType_t dataType, const char data[],
|
|
483
|
+
size_t len) {
|
|
484
|
+
auto handle = atomic_load(&serverHandle);
|
|
485
|
+
assert(uuidLen == 16);
|
|
486
|
+
if (handle) {
|
|
487
|
+
ble_received_from_central(handle.get(),
|
|
488
|
+
(uint8_16_array_t const *)centralUuid, dataType,
|
|
489
|
+
(slice_ref_uint8_t){
|
|
490
|
+
.ptr = (uint8_t const *)data,
|
|
491
|
+
.len = len,
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
(void)uuidLen;
|
|
495
|
+
}
|
|
496
|
+
virtual void centralFinishedConnecting(const char centralUuid[],
|
|
497
|
+
size_t uuidLen, const char data[],
|
|
498
|
+
size_t len, bool l2capAvailable,
|
|
499
|
+
int mtu) {
|
|
500
|
+
auto handle = atomic_load(&serverHandle);
|
|
501
|
+
if (handle) {
|
|
502
|
+
ble_central_finished_connecting(handle.get(),
|
|
503
|
+
(uint8_16_array_t const *)centralUuid,
|
|
504
|
+
(slice_ref_uint8_t){
|
|
505
|
+
.ptr = (uint8_t const *)data,
|
|
506
|
+
.len = len,
|
|
507
|
+
},
|
|
508
|
+
l2capAvailable ? 1 : 0, mtu);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
virtual void centralUnsubscribed(const char centralUuid[], size_t uuidLen) {
|
|
512
|
+
assert(uuidLen == 16);
|
|
513
|
+
auto handle = atomic_load(&serverHandle);
|
|
514
|
+
if (handle) {
|
|
515
|
+
ble_central_unsubscribed(handle.get(),
|
|
516
|
+
(uint8_16_array_t const *)centralUuid);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
virtual void centralReadyToSend(const char uuid[], size_t uuidLen) {
|
|
520
|
+
assert(uuidLen == 16);
|
|
521
|
+
auto handle = atomic_load(&serverHandle);
|
|
522
|
+
if (handle) {
|
|
523
|
+
ble_central_ready_to_send(handle.get(), (uint8_16_array_t const *)uuid);
|
|
524
|
+
}
|
|
525
|
+
(void)uuidLen;
|
|
526
|
+
}
|
|
527
|
+
virtual void centralL2capReadyToSend(const char uuid[], size_t uuidLen) {
|
|
528
|
+
assert(uuidLen == 16);
|
|
529
|
+
auto handle = atomic_load(&serverHandle);
|
|
530
|
+
if (handle) {
|
|
531
|
+
ble_central_l2cap_ready_to_send(handle.get(),
|
|
532
|
+
(uint8_16_array_t const *)uuid);
|
|
533
|
+
}
|
|
534
|
+
(void)uuidLen;
|
|
535
|
+
}
|
|
536
|
+
virtual void centralL2capDataAvailable(const char uuid[], size_t uuidLen) {
|
|
537
|
+
assert(uuidLen == 16);
|
|
538
|
+
auto handle = atomic_load(&serverHandle);
|
|
539
|
+
if (handle) {
|
|
540
|
+
ble_central_l2cap_data_available(handle.get(),
|
|
541
|
+
(uint8_16_array_t const *)uuid);
|
|
542
|
+
}
|
|
543
|
+
(void)uuidLen;
|
|
544
|
+
}
|
|
545
|
+
std::shared_ptr<TransportHandle_BleClientPlatformEvent_t> clientHandle;
|
|
546
|
+
std::shared_ptr<TransportHandle_BleServerPlatformEvent_t> serverHandle;
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
#ifdef SWIG
|
|
550
|
+
%feature("director", assumeoverride=1) StatusRust;
|
|
551
|
+
#endif
|
|
552
|
+
class StatusRust : public Retainable {
|
|
553
|
+
public:
|
|
554
|
+
virtual ~StatusRust() {}
|
|
555
|
+
virtual void transportConditionDidChange(ConditionSource source,
|
|
556
|
+
TransportCondition_t condition) = 0;
|
|
557
|
+
|
|
558
|
+
static void
|
|
559
|
+
invokeTransportConditionDidChange(void *ctx, ConditionSource source,
|
|
560
|
+
TransportCondition_t condition) {
|
|
561
|
+
auto inst = static_cast<StatusRust *>(ctx);
|
|
562
|
+
return inst->transportConditionDidChange(source, condition);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
virtual void submit(struct CDitto *ditto) {
|
|
566
|
+
ditto_register_transport_condition_changed_callback(
|
|
567
|
+
ditto, this, StatusRust::invokeRetain, StatusRust::invokeRelease,
|
|
568
|
+
StatusRust::invokeTransportConditionDidChange);
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
virtual void shutdown(struct CDitto *ditto) {
|
|
572
|
+
ditto_register_transport_condition_changed_callback(ditto, nullptr, nullptr,
|
|
573
|
+
nullptr, nullptr);
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
|
|
577
|
+
#ifdef SWIG
|
|
578
|
+
%feature("director", assumeoverride=1) LoginProviderRust;
|
|
579
|
+
#endif
|
|
580
|
+
class LoginProviderRust : public Retainable {
|
|
581
|
+
public:
|
|
582
|
+
virtual ~LoginProviderRust() {}
|
|
583
|
+
virtual void authenticationExpiring(unsigned int time_remaining) = 0;
|
|
584
|
+
|
|
585
|
+
static void invokeAuthenticationExpiring(void *ctx,
|
|
586
|
+
unsigned int time_remaining) {
|
|
587
|
+
auto inst = static_cast<LoginProviderRust *>(ctx);
|
|
588
|
+
return inst->authenticationExpiring(time_remaining);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
virtual void submit() {
|
|
592
|
+
this->loginProviderPtr = ditto_auth_client_make_login_provider(
|
|
593
|
+
this, LoginProviderRust::invokeRetain, LoginProviderRust::invokeRelease,
|
|
594
|
+
LoginProviderRust::invokeAuthenticationExpiring);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
CLoginProvider *loginProviderPtr;
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
#ifdef SWIG
|
|
601
|
+
%feature("director", assumeoverride=1) ValidityListenerRust;
|
|
602
|
+
#endif
|
|
603
|
+
class ValidityListenerRust : public Retainable {
|
|
604
|
+
public:
|
|
605
|
+
virtual ~ValidityListenerRust() {}
|
|
606
|
+
virtual void validityUpdated(bool web_valid, bool x509_valid) = 0;
|
|
607
|
+
|
|
608
|
+
static void invokeValidityUpdated(void *ctx, int web_valid, int x509_valid) {
|
|
609
|
+
auto inst = static_cast<ValidityListenerRust *>(ctx);
|
|
610
|
+
return inst->validityUpdated((web_valid != 0), (x509_valid != 0));
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
virtual void submit(struct CDitto *ditto) {
|
|
614
|
+
ditto_auth_client_set_validity_listener(
|
|
615
|
+
ditto, this, ValidityListenerRust::invokeRetain,
|
|
616
|
+
ValidityListenerRust::invokeRelease,
|
|
617
|
+
ValidityListenerRust::invokeValidityUpdated);
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
#ifdef SWIG
|
|
622
|
+
%feature("director", assumeoverride=1) DiskUsageObserverRust;
|
|
623
|
+
#endif
|
|
624
|
+
class DiskUsageObserverRust : public Retainable {
|
|
625
|
+
private:
|
|
626
|
+
DiskUsageObserver *observerHandle;
|
|
627
|
+
|
|
628
|
+
public:
|
|
629
|
+
virtual ~DiskUsageObserverRust() {}
|
|
630
|
+
virtual void diskUsageUpdated(slice_ref_uint8_t diskUsageBytes) = 0;
|
|
631
|
+
|
|
632
|
+
static void invokeDiskUsageUpdated(void *ctx,
|
|
633
|
+
slice_ref_uint8_t diskUsageBytes) {
|
|
634
|
+
auto inst = static_cast<DiskUsageObserverRust *>(ctx);
|
|
635
|
+
return inst->diskUsageUpdated(diskUsageBytes);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
virtual void subscribe(struct CDitto *ditto) {
|
|
639
|
+
observerHandle = ditto_register_disk_usage_callback(
|
|
640
|
+
ditto, FsComponent::FS_COMPONENT_ROOT, this,
|
|
641
|
+
DiskUsageObserverRust::invokeRetain,
|
|
642
|
+
DiskUsageObserverRust::invokeRelease,
|
|
643
|
+
DiskUsageObserverRust::invokeDiskUsageUpdated);
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
virtual void stop() { ditto_release_disk_usage_callback(observerHandle); }
|
|
647
|
+
};
|
|
648
|
+
|
|
649
|
+
#ifdef SWIG
|
|
650
|
+
%apply(char *STRING, size_t LENGTH) { (const char value[], size_t valueLen) };
|
|
651
|
+
%extend slice_mut_uint8 {
|
|
652
|
+
// The maximum number of bytes that can be written to this slice. Any larger values will be truncated.
|
|
653
|
+
size_t getCapacity() {
|
|
654
|
+
return $self->len;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// Write a byte array to the mutable memory represented by this slice. Returns the actual number of bytes written.
|
|
658
|
+
size_t setValue(const char value[], size_t valueLen) {
|
|
659
|
+
size_t len = (valueLen < $self->len ? valueLen : $self->len);
|
|
660
|
+
memcpy($self->ptr, value, len);
|
|
661
|
+
return len;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
#endif
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#include "presence.h"
|