react-native-ble-nitro 1.0.0 → 1.1.0

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.
Files changed (40) hide show
  1. package/README.md +19 -15
  2. package/ios/BleNitroBleManager.swift +77 -43
  3. package/lib/commonjs/index.d.ts +15 -13
  4. package/lib/commonjs/index.d.ts.map +1 -1
  5. package/lib/commonjs/index.js +76 -139
  6. package/lib/commonjs/index.js.map +1 -1
  7. package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts +13 -10
  8. package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts.map +1 -1
  9. package/lib/index.d.ts +15 -13
  10. package/lib/index.js +75 -138
  11. package/lib/specs/NativeBleNitro.nitro.d.ts +13 -10
  12. package/nitrogen/generated/android/BleNitroOnLoad.cpp +2 -8
  13. package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.cpp +90 -49
  14. package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.hpp +9 -10
  15. package/nitrogen/generated/android/c++/JOperationResult.hpp +58 -0
  16. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/HybridNativeBleNitroSpec.kt +11 -60
  17. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/OperationResult.kt +32 -0
  18. package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Bridge.cpp +5 -29
  19. package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Bridge.hpp +69 -78
  20. package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Umbrella.hpp +3 -0
  21. package/nitrogen/generated/ios/c++/HybridNativeBleNitroSpecSwift.hpp +39 -24
  22. package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec.swift +9 -10
  23. package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec_cxx.swift +60 -112
  24. package/nitrogen/generated/ios/swift/OperationResult.swift +64 -0
  25. package/nitrogen/generated/shared/c++/HybridNativeBleNitroSpec.cpp +0 -1
  26. package/nitrogen/generated/shared/c++/HybridNativeBleNitroSpec.hpp +13 -11
  27. package/nitrogen/generated/shared/c++/OperationResult.hpp +72 -0
  28. package/package.json +1 -1
  29. package/src/__tests__/index.test.ts +19 -22
  30. package/src/index.ts +100 -156
  31. package/src/specs/NativeBleNitro.nitro.ts +14 -10
  32. package/nitrogen/generated/android/c++/JFunc_void_bool.hpp +0 -74
  33. package/nitrogen/generated/android/c++/JFunc_void_std__vector_BLEDevice_.hpp +0 -99
  34. package/nitrogen/generated/android/c++/JFunc_void_std__vector_std__string_.hpp +0 -93
  35. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/Func_void_bool.kt +0 -81
  36. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/Func_void_std__vector_BLEDevice_.kt +0 -81
  37. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/Func_void_std__vector_std__string_.kt +0 -81
  38. package/nitrogen/generated/ios/swift/Func_void_bool.swift +0 -47
  39. package/nitrogen/generated/ios/swift/Func_void_std__vector_BLEDevice_.swift +0 -47
  40. package/nitrogen/generated/ios/swift/Func_void_std__vector_std__string_.swift +0 -47
package/src/index.ts CHANGED
@@ -47,7 +47,7 @@ export type CharacteristicUpdateCallback = (
47
47
  ) => void;
48
48
 
49
49
  export type Subscription = {
50
- remove: () => Promise<void>;
50
+ remove: () => void;
51
51
  };
52
52
 
