aboutsummaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-07-26 05:35:58 +0200
committerSven Gothel <[email protected]>2020-07-26 05:35:58 +0200
commit083df38df99a0f771388867a8c03b856813ce854 (patch)
treefbe53a1c70151e5d09aa57ce67ea838a85e1db9c /api
parent9feddbb1dee50fcb8c90c2a257cbe0498849b567 (diff)
Have GATT[Service,Characteristic,Descriptor] derived from DBTObject for valid check; Use new JNI getInstance() -> getDBTObject() w/ valid check
Diffstat (limited to 'api')
-rw-r--r--api/direct_bt/DBTAdapter.hpp4
-rw-r--r--api/direct_bt/DBTTypes.hpp13
-rw-r--r--api/direct_bt/GATTCharacteristic.hpp4
-rw-r--r--api/direct_bt/GATTDescriptor.hpp4
-rw-r--r--api/direct_bt/GATTService.hpp4
5 files changed, 21 insertions, 8 deletions
diff --git a/api/direct_bt/DBTAdapter.hpp b/api/direct_bt/DBTAdapter.hpp
index 727f70f1..682c0e0b 100644
--- a/api/direct_bt/DBTAdapter.hpp
+++ b/api/direct_bt/DBTAdapter.hpp
@@ -247,9 +247,9 @@ namespace direct_bt {
/**
* Throws an IllegalStateException if isValid() == false
*/
- inline void checkValid() const {
+ inline void checkValidAdapter() const {
if( !isValid() ) {
- throw IllegalStateException("Adapter state invalid: "+toString(), E_FILE_LINE);
+ throw IllegalStateException("Adapter state invalid: "+aptrHexString(this)+", "+toString(), E_FILE_LINE);
}
}
diff --git a/api/direct_bt/DBTTypes.hpp b/api/direct_bt/DBTTypes.hpp
index c5efa3cd..c900e1d0 100644
--- a/api/direct_bt/DBTTypes.hpp
+++ b/api/direct_bt/DBTTypes.hpp
@@ -46,8 +46,8 @@ namespace direct_bt {
class DBTObject : public JavaUplink
{
protected:
- std::mutex lk;
std::atomic_bool valid;
+ std::mutex lk;
DBTObject() : valid(true) {}
@@ -69,7 +69,16 @@ namespace direct_bt {
valid = false;
}
- bool isValid() const { return valid; }
+ inline bool isValid() const { return valid.load(); }
+
+ /**
+ * Throws an IllegalStateException if isValid() == false
+ */
+ inline void checkValid() const {
+ if( !isValid() ) {
+ throw IllegalStateException("DBTObject state invalid: "+aptrHexString(this), E_FILE_LINE);
+ }
+ }
};
/**
diff --git a/api/direct_bt/GATTCharacteristic.hpp b/api/direct_bt/GATTCharacteristic.hpp
index 67274a32..56d00f3b 100644
--- a/api/direct_bt/GATTCharacteristic.hpp
+++ b/api/direct_bt/GATTCharacteristic.hpp
@@ -40,6 +40,8 @@
#include "OctetTypes.hpp"
#include "ATTPDUTypes.hpp"
+#include "DBTTypes.hpp"
+
#include "GATTDescriptor.hpp"
#include "JavaUplink.hpp"
@@ -71,7 +73,7 @@ namespace direct_bt {
* and the value the Characteristics Property, Characteristics Value Handle _and_ Characteristics UUID.
* </p>
*/
- class GATTCharacteristic : public JavaUplink {
+ class GATTCharacteristic : public DBTObject {
private:
/** Characteristics's service weak back-reference */
std::weak_ptr<GATTService> wbr_service;
diff --git a/api/direct_bt/GATTDescriptor.hpp b/api/direct_bt/GATTDescriptor.hpp
index 97231526..0eaca70e 100644
--- a/api/direct_bt/GATTDescriptor.hpp
+++ b/api/direct_bt/GATTDescriptor.hpp
@@ -40,7 +40,7 @@
#include "OctetTypes.hpp"
#include "ATTPDUTypes.hpp"
-#include "JavaUplink.hpp"
+#include "DBTTypes.hpp"
/**
* - - - - - - - - - - - - - - -
@@ -59,7 +59,7 @@ namespace direct_bt {
/**
* BT Core Spec v5.2: Vol 3, Part G GATT: 3.3.3 Characteristic Descriptor
*/
- class GATTDescriptor : public JavaUplink {
+ class GATTDescriptor : public DBTObject {
private:
/** Descriptor's characteristic weak back-reference */
std::weak_ptr<GATTCharacteristic> wbr_characteristic;
diff --git a/api/direct_bt/GATTService.hpp b/api/direct_bt/GATTService.hpp
index 6f0bc71c..763298bc 100644
--- a/api/direct_bt/GATTService.hpp
+++ b/api/direct_bt/GATTService.hpp
@@ -40,6 +40,8 @@
#include "OctetTypes.hpp"
#include "ATTPDUTypes.hpp"
+#include "DBTTypes.hpp"
+
#include "GATTCharacteristic.hpp"
#include "JavaUplink.hpp"
@@ -61,7 +63,7 @@ namespace direct_bt {
* including its list of Characteristic Declarations,
* which also may include its client config if available.
*/
- class GATTService : public JavaUplink {
+ class GATTService : public DBTObject {
private:
/** Service's device weak back-reference */
std::weak_ptr<DBTDevice> wbr_device;