summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-08-28 07:30:23 +0200
committerSven Gothel <[email protected]>2020-08-28 07:30:23 +0200
commitbae1b8630367f89f290fce5d3e3766cb5455de1e (patch)
tree2306946b6b98bf78b9f20460120738ed33285bbe
parent764c96515f3d0339ec486d8659db25016336fdbe (diff)
DBTDevice::pingGATT(): Disconnect and return false if: GATT not connected or no GATTServices available
This required getGATTServices() (C++) or getServices() (Java) to be completed, hence added remark in API doc. Reasoning is that pingGATT shall not initiated resource creation, but assumes all set set up well. If failing, it shall cause a disconnected.
-rw-r--r--api/direct_bt/DBTDevice.hpp6
-rw-r--r--java/org/tinyb/BluetoothDevice.java7
-rw-r--r--src/direct_bt/DBTDevice.cpp15
3 files changed, 14 insertions, 14 deletions
diff --git a/api/direct_bt/DBTDevice.hpp b/api/direct_bt/DBTDevice.hpp
index 85a217ef..d4d43d5e 100644
--- a/api/direct_bt/DBTDevice.hpp
+++ b/api/direct_bt/DBTDevice.hpp
@@ -383,12 +383,12 @@ namespace direct_bt {
* </p>
* <p>
* In case the device is no more reachable, the GATTHandler will initiate disconnect due to the occurring IO error.
- * will issue a disconnect.
+ * A disconnect will finally being issued.
* </p>
* <p>
- * See {@link #getGATTServices()} regarding GATT initialization.
+ * GATT services must have been initialized via {@link #getGATTServices()}, otherwise {@code false} is being returned.
* </p>
- * @return {@code true} if successful, otherwise false in case no GATT services exists etc.
+ * @return {@code true} if successful, otherwise false in case no GATT services exists or is not connected .. etc.
*/
bool pingGATT();
diff --git a/java/org/tinyb/BluetoothDevice.java b/java/org/tinyb/BluetoothDevice.java
index 03d21e0f..5cc8ff63 100644
--- a/java/org/tinyb/BluetoothDevice.java
+++ b/java/org/tinyb/BluetoothDevice.java
@@ -207,9 +207,12 @@ public interface BluetoothDevice extends BluetoothObject
* <p>
* In case the device is no more reachable, disconnect will be initiated due to the occurring IO error.
* </p>
- *
- * @return {@code true} if successful or not implemented, otherwise false in case GATT connection failed.
+ * <p>
+ * GATT services must have been initialized via {@link #getServices()}, otherwise {@code false} is being returned.
+ * </p>
+ * @return {@code true} if successful or not implemented, otherwise false in case no GATT services exists or is not connected..
* @since 2.0.0
+ * @implNote not implemented in tinyb.dbus.
*/
boolean pingGATT();
diff --git a/src/direct_bt/DBTDevice.cpp b/src/direct_bt/DBTDevice.cpp
index 32f952cb..72f944ae 100644
--- a/src/direct_bt/DBTDevice.cpp
+++ b/src/direct_bt/DBTDevice.cpp
@@ -570,18 +570,15 @@ bool DBTDevice::pingGATT() {
const std::lock_guard<std::recursive_mutex> lock(mtx_gatt); // RAII-style acquire and relinquish via destructor
try {
if( nullptr == gattHandler || !gattHandler->isOpen() ) {
- connectGATT();
- if( nullptr == gattHandler || !gattHandler->isOpen() ) {
- ERR_PRINT("DBTDevice::getServices: connectGATT failed");
- return false;
- }
+ INFO_PRINT("DBTDevice::pingGATT: GATTHandler not connected -> disconnected on %s", toString().c_str());
+ disconnect(false /* fromDisconnectCB */, true /* ioErrorCause */, HCIStatusCode::REMOTE_USER_TERMINATED_CONNECTION);
+ return false;
}
std::vector<std::shared_ptr<GATTService>> & gattServices = gattHandler->getServices(); // reference of the GATTHandler's list
if( gattServices.size() == 0 ) { // discover services
- gattServices = gattHandler->discoverCompletePrimaryServices(); // same reference of the GATTHandler's list
- if( gattServices.size() == 0 ) { // nothing discovered
- return false;
- }
+ INFO_PRINT("DBTDevice::pingGATT: No GATTService available -> disconnected on %s", toString().c_str());
+ disconnect(false /* fromDisconnectCB */, true /* ioErrorCause */, HCIStatusCode::REMOTE_USER_TERMINATED_CONNECTION);
+ return false;
}
return gattHandler->ping();
} catch (std::exception &e) {