aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-09-25 04:06:18 +0200
committerSven Gothel <[email protected]>2020-09-25 04:06:18 +0200
commitcba57aba1f1739f0ca308bf49e9d86c357a27834 (patch)
tree15a26e5d04c0197aa2f1cbe4a9bb07d0c5680781 /src
parent8e8fb67e048db165d5b30720192d4caa82032487 (diff)
DBTDevice, GATTHandler, ..: Ensure take-down (dtor, disconnect, remove*) code path is fully noexcept.
Note that the default dtor is noexcept by specification since C++11. GATTService and childs were marked noexcept earlier.
Diffstat (limited to 'src')
-rw-r--r--src/direct_bt/DBTAdapter.cpp4
-rw-r--r--src/direct_bt/DBTDevice.cpp25
-rw-r--r--src/direct_bt/GATTHandler.cpp20
3 files changed, 24 insertions, 25 deletions
diff --git a/src/direct_bt/DBTAdapter.cpp b/src/direct_bt/DBTAdapter.cpp
index edbd782b..a28c7f99 100644
--- a/src/direct_bt/DBTAdapter.cpp
+++ b/src/direct_bt/DBTAdapter.cpp
@@ -628,7 +628,7 @@ std::shared_ptr<DBTDevice> DBTAdapter::findSharedDevice (EUI48 const & mac, cons
return findDevice(sharedDevices, mac, macType);
}
-void DBTAdapter::removeDevice(DBTDevice & device) {
+void DBTAdapter::removeDevice(DBTDevice & device) noexcept {
const std::lock_guard<std::recursive_mutex> lock(mtx_sharedDevices); // RAII-style acquire and relinquish via destructor
device.disconnect(HCIStatusCode::REMOTE_USER_TERMINATED_CONNECTION);
removeConnectedDevice(device); // usually done in DBTAdapter::mgmtEvDeviceDisconnectedHCI
@@ -907,7 +907,7 @@ bool DBTAdapter::mgmtEvConnectFailedHCI(std::shared_ptr<MgmtEvent> e) {
return true;
}
-bool DBTAdapter::mgmtEvDeviceDisconnectedHCI(std::shared_ptr<MgmtEvent> e) {
+bool DBTAdapter::mgmtEvDeviceDisconnectedHCI(std::shared_ptr<MgmtEvent> e) noexcept {
const MgmtEvtDeviceDisconnected &event = *static_cast<const MgmtEvtDeviceDisconnected *>(e.get());
std::shared_ptr<DBTDevice> device = findConnectedDevice(event.getAddress(), event.getAddressType());
diff --git a/src/direct_bt/DBTDevice.cpp b/src/direct_bt/DBTDevice.cpp
index f3585578..b1f1dccb 100644
--- a/src/direct_bt/DBTDevice.cpp
+++ b/src/direct_bt/DBTDevice.cpp
@@ -72,7 +72,7 @@ DBTDevice::DBTDevice(DBTAdapter & a, EInfoReport const & r)
}
}
-DBTDevice::~DBTDevice() {
+DBTDevice::~DBTDevice() noexcept {
DBG_PRINT("DBTDevice::dtor: ... %p %s", this, getAddressString().c_str());
remove();
advServices.clear();
@@ -392,7 +392,7 @@ HCIStatusCode DBTDevice::connectDefault()
}
}
-void DBTDevice::notifyConnected(const uint16_t handle) {
+void DBTDevice::notifyConnected(const uint16_t handle) noexcept {
const std::lock_guard<std::recursive_mutex> lock_conn(mtx_connect); // RAII-style acquire and relinquish via destructor
DBG_PRINT("DBTDevice::notifyConnected: handle %s -> %s, %s",
@@ -402,24 +402,19 @@ void DBTDevice::notifyConnected(const uint16_t handle) {
hciConnHandle = handle;
}
-void DBTDevice::notifyDisconnected() {
+void DBTDevice::notifyDisconnected() noexcept {
const std::lock_guard<std::recursive_mutex> lock_conn(mtx_connect); // RAII-style acquire and relinquish via destructor
// coming from disconnect callback, ensure cleaning up!
DBG_PRINT("DBTDevice::notifyDisconnected: handle %s -> zero, %s",
uint16HexString(hciConnHandle).c_str(), toString().c_str());
-
- try {
- disconnectGATT();
- } catch (std::exception &e) {
- ERR_PRINT("Exception caught on %s: %s", toString().c_str(), e.what());
- }
+ disconnectGATT();
isConnected = false;
allowDisconnect = false;
hciConnHandle = 0;
}
-void DBTDevice::disconnectGATT() {
+void DBTDevice::disconnectGATT() noexcept {
DBG_PRINT("DBTDevice::disconnectGATT: start");
std::shared_ptr<GATTHandler> gh = gattHandler; // local copy avoiding immediate dtor
if( nullptr != gh ) {
@@ -513,7 +508,7 @@ HCIStatusCode DBTDevice::pair(const std::string & passkey) {
return HCIStatusCode::INTERNAL_FAILURE; // FIXME: Implement LE Secure Connections
}
-void DBTDevice::remove() {
+void DBTDevice::remove() noexcept {
adapter.removeDevice(*this);
}
@@ -542,7 +537,7 @@ std::shared_ptr<GATTHandler> DBTDevice::connectGATT() {
return gattHandler;
}
-std::shared_ptr<GATTHandler> DBTDevice::getGATTHandler() {
+std::shared_ptr<GATTHandler> DBTDevice::getGATTHandler() noexcept {
return gattHandler;
}
@@ -629,7 +624,7 @@ bool DBTDevice::addCharacteristicListener(std::shared_ptr<GATTCharacteristicList
return gatt->addCharacteristicListener(l);
}
-bool DBTDevice::removeCharacteristicListener(std::shared_ptr<GATTCharacteristicListener> l) {
+bool DBTDevice::removeCharacteristicListener(std::shared_ptr<GATTCharacteristicListener> l) noexcept {
std::shared_ptr<GATTHandler> gatt = getGATTHandler();
if( nullptr == gatt ) {
// OK to have GATTHandler being shutdown @ disable
@@ -639,7 +634,7 @@ bool DBTDevice::removeCharacteristicListener(std::shared_ptr<GATTCharacteristicL
return gatt->removeCharacteristicListener(l);
}
-int DBTDevice::removeAllAssociatedCharacteristicListener(std::shared_ptr<GATTCharacteristic> associatedCharacteristic) {
+int DBTDevice::removeAllAssociatedCharacteristicListener(std::shared_ptr<GATTCharacteristic> associatedCharacteristic) noexcept {
std::shared_ptr<GATTHandler> gatt = getGATTHandler();
if( nullptr == gatt ) {
// OK to have GATTHandler being shutdown @ disable
@@ -649,7 +644,7 @@ int DBTDevice::removeAllAssociatedCharacteristicListener(std::shared_ptr<GATTCha
return gatt->removeAllAssociatedCharacteristicListener( associatedCharacteristic );
}
-int DBTDevice::removeAllCharacteristicListener() {
+int DBTDevice::removeAllCharacteristicListener() noexcept {
std::shared_ptr<GATTHandler> gatt = getGATTHandler();
if( nullptr == gatt ) {
// OK to have GATTHandler being shutdown @ disable
diff --git a/src/direct_bt/GATTHandler.cpp b/src/direct_bt/GATTHandler.cpp
index 408441b5..d6251d4d 100644
--- a/src/direct_bt/GATTHandler.cpp
+++ b/src/direct_bt/GATTHandler.cpp
@@ -120,16 +120,18 @@ bool GATTHandler::addCharacteristicListener(std::shared_ptr<GATTCharacteristicLi
return true;
}
-bool GATTHandler::removeCharacteristicListener(std::shared_ptr<GATTCharacteristicListener> l) {
+bool GATTHandler::removeCharacteristicListener(std::shared_ptr<GATTCharacteristicListener> l) noexcept {
if( nullptr == l ) {
- throw IllegalArgumentException("GATTEventListener ref is null", E_FILE_LINE);
+ ERR_PRINT("Given GATTCharacteristicListener ref is null");
+ return false;
}
return removeCharacteristicListener( l.get() );
}
-bool GATTHandler::removeCharacteristicListener(const GATTCharacteristicListener * l) {
+bool GATTHandler::removeCharacteristicListener(const GATTCharacteristicListener * l) noexcept {
if( nullptr == l ) {
- throw IllegalArgumentException("GATTEventListener ref is null", E_FILE_LINE);
+ ERR_PRINT("Given GATTCharacteristicListener ref is null");
+ return false;
}
const std::lock_guard<std::recursive_mutex> lock(mtx_eventListenerList); // RAII-style acquire and relinquish via destructor
for(auto it = characteristicListenerList.begin(); it != characteristicListenerList.end(); ) {
@@ -143,16 +145,18 @@ bool GATTHandler::removeCharacteristicListener(const GATTCharacteristicListener
return false;
}
-int GATTHandler::removeAllAssociatedCharacteristicListener(std::shared_ptr<GATTCharacteristic> associatedCharacteristic) {
+int GATTHandler::removeAllAssociatedCharacteristicListener(std::shared_ptr<GATTCharacteristic> associatedCharacteristic) noexcept {
if( nullptr == associatedCharacteristic ) {
- throw IllegalArgumentException("GATTCharacteristic ref is null", E_FILE_LINE);
+ ERR_PRINT("Given GATTCharacteristic ref is null");
+ return false;
}
return removeAllAssociatedCharacteristicListener( associatedCharacteristic.get() );
}
-int GATTHandler::removeAllAssociatedCharacteristicListener(const GATTCharacteristic * associatedCharacteristic) {
+int GATTHandler::removeAllAssociatedCharacteristicListener(const GATTCharacteristic * associatedCharacteristic) noexcept {
if( nullptr == associatedCharacteristic ) {
- throw IllegalArgumentException("GATTCharacteristic ref is null", E_FILE_LINE);
+ ERR_PRINT("Given GATTCharacteristic ref is null");
+ return false;
}
const std::lock_guard<std::recursive_mutex> lock(mtx_eventListenerList); // RAII-style acquire and relinquish via destructor
for(auto it = characteristicListenerList.begin(); it != characteristicListenerList.end(); ) {