summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/direct_bt/BTDevice.hpp20
-rw-r--r--java/jau/direct_bt/DBTDevice.java21
-rw-r--r--java/jau/direct_bt/DBTGattService.java2
-rw-r--r--java/org/direct_bt/BTDevice.java76
-rw-r--r--src/direct_bt/BTDevice.cpp13
5 files changed, 104 insertions, 28 deletions
diff --git a/api/direct_bt/BTDevice.hpp b/api/direct_bt/BTDevice.hpp
index ddd86d30..0d60e6c9 100644
--- a/api/direct_bt/BTDevice.hpp
+++ b/api/direct_bt/BTDevice.hpp
@@ -1113,6 +1113,7 @@ namespace direct_bt {
*
* @parameter service_uuid the jau::uuid_t of the desired BTGattService
* @return The matching service or null if not found
+ * @see findGattChar()
*/
BTGattServiceRef findGattService(const jau::uuid_t& service_uuid) noexcept;
@@ -1126,9 +1127,28 @@ namespace direct_bt {
* @parameter service_uuid the jau::uuid_t of the intermediate BTGattService
* @parameter char_uuid the jau::uuid_t of the desired BTGattChar, within the intermediate BTGattService.
* @return The matching characteristic or null if not found
+ * @since 2.4.0
+ * @see findGattService()
*/
BTGattCharRef findGattChar(const jau::uuid_t& service_uuid, const jau::uuid_t& char_uuid) noexcept;
+ /**
+ * Find a BTGattChar by its char_uuid only.
+ *
+ * It will check objects of this connected device using getGattService().
+ *
+ * It will not turn on discovery or connect to this remote device.
+ *
+ * This variation is less efficient than findGattChar() by service_uuid and char_uuid,
+ * since it has to traverse through all services.
+ *
+ * @parameter char_uuid the jau::uuid_t of the desired BTGattChar, within the intermediate BTGattService.
+ * @return The matching characteristic or null if not found
+ * @since 2.4.0
+ * @see findGattService()
+ */
+ BTGattCharRef findGattChar(const jau::uuid_t& char_uuid) noexcept;
+
/** Returns the shared GenericAccess instance, retrieved by {@link #getGattService()} or nullptr if not available. */
std::shared_ptr<GattGenericAccessSvc> getGattGenericAccess();
diff --git a/java/jau/direct_bt/DBTDevice.java b/java/jau/direct_bt/DBTDevice.java
index c4241cce..4bf191f7 100644
--- a/java/jau/direct_bt/DBTDevice.java
+++ b/java/jau/direct_bt/DBTDevice.java
@@ -213,6 +213,27 @@ public class DBTDevice extends DBTObject implements BTDevice
return s.findGattChar(char_uuid);
}
+ @Override
+ public BTGattChar findGattChar(final String char_uuid) {
+ synchronized(serviceCache) {
+ if( !checkServiceCache(true) ) {
+ return null;
+ }
+ for(int srvIdx = serviceCache.size() - 1; srvIdx >= 0; srvIdx-- ) {
+ final DBTGattService s = serviceCache.get(srvIdx).get();
+ if( null == s ) {
+ serviceCache.remove(srvIdx); // remove dead ref
+ continue; // cont w/ next service
+ }
+ final BTGattChar c = s.findGattChar(char_uuid);
+ if( null != c ) {
+ return c;
+ }
+ }
+ return null;
+ }
+ }
+
/* internal */
private native void initImpl();
diff --git a/java/jau/direct_bt/DBTGattService.java b/java/jau/direct_bt/DBTGattService.java
index 97630a80..87a7f9a4 100644
--- a/java/jau/direct_bt/DBTGattService.java
+++ b/java/jau/direct_bt/DBTGattService.java
@@ -77,7 +77,7 @@ public class DBTGattService extends DBTObject implements BTGattService
@Override
public BTGattChar findGattChar(final String char_uuid) {
final DBTDevice device = wbr_device.get();
- if( null != device ) {
+ if( null == device ) {
return null;
}
final int characteristicSize = charList.size();
diff --git a/java/org/direct_bt/BTDevice.java b/java/org/direct_bt/BTDevice.java
index e21af67e..53a8f673 100644
--- a/java/org/direct_bt/BTDevice.java
+++ b/java/org/direct_bt/BTDevice.java
@@ -46,33 +46,6 @@ import java.util.Map;
public interface BTDevice extends BTObject
{
/**
- * Find a {@link BTGattService} by its service_uuid.
- *
- * It will check objects of this connected device.
- *
- * It will not turn on discovery or connect to this remote device.
- *
- * @parameter service_uuid the UUID of the desired {@link BTGattService}
- * @return The matching service or null if not found
- */
- BTGattService findGattService(String service_uuid);
-
- /**
- * Find a {@link BTGattChar} by its service_uuid and char_uuid.
- *
- * It will check objects of this connected device.
- *
- * It will not turn on discovery or connect to this remote device.
- *
- * @parameter service_uuid the UUID of the intermediate {@link BTGattService}
- * @parameter char_uuid the UUID of the desired {@link BTGattChar}, within the intermediate {@link BTGattService}.
- * @return The matching characteristic or null if not found
- */
- BTGattChar findGattChar(String service_uuid, String char_uuid);
-
- /* Bluetooth method calls: */
-
- /**
* Add the given {@link AdapterStatusListener} to the list if not already present,
* listening only for events matching this device.
*
@@ -728,6 +701,55 @@ public interface BTDevice extends BTObject
List<BTGattService> getServices();
/**
+ * Find a {@link BTGattService} by its service_uuid.
+ *
+ * It will check objects of this connected device.
+ *
+ * It will not turn on discovery or connect to this remote device.
+ *
+ * @parameter service_uuid the UUID of the desired {@link BTGattService}
+ * @return The matching service or null if not found
+ * @since 2.4.0
+ * @see #findGattChar(String, String)
+ * @see #findGattChar(String)
+ */
+ BTGattService findGattService(String service_uuid);
+
+ /**
+ * Find a {@link BTGattChar} by its service_uuid and char_uuid.
+ *
+ * It will check objects of this connected device.
+ *
+ * It will not turn on discovery or connect to this remote device.
+ *
+ * @parameter service_uuid the UUID of the intermediate {@link BTGattService}
+ * @parameter char_uuid the UUID of the desired {@link BTGattChar}, within the intermediate {@link BTGattService}.
+ * @return The matching characteristic or null if not found
+ * @since 2.4.0
+ * @see #findGattChar(String)
+ * @see #findGattService(String)
+ */
+ BTGattChar findGattChar(String service_uuid, String char_uuid);
+
+ /**
+ * Find a {@link BTGattChar} by its char_uuid only.
+ *
+ * It will check objects of this connected device.
+ *
+ * It will not turn on discovery or connect to this remote device.
+ *
+ * This variation is less efficient than findGattChar() by service_uuid and char_uuid,
+ * since it has to traverse through all services.
+ *
+ * @parameter char_uuid the UUID of the desired {@link BTGattChar}, within the intermediate {@link BTGattService}.
+ * @return The matching characteristic or null if not found
+ * @since 2.4.0
+ * @see #findGattChar(String, String)
+ * @see #findGattService(String)
+ */
+ BTGattChar findGattChar(String char_uuid);
+
+ /**
* Issues a GATT ping to the device, validating whether it is still reachable.
* <p>
* This method could be periodically utilized to shorten the underlying OS disconnect period
diff --git a/src/direct_bt/BTDevice.cpp b/src/direct_bt/BTDevice.cpp
index 4d1689d8..3e358efb 100644
--- a/src/direct_bt/BTDevice.cpp
+++ b/src/direct_bt/BTDevice.cpp
@@ -2017,6 +2017,19 @@ BTGattCharRef BTDevice::findGattChar(const jau::uuid_t& service_uuid, const jau
return service->findGattChar(char_uuid);
}
+BTGattCharRef BTDevice::findGattChar(const jau::uuid_t& char_uuid) noexcept {
+ const jau::darray<std::shared_ptr<BTGattService>> & services = getGattServices(); // reference of the GATTHandler's list
+ for(const BTGattServiceRef& s : services) {
+ if ( nullptr != s ) {
+ BTGattCharRef c = s->findGattChar(char_uuid);
+ if ( nullptr != c ) {
+ return c;
+ }
+ }
+ }
+ return nullptr;
+}
+
bool BTDevice::sendNotification(const uint16_t char_value_handle, const jau::TROOctets & value) {
std::shared_ptr<BTGattHandler> gh = getGattHandler();
if( nullptr == gh || !gh->isConnected() ) {