summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--java/jni/direct_bt/DBTAdapter.cxx167
-rw-r--r--java/jni/direct_bt/DBTDevice.cxx44
-rw-r--r--src/direct_bt/DBTAdapter.cpp90
-rw-r--r--src/direct_bt/DBTDevice.cpp4
-rw-r--r--src/direct_bt/DBTManager.cpp8
-rw-r--r--src/direct_bt/GATTHandler.cpp24
6 files changed, 185 insertions, 152 deletions
diff --git a/java/jni/direct_bt/DBTAdapter.cxx b/java/jni/direct_bt/DBTAdapter.cxx
index decfbd41..1ca9effa 100644
--- a/java/jni/direct_bt/DBTAdapter.cxx
+++ b/java/jni/direct_bt/DBTAdapter.cxx
@@ -193,129 +193,89 @@ class JNIAdapterStatusListener : public AdapterStatusListener {
void adapterSettingsChanged(DBTAdapter const &a, const AdapterSetting oldmask, const AdapterSetting newmask,
const AdapterSetting changedmask, const uint64_t timestamp) override {
JNIEnv *env = *jni_env;
- try {
- #ifdef VERBOSE_ON
- fprintf(stderr, "****** Native Adapter SETTINGS_CHANGED: %s -> %s, changed %s\n",
- direct_bt::adapterSettingsToString(oldmask).c_str(),
- direct_bt::adapterSettingsToString(newmask).c_str(),
- direct_bt::adapterSettingsToString(changedmask).c_str());
- fprintf(stderr, "Status DBTAdapter:\n");
- fprintf(stderr, "%s\n", a.toString().c_str());
- #endif
- (void)a;
- jobject adapterSettingOld = env->NewObject(adapterSettingsClazzRef->getClass(), adapterSettingsClazzCtor, (jint)oldmask);
- java_exception_check_and_throw(env, E_FILE_LINE);
- JNIGlobalRef::check(adapterSettingOld, E_FILE_LINE);
+ DBG_PRINT("****** JNI Adapter SETTINGS_CHANGED: %s -> %s, changed %s\n",
+ direct_bt::adapterSettingsToString(oldmask).c_str(),
+ direct_bt::adapterSettingsToString(newmask).c_str(),
+ direct_bt::adapterSettingsToString(changedmask).c_str());
+ (void)a;
+ jobject adapterSettingOld = env->NewObject(adapterSettingsClazzRef->getClass(), adapterSettingsClazzCtor, (jint)oldmask);
+ java_exception_check_and_throw(env, E_FILE_LINE);
+ JNIGlobalRef::check(adapterSettingOld, E_FILE_LINE);
- jobject adapterSettingNew = env->NewObject(adapterSettingsClazzRef->getClass(), adapterSettingsClazzCtor, (jint)newmask);
- java_exception_check_and_throw(env, E_FILE_LINE);
- JNIGlobalRef::check(adapterSettingNew, E_FILE_LINE);
+ jobject adapterSettingNew = env->NewObject(adapterSettingsClazzRef->getClass(), adapterSettingsClazzCtor, (jint)newmask);
+ java_exception_check_and_throw(env, E_FILE_LINE);
+ JNIGlobalRef::check(adapterSettingNew, E_FILE_LINE);
- jobject adapterSettingChanged = env->NewObject(adapterSettingsClazzRef->getClass(), adapterSettingsClazzCtor, (jint)changedmask);
- java_exception_check_and_throw(env, E_FILE_LINE);
- JNIGlobalRef::check(adapterSettingChanged, E_FILE_LINE);
+ jobject adapterSettingChanged = env->NewObject(adapterSettingsClazzRef->getClass(), adapterSettingsClazzCtor, (jint)changedmask);
+ java_exception_check_and_throw(env, E_FILE_LINE);
+ JNIGlobalRef::check(adapterSettingChanged, E_FILE_LINE);
- env->CallVoidMethod(listenerObjRef->getObject(), mAdapterSettingsChanged,
- JavaGlobalObj::GetObject(adapterObjRef), adapterSettingOld, adapterSettingNew, adapterSettingChanged, (jlong)timestamp);
- java_exception_check_and_throw(env, E_FILE_LINE);
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
+ env->CallVoidMethod(listenerObjRef->getObject(), mAdapterSettingsChanged,
+ JavaGlobalObj::GetObject(adapterObjRef), adapterSettingOld, adapterSettingNew, adapterSettingChanged, (jlong)timestamp);
+ java_exception_check_and_throw(env, E_FILE_LINE);
}
void discoveringChanged(DBTAdapter const &a, const bool enabled, const bool keepAlive, const uint64_t timestamp) override {
JNIEnv *env = *jni_env;
- try {
- #ifdef VERBOSE_ON
- fprintf(stderr, "****** DBTAdapter Device DISCOVERING: enabled %d, keepAlive %d: %s\n", enabled, keepAlive, a.toString().c_str());
- fprintf(stderr, "Status DBTAdapter:\n");
- fprintf(stderr, "%s\n", device->getAdapter().toString().c_str());
- #endif
- (void)a;
- env->CallVoidMethod(listenerObjRef->getObject(), mDiscoveringChanged, JavaGlobalObj::GetObject(adapterObjRef),
- (jboolean)enabled, (jboolean)keepAlive, (jlong)timestamp);
- java_exception_check_and_throw(env, E_FILE_LINE);
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
+ DBG_PRINT("****** JNI Adapter Device DISCOVERING: enabled %d, keepAlive %d: %s\n", enabled, keepAlive, a.toString().c_str());
+ (void)a;
+ env->CallVoidMethod(listenerObjRef->getObject(), mDiscoveringChanged, JavaGlobalObj::GetObject(adapterObjRef),
+ (jboolean)enabled, (jboolean)keepAlive, (jlong)timestamp);
+ java_exception_check_and_throw(env, E_FILE_LINE);
}
void deviceFound(std::shared_ptr<DBTDevice> device, const uint64_t timestamp) override {
JNIEnv *env = *jni_env;
- try {
- #ifdef VERBOSE_ON
- fprintf(stderr, "****** Native Adapter Device FOUND__: %s\n", device->toString().c_str());
- fprintf(stderr, "Status DBTAdapter:\n");
- fprintf(stderr, "%s\n", device->getAdapter().toString().c_str());
- #endif
- jobject jdevice;
- std::shared_ptr<JavaAnonObj> jDeviceRef = device->getJavaObject();
- if( JavaGlobalObj::isValid(jDeviceRef) ) {
- // Reuse Java instance
- jdevice = JavaGlobalObj::GetObject(jDeviceRef);
- } else {
- // New Java instance
- // Device(final long nativeInstance, final Adapter adptr, final String address, final String name)
- const jstring addr = from_string_to_jstring(env, device->getAddressString());
- const jstring name = from_string_to_jstring(env, device->getName());
- java_exception_check_and_throw(env, E_FILE_LINE);
- jobject jDevice = env->NewObject(deviceClazzRef->getClass(), deviceClazzCtor,
- (jlong)device.get(), JavaGlobalObj::GetObject(adapterObjRef), addr, device->getAddressType(), name, (jlong)timestamp);
- java_exception_check_and_throw(env, E_FILE_LINE);
- JNIGlobalRef::check(jDevice, E_FILE_LINE);
- std::shared_ptr<JavaAnonObj> jDeviceRef = device->getJavaObject();
- JavaGlobalObj::check(jDeviceRef, E_FILE_LINE);
- jdevice = JavaGlobalObj::GetObject(jDeviceRef);
- }
- env->CallVoidMethod(listenerObjRef->getObject(), mDeviceFound, jdevice, (jlong)timestamp);
+ DBG_PRINT("****** JNI Adapter Device FOUND__: %s\n", device->toString(true).c_str());
+ jobject jdevice;
+ std::shared_ptr<JavaAnonObj> jDeviceRef = device->getJavaObject();
+ if( JavaGlobalObj::isValid(jDeviceRef) ) {
+ // Reuse Java instance
+ jdevice = JavaGlobalObj::GetObject(jDeviceRef);
+ } else {
+ // New Java instance
+ // Device(final long nativeInstance, final Adapter adptr, final String address, final int intAddressType, final String name)
+ const jstring addr = from_string_to_jstring(env, device->getAddressString());
+ const jstring name = from_string_to_jstring(env, device->getName());
java_exception_check_and_throw(env, E_FILE_LINE);
- } catch(...) {
- rethrow_and_raise_java_exception(env);
+ jobject jDevice = env->NewObject(deviceClazzRef->getClass(), deviceClazzCtor,
+ (jlong)device.get(), JavaGlobalObj::GetObject(adapterObjRef), addr, device->getAddressType(), name, (jlong)timestamp);
+ java_exception_check_and_throw(env, E_FILE_LINE);
+ JNIGlobalRef::check(jDevice, E_FILE_LINE);
+ std::shared_ptr<JavaAnonObj> jDeviceRef = device->getJavaObject();
+ JavaGlobalObj::check(jDeviceRef, E_FILE_LINE);
+ jdevice = JavaGlobalObj::GetObject(jDeviceRef);
}
+ env->CallVoidMethod(listenerObjRef->getObject(), mDeviceFound, jdevice, (jlong)timestamp);
+ java_exception_check_and_throw(env, E_FILE_LINE);
}
void deviceUpdated(std::shared_ptr<DBTDevice> device, const uint64_t timestamp, const EIRDataType updateMask) override {
JNIEnv *env = *jni_env;
- try {
- #ifdef VERBOSE_ON
- fprintf(stderr, "****** Native Adapter Device UPDATED: %s of %s\n", direct_bt::eirDataMaskToString(updateMask).c_str(), device->toString().c_str());
- fprintf(stderr, "Status DBTAdapter:\n");
- fprintf(stderr, "%s\n", device->getAdapter().toString().c_str());
- #endif
- std::shared_ptr<JavaAnonObj> jDeviceRef = device->getJavaObject();
- JavaGlobalObj::check(jDeviceRef, E_FILE_LINE);
- env->SetLongField(JavaGlobalObj::GetObject(jDeviceRef), deviceClazzTSUpdateField, (jlong)timestamp);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ DBG_PRINT("****** JNI Adapter Device UPDATED: %s of %s\n", direct_bt::eirDataMaskToString(updateMask).c_str(), device->toString(true).c_str());
+ std::shared_ptr<JavaAnonObj> jDeviceRef = device->getJavaObject();
+ JavaGlobalObj::check(jDeviceRef, E_FILE_LINE);
+ env->SetLongField(JavaGlobalObj::GetObject(jDeviceRef), deviceClazzTSUpdateField, (jlong)timestamp);
+ java_exception_check_and_throw(env, E_FILE_LINE);
- jobject eirDataTypeSet = env->NewObject(eirDataTypeSetClazzRef->getClass(), eirDataTypeSetClazzCtor, (jint)updateMask);
- java_exception_check_and_throw(env, E_FILE_LINE);
- JNIGlobalRef::check(eirDataTypeSet, E_FILE_LINE);
+ jobject eirDataTypeSet = env->NewObject(eirDataTypeSetClazzRef->getClass(), eirDataTypeSetClazzCtor, (jint)updateMask);
+ java_exception_check_and_throw(env, E_FILE_LINE);
+ JNIGlobalRef::check(eirDataTypeSet, E_FILE_LINE);
- env->CallVoidMethod(listenerObjRef->getObject(), mDeviceUpdated, JavaGlobalObj::GetObject(jDeviceRef), (jlong)timestamp, eirDataTypeSet);
- java_exception_check_and_throw(env, E_FILE_LINE);
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
+ env->CallVoidMethod(listenerObjRef->getObject(), mDeviceUpdated, JavaGlobalObj::GetObject(jDeviceRef), (jlong)timestamp, eirDataTypeSet);
+ java_exception_check_and_throw(env, E_FILE_LINE);
}
void deviceConnectionChanged(std::shared_ptr<DBTDevice> device, const bool connected, const uint64_t timestamp) override {
JNIEnv *env = *jni_env;
- try {
- #ifdef VERBOSE_ON
- fprintf(stderr, "****** DBTAdapter Device CONNECTION: connected %d: %s\n", connected, device->toString().c_str());
- fprintf(stderr, "Status DBTAdapter:\n");
- fprintf(stderr, "%s\n", device->getAdapter().toString().c_str());
- #endif
- std::shared_ptr<JavaAnonObj> jDeviceRef = device->getJavaObject();
- JavaGlobalObj::check(jDeviceRef, E_FILE_LINE);
- env->SetLongField(JavaGlobalObj::GetObject(jDeviceRef), deviceClazzTSUpdateField, (jlong)timestamp);
- java_exception_check_and_throw(env, E_FILE_LINE);
- env->CallVoidMethod(listenerObjRef->getObject(), mDeviceConnectionChanged, JavaGlobalObj::GetObject(jDeviceRef),
- (jboolean)connected, (jlong)timestamp);
- java_exception_check_and_throw(env, E_FILE_LINE);
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
+ DBG_PRINT("****** JNI Adapter Device CONNECTION: connected %d: %s\n", connected, device->toString(true).c_str());
+ std::shared_ptr<JavaAnonObj> jDeviceRef = device->getJavaObject();
+ JavaGlobalObj::check(jDeviceRef, E_FILE_LINE);
+ env->SetLongField(JavaGlobalObj::GetObject(jDeviceRef), deviceClazzTSUpdateField, (jlong)timestamp);
+ java_exception_check_and_throw(env, E_FILE_LINE);
+ env->CallVoidMethod(listenerObjRef->getObject(), mDeviceConnectionChanged, JavaGlobalObj::GetObject(jDeviceRef),
+ (jboolean)connected, (jlong)timestamp);
+ java_exception_check_and_throw(env, E_FILE_LINE);
}
};
std::atomic<int> JNIAdapterStatusListener::iname_next(0);
@@ -324,13 +284,13 @@ jboolean Java_direct_1bt_tinyb_DBTAdapter_addStatusListener(JNIEnv *env, jobject
{
try {
if( nullptr == statusListener ) {
- throw IllegalArgumentException("statusListener is null", E_FILE_LINE);
+ throw IllegalArgumentException("JNIAdapterStatusListener::addStatusListener: statusListener is null", E_FILE_LINE);
}
{
JNIAdapterStatusListener * pre =
getObjectRef<JNIAdapterStatusListener>(env, statusListener, "nativeInstance");
if( nullptr != pre ) {
- WARN_PRINT("statusListener's nativeInstance not null, already in use");
+ WARN_PRINT("JNIAdapterStatusListener::addStatusListener: statusListener's nativeInstance not null, already in use");
return false;
}
}
@@ -348,11 +308,14 @@ jboolean Java_direct_1bt_tinyb_DBTAdapter_addStatusListener(JNIEnv *env, jobject
if( adapter->addStatusListener( l ) ) {
setInstance(env, statusListener, l.get());
+ DBG_PRINT("JNIAdapterStatusListener::addStatusListener: OK: %s", l->toString().c_str());
return JNI_TRUE;
}
+ ERR_PRINT("JNIAdapterStatusListener::addStatusListener: FAILED: %s", l->toString().c_str());
} catch(...) {
rethrow_and_raise_java_exception(env);
}
+ DBG_PRINT("JNIAdapterStatusListener::addStatusListener: FAILED XX");
return JNI_FALSE;
}
diff --git a/java/jni/direct_bt/DBTDevice.cxx b/java/jni/direct_bt/DBTDevice.cxx
index 8ac344b5..2e727d52 100644
--- a/java/jni/direct_bt/DBTDevice.cxx
+++ b/java/jni/direct_bt/DBTDevice.cxx
@@ -102,44 +102,36 @@ class JNICharacteristicListener : public GATTCharacteristicListener {
void notificationReceived(GATTCharacteristicRef charDecl,
std::shared_ptr<TROOctets> charValue, const uint64_t timestamp) override {
JNIEnv *env = *jni_env;
- try {
- JavaGlobalObj::check(charDecl->getJavaObject(), E_FILE_LINE);
- jobject jCharDecl = JavaGlobalObj::GetObject(charDecl->getJavaObject());
+ JavaGlobalObj::check(charDecl->getJavaObject(), E_FILE_LINE);
+ jobject jCharDecl = JavaGlobalObj::GetObject(charDecl->getJavaObject());
- const size_t value_size = charValue->getSize();
- jbyteArray jvalue = env->NewByteArray((jsize)value_size);
- env->SetByteArrayRegion(jvalue, 0, (jsize)value_size, (const jbyte *)charValue->get_ptr());
- java_exception_check_and_throw(env, E_FILE_LINE);
+ const size_t value_size = charValue->getSize();
+ jbyteArray jvalue = env->NewByteArray((jsize)value_size);
+ env->SetByteArrayRegion(jvalue, 0, (jsize)value_size, (const jbyte *)charValue->get_ptr());
+ java_exception_check_and_throw(env, E_FILE_LINE);
- env->CallVoidMethod(listenerObjRef->getObject(), mNotificationReceived,
- jCharDecl, jvalue, (jlong)timestamp);
- java_exception_check_and_throw(env, E_FILE_LINE);
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
+ env->CallVoidMethod(listenerObjRef->getObject(), mNotificationReceived,
+ jCharDecl, jvalue, (jlong)timestamp);
+ java_exception_check_and_throw(env, E_FILE_LINE);
}
void indicationReceived(GATTCharacteristicRef charDecl,
std::shared_ptr<TROOctets> charValue, const uint64_t timestamp,
const bool confirmationSent) override {
JNIEnv *env = *jni_env;
- try {
- JavaGlobalObj::check(charDecl->getJavaObject(), E_FILE_LINE);
- jobject jCharDecl = JavaGlobalObj::GetObject(charDecl->getJavaObject());
+ JavaGlobalObj::check(charDecl->getJavaObject(), E_FILE_LINE);
+ jobject jCharDecl = JavaGlobalObj::GetObject(charDecl->getJavaObject());
- const size_t value_size = charValue->getSize();
- jbyteArray jvalue = env->NewByteArray((jsize)value_size);
- env->SetByteArrayRegion(jvalue, 0, (jsize)value_size, (const jbyte *)charValue->get_ptr());
- java_exception_check_and_throw(env, E_FILE_LINE);
+ const size_t value_size = charValue->getSize();
+ jbyteArray jvalue = env->NewByteArray((jsize)value_size);
+ env->SetByteArrayRegion(jvalue, 0, (jsize)value_size, (const jbyte *)charValue->get_ptr());
+ java_exception_check_and_throw(env, E_FILE_LINE);
- env->CallVoidMethod(listenerObjRef->getObject(), mIndicationReceived,
- jCharDecl, jvalue, (jlong)timestamp, (jboolean)confirmationSent);
- java_exception_check_and_throw(env, E_FILE_LINE);
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
+ env->CallVoidMethod(listenerObjRef->getObject(), mIndicationReceived,
+ jCharDecl, jvalue, (jlong)timestamp, (jboolean)confirmationSent);
+ java_exception_check_and_throw(env, E_FILE_LINE);
}
};
diff --git a/src/direct_bt/DBTAdapter.cpp b/src/direct_bt/DBTAdapter.cpp
index ca8db464..47465254 100644
--- a/src/direct_bt/DBTAdapter.cpp
+++ b/src/direct_bt/DBTAdapter.cpp
@@ -440,8 +440,16 @@ bool DBTAdapter::mgmtEvDeviceDiscoveringCB(std::shared_ptr<MgmtEvent> e) {
dev_id, keepDiscoveringAlive.load(), e->toString().c_str());
const MgmtEvtDiscovering &event = *static_cast<const MgmtEvtDiscovering *>(e.get());
const bool enabled = event.getEnabled();
+ int i=0;
for_each_idx_mtx(mtx_statusListenerList, statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) {
- l->discoveringChanged(*this, enabled, keepDiscoveringAlive, event.getTimestamp());
+ try {
+ l->discoveringChanged(*this, enabled, keepDiscoveringAlive, event.getTimestamp());
+ } catch (std::exception &e) {
+ ERR_PRINT("DBTAdapter::EventCB:DeviceDiscovering-CBs %d/%zd: %s of %s: Caught exception %s",
+ i+1, statusListenerList.size(),
+ l->toString().c_str(), toString().c_str(), e.what());
+ }
+ i++;
});
if( keepDiscoveringAlive && !enabled ) {
std::thread bg(&DBTAdapter::startDiscoveryBackground, this);
@@ -460,8 +468,16 @@ bool DBTAdapter::mgmtEvNewSettingsCB(std::shared_ptr<MgmtEvent> e) {
adapterSettingsToString(adapterInfo->getCurrentSetting()).c_str(),
adapterSettingsToString(changes).c_str() );
+ int i=0;
for_each_idx_mtx(mtx_statusListenerList, statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) {
- l->adapterSettingsChanged(*this, old_setting, adapterInfo->getCurrentSetting(), changes, event.getTimestamp());
+ try {
+ l->adapterSettingsChanged(*this, old_setting, adapterInfo->getCurrentSetting(), changes, event.getTimestamp());
+ } catch (std::exception &e) {
+ ERR_PRINT("DBTAdapter::EventCB:NewSettings-CBs %d/%zd: %s of %s: Caught exception %s",
+ i+1, statusListenerList.size(),
+ l->toString().c_str(), toString().c_str(), e.what());
+ }
+ i++;
});
return true;
@@ -488,11 +504,19 @@ bool DBTAdapter::mgmtEvLocalNameChangedCB(std::shared_ptr<MgmtEvent> e) {
return true;
}
-void DBTAdapter::sendDeviceUpdated(std::shared_ptr<DBTDevice> device, uint64_t timestamp, EIRDataType updateMask) {
+void DBTAdapter::sendDeviceUpdated(std::string cause, std::shared_ptr<DBTDevice> device, uint64_t timestamp, EIRDataType updateMask) {
+ int i=0;
for_each_idx_mtx(mtx_statusListenerList, statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) {
- if( l->matchDevice(*device) ) {
- l->deviceUpdated(device, timestamp, updateMask);
+ try {
+ if( l->matchDevice(*device) ) {
+ l->deviceUpdated(device, timestamp, updateMask);
+ }
+ } catch (std::exception &e) {
+ ERR_PRINT("DBTAdapter::sendDeviceUpdated-CBs (%s) %d/%zd: %s of %s: Caught exception %s",
+ cause.c_str(), i+1, statusListenerList.size(),
+ l->toString().c_str(), device->toString().c_str(), e.what());
}
+ i++;
});
}
@@ -533,13 +557,21 @@ bool DBTAdapter::mgmtEvDeviceConnectedCB(std::shared_ptr<MgmtEvent> e) {
if( 0 < new_connect ) {
addConnectedDevice(device); // track it
}
+ int i=0;
for_each_idx_mtx(mtx_statusListenerList, statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) {
- if( l->matchDevice(*device) ) {
- if( EIRDataType::NONE != updateMask ) {
- l->deviceUpdated(device, ad_report.getTimestamp(), updateMask);
+ try {
+ if( l->matchDevice(*device) ) {
+ if( EIRDataType::NONE != updateMask ) {
+ l->deviceUpdated(device, ad_report.getTimestamp(), updateMask);
+ }
+ l->deviceConnectionChanged(device, true, event.getTimestamp());
}
- l->deviceConnectionChanged(device, true, event.getTimestamp());
+ } catch (std::exception &e) {
+ ERR_PRINT("DBTAdapter::EventCB:DeviceConnected-CBs %d/%zd: %s of %s: Caught exception %s",
+ i+1, statusListenerList.size(),
+ l->toString().c_str(), device->toString().c_str(), e.what());
}
+ i++;
});
} else {
DBG_PRINT("DBTAdapter::EventCB:DeviceConnected(dev_id %d): %s,\n %s\n -> Device not tracked nor discovered",
@@ -556,10 +588,18 @@ bool DBTAdapter::mgmtEvDeviceDisconnectedCB(std::shared_ptr<MgmtEvent> e) {
device->notifyDisconnected();
removeConnectedDevice(*device);
+ int i=0;
for_each_idx_mtx(mtx_statusListenerList, statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) {
- if( l->matchDevice(*device) ) {
- l->deviceConnectionChanged(device, false, event.getTimestamp());
+ try {
+ if( l->matchDevice(*device) ) {
+ l->deviceConnectionChanged(device, false, event.getTimestamp());
+ }
+ } catch (std::exception &e) {
+ ERR_PRINT("DBTAdapter::EventCB:DeviceDisconnected-CBs %d/%zd: %s of %s: Caught exception %s",
+ i+1, statusListenerList.size(),
+ l->toString().c_str(), device->toString().c_str(), e.what());
}
+ i++;
});
} else {
DBG_PRINT("DBTAdapter::EventCB:DeviceDisconnected(dev_id %d): %s\n -> Device not tracked",
@@ -588,7 +628,7 @@ bool DBTAdapter::mgmtEvDeviceFoundCB(std::shared_ptr<MgmtEvent> e) {
//
EIRDataType updateMask = dev->update(ad_report);
if( EIRDataType::NONE != updateMask ) {
- sendDeviceUpdated(dev, ad_report.getTimestamp(), updateMask);
+ sendDeviceUpdated("DiscoveredDeviceFound", dev, ad_report.getTimestamp(), updateMask);
}
return true;
}
@@ -603,13 +643,21 @@ bool DBTAdapter::mgmtEvDeviceFoundCB(std::shared_ptr<MgmtEvent> e) {
//
EIRDataType updateMask = dev->update(ad_report);
addDiscoveredDevice(dev); // re-add to discovered devices!
+ int i=0;
for_each_idx_mtx(mtx_statusListenerList, statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) {
- if( l->matchDevice(*dev) ) {
- l->deviceFound(dev, ad_report.getTimestamp());
+ try {
+ if( l->matchDevice(*dev) ) {
+ l->deviceFound(dev, ad_report.getTimestamp());
+ }
+ } catch (std::exception &e) {
+ ERR_PRINT("DBTAdapter::EventCB:SharedDeviceFound-CBs %d/%zd: %s of %s: Caught exception %s",
+ i+1, statusListenerList.size(),
+ l->toString().c_str(), dev->toString().c_str(), e.what());
}
+ i++;
});
if( EIRDataType::NONE != updateMask ) {
- sendDeviceUpdated(dev, ad_report.getTimestamp(), updateMask);
+ sendDeviceUpdated("SharedDeviceFound", dev, ad_report.getTimestamp(), updateMask);
}
return true;
}
@@ -621,10 +669,18 @@ bool DBTAdapter::mgmtEvDeviceFoundCB(std::shared_ptr<MgmtEvent> e) {
addDiscoveredDevice(dev);
addSharedDevice(dev);
+ int i=0;
for_each_idx_mtx(mtx_statusListenerList, statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) {
- if( l->matchDevice(*dev) ) {
- l->deviceFound(dev, ad_report.getTimestamp());
+ try {
+ if( l->matchDevice(*dev) ) {
+ l->deviceFound(dev, ad_report.getTimestamp());
+ }
+ } catch (std::exception &e) {
+ ERR_PRINT("DBTAdapter::EventCB:NewDeviceFound-CBs %d/%zd: %s of %s: Caught exception %s",
+ i+1, statusListenerList.size(),
+ l->toString().c_str(), dev->toString().c_str(), e.what());
}
+ i++;
});
return true;
diff --git a/src/direct_bt/DBTDevice.cpp b/src/direct_bt/DBTDevice.cpp
index b33d4946..f96d63ac 100644
--- a/src/direct_bt/DBTDevice.cpp
+++ b/src/direct_bt/DBTDevice.cpp
@@ -230,7 +230,7 @@ std::shared_ptr<ConnectionInfo> DBTDevice::getConnectionInfo() {
if( nullptr == sharedInstance ) {
ERR_PRINT("DBTDevice::getConnectionInfo: Device unknown to adapter and not tracked: %s", toString().c_str());
} else {
- adapter.sendDeviceUpdated(sharedInstance, getCurrentMilliseconds(), updateMask);
+ adapter.sendDeviceUpdated("getConnectionInfo", sharedInstance, getCurrentMilliseconds(), updateMask);
}
}
}
@@ -439,7 +439,7 @@ std::vector<std::shared_ptr<GATTService>> DBTDevice::getGATTServices() {
if( nullptr == sharedInstance ) {
ERR_PRINT("DBTDevice::getGATTServices: Device unknown to adapter and not tracked: %s", toString().c_str());
} else {
- adapter.sendDeviceUpdated(sharedInstance, ts, updateMask);
+ adapter.sendDeviceUpdated("getGATTServices", sharedInstance, ts, updateMask);
}
}
}
diff --git a/src/direct_bt/DBTManager.cpp b/src/direct_bt/DBTManager.cpp
index 4e400d9f..876ac7e2 100644
--- a/src/direct_bt/DBTManager.cpp
+++ b/src/direct_bt/DBTManager.cpp
@@ -87,7 +87,13 @@ void DBTManager::mgmtReaderThreadImpl() {
int invokeCount = 0;
for (auto it = mgmtEventCallbackList.begin(); it != mgmtEventCallbackList.end(); ++it) {
if( 0 > it->getDevID() || dev_id == it->getDevID() ) {
- it->getCallback().invoke(event);
+ try {
+ it->getCallback().invoke(event);
+ } catch (std::exception &e) {
+ ERR_PRINT("DBTManager::fwdPacketReceived-CBs %d/%zd: MgmtAdapterEventCallback %s : Caught exception %s",
+ invokeCount+1, mgmtEventCallbackList.size(),
+ it->toString().c_str(), e.what());
+ }
invokeCount++;
}
}
diff --git a/src/direct_bt/GATTHandler.cpp b/src/direct_bt/GATTHandler.cpp
index 02b1747c..36d61846 100644
--- a/src/direct_bt/GATTHandler.cpp
+++ b/src/direct_bt/GATTHandler.cpp
@@ -193,10 +193,18 @@ void GATTHandler::l2capReaderThreadImpl() {
GATTCharacteristicRef decl = findCharacterisicsByValueHandle(a->getHandle());
const std::shared_ptr<TROOctets> data(new POctets(a->getValue()));
const uint64_t timestamp = a->ts_creation;
+ int i=0;
for_each_idx_mtx(mtx_eventListenerList, eventListenerList, [&](std::shared_ptr<GATTCharacteristicListener> &l) {
- if( l->match(*decl) ) {
- l->notificationReceived(decl, data, timestamp);
+ try {
+ if( l->match(*decl) ) {
+ l->notificationReceived(decl, data, timestamp);
+ }
+ } catch (std::exception &e) {
+ ERR_PRINT("GATTHandler::notificationReceived-CBs %d/%zd: GATTCharacteristicListener %s: Caught exception %s",
+ i+1, eventListenerList.size(),
+ aptrHexString((void*)l.get()).c_str(), e.what());
}
+ i++;
});
attPDU = nullptr;
} else if( AttPDUMsg::Opcode::ATT_HANDLE_VALUE_IND == opc ) {
@@ -211,10 +219,18 @@ void GATTHandler::l2capReaderThreadImpl() {
GATTCharacteristicRef decl = findCharacterisicsByValueHandle(a->getHandle());
const std::shared_ptr<TROOctets> data(new POctets(a->getValue()));
const uint64_t timestamp = a->ts_creation;
+ int i=0;
for_each_idx_mtx(mtx_eventListenerList, eventListenerList, [&](std::shared_ptr<GATTCharacteristicListener> &l) {
- if( l->match(*decl) ) {
- l->indicationReceived(decl, data, timestamp, cfmSent);
+ try {
+ if( l->match(*decl) ) {
+ l->indicationReceived(decl, data, timestamp, cfmSent);
+ }
+ } catch (std::exception &e) {
+ ERR_PRINT("GATTHandler::indicationReceived-CBs %d/%zd: GATTCharacteristicListener %s, cfmSent %d: Caught exception %s",
+ i+1, eventListenerList.size(),
+ aptrHexString((void*)l.get()).c_str(), cfmSent, e.what());
}
+ i++;
});
attPDU = nullptr;
} else if( AttPDUMsg::Opcode::ATT_MULTIPLE_HANDLE_VALUE_NTF == opc ) {