Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
DBTAdapter.cxx
Go to the documentation of this file.
1/*
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2020 Gothel Software e.K.
4 * Copyright (c) 2020 ZAFENA AB
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26#include "org_direct_bt_AdapterStatusListener.h"
27#include "jau_direct_bt_DBTAdapter.h"
28
29// #define VERBOSE_ON 1
30#include <jau/debug.hpp>
31
32#include "helper_base.hpp"
33#include "helper_dbt.hpp"
34
37
38using namespace direct_bt;
39using namespace jau::jni;
40
41static const std::string _adapterSettingsClassName("org/direct_bt/AdapterSettings");
42static const std::string _adapterSettingsClazzCtorArgs("(I)V");
43static const std::string _eirDataTypeSetClassName("org/direct_bt/EIRDataTypeSet");
44static const std::string _eirDataTypeSetClazzCtorArgs("(I)V");
45static const std::string _hciStatusCodeClassName("org/direct_bt/HCIStatusCode");
46static const std::string _hciStatusCodeClazzGetArgs("(B)Lorg/direct_bt/HCIStatusCode;");
47static const std::string _scanTypeClassName("org/direct_bt/ScanType");
48static const std::string _scanTypeClazzGetArgs("(B)Lorg/direct_bt/ScanType;");
49static const std::string _discoveryPolicyClassName("org/direct_bt/DiscoveryPolicy");
50static const std::string _discoveryPolicyClazzGetArgs("(B)Lorg/direct_bt/DiscoveryPolicy;");
51static const std::string _pairingModeClassName("org/direct_bt/PairingMode");
52static const std::string _pairingModeClazzGetArgs("(B)Lorg/direct_bt/PairingMode;");
53static const std::string _pairingStateClassName("org/direct_bt/SMPPairingState");
54static const std::string _pairingStateClazzGetArgs("(B)Lorg/direct_bt/SMPPairingState;");
55static const std::string _deviceClazzCtorArgs("(JLjau/direct_bt/DBTAdapter;[BBJLjava/lang/String;)V");
56
57static const std::string _adapterSettingsChangedMethodArgs("(Lorg/direct_bt/BTAdapter;Lorg/direct_bt/AdapterSettings;Lorg/direct_bt/AdapterSettings;Lorg/direct_bt/AdapterSettings;J)V");
58static const std::string _discoveringChangedMethodArgs("(Lorg/direct_bt/BTAdapter;Lorg/direct_bt/ScanType;Lorg/direct_bt/ScanType;ZLorg/direct_bt/DiscoveryPolicy;J)V");
59static const std::string _deviceFoundMethodArgs("(Lorg/direct_bt/BTDevice;J)Z");
60static const std::string _deviceUpdatedMethodArgs("(Lorg/direct_bt/BTDevice;Lorg/direct_bt/EIRDataTypeSet;J)V");
61static const std::string _deviceConnectedMethodArgs("(Lorg/direct_bt/BTDevice;ZJ)V");
62static const std::string _devicePairingStateMethodArgs("(Lorg/direct_bt/BTDevice;Lorg/direct_bt/SMPPairingState;Lorg/direct_bt/PairingMode;J)V");
63static const std::string _deviceReadyMethodArgs("(Lorg/direct_bt/BTDevice;J)V");
64static const std::string _deviceDisconnectedMethodArgs("(Lorg/direct_bt/BTDevice;Lorg/direct_bt/HCIStatusCode;SJ)V");
65
67 private:
68 /**
69 public abstract class AdapterStatusListener {
70 public void adapterSettingsChanged(final BluetoothAdapter adapter,
71 final AdapterSettings oldmask, final AdapterSettings newmask,
72 final AdapterSettings changedmask, final long timestamp) { }
73 public void discoveringChanged(final BluetoothAdapter adapter, final ScanType currentMeta, final ScanType changedType, final boolean changedEnabled,
74 final DiscoveryPolicy policy, final long timestamp) { }
75 public void deviceFound(final BluetoothDevice device, final long timestamp) { }
76 public void deviceUpdated(final BluetoothDevice device, final EIRDataTypeSet updateMask, final long timestamp) { }
77 public void deviceConnected(final BluetoothDevice device, final short handle, final long timestamp) { }
78 public void devicePairingState(final BluetoothDevice device, final SMPPairingState state, final PairingMode mode, final long timestamp) {}
79 public void deviceReady(final BluetoothDevice device, final long timestamp) {}
80 public void deviceDisconnected(final BluetoothDevice device, final HCIStatusCode reason, final short handle, final long timestamp) { }
81
82 };
83 */
84 static std::atomic<int> iname_next;
85 int const iname;
86
87 JNIGlobalRef adapterSettingsClazzRef;
88 jmethodID adapterSettingsClazzCtor;
89 JNIGlobalRef eirDataTypeSetClazzRef;
90 jmethodID eirDataTypeSetClazzCtor;
91 JNIGlobalRef hciStatusCodeClazzRef;
92 jmethodID hciStatusCodeClazzGet;
93 JNIGlobalRef scanTypeClazzRef;
94 jmethodID scanTypeClazzGet;
95 JNIGlobalRef discoveryPolicyClazzRef;
96 jmethodID discoveryPolicyClazzGet;
97 JNIGlobalRef pairingModeClazzRef;
98 jmethodID pairingModeClazzGet;
99 JNIGlobalRef pairingStateClazzRef;
100 jmethodID pairingStateClazzGet;
101
102 JNIGlobalRef deviceClazzRef;
103 jmethodID deviceClazzCtor;
104 jfieldID deviceClazzTSLastDiscoveryField;
105 jfieldID deviceClazzTSLastUpdateField;
106 jfieldID deviceClazzConnectionHandleField;
107 jmethodID mAdapterSettingsChanged = nullptr;
108 jmethodID mDiscoveringChanged = nullptr;
109 jmethodID mDeviceFound = nullptr;
110 jmethodID mDeviceUpdated = nullptr;
111 jmethodID mDeviceConnected= nullptr;
112 jmethodID mDevicePairingState= nullptr;
113 jmethodID mDeviceReady = nullptr;
114 jmethodID mDeviceDisconnected = nullptr;
115
116 public:
117
118 std::string toString() const noexcept override {
119 return "JNIAdapterStatusListener[this "+jau::to_hexstring(this)+", iname "+std::to_string(iname)+"]";
120 }
121
122 // listenerObjRef dtor will call notifyDelete and clears the nativeInstance handle
123 ~JNIAdapterStatusListener() override = default;
124
125 JNIAdapterStatusListener(JNIEnv *env, jobject statusListenerObj)
126 : iname(iname_next.fetch_add(1))
127 {
128 jclass listenerClazz = search_class(env, statusListenerObj);
129
130 // adapterSettingsClazzRef, adapterSettingsClazzCtor
131 {
132 jclass adapterSettingsClazz = search_class(env, _adapterSettingsClassName.c_str());
133 adapterSettingsClazzRef = JNIGlobalRef(adapterSettingsClazz);
134 env->DeleteLocalRef(adapterSettingsClazz);
135 }
136 adapterSettingsClazzCtor = search_method(env, adapterSettingsClazzRef.getClass(), "<init>", _adapterSettingsClazzCtorArgs.c_str(), false);
137
138 // eirDataTypeSetClazzRef, eirDataTypeSetClazzCtor
139 {
140 jclass eirDataTypeSetClazz = search_class(env, _eirDataTypeSetClassName.c_str());
141 eirDataTypeSetClazzRef = JNIGlobalRef(eirDataTypeSetClazz);
142 env->DeleteLocalRef(eirDataTypeSetClazz);
143 }
144 eirDataTypeSetClazzCtor = search_method(env, eirDataTypeSetClazzRef.getClass(), "<init>", _eirDataTypeSetClazzCtorArgs.c_str(), false);
145
146 // hciStatusCodeClazzRef, hciStatusCodeClazzGet
147 {
148 jclass hciErrorCodeClazz = search_class(env, _hciStatusCodeClassName.c_str());
149 hciStatusCodeClazzRef = JNIGlobalRef(hciErrorCodeClazz);
150 env->DeleteLocalRef(hciErrorCodeClazz);
151 }
152 hciStatusCodeClazzGet = search_method(env, hciStatusCodeClazzRef.getClass(), "get", _hciStatusCodeClazzGetArgs.c_str(), true);
153
154 // scanTypeClazzRef, scanTypeClazzGet
155 {
156 jclass scanTypeClazz = search_class(env, _scanTypeClassName.c_str());
157 scanTypeClazzRef = JNIGlobalRef(scanTypeClazz);
158 env->DeleteLocalRef(scanTypeClazz);
159 }
160 scanTypeClazzGet = search_method(env, scanTypeClazzRef.getClass(), "get", _scanTypeClazzGetArgs.c_str(), true);
161
162 // discoveryPolicyClazzRef, discoveryPolicyClazzGet;
163 {
164 jclass discoveryPolicyClazz = search_class(env, _discoveryPolicyClassName.c_str());
165 discoveryPolicyClazzRef = JNIGlobalRef(discoveryPolicyClazz);
166 env->DeleteLocalRef(discoveryPolicyClazz);
167 }
168 discoveryPolicyClazzGet = search_method(env, discoveryPolicyClazzRef.getClass(), "get", _discoveryPolicyClazzGetArgs.c_str(), true);
169
170 // pairingModeClazzRef, pairingModeClazzGet
171 {
172 jclass pairingModeClazz = search_class(env, _pairingModeClassName.c_str());
173 pairingModeClazzRef = JNIGlobalRef(pairingModeClazz);
174 env->DeleteLocalRef(pairingModeClazz);
175 }
176 pairingModeClazzGet = search_method(env, pairingModeClazzRef.getClass(), "get", _pairingModeClazzGetArgs.c_str(), true);
177
178 // pairingStateClazzRef, pairingStateClazzGet
179 {
180 jclass pairingStateClazz = search_class(env, _pairingStateClassName.c_str());
181 pairingStateClazzRef = JNIGlobalRef(pairingStateClazz);
182 env->DeleteLocalRef(pairingStateClazz);
183 }
184 pairingStateClazzGet = search_method(env, pairingStateClazzRef.getClass(), "get", _pairingStateClazzGetArgs.c_str(), true);
185
186 // deviceClazzRef, deviceClazzCtor
187 {
188 jclass deviceClazz = search_class(env, BTDevice::java_class().c_str());
189 deviceClazzRef = JNIGlobalRef(deviceClazz);
190 env->DeleteLocalRef(deviceClazz);
191 }
192 deviceClazzCtor = search_method(env, deviceClazzRef.getClass(), "<init>", _deviceClazzCtorArgs.c_str(), false);
193
194 deviceClazzTSLastDiscoveryField = search_field(env, deviceClazzRef.getClass(), "ts_last_discovery", "J", false);
195 deviceClazzTSLastUpdateField = search_field(env, deviceClazzRef.getClass(), "ts_last_update", "J", false);
196 deviceClazzConnectionHandleField = search_field(env, deviceClazzRef.getClass(), "hciConnHandle", "S", false);
197
198 mAdapterSettingsChanged = search_method(env, listenerClazz, "adapterSettingsChanged", _adapterSettingsChangedMethodArgs.c_str(), false);
199 mDiscoveringChanged = search_method(env, listenerClazz, "discoveringChanged", _discoveringChangedMethodArgs.c_str(), false);
200 mDeviceFound = search_method(env, listenerClazz, "deviceFound", _deviceFoundMethodArgs.c_str(), false);
201 mDeviceUpdated = search_method(env, listenerClazz, "deviceUpdated", _deviceUpdatedMethodArgs.c_str(), false);
202 mDeviceConnected = search_method(env, listenerClazz, "deviceConnected", _deviceConnectedMethodArgs.c_str(), false);
203 mDevicePairingState = search_method(env, listenerClazz, "devicePairingState", _devicePairingStateMethodArgs.c_str(), false);
204 mDeviceReady = search_method(env, listenerClazz, "deviceReady", _deviceReadyMethodArgs.c_str(), false);
205 mDeviceDisconnected = search_method(env, listenerClazz, "deviceDisconnected", _deviceDisconnectedMethodArgs.c_str(), false);
206 }
207
208 void adapterSettingsChanged(BTAdapter &a, const AdapterSetting oldmask, const AdapterSetting newmask,
209 const AdapterSetting changedmask, const uint64_t timestamp) override {
210 JNIEnv *env = *jni_env;
211 (void)a;
212 JavaAnonRef asl_java = getJavaObject(); // hold until done!
213 JavaGlobalObj::check(asl_java, E_FILE_LINE);
214
215 JavaAnonRef adapter_java = a.getJavaObject(); // hold until done!
216 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
217
218 jobject adapterSettingOld = env->NewObject(adapterSettingsClazzRef.getClass(), adapterSettingsClazzCtor, (jint)oldmask);
220 JNIGlobalRef::check(adapterSettingOld, E_FILE_LINE);
221
222 jobject adapterSettingNew = env->NewObject(adapterSettingsClazzRef.getClass(), adapterSettingsClazzCtor, (jint)newmask);
224 JNIGlobalRef::check(adapterSettingNew, E_FILE_LINE);
225
226 jobject adapterSettingChanged = env->NewObject(adapterSettingsClazzRef.getClass(), adapterSettingsClazzCtor, (jint)changedmask);
228 JNIGlobalRef::check(adapterSettingChanged, E_FILE_LINE);
229
230 env->CallVoidMethod(JavaGlobalObj::GetObject(asl_java), mAdapterSettingsChanged,
231 JavaGlobalObj::GetObject(adapter_java), adapterSettingOld, adapterSettingNew, adapterSettingChanged, (jlong)timestamp);
233 env->DeleteLocalRef(adapterSettingOld);
234 env->DeleteLocalRef(adapterSettingNew);
235 env->DeleteLocalRef(adapterSettingChanged);
236 }
237
238 void discoveringChanged(BTAdapter &a, const ScanType currentMeta, const ScanType changedType, const bool changedEnabled, const DiscoveryPolicy policy, const uint64_t timestamp) override {
239 JNIEnv *env = *jni_env;
240 (void)a;
241 JavaAnonRef asl_java = getJavaObject(); // hold until done!
242 JavaGlobalObj::check(asl_java, E_FILE_LINE);
243
244 JavaAnonRef adapter_java = a.getJavaObject(); // hold until done!
245 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
246
247 jobject jcurrentMeta = env->CallStaticObjectMethod(scanTypeClazzRef.getClass(), scanTypeClazzGet, (jbyte)number(currentMeta));
249 JNIGlobalRef::check(jcurrentMeta, E_FILE_LINE);
250
251 jobject jchangedType = env->CallStaticObjectMethod(scanTypeClazzRef.getClass(), scanTypeClazzGet, (jbyte)number(changedType));
253 JNIGlobalRef::check(jchangedType, E_FILE_LINE);
254
255 jobject jdiscoveryPolicy = env->CallStaticObjectMethod(discoveryPolicyClazzRef.getClass(), discoveryPolicyClazzGet, (jbyte)number(policy));
257 JNIGlobalRef::check(jdiscoveryPolicy, E_FILE_LINE);
258
259 env->CallVoidMethod(JavaGlobalObj::GetObject(asl_java), mDiscoveringChanged,
260 JavaGlobalObj::GetObject(adapter_java),
261 jcurrentMeta, jchangedType, (jboolean)changedEnabled, jdiscoveryPolicy, (jlong)timestamp);
263 }
264
265 private:
266
267 jobject newJavaBTDevice(JNIEnv *env, const BTDeviceRef& device, const uint64_t timestamp) {
268 // DBTDevice(final long nativeInstance, final DBTAdapter adptr, final byte byteAddress[/*6*/], final byte byteAddressType,
269 // final long ts_creation, final String name)
270 JavaAnonRef adapter_java = device->getAdapter().getJavaObject(); // hold until done!
271 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
272
273 const EUI48 & addr = device->getAddressAndType().address;
274 jbyteArray jaddr = env->NewByteArray(sizeof(addr));
275 env->SetByteArrayRegion(jaddr, 0, sizeof(addr), (const jbyte*)(addr.b));
277 const jstring name = from_string_to_jstring(env, device->getName());
279 shared_ptr_ref<BTDevice> device_sref(device); // new instance to be released into new jobject
280 jobject tmp_jdevice = env->NewObject(deviceClazzRef.getClass(), deviceClazzCtor,
281 device_sref.release_to_jlong(), JavaGlobalObj::GetObject(adapter_java),
282 jaddr, device->getAddressAndType().type, (jlong)timestamp, name);
284 JNIGlobalRef::check(tmp_jdevice, E_FILE_LINE);
285 JavaAnonRef jDeviceRef1 = device->getJavaObject();
286 JavaGlobalObj::check(jDeviceRef1, E_FILE_LINE);
287 jobject jdevice = JavaGlobalObj::GetObject(jDeviceRef1);
288 env->DeleteLocalRef(jaddr);
289 env->DeleteLocalRef(name);
290 env->DeleteLocalRef(tmp_jdevice);
291 return jdevice;
292 }
293
294 public:
295
296 bool deviceFound(const BTDeviceRef& device, const uint64_t timestamp) override {
297 JNIEnv *env = *jni_env;
298 JavaAnonRef asl_java = getJavaObject(); // hold until done!
299 JavaGlobalObj::check(asl_java, E_FILE_LINE);
300
301 jobject jdevice;
302 JavaAnonRef device_java = device->getJavaObject();
303 if( JavaGlobalObj::isValid(device_java) ) {
304 // Reuse Java instance
305 jdevice = JavaGlobalObj::GetObject(device_java);
306 } else {
307 jdevice = newJavaBTDevice(env, device, timestamp);
308 }
309 env->SetLongField(jdevice, deviceClazzTSLastDiscoveryField, (jlong)device->getLastDiscoveryTimestamp());
311 jboolean res = env->CallBooleanMethod(JavaGlobalObj::GetObject(asl_java), mDeviceFound, jdevice, (jlong)timestamp);
313 return JNI_TRUE == res;
314 }
315
316 void deviceUpdated(const BTDeviceRef& device, const EIRDataType updateMask, const uint64_t timestamp) override {
317 JNIEnv *env = *jni_env;
318 JavaAnonRef asl_java = getJavaObject(); // hold until done!
319 JavaGlobalObj::check(asl_java, E_FILE_LINE);
320
321 JavaAnonRef device_java = device->getJavaObject();
322 if( !JavaGlobalObj::isValid(device_java) ) {
323 return; // java device has been pulled
324 }
325 env->SetLongField(JavaGlobalObj::GetObject(device_java), deviceClazzTSLastUpdateField, (jlong)timestamp);
327
328 jobject eirDataTypeSet = env->NewObject(eirDataTypeSetClazzRef.getClass(), eirDataTypeSetClazzCtor, (jint)updateMask);
330 JNIGlobalRef::check(eirDataTypeSet, E_FILE_LINE);
331
332 env->CallVoidMethod(JavaGlobalObj::GetObject(asl_java), mDeviceUpdated, JavaGlobalObj::GetObject(device_java), eirDataTypeSet, (jlong)timestamp);
334 env->DeleteLocalRef(eirDataTypeSet);
335 }
336
337 void deviceConnected(const BTDeviceRef& device, const bool discovered, const uint64_t timestamp) override {
338 JNIEnv *env = *jni_env;
339 JavaAnonRef asl_java = getJavaObject(); // hold until done!
340 JavaGlobalObj::check(asl_java, E_FILE_LINE);
341
342 jobject jdevice;
343 JavaAnonRef device_java = device->getJavaObject();
344 if( JavaGlobalObj::isValid(device_java) ) {
345 // Reuse Java instance
346 jdevice = JavaGlobalObj::GetObject(device_java);
347 } else {
348 jdevice = newJavaBTDevice(env, device, timestamp);
349 }
350 env->SetShortField(jdevice, deviceClazzConnectionHandleField, (jshort)device->getConnectionHandle());
352 env->SetLongField(jdevice, deviceClazzTSLastDiscoveryField, (jlong)device->getLastDiscoveryTimestamp());
354 env->SetLongField(jdevice, deviceClazzTSLastUpdateField, (jlong)timestamp);
356
357 env->CallVoidMethod(JavaGlobalObj::GetObject(asl_java), mDeviceConnected, jdevice, (jboolean)discovered, (jlong)timestamp);
359 }
360 void devicePairingState(const BTDeviceRef& device, const SMPPairingState state, const PairingMode mode, const uint64_t timestamp) override {
361 JNIEnv *env = *jni_env;
362 JavaAnonRef asl_java = getJavaObject(); // hold until done!
363 JavaGlobalObj::check(asl_java, E_FILE_LINE);
364
365 JavaAnonRef device_java = device->getJavaObject();
366 if( !JavaGlobalObj::isValid(device_java) ) {
367 return; // java device has been pulled
368 }
369
370 jobject jdevice = JavaGlobalObj::GetObject(device_java);
371 env->SetLongField(jdevice, deviceClazzTSLastUpdateField, (jlong)timestamp);
373
374 jobject jstate = env->CallStaticObjectMethod(pairingStateClazzRef.getClass(), pairingStateClazzGet, static_cast<uint8_t>(state));
376 JNIGlobalRef::check(jstate, E_FILE_LINE);
377
378 jobject jmode = env->CallStaticObjectMethod(pairingModeClazzRef.getClass(), pairingModeClazzGet, static_cast<uint8_t>(mode));
380 JNIGlobalRef::check(jmode, E_FILE_LINE);
381
382 env->CallVoidMethod(JavaGlobalObj::GetObject(asl_java), mDevicePairingState, jdevice, jstate, jmode, (jlong)timestamp);
384 }
385 void deviceReady(const BTDeviceRef& device, const uint64_t timestamp) override {
386 JNIEnv *env = *jni_env;
387 JavaAnonRef asl_java = getJavaObject(); // hold until done!
388 JavaGlobalObj::check(asl_java, E_FILE_LINE);
389
390 JavaAnonRef device_java = device->getJavaObject();
391 if( !JavaGlobalObj::isValid(device_java) ) {
392 return; // java device has been pulled
393 }
394
395 jobject jdevice = JavaGlobalObj::GetObject(device_java);
396 env->SetLongField(jdevice, deviceClazzTSLastUpdateField, (jlong)timestamp);
398
399 env->CallVoidMethod(JavaGlobalObj::GetObject(asl_java), mDeviceReady, jdevice, (jlong)timestamp);
401 }
402 void deviceDisconnected(const BTDeviceRef& device, const HCIStatusCode reason, const uint16_t handle, const uint64_t timestamp) override {
403 JNIEnv *env = *jni_env;
404 JavaAnonRef asl_java = getJavaObject(); // hold until done!
405 JavaGlobalObj::check(asl_java, E_FILE_LINE);
406
407 JavaAnonRef device_java = device->getJavaObject();
408 if( !JavaGlobalObj::isValid(device_java) ) {
409 return; // java device has been pulled
410 }
411
412 jobject jdevice = JavaGlobalObj::GetObject(device_java);
413 env->SetLongField(jdevice, deviceClazzTSLastUpdateField, (jlong)timestamp);
415
416 jobject hciErrorCode = env->CallStaticObjectMethod(hciStatusCodeClazzRef.getClass(), hciStatusCodeClazzGet, (jbyte)static_cast<uint8_t>(reason));
418 JNIGlobalRef::check(hciErrorCode, E_FILE_LINE);
419
420 env->SetShortField(jdevice, deviceClazzConnectionHandleField, (jshort)0); // zero out, disconnected
422
423 env->CallVoidMethod(JavaGlobalObj::GetObject(asl_java), mDeviceDisconnected, jdevice, hciErrorCode, (jshort)handle, (jlong)timestamp);
425 }
426};
427std::atomic<int> JNIAdapterStatusListener::iname_next(0);
428
429/*
430 * Class: org_direct_bt_AdapterStatusListener
431 * Method: ctorImpl
432 * Signature: ()J
433 */
435 try {
436 // new instance
438
439 return ref.release_to_jlong();
440 } catch(...) {
442 }
443 return (jlong) (intptr_t) nullptr;
444}
445
446
447/*
448 * Class: org_direct_bt_AdapterStatusListener
449 * Method: deleteImpl
450 * Signature: (J)V
451 */
452void Java_org_direct_1bt_AdapterStatusListener_deleteImpl(JNIEnv *env, jobject obj, jlong nativeInstance) {
453 (void)obj;
454 try {
455 shared_ptr_ref<JNIAdapterStatusListener> sref(nativeInstance, false /* throw_on_nullptr */); // hold copy until done
456 if( nullptr != sref.pointer() ) {
457 std::shared_ptr<JNIAdapterStatusListener>* sref_ptr = castInstance<JNIAdapterStatusListener>(nativeInstance);
458 delete sref_ptr;
459 }
460 } catch(...) {
462 }
463}
464
465void Java_jau_direct_1bt_DBTAdapter_deleteImpl(JNIEnv *env, jobject obj, jlong nativeInstance)
466{
467 (void)obj;
468 try {
469 shared_ptr_ref<BTAdapter> adapter(nativeInstance, false /* throw_on_nullptr */); // hold copy until done
470 if( nullptr != adapter.pointer() ) {
471 if( !adapter.is_null() ) {
472 DBG_PRINT("Java_jau_direct_1bt_DBTAdapter_deleteImpl (w/ close) %s", adapter->toString().c_str());
473 adapter->close();
474 } else {
475 DBG_PRINT("Java_jau_direct_1bt_DBTAdapter_deleteImpl null reference");
476 }
477 std::shared_ptr<BTAdapter>* ref_ptr = castInstance<BTAdapter>(nativeInstance);
478 delete ref_ptr;
479 } else {
480 DBG_PRINT("Java_jau_direct_1bt_DBTAdapter_deleteImpl null reference store");
481 }
482 } catch(...) {
484 }
485}
486
487jboolean Java_jau_direct_1bt_DBTAdapter_addStatusListenerImpl(JNIEnv *env, jobject obj, jobject jdeviceOwnerAndMatch, jobject jstatusListener)
488{
489 try {
490 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
491 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
492 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
493
494 shared_ptr_ref<JNIAdapterStatusListener> asl(env, jstatusListener); // hold until done
495 JavaAnonRef asl_java = asl->getJavaObject(); // hold until done!
496 JavaGlobalObj::check(asl_java, E_FILE_LINE);
497
498 shared_ptr_ref<BTDevice> deviceOwnerAndMatchRef(env, jdeviceOwnerAndMatch, false /* throw_on_nullptr */);
499 if( !deviceOwnerAndMatchRef.is_null() ) {
500 JavaGlobalObj::check(deviceOwnerAndMatchRef->getJavaObject(), E_FILE_LINE);
501 }
502
503 bool addRes;
504 if( !deviceOwnerAndMatchRef.is_null() ) {
505 addRes = adapter->addStatusListener( deviceOwnerAndMatchRef.shared_ptr(), asl.shared_ptr() );
506 } else {
507 addRes = adapter->addStatusListener( asl.shared_ptr() );
508 }
509 if( addRes ) {
510 return JNI_TRUE;
511 }
512 ERR_PRINT("BTAdapter::addStatusListener: FAILED: %s", asl->toString().c_str());
513 } catch(...) {
515 }
516 return JNI_FALSE;
517}
518
519jboolean Java_jau_direct_1bt_DBTAdapter_removeStatusListenerImpl(JNIEnv *env, jobject obj, jobject jstatusListener)
520{
521 try {
522 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
523 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
524 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
525
526 shared_ptr_ref<JNIAdapterStatusListener> asl(env, jstatusListener); // hold until done
527 JavaAnonRef asl_java = asl->getJavaObject(); // hold until done!
528 JavaGlobalObj::check(asl_java, E_FILE_LINE);
529
530 if( ! adapter->removeStatusListener( asl.shared_ptr() ) ) {
531 WARN_PRINT("Failed to remove statusListener with nativeInstance: %p at %s", asl.shared_ptr().get(), adapter->toString().c_str());
532 return false;
533 }
534 return true;
535 } catch(...) {
537 }
538 return JNI_FALSE;
539}
540
542 try {
543 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
544 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
545 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
546 return (jint)adapter->removeAllStatusListener();
547 } catch(...) {
549 }
550 return 0;
551}
552
553jboolean Java_jau_direct_1bt_DBTAdapter_isDeviceWhitelisted(JNIEnv *env, jobject obj, jbyteArray jaddress, jbyte jaddressType) {
554 try {
555 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
556 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
557 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
558
559 if( nullptr == jaddress ) {
560 throw jau::IllegalArgumentException("address null", E_FILE_LINE);
561 }
562 const size_t address_size = env->GetArrayLength(jaddress);
563 if( sizeof(EUI48) > address_size ) {
564 throw jau::IllegalArgumentException("address byte size "+std::to_string(address_size)+" < "+std::to_string(sizeof(EUI48)), E_FILE_LINE);
565 }
566 JNICriticalArray<uint8_t, jbyteArray> criticalArray(env); // RAII - release
567 uint8_t * address_ptr = criticalArray.get(jaddress, criticalArray.Mode::NO_UPDATE_AND_RELEASE);
568 if( nullptr == address_ptr ) {
569 throw jau::InternalError("GetPrimitiveArrayCritical(address byte array) is null", E_FILE_LINE);
570 }
571 const EUI48& address = *reinterpret_cast<EUI48 *>(address_ptr);
572 const BDAddressAndType addressAndType(address, static_cast<BDAddressType>( jaddressType ));
573
574 return adapter->isDeviceWhitelisted(addressAndType);
575 } catch(...) {
577 }
578 return JNI_FALSE;
579}
581 jbyteArray jaddress, jbyte jaddressType, int jctype,
582 jshort min_interval, jshort max_interval,
583 jshort latency, jshort timeout) {
584 try {
585 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
586 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
587 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
588
589 if( nullptr == jaddress ) {
590 throw jau::IllegalArgumentException("address null", E_FILE_LINE);
591 }
592 const size_t address_size = env->GetArrayLength(jaddress);
593 if( sizeof(EUI48) > address_size ) {
594 throw jau::IllegalArgumentException("address byte size "+std::to_string(address_size)+" < "+std::to_string(sizeof(EUI48)), E_FILE_LINE);
595 }
596 JNICriticalArray<uint8_t, jbyteArray> criticalArray(env); // RAII - release
597 uint8_t * address_ptr = criticalArray.get(jaddress, criticalArray.Mode::NO_UPDATE_AND_RELEASE);
598 if( nullptr == address_ptr ) {
599 throw jau::InternalError("GetPrimitiveArrayCritical(address byte array) is null", E_FILE_LINE);
600 }
601 const EUI48& address = *reinterpret_cast<EUI48 *>(address_ptr);
602
603 const BDAddressAndType addressAndType(address, static_cast<BDAddressType>( jaddressType ));
604 const HCIWhitelistConnectType ctype = static_cast<HCIWhitelistConnectType>( jctype );
605 return adapter->addDeviceToWhitelist(addressAndType, ctype, (uint16_t)min_interval, (uint16_t)max_interval, (uint16_t)latency, (uint16_t)timeout);
606 } catch(...) {
608 }
609 return JNI_FALSE;
610}
612 jbyteArray jaddress, jbyte jaddressType, int jctype) {
613 try {
614 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
615 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
616 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
617
618 if( nullptr == jaddress ) {
619 throw jau::IllegalArgumentException("address null", E_FILE_LINE);
620 }
621 const size_t address_size = env->GetArrayLength(jaddress);
622 if( sizeof(EUI48) > address_size ) {
623 throw jau::IllegalArgumentException("address byte size "+std::to_string(address_size)+" < "+std::to_string(sizeof(EUI48)), E_FILE_LINE);
624 }
625 JNICriticalArray<uint8_t, jbyteArray> criticalArray(env); // RAII - release
626 uint8_t * address_ptr = criticalArray.get(jaddress, criticalArray.Mode::NO_UPDATE_AND_RELEASE);
627 if( nullptr == address_ptr ) {
628 throw jau::InternalError("GetPrimitiveArrayCritical(address byte array) is null", E_FILE_LINE);
629 }
630 const EUI48& address = *reinterpret_cast<EUI48 *>(address_ptr);
631
632 const BDAddressAndType addressAndType(address, static_cast<BDAddressType>( jaddressType ));
633 const HCIWhitelistConnectType ctype = static_cast<HCIWhitelistConnectType>( jctype );
634 return adapter->addDeviceToWhitelist(addressAndType, ctype);
635 } catch(...) {
637 }
638 return JNI_FALSE;
639}
640jboolean Java_jau_direct_1bt_DBTAdapter_removeDeviceFromWhitelistImpl(JNIEnv *env, jobject obj, jbyteArray jaddress, jbyte jaddressType) {
641 try {
642 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
643 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
644 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
645
646 if( nullptr == jaddress ) {
647 throw jau::IllegalArgumentException("address null", E_FILE_LINE);
648 }
649 const size_t address_size = env->GetArrayLength(jaddress);
650 if( sizeof(EUI48) > address_size ) {
651 throw jau::IllegalArgumentException("address byte size "+std::to_string(address_size)+" < "+std::to_string(sizeof(EUI48)), E_FILE_LINE);
652 }
653 JNICriticalArray<uint8_t, jbyteArray> criticalArray(env); // RAII - release
654 uint8_t * address_ptr = criticalArray.get(jaddress, criticalArray.Mode::NO_UPDATE_AND_RELEASE);
655 if( nullptr == address_ptr ) {
656 throw jau::InternalError("GetPrimitiveArrayCritical(address byte array) is null", E_FILE_LINE);
657 }
658 const EUI48& address = *reinterpret_cast<EUI48 *>(address_ptr);
659
660 const BDAddressAndType addressAndType(address, static_cast<BDAddressType>( jaddressType ));
661 return adapter->removeDeviceFromWhitelist(addressAndType);
662 } catch(...) {
664 }
665 return JNI_FALSE;
666}
667
668jstring Java_jau_direct_1bt_DBTAdapter_toStringImpl(JNIEnv *env, jobject obj) {
669 try {
670 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
671 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
672 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
673
674 return from_string_to_jstring(env, adapter->toString());
675 } catch(...) {
677 }
678 return nullptr;
679}
680
682{
683 try {
684 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
685 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
686 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
687
688 return (jint) adapter->getBTMajorVersion();
689 } catch(...) {
691 }
692 return 0;
693}
694
695jboolean Java_jau_direct_1bt_DBTAdapter_isPoweredImpl(JNIEnv *env, jobject obj)
696{
697 try {
698 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
699 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
700 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
701
702 return adapter->isPowered();
703 } catch(...) {
705 }
706 return JNI_FALSE;
707}
708
709jboolean Java_jau_direct_1bt_DBTAdapter_isSuspendedImpl(JNIEnv *env, jobject obj)
710{
711 try {
712 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
713 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
714 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
715
716 return adapter->isSuspended();
717 } catch(...) {
719 }
720 return JNI_FALSE;
721}
722
723jboolean Java_jau_direct_1bt_DBTAdapter_isValidImpl(JNIEnv *env, jobject obj)
724{
725 try {
726 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
727 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
728 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
729
730 return adapter->isValid();
731 } catch(...) {
733 }
734 return JNI_FALSE;
735}
736
738{
739 try {
740 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
741 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
742 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
743
744 return (jlong) number( adapter->getLEFeatures() );
745 } catch(...) {
747 }
748 return JNI_FALSE;
749}
750
751jbyte Java_jau_direct_1bt_DBTAdapter_startDiscoveryImpl(JNIEnv *env, jobject obj, jobject jgattServerData,
752 jbyte policy, jboolean le_scan_active,
753 jshort le_scan_interval, jshort le_scan_window,
754 jbyte filter_policy,
755 jboolean filter_dup)
756{
757 try {
758 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
759 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
760 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
761
762 shared_ptr_ref<DBGattServer> gatt_server_ref(env, jgattServerData, false /** throw_on_null */); // hold until done
763 gatt_server_ref.null_check1();
764
765 return (jbyte) number( adapter->startDiscovery(gatt_server_ref.shared_ptr(),
766 static_cast<DiscoveryPolicy>(policy), le_scan_active,
768 } catch(...) {
770 }
771 return (jbyte) number(HCIStatusCode::INTERNAL_FAILURE);
772}
773
775{
776 try {
777 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
778 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
779 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
780
781 return (jbyte) number( adapter->stopDiscovery() );
782 } catch(...) {
784 }
785 return (jbyte) number(HCIStatusCode::INTERNAL_FAILURE);
786}
787
789 DiscoveryPolicy current = DiscoveryPolicy::AUTO_OFF;
790 try {
791 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
792 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
793 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
794
795 current = adapter->getCurrentDiscoveryPolicy();
796 } catch(...) {
798 }
799 return (jbyte)number(current);
800}
801
802jboolean Java_jau_direct_1bt_DBTAdapter_removeDevicePausingDiscovery(JNIEnv *env, jobject obj, jobject jdevice) {
803 try {
804 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
805 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
806 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
807
808 shared_ptr_ref<BTDevice> device(env, jdevice); // hold until done
809 JavaAnonRef device_java = device->getJavaObject(); // hold until done!
810 JavaGlobalObj::check(device_java, E_FILE_LINE);
811
812 return adapter->removeDevicePausingDiscovery(*device) ? JNI_TRUE : JNI_FALSE;
813 } catch(...) {
815 }
816 return JNI_FALSE;
817}
818
819jbyte Java_jau_direct_1bt_DBTAdapter_getRoleImpl(JNIEnv *env, jobject obj)
820{
821 try {
822 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
823 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
824 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
825
826 return (jbyte) number( adapter->getRole() );
827 } catch(...) {
829 }
830 return (jbyte) number( BTRole::None );
831}
832
833jbyte Java_jau_direct_1bt_DBTAdapter_getBTModeImpl(JNIEnv *env, jobject obj)
834{
835 try {
836 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
837 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
838 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
839
840 return (jbyte) number( adapter->getBTMode() );
841 } catch(...) {
843 }
844 return (jbyte) number( BTMode::NONE );
845}
846
848{
849 try {
850 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
851 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
852 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
853
854 jau::darray<BTDeviceRef> array = adapter->getDiscoveredDevices();
856 } catch(...) {
858 }
859 return nullptr;
860}
861
863{
864 try {
865 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
866 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
867 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
868
869 return (jint) adapter->removeDiscoveredDevices();
870 } catch(...) {
872 }
873 return 0;
874}
875
876jboolean Java_jau_direct_1bt_DBTAdapter_removeDiscoveredDeviceImpl1(JNIEnv *env, jobject obj, jbyteArray jaddress, jbyte jaddressType)
877{
878 try {
879 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
880 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
881 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
882
883 if( nullptr == jaddress ) {
884 throw jau::IllegalArgumentException("address null", E_FILE_LINE);
885 }
886 const size_t address_size = env->GetArrayLength(jaddress);
887 if( sizeof(EUI48) > address_size ) {
888 throw jau::IllegalArgumentException("address byte size "+std::to_string(address_size)+" < "+std::to_string(sizeof(EUI48)), E_FILE_LINE);
889 }
890 JNICriticalArray<uint8_t, jbyteArray> criticalArray(env); // RAII - release
891 uint8_t * address_ptr = criticalArray.get(jaddress, criticalArray.Mode::NO_UPDATE_AND_RELEASE);
892 if( nullptr == address_ptr ) {
893 throw jau::InternalError("GetPrimitiveArrayCritical(address byte array) is null", E_FILE_LINE);
894 }
895 const EUI48& address = *reinterpret_cast<EUI48 *>(address_ptr);
896 const BDAddressAndType addressAndType(address, static_cast<BDAddressType>( jaddressType ));
897
898 return adapter->removeDiscoveredDevice(addressAndType);
899 } catch(...) {
901 }
902 return JNI_FALSE;
903}
904
905//
906// misc
907//
908
909jboolean Java_jau_direct_1bt_DBTAdapter_setPowered(JNIEnv *env, jobject obj, jboolean power_on) {
910 try {
911 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
912 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
913 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
914
915 return adapter->setPowered(JNI_TRUE == power_on ? true : false) ? JNI_TRUE : JNI_FALSE;
916 } catch(...) {
918 }
919 return JNI_FALSE;
920}
921
922jbyte Java_jau_direct_1bt_DBTAdapter_setPrivacyImpl(JNIEnv *env, jobject obj, jboolean enable) {
923 try {
924 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
925 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
926 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
927
928 HCIStatusCode res = adapter->setPrivacy(JNI_TRUE == enable ? true : false);
929 return (jbyte) number(res);
930 } catch(...) {
932 }
933 return (jbyte) number(HCIStatusCode::INTERNAL_FAILURE);
934}
935
937 try {
938 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
939 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
940 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
941
942 return adapter->getSecureConnectionsEnabled() ? JNI_TRUE : JNI_FALSE;
943 } catch(...) {
945 }
946 return JNI_FALSE;
947}
948
949jbyte Java_jau_direct_1bt_DBTAdapter_setSecureConnectionsImpl(JNIEnv *env, jobject obj, jboolean enable) {
950 try {
951 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
952 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
953 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
954
955 HCIStatusCode res = adapter->setSecureConnections(JNI_TRUE == enable ? true : false);
956 return (jbyte) number(res);
957 } catch(...) {
959 }
960 return (jbyte) number(HCIStatusCode::INTERNAL_FAILURE);
961}
962
964 jshort conn_interval_min, jshort conn_interval_max,
965 jshort conn_latency, jshort supervision_timeout) {
966 try {
967 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
968 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
969 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
970
971 HCIStatusCode res = adapter->setDefaultConnParam(static_cast<uint16_t>(conn_interval_min),
972 static_cast<uint16_t>(conn_interval_max),
973 static_cast<uint16_t>(conn_latency),
974 static_cast<uint16_t>(supervision_timeout));
975 return (jbyte) number(res);
976 } catch(...) {
978 }
979 return (jbyte) number(HCIStatusCode::INTERNAL_FAILURE);
980}
981
982void Java_jau_direct_1bt_DBTAdapter_setServerConnSecurityImpl(JNIEnv *env, jobject obj, jbyte jsec_level, jbyte jio_cap) {
983 try {
984 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
985 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
986 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
987
988 adapter->setServerConnSecurity( to_BTSecurityLevel( static_cast<uint8_t>(jsec_level) ),
989 to_SMPIOCapability( static_cast<uint8_t>(jio_cap) ) );
990 } catch(...) {
992 }
993}
994
995void Java_jau_direct_1bt_DBTAdapter_setSMPKeyPath(JNIEnv *env, jobject obj, jstring jpath) {
996 try {
997 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
998 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
999 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
1000
1001 std::string path = from_jstring_to_string(env, jpath);
1002 adapter->setSMPKeyPath(path);
1003 } catch(...) {
1005 }
1006}
1007
1008jbyte Java_jau_direct_1bt_DBTAdapter_initializeImpl(JNIEnv *env, jobject obj, jbyte jbtMode, jboolean powerOn) {
1009 try {
1010 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
1011 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
1012 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
1013
1014 const BTMode btMode = static_cast<BTMode>(jbtMode);
1015 HCIStatusCode res = adapter->initialize(btMode, JNI_TRUE == powerOn);
1016 return (jbyte) number(res);
1017 } catch(...) {
1019 }
1020 return (jbyte) number(HCIStatusCode::INTERNAL_FAILURE);
1021}
1022
1023jboolean Java_jau_direct_1bt_DBTAdapter_isInitialized(JNIEnv *env, jobject obj) {
1024 try {
1025 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
1026 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
1027 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
1028
1029 return adapter->isInitialized();
1030 } catch(...) {
1032 }
1033 return JNI_FALSE;
1034}
1035
1036jbyte Java_jau_direct_1bt_DBTAdapter_resetImpl(JNIEnv *env, jobject obj) {
1037 try {
1038 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
1039 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
1040 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
1041
1042 HCIStatusCode res = adapter->reset();
1043 return (jbyte) number(res);
1044 } catch(...) {
1046 }
1047 return (jbyte) number(HCIStatusCode::INTERNAL_FAILURE);
1048}
1049
1051 jbyte jTx, jbyte jRx) {
1052 try {
1053 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
1054 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
1055 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
1056
1057 const LE_PHYs Tx = static_cast<LE_PHYs>(jTx);
1058 const LE_PHYs Rx = static_cast<LE_PHYs>(jRx);
1059
1060 return (jbyte)number ( adapter->setDefaultLE_PHY(Tx, Rx) );
1061 } catch(...) {
1063 }
1064 return (jbyte) number(HCIStatusCode::INTERNAL_FAILURE);
1065}
1066
1067jstring Java_jau_direct_1bt_DBTAdapter_getNameImpl(JNIEnv *env, jobject obj) {
1068 try {
1069 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
1070 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
1071 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
1072
1073 return from_string_to_jstring(env, adapter->getName());
1074 } catch(...) {
1076 }
1077 return nullptr;
1078}
1079
1080jstring Java_jau_direct_1bt_DBTAdapter_getShortNameImpl(JNIEnv *env, jobject obj) {
1081 try {
1082 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
1083 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
1084 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
1085
1086 return from_string_to_jstring(env, adapter->getShortName());
1087 } catch(...) {
1089 }
1090 return nullptr;
1091}
1092
1093jbyte Java_jau_direct_1bt_DBTAdapter_setNameImpl(JNIEnv *env, jobject obj, jstring jname, jstring jshort_name) {
1094 try {
1095 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
1096 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
1097 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
1098
1099 std::string name = from_jstring_to_string(env, jname);
1100 std::string short_name = from_jstring_to_string(env, jshort_name);
1101 return (jbyte) number( adapter->setName(name, short_name) );
1102 } catch(...) {
1104 }
1105 return (jbyte) number(HCIStatusCode::INTERNAL_FAILURE);
1106}
1107
1108jobject Java_jau_direct_1bt_DBTAdapter_connectDeviceImpl(JNIEnv *env, jobject obj, jbyteArray jaddress, jbyte jaddressType) {
1109 try {
1110 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
1111 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
1112 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
1113
1114 if( nullptr == jaddress ) {
1115 throw jau::IllegalArgumentException("address null", E_FILE_LINE);
1116 }
1117 const size_t address_size = env->GetArrayLength(jaddress);
1118 if( sizeof(EUI48) > address_size ) {
1119 throw jau::IllegalArgumentException("address byte size "+std::to_string(address_size)+" < "+std::to_string(sizeof(EUI48)), E_FILE_LINE);
1120 }
1121 JNICriticalArray<uint8_t, jbyteArray> criticalArray(env); // RAII - release
1122 uint8_t * address_ptr = criticalArray.get(jaddress, criticalArray.Mode::NO_UPDATE_AND_RELEASE);
1123 if( nullptr == address_ptr ) {
1124 throw jau::InternalError("GetPrimitiveArrayCritical(address byte array) is null", E_FILE_LINE);
1125 }
1126 const EUI48& address = *reinterpret_cast<EUI48 *>(address_ptr);
1127
1128 const BDAddressType addressType = static_cast<BDAddressType>( jaddressType );
1129 BTDeviceRef device = adapter->findSharedDevice(address, addressType);
1130 if( nullptr == device ) {
1131 device = adapter->findDiscoveredDevice(address, addressType);
1132 }
1133 if( nullptr != device ) {
1134 direct_bt::HCIHandler & hci = adapter->getHCI();
1135 if( !hci.isOpen() ) {
1136 throw BTException("Adapter's HCI closed "+adapter->toString(), E_FILE_LINE);
1137 }
1138 JavaAnonRef jDeviceRef = device->getJavaObject();
1139 JavaGlobalObj::check(jDeviceRef, E_FILE_LINE);
1140
1141 device->connectDefault();
1142 return JavaGlobalObj::GetObject(jDeviceRef);
1143 }
1144 } catch(...) {
1146 }
1147 return nullptr;
1148}
1149
1151 try {
1152 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
1153 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
1154 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
1155
1156 adapter->printDeviceLists();
1157 } catch(...) {
1159 }
1160}
1161
1163 jobject jgattServerData,
1164 jobject jeir,
1165 jint jadv_mask,
1166 jint jscanrsp_mask,
1167 jshort adv_interval_min, jshort adv_interval_max,
1168 jbyte jadv_type, jbyte adv_chan_map, jbyte filter_policy) {
1169 try {
1170 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
1171 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
1172 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
1173
1174 shared_ptr_ref<DBGattServer> gatt_server_ref(env, jgattServerData, false /** throw_on_null */); // hold until done
1175 gatt_server_ref.null_check1();
1176 shared_ptr_ref<EInfoReport> eir_ref(env, jeir); // hold until done
1177
1178 const EIRDataType adv_mask = static_cast<EIRDataType>(jadv_mask);
1179 const EIRDataType scanrsp_mask = static_cast<EIRDataType>(jscanrsp_mask);
1180 const AD_PDU_Type adv_type = static_cast<AD_PDU_Type>(jadv_type);
1181 HCIStatusCode res = adapter->startAdvertising(gatt_server_ref.shared_ptr(), *eir_ref, adv_mask, scanrsp_mask, adv_interval_min, adv_interval_max, adv_type, adv_chan_map, filter_policy);
1182 return (jbyte) number(res);
1183 } catch(...) {
1185 }
1186 return (jbyte) number(HCIStatusCode::INTERNAL_FAILURE);
1187}
1188
1190 jobject jgattServerData,
1191 jshort adv_interval_min, jshort adv_interval_max, jbyte jadv_type, jbyte adv_chan_map,
1192 jbyte filter_policy) {
1193 try {
1194 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
1195 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
1196 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
1197
1198 shared_ptr_ref<DBGattServer> gatt_server_ref(env, jgattServerData, false /** throw_on_null */); // hold until done
1199 gatt_server_ref.null_check1();
1200
1201 const AD_PDU_Type adv_type = static_cast<AD_PDU_Type>(jadv_type);
1202 HCIStatusCode res = adapter->startAdvertising(gatt_server_ref.shared_ptr(), adv_interval_min, adv_interval_max, adv_type, adv_chan_map, filter_policy);
1203 return (jbyte) number(res);
1204 } catch(...) {
1206 }
1207 return (jbyte) number(HCIStatusCode::INTERNAL_FAILURE);
1208}
1209
1211 try {
1212 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
1213 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
1214 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
1215
1216 HCIStatusCode res = adapter->stopAdvertising();
1217 return (jbyte) number(res);
1218 } catch(...) {
1220 }
1221 return (jbyte) number(HCIStatusCode::INTERNAL_FAILURE);
1222}
1223
1224jboolean Java_jau_direct_1bt_DBTAdapter_isAdvertising(JNIEnv *env, jobject obj) {
1225 try {
1226 shared_ptr_ref<BTAdapter> adapter(env, obj); // hold until done
1227 JavaAnonRef adapter_java = adapter->getJavaObject(); // hold until done!
1228 JavaGlobalObj::check(adapter_java, E_FILE_LINE);
1229
1230 return adapter->isAdvertising() ? JNI_TRUE : JNI_FALSE;
1231 } catch(...) {
1233 }
1234 return JNI_FALSE;
1235}
1236
jobject Java_jau_direct_1bt_DBTAdapter_connectDeviceImpl(JNIEnv *env, jobject obj, jbyteArray jaddress, jbyte jaddressType)
jbyte Java_jau_direct_1bt_DBTAdapter_resetImpl(JNIEnv *env, jobject obj)
jbyte Java_jau_direct_1bt_DBTAdapter_startDiscoveryImpl(JNIEnv *env, jobject obj, jobject jgattServerData, jbyte policy, jboolean le_scan_active, jshort le_scan_interval, jshort le_scan_window, jbyte filter_policy, jboolean filter_dup)
Definition: DBTAdapter.cxx:751
static const std::string _adapterSettingsChangedMethodArgs("(Lorg/direct_bt/BTAdapter;Lorg/direct_bt/AdapterSettings;Lorg/direct_bt/AdapterSettings;Lorg/direct_bt/AdapterSettings;J)V")
static const std::string _adapterSettingsClazzCtorArgs("(I)V")
jboolean Java_jau_direct_1bt_DBTAdapter_addDeviceToWhitelistImpl1(JNIEnv *env, jobject obj, jbyteArray jaddress, jbyte jaddressType, int jctype, jshort min_interval, jshort max_interval, jshort latency, jshort timeout)
Definition: DBTAdapter.cxx:580
static const std::string _deviceDisconnectedMethodArgs("(Lorg/direct_bt/BTDevice;Lorg/direct_bt/HCIStatusCode;SJ)V")
static const std::string _adapterSettingsClassName("org/direct_bt/AdapterSettings")
jbyte Java_jau_direct_1bt_DBTAdapter_getBTModeImpl(JNIEnv *env, jobject obj)
Definition: DBTAdapter.cxx:833
static const std::string _discoveryPolicyClazzGetArgs("(B)Lorg/direct_bt/DiscoveryPolicy;")
static const std::string _hciStatusCodeClassName("org/direct_bt/HCIStatusCode")
jlong Java_org_direct_1bt_AdapterStatusListener_ctorImpl(JNIEnv *env, jobject obj)
Definition: DBTAdapter.cxx:434
jbyte Java_jau_direct_1bt_DBTAdapter_stopDiscoveryImpl(JNIEnv *env, jobject obj)
Definition: DBTAdapter.cxx:774
static const std::string _deviceFoundMethodArgs("(Lorg/direct_bt/BTDevice;J)Z")
jboolean Java_jau_direct_1bt_DBTAdapter_getSecureConnectionsEnabled(JNIEnv *env, jobject obj)
Definition: DBTAdapter.cxx:936
void Java_jau_direct_1bt_DBTAdapter_printDeviceListsImpl(JNIEnv *env, jobject obj)
jbyte Java_jau_direct_1bt_DBTAdapter_startAdvertising1Impl(JNIEnv *env, jobject obj, jobject jgattServerData, jobject jeir, jint jadv_mask, jint jscanrsp_mask, jshort adv_interval_min, jshort adv_interval_max, jbyte jadv_type, jbyte adv_chan_map, jbyte filter_policy)
jobject Java_jau_direct_1bt_DBTAdapter_getDiscoveredDevicesImpl(JNIEnv *env, jobject obj)
Definition: DBTAdapter.cxx:847
jboolean Java_jau_direct_1bt_DBTAdapter_isPoweredImpl(JNIEnv *env, jobject obj)
Definition: DBTAdapter.cxx:695
jbyte Java_jau_direct_1bt_DBTAdapter_setSecureConnectionsImpl(JNIEnv *env, jobject obj, jboolean enable)
Definition: DBTAdapter.cxx:949
jint Java_jau_direct_1bt_DBTAdapter_getBTMajorVersion(JNIEnv *env, jobject obj)
Definition: DBTAdapter.cxx:681
jboolean Java_jau_direct_1bt_DBTAdapter_isDeviceWhitelisted(JNIEnv *env, jobject obj, jbyteArray jaddress, jbyte jaddressType)
Definition: DBTAdapter.cxx:553
void Java_jau_direct_1bt_DBTAdapter_setServerConnSecurityImpl(JNIEnv *env, jobject obj, jbyte jsec_level, jbyte jio_cap)
Definition: DBTAdapter.cxx:982
void Java_org_direct_1bt_AdapterStatusListener_deleteImpl(JNIEnv *env, jobject obj, jlong nativeInstance)
Definition: DBTAdapter.cxx:452
static const std::string _deviceReadyMethodArgs("(Lorg/direct_bt/BTDevice;J)V")
static const std::string _hciStatusCodeClazzGetArgs("(B)Lorg/direct_bt/HCIStatusCode;")
static const std::string _deviceClazzCtorArgs("(JLjau/direct_bt/DBTAdapter;[BBJLjava/lang/String;)V")
jbyte Java_jau_direct_1bt_DBTAdapter_setNameImpl(JNIEnv *env, jobject obj, jstring jname, jstring jshort_name)
static const std::string _eirDataTypeSetClassName("org/direct_bt/EIRDataTypeSet")
jbyte Java_jau_direct_1bt_DBTAdapter_setDefaultConnParamImpl(JNIEnv *env, jobject obj, jshort conn_interval_min, jshort conn_interval_max, jshort conn_latency, jshort supervision_timeout)
Definition: DBTAdapter.cxx:963
jboolean Java_jau_direct_1bt_DBTAdapter_removeDeviceFromWhitelistImpl(JNIEnv *env, jobject obj, jbyteArray jaddress, jbyte jaddressType)
Definition: DBTAdapter.cxx:640
jboolean Java_jau_direct_1bt_DBTAdapter_isAdvertising(JNIEnv *env, jobject obj)
jboolean Java_jau_direct_1bt_DBTAdapter_isSuspendedImpl(JNIEnv *env, jobject obj)
Definition: DBTAdapter.cxx:709
jbyte Java_jau_direct_1bt_DBTAdapter_initializeImpl(JNIEnv *env, jobject obj, jbyte jbtMode, jboolean powerOn)
static const std::string _pairingStateClazzGetArgs("(B)Lorg/direct_bt/SMPPairingState;")
jboolean Java_jau_direct_1bt_DBTAdapter_removeDiscoveredDeviceImpl1(JNIEnv *env, jobject obj, jbyteArray jaddress, jbyte jaddressType)
Definition: DBTAdapter.cxx:876
jlong Java_jau_direct_1bt_DBTAdapter_getLEFeaturesImpl(JNIEnv *env, jobject obj)
Definition: DBTAdapter.cxx:737
jint Java_jau_direct_1bt_DBTAdapter_removeDiscoveredDevicesImpl1(JNIEnv *env, jobject obj)
Definition: DBTAdapter.cxx:862
static const std::string _pairingModeClazzGetArgs("(B)Lorg/direct_bt/PairingMode;")
jboolean Java_jau_direct_1bt_DBTAdapter_removeStatusListenerImpl(JNIEnv *env, jobject obj, jobject jstatusListener)
Definition: DBTAdapter.cxx:519
jboolean Java_jau_direct_1bt_DBTAdapter_addStatusListenerImpl(JNIEnv *env, jobject obj, jobject jdeviceOwnerAndMatch, jobject jstatusListener)
Definition: DBTAdapter.cxx:487
static const std::string _scanTypeClassName("org/direct_bt/ScanType")
static const std::string _discoveryPolicyClassName("org/direct_bt/DiscoveryPolicy")
jboolean Java_jau_direct_1bt_DBTAdapter_removeDevicePausingDiscovery(JNIEnv *env, jobject obj, jobject jdevice)
Definition: DBTAdapter.cxx:802
jboolean Java_jau_direct_1bt_DBTAdapter_isValidImpl(JNIEnv *env, jobject obj)
Definition: DBTAdapter.cxx:723
static const std::string _eirDataTypeSetClazzCtorArgs("(I)V")
jboolean Java_jau_direct_1bt_DBTAdapter_setPowered(JNIEnv *env, jobject obj, jboolean power_on)
Definition: DBTAdapter.cxx:909
static const std::string _scanTypeClazzGetArgs("(B)Lorg/direct_bt/ScanType;")
jboolean Java_jau_direct_1bt_DBTAdapter_isInitialized(JNIEnv *env, jobject obj)
jbyte Java_jau_direct_1bt_DBTAdapter_startAdvertising2Impl(JNIEnv *env, jobject obj, jobject jgattServerData, jshort adv_interval_min, jshort adv_interval_max, jbyte jadv_type, jbyte adv_chan_map, jbyte filter_policy)
jstring Java_jau_direct_1bt_DBTAdapter_getNameImpl(JNIEnv *env, jobject obj)
void Java_jau_direct_1bt_DBTAdapter_deleteImpl(JNIEnv *env, jobject obj, jlong nativeInstance)
Definition: DBTAdapter.cxx:465
jbyte Java_jau_direct_1bt_DBTAdapter_setDefaultLE_1PHYImpl(JNIEnv *env, jobject obj, jbyte jTx, jbyte jRx)
jstring Java_jau_direct_1bt_DBTAdapter_getShortNameImpl(JNIEnv *env, jobject obj)
jboolean Java_jau_direct_1bt_DBTAdapter_addDeviceToWhitelistImpl2(JNIEnv *env, jobject obj, jbyteArray jaddress, jbyte jaddressType, int jctype)
Definition: DBTAdapter.cxx:611
jint Java_jau_direct_1bt_DBTAdapter_removeAllStatusListenerImpl(JNIEnv *env, jobject obj)
Definition: DBTAdapter.cxx:541
static const std::string _pairingStateClassName("org/direct_bt/SMPPairingState")
jstring Java_jau_direct_1bt_DBTAdapter_toStringImpl(JNIEnv *env, jobject obj)
Definition: DBTAdapter.cxx:668
jbyte Java_jau_direct_1bt_DBTAdapter_setPrivacyImpl(JNIEnv *env, jobject obj, jboolean enable)
Definition: DBTAdapter.cxx:922
static const std::string _deviceUpdatedMethodArgs("(Lorg/direct_bt/BTDevice;Lorg/direct_bt/EIRDataTypeSet;J)V")
jbyte Java_jau_direct_1bt_DBTAdapter_getCurrentDiscoveryPolicyImpl(JNIEnv *env, jobject obj)
Definition: DBTAdapter.cxx:788
jbyte Java_jau_direct_1bt_DBTAdapter_getRoleImpl(JNIEnv *env, jobject obj)
Definition: DBTAdapter.cxx:819
static const std::string _pairingModeClassName("org/direct_bt/PairingMode")
static const std::string _discoveringChangedMethodArgs("(Lorg/direct_bt/BTAdapter;Lorg/direct_bt/ScanType;Lorg/direct_bt/ScanType;ZLorg/direct_bt/DiscoveryPolicy;J)V")
static const std::string _devicePairingStateMethodArgs("(Lorg/direct_bt/BTDevice;Lorg/direct_bt/SMPPairingState;Lorg/direct_bt/PairingMode;J)V")
static const std::string _deviceConnectedMethodArgs("(Lorg/direct_bt/BTDevice;ZJ)V")
jbyte Java_jau_direct_1bt_DBTAdapter_stopAdvertisingImpl(JNIEnv *env, jobject obj)
void Java_jau_direct_1bt_DBTAdapter_setSMPKeyPath(JNIEnv *env, jobject obj, jstring jpath)
Definition: DBTAdapter.cxx:995
#define E_FILE_LINE
JNIAdapterStatusListener(JNIEnv *env, jobject statusListenerObj)
Definition: DBTAdapter.cxx:125
void deviceConnected(const BTDeviceRef &device, const bool discovered, const uint64_t timestamp) override
Remote BTDevice got connected.
Definition: DBTAdapter.cxx:337
void deviceReady(const BTDeviceRef &device, const uint64_t timestamp) override
Remote BTDevice is ready for user (GATT) processing, i.e.
Definition: DBTAdapter.cxx:385
~JNIAdapterStatusListener() override=default
void deviceUpdated(const BTDeviceRef &device, const EIRDataType updateMask, const uint64_t timestamp) override
An already discovered remote BTDevice has been updated.
Definition: DBTAdapter.cxx:316
void deviceDisconnected(const BTDeviceRef &device, const HCIStatusCode reason, const uint16_t handle, const uint64_t timestamp) override
Remote BTDevice got disconnected.
Definition: DBTAdapter.cxx:402
void adapterSettingsChanged(BTAdapter &a, const AdapterSetting oldmask, const AdapterSetting newmask, const AdapterSetting changedmask, const uint64_t timestamp) override
BTAdapter setting(s) changed.
Definition: DBTAdapter.cxx:208
bool deviceFound(const BTDeviceRef &device, const uint64_t timestamp) override
A remote BTDevice has been newly discovered.
Definition: DBTAdapter.cxx:296
void devicePairingState(const BTDeviceRef &device, const SMPPairingState state, const PairingMode mode, const uint64_t timestamp) override
An already connected remote BTDevice's ::SMPPairingState has changed.
Definition: DBTAdapter.cxx:360
void discoveringChanged(BTAdapter &a, const ScanType currentMeta, const ScanType changedType, const bool changedEnabled, const DiscoveryPolicy policy, const uint64_t timestamp) override
BTAdapter's discovery state has changed, i.e.
Definition: DBTAdapter.cxx:238
std::string toString() const noexcept override
Definition: DBTAdapter.cxx:118
BTAdapter status listener for remote BTDevice discovery events: Added, updated and removed; as well a...
Definition: BTAdapter.hpp:127
Unique Bluetooth EUI48 address and BDAddressType tuple.
Definition: BTAddress.hpp:175
BTAdapter represents one local Bluetooth Controller.
Definition: BTAdapter.hpp:324
A thread safe singleton handler of the HCI control channel to one controller (BT adapter)
Definition: HCIHandler.hpp:179
bool isOpen() const noexcept
Returns true if this mgmt instance is open, connected and hence valid, otherwise false.
Definition: HCIHandler.hpp:405
Implementation of a dynamic linear array storage, aka vector.
Definition: darray.hpp:148
T * get(U jarray_val, Mode mode_val=UPDATE_AND_RELEASE)
Acquired the primitive array.
Definition: jni_mem.hpp:193
jclass getClass() const noexcept
Definition: jni_mem.hpp:126
A std::shared_ptr<T> storage instance to be copied from and released into a java object's long native...
Definition: helper_jni.hpp:393
void null_check1() const
Throws an exception if this instances shared_ptr<T> storage is nullptr.
Definition: helper_jni.hpp:498
bool is_null() const noexcept
Returns true if either this instances shared_ptr<T> storage or the managed object reference is nullpt...
Definition: helper_jni.hpp:614
const std::shared_ptr< T > & shared_ptr() const
Provides access to const reference of shared_ptr<T>, r-value.
Definition: helper_jni.hpp:630
std::shared_ptr< T > * pointer() noexcept
Provides access to the shared_ptr<T> pointer, l-value of storage.
Definition: helper_jni.hpp:621
std::string toString() const noexcept
Definition: helper_jni.hpp:657
jlong release_to_jlong() noexcept
Release ownership and return the jlong representation of the shared_ptr<T> storage.
Definition: helper_jni.hpp:574
static const uint8_t filter_policy
static const uint16_t le_scan_interval
static const uint16_t le_scan_window
static const bool filter_dup
static bool le_scan_active
static BTMode btMode
static const uint16_t adv_interval_max
static const uint8_t adv_chan_map
static const uint16_t adv_interval_min
static const AD_PDU_Type adv_type
#define ERR_PRINT(...)
Use for unconditional error messages, prefix '[elapsed_time] Error @ FILE:LINE FUNC: '.
Definition: debug.hpp:109
#define DBG_PRINT(...)
Use for environment-variable environment::DEBUG conditional debug messages, prefix '[elapsed_time] De...
Definition: debug.hpp:52
#define WARN_PRINT(...)
Use for unconditional warning messages, prefix '[elapsed_time] Warning @ FILE:LINE FUNC: '.
Definition: debug.hpp:123
std::string to_string(const alphabet &v) noexcept
Definition: base_codec.hpp:97
SMPPairingState
SMP Pairing Process state definition.
Definition: SMPTypes.hpp:107
constexpr SMPIOCapability to_SMPIOCapability(const uint8_t v) noexcept
Definition: SMPTypes.hpp:223
constexpr BTSecurityLevel to_BTSecurityLevel(const uint8_t v) noexcept
Definition: BTTypes0.hpp:300
BTMode
Bluetooth adapter operating mode.
Definition: BTTypes0.hpp:112
HCIWhitelistConnectType
HCI Whitelist connection type.
Definition: BTTypes0.hpp:471
DiscoveryPolicy
Discovery policy defines the BTAdapter discovery mode after connecting a remote BTDevice:
Definition: BTAdapter.hpp:82
std::shared_ptr< BTDevice > BTDeviceRef
Definition: BTDevice.hpp:1347
LE_PHYs
LE Transport PHY bit values.
Definition: BTTypes0.hpp:231
ScanType
Meta ScanType as derived from BTMode, with defined value mask consisting of BDAddressType bits.
Definition: BTTypes0.hpp:350
AdapterSetting
Adapter Setting Bits.
Definition: BTTypes1.hpp:144
BDAddressType
BT Core Spec v5.2: Vol 3, Part C Generic Access Profile (GAP): 15.1.1.1 Public Bluetooth address.
Definition: BTAddress.hpp:60
AD_PDU_Type
LE Advertising (AD) Protocol Data Unit (PDU) Types.
Definition: BTTypes0.hpp:397
PairingMode
Bluetooth secure pairing mode.
Definition: BTTypes0.hpp:317
HCIStatusCode
BT Core Spec v5.2: Vol 1, Part F Controller Error Codes: 1.3 List of Error Codes.
Definition: HCITypes.hpp:138
EIRDataType
Bit mask of 'Extended Inquiry Response' (EIR) data fields, indicating a set of related data.
Definition: BTTypes0.hpp:838
constexpr uint32_t number(const iostate rhs) noexcept
Definition: byte_stream.hpp:72
void java_exception_check_and_throw(JNIEnv *env, const char *file, int line)
Throws a C++ exception if a java exception occurred, otherwise do nothing.
thread_local JNIEnvContainer jni_env
jstring from_string_to_jstring(JNIEnv *env, const std::string &str)
jobject convert_vector_sharedptr_to_jarraylist(JNIEnv *env, T &array)
Definition: helper_jni.hpp:702
jfieldID search_field(JNIEnv *env, jclass clazz, const char *field_name, const char *type, bool is_static)
jmethodID search_method(JNIEnv *env, jclass clazz, const char *method_name, const char *prototype, bool is_static)
std::shared_ptr< JavaAnon > JavaAnonRef
Definition: java_uplink.hpp:55
std::string from_jstring_to_string(JNIEnv *env, jstring str)
jclass search_class(JNIEnv *env, const char *clazz_name)
std::string to_hexstring(value_type const &v) noexcept
Produce a lower-case hexadecimal string representation of the given pointer.
#define rethrow_and_raise_java_exception(E)
Re-throw current exception and raise respective java exception using any matching function above.
Definition: helper_base.hpp:52
A packed 48 bit EUI-48 identifier, formerly known as MAC-48 or simply network device MAC address (Med...
Definition: eui48.hpp:324
uint8_t b[6]
Definition: eui48.hpp:324