aboutsummaryrefslogtreecommitdiffstats
path: root/api/direct_bt
diff options
context:
space:
mode:
Diffstat (limited to 'api/direct_bt')
-rw-r--r--api/direct_bt/DBTAdapter.hpp2
-rw-r--r--api/direct_bt/DBTTypes.hpp4
-rw-r--r--api/direct_bt/GATTCharacteristic.hpp13
-rw-r--r--api/direct_bt/GATTDescriptor.hpp13
-rw-r--r--api/direct_bt/GATTHandler.hpp6
-rw-r--r--api/direct_bt/GATTService.hpp9
-rw-r--r--api/direct_bt/dbt_debug.hpp18
7 files changed, 51 insertions, 14 deletions
diff --git a/api/direct_bt/DBTAdapter.hpp b/api/direct_bt/DBTAdapter.hpp
index c493f438..b70f80c4 100644
--- a/api/direct_bt/DBTAdapter.hpp
+++ b/api/direct_bt/DBTAdapter.hpp
@@ -457,6 +457,8 @@ namespace direct_bt {
std::shared_ptr<DBTDevice> findDiscoveredDevice (EUI48 const & mac);
std::string toString() const override;
+
+ void printDevices();
};
} // namespace direct_bt
diff --git a/api/direct_bt/DBTTypes.hpp b/api/direct_bt/DBTTypes.hpp
index 08f8efa6..de827604 100644
--- a/api/direct_bt/DBTTypes.hpp
+++ b/api/direct_bt/DBTTypes.hpp
@@ -65,6 +65,10 @@ namespace direct_bt {
}
public:
+ virtual ~DBTObject() {
+ valid = false;
+ }
+
bool isValid() { return valid; }
};
diff --git a/api/direct_bt/GATTCharacteristic.hpp b/api/direct_bt/GATTCharacteristic.hpp
index caaaa8ad..16aecb1a 100644
--- a/api/direct_bt/GATTCharacteristic.hpp
+++ b/api/direct_bt/GATTCharacteristic.hpp
@@ -72,6 +72,10 @@ namespace direct_bt {
* </p>
*/
class GATTCharacteristic : public JavaUplink {
+ private:
+ /* Characteristics's Service back-reference */
+ std::weak_ptr<GATTService> wbr_service;
+
public:
/** BT Core Spec v5.2: Vol 3, Part G GATT: 3.3.1.1 Characteristic Properties */
enum PropertyBitVal : uint8_t {
@@ -95,9 +99,6 @@ namespace direct_bt {
static std::string getPropertiesString(const PropertyBitVal properties);
static std::vector<std::unique_ptr<std::string>> getPropertiesStringList(const PropertyBitVal properties);
- /* Characteristics's Service back-reference */
- GATTServiceRef service;
-
/**
* Characteristics's Service Handle - key to service's handle range, retrieved from Characteristics data.
* <p>
@@ -136,7 +137,7 @@ namespace direct_bt {
GATTCharacteristic(const GATTServiceRef & service, const uint16_t service_handle, const uint16_t handle,
const PropertyBitVal properties, const uint16_t value_handle, std::shared_ptr<const uuid_t> value_type)
- : service(service), service_handle(service_handle), handle(handle),
+ : wbr_service(service), service_handle(service_handle), handle(handle),
properties(properties), value_handle(value_handle), value_type(value_type) {}
std::string get_java_class() const override {
@@ -146,7 +147,9 @@ namespace direct_bt {
return std::string(JAVA_DBT_PACKAGE "DBTGattCharacteristic");
}
- std::shared_ptr<DBTDevice> getDevice();
+ std::shared_ptr<GATTService> getService() const { return wbr_service.lock(); }
+
+ std::shared_ptr<DBTDevice> getDevice() const;
bool hasProperties(const PropertyBitVal v) const { return v == ( properties & v ); }
diff --git a/api/direct_bt/GATTDescriptor.hpp b/api/direct_bt/GATTDescriptor.hpp
index 3c847f20..5aa75656 100644
--- a/api/direct_bt/GATTDescriptor.hpp
+++ b/api/direct_bt/GATTDescriptor.hpp
@@ -60,6 +60,10 @@ namespace direct_bt {
* BT Core Spec v5.2: Vol 3, Part G GATT: 3.3.3 Characteristic Descriptor
*/
class GATTDescriptor : public JavaUplink {
+ private:
+ /* Characteristic Descriptor's Characteristic back-reference */
+ std::weak_ptr<GATTCharacteristic> wbr_characteristic;
+
public:
static const uuid16_t TYPE_EXT_PROP;
static const uuid16_t TYPE_USER_DESC;
@@ -95,9 +99,6 @@ namespace direct_bt {
CUSTOM_CHARACTERISTIC_DESCRIPTION = 0x8888
};
- /* Characteristic Descriptor's Characteristic back-reference */
- GATTCharacteristicRef characteristic;
-
/** Type of descriptor */
std::shared_ptr<const uuid_t> type;
@@ -114,7 +115,7 @@ namespace direct_bt {
GATTDescriptor(const GATTCharacteristicRef & characteristic, const std::shared_ptr<const uuid_t> & type,
const uint16_t handle)
- : characteristic(characteristic), type(type), handle(handle), value(0) {}
+ : wbr_characteristic(characteristic), type(type), handle(handle), value(0) {}
std::string get_java_class() const override {
return java_class();
@@ -123,7 +124,9 @@ namespace direct_bt {
return std::string(JAVA_DBT_PACKAGE "DBTGattDescriptor");
}
- std::shared_ptr<DBTDevice> getDevice();
+ std::shared_ptr<GATTCharacteristic> getCharacteristic() const { return wbr_characteristic.lock(); }
+
+ std::shared_ptr<DBTDevice> getDevice() const;
virtual std::string toString() const {
return "[type 0x"+type->toString()+", handle "+uint16HexString(handle)+", value["+value.toString()+"]]";
diff --git a/api/direct_bt/GATTHandler.hpp b/api/direct_bt/GATTHandler.hpp
index 4652a4f2..8ad5c78f 100644
--- a/api/direct_bt/GATTHandler.hpp
+++ b/api/direct_bt/GATTHandler.hpp
@@ -82,7 +82,9 @@ namespace direct_bt {
static inline int number(const Defaults d) { return static_cast<int>(d); }
private:
- std::shared_ptr<DBTDevice> device;
+ /* GATTHandle's Device back-reference */
+ std::weak_ptr<DBTDevice> wbr_device;
+
const std::string deviceString;
std::recursive_mutex mtx_write;
std::recursive_mutex mtx_command;
@@ -109,6 +111,8 @@ namespace direct_bt {
uint16_t usedMTU;
std::vector<GATTServiceRef> services;
+ std::shared_ptr<DBTDevice> getDevice() const { return wbr_device.lock(); }
+
bool validateConnected();
void l2capReaderThreadImpl();
diff --git a/api/direct_bt/GATTService.hpp b/api/direct_bt/GATTService.hpp
index c02628fe..fd70e24a 100644
--- a/api/direct_bt/GATTService.hpp
+++ b/api/direct_bt/GATTService.hpp
@@ -62,10 +62,11 @@ namespace direct_bt {
* which also may include its client config if available.
*/
class GATTService : public JavaUplink {
- public:
+ private:
/* Service's Device back-reference */
- std::shared_ptr<DBTDevice> device;
+ std::weak_ptr<DBTDevice> wbr_device;
+ public:
const bool isPrimary;
/**
@@ -92,7 +93,7 @@ namespace direct_bt {
GATTService(const std::shared_ptr<DBTDevice> &device, const bool isPrimary,
const uint16_t startHandle, const uint16_t endHandle, std::shared_ptr<const uuid_t> type)
- : device(device), isPrimary(isPrimary), startHandle(startHandle), endHandle(endHandle), type(type), characteristicList() {
+ : wbr_device(device), isPrimary(isPrimary), startHandle(startHandle), endHandle(endHandle), type(type), characteristicList() {
characteristicList.reserve(10);
}
@@ -103,6 +104,8 @@ namespace direct_bt {
return std::string(JAVA_DBT_PACKAGE "DBTGattService");
}
+ std::shared_ptr<DBTDevice> getDevice() const { return wbr_device.lock(); }
+
std::string toString() const;
};
diff --git a/api/direct_bt/dbt_debug.hpp b/api/direct_bt/dbt_debug.hpp
index 164d9b8c..c09f9a3e 100644
--- a/api/direct_bt/dbt_debug.hpp
+++ b/api/direct_bt/dbt_debug.hpp
@@ -28,6 +28,9 @@
#include <cstdint>
#include <cstdio>
+#include <vector>
+#include <memory>
+
extern "C" {
#include <errno.h>
}
@@ -60,4 +63,19 @@ extern "C" {
#define INFO_PRINT(...) { fprintf(stderr, "INFO: "); fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); fflush(stderr); }
+template<class ListElemType>
+inline void printSharedPtrList(std::string prefix, std::vector<std::shared_ptr<ListElemType>> & list) {
+ fprintf(stderr, "%s: Start: %zd elements\n", prefix.c_str(), list.size());
+ int idx = 0;
+ for (auto it = list.begin(); it != list.end(); idx++) {
+ std::shared_ptr<ListElemType> & e = *it;
+ if ( nullptr != e ) {
+ fprintf(stderr, "%s[%d]: useCount %zd, mem %p\n", prefix.c_str(), idx, e.use_count(), e.get());
+ } else {
+ fprintf(stderr, "%s[%d]: NULL\n", prefix.c_str(), idx);
+ }
+ ++it;
+ }
+}
+
#endif /* DBT_DEBUG_HPP_ */