53
53
  export enum BLEState {
@@ -117,85 +117,62 @@ export class BleNitro {
117
117
  public startScan(
118
118
  filter: ScanFilter = {},
119
119
  callback: ScanCallback
120
- ): Promise<boolean> {
121
- return new Promise((resolve) => {
122
- // Don't start scanning if already scanning
123
- if (this._isScanning) {
124
- resolve(true);
125
- return;
126
- }
127
-
128
- // Create native scan filter with defaults
129
- const nativeFilter: NativeScanFilter = {
130
- serviceUUIDs: filter.serviceUUIDs || [],
131
- rssiThreshold: filter.rssiThreshold ?? -100,
132
- allowDuplicates: filter.allowDuplicates ?? false,
133
- };
134
-
135
- // Create callback wrapper
136
- const scanCallback = (device: NativeBLEDevice) => {
137
- device.serviceUUIDs = BleNitro.normalizeGattUUIDs(device.serviceUUIDs);
138
- callback(device);
139
- };
120
+ ): void {
121
+ if (this._isScanning) {
122
+ return;
123
+ }
140
124
 
141
- // Start scan
142
- BleNitroNative.startScan(nativeFilter, scanCallback);
143
- this._isScanning = true;
144
- resolve(true);
145
- });
125
+ // Create native scan filter with defaults
126
+ const nativeFilter: NativeScanFilter = {
127
+ serviceUUIDs: filter.serviceUUIDs || [],
128
+ rssiThreshold: filter.rssiThreshold ?? -100,
129
+ allowDuplicates: filter.allowDuplicates ?? false,
130
+ };
131
+
132
+ // Create callback wrapper
133
+ const scanCallback = (device: NativeBLEDevice) => {
134
+ device.serviceUUIDs = BleNitro.normalizeGattUUIDs(device.serviceUUIDs);
135
+ callback(device);
136
+ };
137
+
138
+ // Start scan
139
+ BleNitroNative.startScan(nativeFilter, scanCallback);
140
+ this._isScanning = true;
146
141
  }
147
142
 
148
143
  /**
149
144
  * Stop scanning for Bluetooth devices
150
145
  * @returns Promise resolving to success state
151
146
  */
152
- public stopScan(): Promise<boolean> {
153
- return new Promise((resolve, reject) => {
154
- // Don't stop scanning if not scanning
155
- if (!this._isScanning) {
156
- resolve(true);
157
- return;
158
- }
147
+ public stopScan(): void {
148
+ if (!this._isScanning) {
149
+ return;
150
+ }
159
151
 
160
- BleNitroNative.stopScan((success: boolean, error: string) => {
161
- if (success) {
162
- this._isScanning = false;
163
- resolve(true);
164
- } else {
165
- reject(new Error(error));
166
- }
167
- });
168
- });
152
+ BleNitroNative.stopScan();
169
153
  }
170
154
 
171
155
  /**
172
156
  * Check if currently scanning for devices
173
157
  * @returns Promise resolving to scanning state
174
158
  */
175
- public isScanning(): Promise<boolean> {
176
- return new Promise((resolve) => {
177
- BleNitroNative.isScanning((scanning: boolean) => {
178
- this._isScanning = scanning;
179
- resolve(scanning);
180
- });
181
- });
159
+ public isScanning(): boolean {
160
+ this._isScanning = BleNitroNative.isScanning();
161
+ return this._isScanning;
182
162
  }
183
163
 
184
164
  /**
185
165
  * Get all currently connected devices
186
- * @returns Promise resolving to array of connected devices
166
+ * @param services Optional list of service UUIDs to filter by
167
+ * @returns Array of connected devices
187
168
  */
188
- public getConnectedDevices(): Promise<BLEDevice[]> {
189
- return new Promise((resolve) => {
190
- BleNitroNative.getConnectedDevices((devices: BLEDevice[]) => {
191
- // Normalize service UUIDs for connected devices
192
- const normalizedDevices = devices.map(device => ({
193
- ...device,
194
- serviceUUIDs: BleNitro.normalizeGattUUIDs(device.serviceUUIDs)
195
- }));
196
- resolve(normalizedDevices);
197
- });
198
- });
169
+ public getConnectedDevices(services?: string[]): BLEDevice[] {
170
+ const devices = BleNitroNative.getConnectedDevices(services || []);
171
+ // Normalize service UUIDs for connected devices
172
+ return devices.map(device => ({
173
+ ...device,
174
+ serviceUUIDs: BleNitro.normalizeGattUUIDs(device.serviceUUIDs)
175
+ }));
199
176
  }
200
177
 
201
178
  /**
@@ -239,11 +216,11 @@ export class BleNitro {
239
216
  * @param deviceId ID of the device to disconnect from
240
217
  * @returns Promise resolving when disconnected
241
218
  */
242
- public disconnect(deviceId: string): Promise<boolean> {
219
+ public disconnect(deviceId: string): Promise<void> {
243
220
  return new Promise((resolve, reject) => {
244
221
  // Check if already disconnected
245
222
  if (!this._connectedDevices[deviceId]) {
246
- resolve(true);
223
+ resolve();
247
224
  return;
248
225
  }
249
226
 
@@ -252,7 +229,7 @@ export class BleNitro {
252
229
  (success: boolean, error: string) => {
253
230
  if (success) {
254
231
  delete this._connectedDevices[deviceId];
255
- resolve(true);
232
+ resolve();
256
233
  } else {
257
234
  reject(new Error(error));
258
235
  }
@@ -266,13 +243,8 @@ export class BleNitro {
266
243
  * @param deviceId ID of the device to check
267
244
  * @returns Promise resolving to connection state
268
245
  */
269
- public isConnected(deviceId: string): Promise<boolean> {
270
- return new Promise((resolve) => {
271
- BleNitroNative.isConnected(deviceId, (connected: boolean) => {
272
- this._connectedDevices[deviceId] = connected;
273
- resolve(connected);
274
- });
275
- });
246
+ public isConnected(deviceId: string): boolean {
247
+ return BleNitroNative.isConnected(deviceId);
276
248
  }
277
249
 
278
250
  /**
@@ -319,9 +291,8 @@ export class BleNitro {
319
291
  reject(new Error('Failed to discover services'));
320
292
  return;
321
293
  }
322
- BleNitroNative.getServices(deviceId, (services: string[]) => {
323
- resolve(BleNitro.normalizeGattUUIDs(services));
324
- });
294
+ const services = BleNitroNative.getServices(deviceId);
295
+ resolve(BleNitro.normalizeGattUUIDs(services));
325
296
  });
326
297
  }
327
298
 
@@ -334,22 +305,16 @@ export class BleNitro {
334
305
  public getCharacteristics(
335
306
  deviceId: string,
336
307
  serviceId: string
337
- ): Promise<string[]> {
338
- return new Promise((resolve, reject) => {
339
- // Check if connected first
340
- if (!this._connectedDevices[deviceId]) {
341
- reject(new Error('Device not connected'));
342
- return;
343
- }
308
+ ): string[] {
309
+ if (!this._connectedDevices[deviceId]) {
310
+ throw new Error('Device not connected');
311
+ }
344
312
 
345
- BleNitroNative.getCharacteristics(
346
- deviceId,
347
- BleNitro.normalizeGattUUID(serviceId),
348
- (characteristics: string[]) => {
349
- resolve(BleNitro.normalizeGattUUIDs(characteristics));
350
- }
351
- );
352
- });
313
+ const characteristics = BleNitroNative.getCharacteristics(
314
+ deviceId,
315
+ BleNitro.normalizeGattUUID(serviceId),
316
+ );
317
+ return BleNitro.normalizeGattUUIDs(characteristics);
353
318
  }
354
319
 
355
320
  /**
@@ -439,40 +404,41 @@ export class BleNitro {
439
404
  serviceId: string,
440
405
  characteristicId: string,
441
406
  callback: CharacteristicUpdateCallback
442
- ): Promise<Subscription> {
443
- return new Promise((resolve, reject) => {
444
- // Check if connected first
445
- if (!this._connectedDevices[deviceId]) {
446
- reject(new Error('Device not connected'));
447
- return;
407
+ ): Subscription {
408
+ // Check if connected first
409
+ if (!this._connectedDevices[deviceId]) {
410
+ throw new Error('Device not connected');
411
+ }
412
+
413
+ let _success = false;
414
+
415
+ BleNitroNative.subscribeToCharacteristic(
416
+ deviceId,
417
+ BleNitro.normalizeGattUUID(serviceId),
418
+ BleNitro.normalizeGattUUID(characteristicId),
419
+ (charId: string, data: number[]) => {
420
+ callback(charId, data);
421
+ },
422
+ (success, error) => {
423
+ _success = success;
424
+ if (!success) {
425
+ throw new Error(error);
426
+ }
448
427
  }
428
+ );
449
429
 
450
- BleNitroNative.subscribeToCharacteristic(
451
- deviceId,
452
- BleNitro.normalizeGattUUID(serviceId),
453
- BleNitro.normalizeGattUUID(characteristicId),
454
- (charId: string, data: number[]) => {
455
- callback(charId, data);
456
- },
457
- (success: boolean, error: string) => {
458
- if (success) {
459
- resolve({
460
- remove: () => {
461
- return new Promise((resolve, reject) => {
462
- this.unsubscribeFromCharacteristic(
463
- deviceId,
464
- serviceId,
465
- characteristicId
466
- ).then(resolve).catch(reject);
467
- });
468
- },
469
- });
470
- } else {
471
- reject(new Error(error));
472
- }
430
+ return {
431
+ remove: () => {
432
+ if (!_success) {
433
+ return;
473
434
  }
474
- );
475
- });
435
+ this.unsubscribeFromCharacteristic(
436
+ deviceId,
437
+ serviceId,
438
+ characteristicId
439
+ ).catch(() => {});
440
+ }
441
+ };
476
442
  }
477
443
 
478
444
  /**
@@ -513,16 +479,13 @@ export class BleNitro {
513
479
  * Check if Bluetooth is enabled
514
480
  * @returns Promise resolving to Bluetooth state
515
481
  */
516
- public isBluetoothEnabled(): Promise<boolean> {
517
- return new Promise((resolve) => {
518
- BleNitroNative.isBluetoothEnabled((enabled: boolean) => {
519
- resolve(enabled);
520
- });
521
- });
482
+ public isBluetoothEnabled(): boolean {
483
+ return this.state() === BLEState.PoweredOn;
522
484
  }
523
485
 
524
486
  /**
525
487
  * Request to enable Bluetooth
488
+ * Only works on Android
526
489
  * @returns Promise resolving when Bluetooth is enabled
527
490
  */
528
491
  public requestBluetoothEnable(): Promise<boolean> {
@@ -544,12 +507,8 @@ export class BleNitro {
544
507
  * @returns Promise resolving to Bluetooth state
545
508
  * @see BLEState
546
509
  */
547
- public state(): Promise<BLEState> {
548
- return new Promise((resolve) => {
549
- BleNitroNative.state((state: NativeBLEState) => {
550
- resolve(mapNativeBLEStateToBLEState(state));
551
- });
552
- });
510
+ public state(): BLEState {
511
+ return mapNativeBLEStateToBLEState(BleNitroNative.state());
553
512
  }
554
513
 
555
514
  /**
@@ -559,36 +518,21 @@ export class BleNitro {
559
518
  * @returns Promise resolving when subscription is complete
560
519
  * @see BLEState
561
520
  */
562
- public subscribeToStateChange(callback: (state: BLEState) => void, emitInitial = false): Promise<Subscription> {
563
- return new Promise(async (resolve, reject) => {
521
+ public subscribeToStateChange(callback: (state: BLEState) => void, emitInitial = false): Subscription {
564
522
  if (emitInitial) {
565
- const state = await this.state().catch(() => {
566
- return BLEState.Unknown;
567
- });
523
+ const state = this.state();
568
524
  callback(state);
569
525
  }
526
+
570
527
  BleNitroNative.subscribeToStateChange((nativeState: NativeBLEState) => {
571
528
  callback(mapNativeBLEStateToBLEState(nativeState));
572
- }, (success: boolean, error: string) => {
573
- if (success) {
574
- resolve({
575
- remove: () => {
576
- return new Promise((resolve, reject) => {
577
- BleNitroNative.unsubscribeFromStateChange((success, error) => {
578
- if (success) {
579
- resolve();
580
- } else {
581
- reject(new Error(error));
582
- }
583
- });
584
- });
585
- },
586
- });
587
- } else {
588
- reject(new Error(error));
589
- }
590
529
  });
591
- })
530
+
531
+ return {
532
+ remove: () => {
533
+ BleNitroNative.unsubscribeFromStateChange();
534
+ },
535
+ };
592
536
  }
593
537
 
594
538
  /**
@@ -45,6 +45,11 @@ export type BooleanCallback = (result: boolean) => void;
45
45
  export type StringArrayCallback = (result: string[]) => void;
46
46
  export type ReadCharacteristicCallback = (success: boolean, data: number[], error: string) => void;
47
47
 
48
+ export type OperationResult = {
49
+ success: boolean;
50
+ error?: string;
51
+ };
52
+
48
53
  /**
49
54
  * Native BLE Nitro Module Specification
50
55
  * Defines the interface between TypeScript and native implementations
@@ -52,21 +57,21 @@ export type ReadCharacteristicCallback = (success: boolean, data: number[], erro
52
57
  export interface NativeBleNitro extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
53
58
  // Scanning operations
54
59
  startScan(filter: ScanFilter, callback: ScanCallback): void;
55
- stopScan(callback: OperationCallback): void;
56
- isScanning(callback: BooleanCallback): void;
60
+ stopScan(): boolean;
61
+ isScanning(): boolean;
57
62
 
58
63
  // Device discovery
59
- getConnectedDevices(callback: DevicesCallback): void;
64
+ getConnectedDevices(services: string[]): BLEDevice[];
60
65
 
61
66
  // Connection management
62
67
  connect(deviceId: string, callback: ConnectionCallback, disconnectCallback?: DisconnectionEventCallback): void;
63
68
  disconnect(deviceId: string, callback: OperationCallback): void;
64
- isConnected(deviceId: string, callback: BooleanCallback): void;
69
+ isConnected(deviceId: string): boolean;
65
70
 
66
71
  // Service discovery
67
72
  discoverServices(deviceId: string, callback: OperationCallback): void;
68
- getServices(deviceId: string, callback: StringArrayCallback): void;
69
- getCharacteristics(deviceId: string, serviceId: string, callback: StringArrayCallback): void;
73
+ getServices(deviceId: string): string[];
74
+ getCharacteristics(deviceId: string, serviceId: string): string[];
70
75
 
71
76
  // Characteristic operations
72
77
  readCharacteristic(deviceId: string, serviceId: string, characteristicId: string, callback: ReadCharacteristicCallback): void;
@@ -75,10 +80,9 @@ export interface NativeBleNitro extends HybridObject<{ ios: 'swift'; android: 'k
75
80
  unsubscribeFromCharacteristic(deviceId: string, serviceId: string, characteristicId: string, callback: OperationCallback): void;
76
81
 
77
82
  // Bluetooth state management
78
- isBluetoothEnabled(callback: BooleanCallback): void;
79
83
  requestBluetoothEnable(callback: OperationCallback): void;
80
- state(callback: StateCallback): void;
81
- subscribeToStateChange(stateCallback: StateCallback, resultCallback: OperationCallback): void;
82
- unsubscribeFromStateChange(resultCallback: OperationCallback): void;
84
+ state(): BLEState;
85
+ subscribeToStateChange(stateCallback: StateCallback): OperationResult;
86
+ unsubscribeFromStateChange(): OperationResult;
83
87
  openSettings(): Promise<void>;
84
88
  }
@@ -1,74 +0,0 @@
1
- ///
2
- /// JFunc_void_bool.hpp
3
- /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
- /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
6
- ///
7
-
8
- #pragma once
9
-
10
- #include <fbjni/fbjni.h>
11
- #include <functional>
12
-
13
- #include <functional>
14
-
15
- namespace margelo::nitro::co::zyke::ble {
16
-
17
- using namespace facebook;
18
-
19
- /**
20
- * Represents the Java/Kotlin callback `(result: Boolean) -> Unit`.
21
- * This can be passed around between C++ and Java/Kotlin.
22
- */
23
- struct JFunc_void_bool: public jni::JavaClass<JFunc_void_bool> {
24
- public:
25
- static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/Func_void_bool;";
26
-
27
- public:
28
- /**
29
- * Invokes the function this `JFunc_void_bool` instance holds through JNI.
30
- */
31
- void invoke(bool result) const {
32
- static const auto method = javaClassStatic()->getMethod<void(jboolean /* result */)>("invoke");
33
- method(self(), result);
34
- }
35
- };
36
-
37
- /**
38
- * An implementation of Func_void_bool that is backed by a C++ implementation (using `std::function<...>`)
39
- */
40
- struct JFunc_void_bool_cxx final: public jni::HybridClass<JFunc_void_bool_cxx, JFunc_void_bool> {
41
- public:
42
- static jni::local_ref<JFunc_void_bool::javaobject> fromCpp(const std::function<void(bool /* result */)>& func) {
43
- return JFunc_void_bool_cxx::newObjectCxxArgs(func);
44
- }
45
-
46
- public:
47
- /**
48
- * Invokes the C++ `std::function<...>` this `JFunc_void_bool_cxx` instance holds.
49
- */
50
- void invoke_cxx(jboolean result) {
51
- _func(static_cast<bool>(result));
52
- }
53
-
54
- public:
55
- [[nodiscard]]
56
- inline const std::function<void(bool /* result */)>& getFunction() const {
57
- return _func;
58
- }
59
-
60
- public:
61
- static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/Func_void_bool_cxx;";
62
- static void registerNatives() {
63
- registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_bool_cxx::invoke_cxx)});
64
- }
65
-
66
- private:
67
- explicit JFunc_void_bool_cxx(const std::function<void(bool /* result */)>& func): _func(func) { }
68
-
69
- private:
70
- friend HybridBase;
71
- std::function<void(bool /* result */)> _func;
72
- };
73
-
74
- } // namespace margelo::nitro::co::zyke::ble
@@ -1,99 +0,0 @@
1
- ///
2
- /// JFunc_void_std__vector_BLEDevice_.hpp
3
- /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
- /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
6
- ///
7
-
8
- #pragma once
9
-
10
- #include <fbjni/fbjni.h>
11
- #include <functional>
12
-
13
- #include "BLEDevice.hpp"
14
- #include <vector>
15
- #include <functional>
16
- #include "JBLEDevice.hpp"
17
- #include <string>
18
- #include "ManufacturerData.hpp"
19
- #include "JManufacturerData.hpp"
20
- #include "ManufacturerDataEntry.hpp"
21
- #include "JManufacturerDataEntry.hpp"
22
-
23
- namespace margelo::nitro::co::zyke::ble {
24
-
25
- using namespace facebook;
26
-
27
- /**
28
- * Represents the Java/Kotlin callback `(devices: Array<BLEDevice>) -> Unit`.
29
- * This can be passed around between C++ and Java/Kotlin.
30
- */
31
- struct JFunc_void_std__vector_BLEDevice_: public jni::JavaClass<JFunc_void_std__vector_BLEDevice_> {
32
- public:
33
- static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/Func_void_std__vector_BLEDevice_;";
34
-
35
- public:
36
- /**
37
- * Invokes the function this `JFunc_void_std__vector_BLEDevice_` instance holds through JNI.
38
- */
39
- void invoke(const std::vector<BLEDevice>& devices) const {
40
- static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JArrayClass<JBLEDevice>> /* devices */)>("invoke");
41
- method(self(), [&]() {
42
- size_t __size = devices.size();
43
- jni::local_ref<jni::JArrayClass<JBLEDevice>> __array = jni::JArrayClass<JBLEDevice>::newArray(__size);
44
- for (size_t __i = 0; __i < __size; __i++) {
45
- const auto& __element = devices[__i];
46
- __array->setElement(__i, *JBLEDevice::fromCpp(__element));
47
- }
48
- return __array;
49
- }());
50
- }
51
- };
52
-
53
- /**
54
- * An implementation of Func_void_std__vector_BLEDevice_ that is backed by a C++ implementation (using `std::function<...>`)
55
- */
56
- struct JFunc_void_std__vector_BLEDevice__cxx final: public jni::HybridClass<JFunc_void_std__vector_BLEDevice__cxx, JFunc_void_std__vector_BLEDevice_> {
57
- public:
58
- static jni::local_ref<JFunc_void_std__vector_BLEDevice_::javaobject> fromCpp(const std::function<void(const std::vector<BLEDevice>& /* devices */)>& func) {
59
- return JFunc_void_std__vector_BLEDevice__cxx::newObjectCxxArgs(func);
60
- }
61
-
62
- public:
63
- /**
64
- * Invokes the C++ `std::function<...>` this `JFunc_void_std__vector_BLEDevice__cxx` instance holds.
65
- */
66
- void invoke_cxx(jni::alias_ref<jni::JArrayClass<JBLEDevice>> devices) {
67
- _func([&]() {
68
- size_t __size = devices->size();
69
- std::vector<BLEDevice> __vector;
70
- __vector.reserve(__size);
71
- for (size_t __i = 0; __i < __size; __i++) {
72
- auto __element = devices->getElement(__i);
73
- __vector.push_back(__element->toCpp());
74
- }
75
- return __vector;
76
- }());
77
- }
78
-
79
- public:
80
- [[nodiscard]]
81
- inline const std::function<void(const std::vector<BLEDevice>& /* devices */)>& getFunction() const {
82
- return _func;
83
- }
84
-
85
- public:
86
- static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/Func_void_std__vector_BLEDevice__cxx;";
87
- static void registerNatives() {
88
- registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_std__vector_BLEDevice__cxx::invoke_cxx)});
89
- }
90
-
91
- private:
92
- explicit JFunc_void_std__vector_BLEDevice__cxx(const std::function<void(const std::vector<BLEDevice>& /* devices */)>& func): _func(func) { }
93
-
94
- private:
95
- friend HybridBase;
96
- std::function<void(const std::vector<BLEDevice>& /* devices */)> _func;
97
- };
98
-
99
- } // namespace margelo::nitro::co::zyke::ble
@@ -1,93 +0,0 @@
1
- ///
2
- /// JFunc_void_std__vector_std__string_.hpp
3
- /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
- /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
6
- ///
7
-
8
- #pragma once
9
-
10
- #include <fbjni/fbjni.h>
11
- #include <functional>
12
-
13
- #include <string>
14
- #include <vector>
15
- #include <functional>
16
-
17
- namespace margelo::nitro::co::zyke::ble {
18
-
19
- using namespace facebook;
20
-
21
- /**
22
- * Represents the Java/Kotlin callback `(result: Array<String>) -> Unit`.
23
- * This can be passed around between C++ and Java/Kotlin.
24
- */
25
- struct JFunc_void_std__vector_std__string_: public jni::JavaClass<JFunc_void_std__vector_std__string_> {
26
- public:
27
- static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/Func_void_std__vector_std__string_;";
28
-
29
- public:
30
- /**
31
- * Invokes the function this `JFunc_void_std__vector_std__string_` instance holds through JNI.
32
- */
33
- void invoke(const std::vector<std::string>& result) const {
34
- static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JArrayClass<jni::JString>> /* result */)>("invoke");
35
- method(self(), [&]() {
36
- size_t __size = result.size();
37
- jni::local_ref<jni::JArrayClass<jni::JString>> __array = jni::JArrayClass<jni::JString>::newArray(__size);
38
- for (size_t __i = 0; __i < __size; __i++) {
39
- const auto& __element = result[__i];
40
- __array->setElement(__i, *jni::make_jstring(__element));
41
- }
42
- return __array;
43
- }());
44
- }
45
- };
46
-
47
- /**
48
- * An implementation of Func_void_std__vector_std__string_ that is backed by a C++ implementation (using `std::function<...>`)
49
- */
50
- struct JFunc_void_std__vector_std__string__cxx final: public jni::HybridClass<JFunc_void_std__vector_std__string__cxx, JFunc_void_std__vector_std__string_> {
51
- public:
52
- static jni::local_ref<JFunc_void_std__vector_std__string_::javaobject> fromCpp(const std::function<void(const std::vector<std::string>& /* result */)>& func) {
53
- return JFunc_void_std__vector_std__string__cxx::newObjectCxxArgs(func);
54
- }
55
-
56
- public:
57
- /**
58
- * Invokes the C++ `std::function<...>` this `JFunc_void_std__vector_std__string__cxx` instance holds.
59
- */
60
- void invoke_cxx(jni::alias_ref<jni::JArrayClass<jni::JString>> result) {
61
- _func([&]() {
62
- size_t __size = result->size();
63
- std::vector<std::string> __vector;
64
- __vector.reserve(__size);
65
- for (size_t __i = 0; __i < __size; __i++) {
66
- auto __element = result->getElement(__i);
67
- __vector.push_back(__element->toStdString());
68
- }
69
- return __vector;
70
- }());
71
- }
72
-
73
- public:
74
- [[nodiscard]]
75
- inline const std::function<void(const std::vector<std::string>& /* result */)>& getFunction() const {
76
- return _func;
77
- }
78
-
79
- public:
80
- static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/Func_void_std__vector_std__string__cxx;";
81
- static void registerNatives() {
82
- registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_std__vector_std__string__cxx::invoke_cxx)});
83
- }
84
-
85
- private:
86
- explicit JFunc_void_std__vector_std__string__cxx(const std::function<void(const std::vector<std::string>& /* result */)>& func): _func(func) { }
87
-
88
- private:
89
- friend HybridBase;
90
- std::function<void(const std::vector<std::string>& /* result */)> _func;
91
- };
92
-
93
- } // namespace margelo::nitro::co::zyke::ble