aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-04-20 09:31:54 +0200
committerSven Gothel <[email protected]>2020-04-20 09:31:54 +0200
commitf6fcec6415006918c0d938659379034fad9a2c72 (patch)
tree420b677adfb5887475c4fae07b4f600c6700fdae
parent6fdcdb13db5e13f11c44f0f9bba088252d9ffa18 (diff)
Direct-BT: Fix BluetoothFactory; Renaming using 'DBT' prefix
- Fix BluetoothFactory: Group implementation identification (class-name and lib-names) - Renaming using 'DBT' prefix, easing identification (java and HCITypes -> DBTTypes)
-rw-r--r--api/direct_bt/DBTTypes.hpp (renamed from api/direct_bt/HCITypes.hpp)132
-rw-r--r--api/direct_bt/GATTHandler.hpp8
-rw-r--r--api/direct_bt/JavaUplink.hpp (renamed from api/direct_bt/JavaAccess.hpp)0
-rw-r--r--api/direct_bt/L2CAPComm.hpp8
-rw-r--r--api/direct_bt/MgmtComm.hpp2
-rw-r--r--examples/CMakeLists.txt18
-rw-r--r--examples/direct_bt_scanner/dbt_scanner.cpp24
-rw-r--r--examples/java/AsyncTinyB.java11
-rw-r--r--examples/java/HelloTinyB.java16
-rw-r--r--examples/java/Notification.java12
-rw-r--r--examples/java/ScannerTinyB00.java9
-rw-r--r--examples/java/ScannerTinyB01.java9
-rw-r--r--java/direct_bt/tinyb/DBTAdapter.java (renamed from java/direct_bt/tinyb/Adapter.java)10
-rw-r--r--java/direct_bt/tinyb/DBTDevice.java (renamed from java/direct_bt/tinyb/Device.java)14
-rw-r--r--java/direct_bt/tinyb/DBTGattCharacteristic.java (renamed from java/direct_bt/tinyb/GattCharacteristic.java)14
-rw-r--r--java/direct_bt/tinyb/DBTGattDescriptor.java (renamed from java/direct_bt/tinyb/GattDescriptor.java)12
-rw-r--r--java/direct_bt/tinyb/DBTGattService.java (renamed from java/direct_bt/tinyb/GattService.java)16
-rw-r--r--java/direct_bt/tinyb/DBTManager.java (renamed from java/direct_bt/tinyb/Manager.java)10
-rw-r--r--java/direct_bt/tinyb/DBTNativeDownlink.java (renamed from java/direct_bt/tinyb/NativeDownlink.java)12
-rw-r--r--java/direct_bt/tinyb/DBTObject.java2
-rw-r--r--java/jni/direct_bt/DBTAdapter.cxx77
-rw-r--r--java/jni/direct_bt/DBTDevice.cxx24
-rw-r--r--java/jni/direct_bt/DBTGattCharacteristic.cxx4
-rw-r--r--java/jni/direct_bt/DBTGattDescriptor.cxx4
-rw-r--r--java/jni/direct_bt/DBTGattService.cxx4
-rw-r--r--java/jni/direct_bt/DBTManager.cxx24
-rw-r--r--java/jni/direct_bt/DBTNativeDownlink.cxx10
-rw-r--r--java/jni/direct_bt/DBTObject.cxx2
-rw-r--r--java/jni/direct_bt/helper_dbt.hpp2
-rw-r--r--java/manifest.txt.in4
-rw-r--r--java/org/tinyb/BluetoothFactory.java150
-rw-r--r--java/tinyb/dbus/DBusObject.java8
-rw-r--r--src/direct_bt/HCIAdapter.cpp62
-rw-r--r--src/direct_bt/HCIDevice.cpp22
-rw-r--r--src/direct_bt/MgmtComm.cpp2
-rw-r--r--test/direct_bt/test_attpdu01.cpp2
36 files changed, 410 insertions, 330 deletions
diff --git a/api/direct_bt/HCITypes.hpp b/api/direct_bt/DBTTypes.hpp
index 17368aed..94a62dc0 100644
--- a/api/direct_bt/HCITypes.hpp
+++ b/api/direct_bt/DBTTypes.hpp
@@ -23,8 +23,8 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#ifndef HCI_TYPES_HPP_
-#define HCI_TYPES_HPP_
+#ifndef DBT_TYPES_HPP_
+#define DBT_TYPES_HPP_
#include <cstring>
#include <string>
@@ -41,7 +41,7 @@
#include "BTTypes.hpp"
#include "HCIComm.hpp"
#include "MgmtComm.hpp"
-#include "JavaAccess.hpp"
+#include "JavaUplink.hpp"
#define JAVA_MAIN_PACKAGE "org/tinyb"
#define JAVA_HCI_PACKAGE "tinyb/hci"
@@ -52,37 +52,37 @@ namespace direct_bt {
// *************************************************
// *************************************************
- class HCIAdapter; // forward
- class HCIDevice; // forward
+ class DBTAdapter; // forward
+ class DBTDevice; // forward
- class HCISession
+ class DBTSession
{
- friend class HCIAdapter; // top manager: adapter open/close
- friend class HCIDevice; // local device manager: device connect/disconnect
+ friend class DBTAdapter; // top manager: adapter open/close
+ friend class DBTDevice; // local device manager: device connect/disconnect
private:
static std::atomic_int name_counter;
- HCIAdapter &adapter;
+ DBTAdapter &adapter;
HCIComm hciComm;
- std::shared_ptr<HCIDevice> connectedDevice;
+ std::shared_ptr<DBTDevice> connectedDevice;
- HCISession(HCIAdapter &a, const uint16_t dev_id, const uint16_t channel, const int timeoutMS=HCI_TO_SEND_REQ_POLL_MS)
+ DBTSession(DBTAdapter &a, const uint16_t dev_id, const uint16_t channel, const int timeoutMS=HCI_TO_SEND_REQ_POLL_MS)
: adapter(a), hciComm(dev_id, channel, timeoutMS),
connectedDevice(nullptr), name(name_counter.fetch_add(1))
{}
- void connected(std::shared_ptr<HCIDevice> device) {
+ void connected(std::shared_ptr<DBTDevice> device) {
connectedDevice = device;
}
public:
const int name;
- ~HCISession() { disconnect(); close(); }
+ ~DBTSession() { disconnect(); close(); }
- const HCIAdapter &getAdapter() { return adapter; }
+ const DBTAdapter &getAdapter() { return adapter; }
uint16_t getConnectedDeviceHandle() const { return hciComm.leConnHandle(); }
- std::shared_ptr<HCIDevice> getConnectedDevice() { return connectedDevice; }
+ std::shared_ptr<DBTDevice> getConnectedDevice() { return connectedDevice; }
void disconnect(const uint8_t reason=0);
@@ -92,13 +92,13 @@ namespace direct_bt {
int dd() const { return hciComm.dd(); }
};
- inline bool operator<(const HCISession& lhs, const HCISession& rhs)
+ inline bool operator<(const DBTSession& lhs, const DBTSession& rhs)
{ return lhs.name < rhs.name; }
- inline bool operator==(const HCISession& lhs, const HCISession& rhs)
+ inline bool operator==(const DBTSession& lhs, const DBTSession& rhs)
{ return lhs.name == rhs.name; }
- inline bool operator!=(const HCISession& lhs, const HCISession& rhs)
+ inline bool operator!=(const DBTSession& lhs, const DBTSession& rhs)
{ return !(lhs == rhs); }
@@ -106,13 +106,13 @@ namespace direct_bt {
// *************************************************
// *************************************************
- class HCIObject : public JavaUplink
+ class DBTObject : public JavaUplink
{
protected:
std::mutex lk;
std::atomic_bool valid;
- HCIObject() : valid(true) {}
+ DBTObject() : valid(true) {}
bool lock() {
if (valid) {
@@ -135,24 +135,24 @@ namespace direct_bt {
// *************************************************
// *************************************************
- class HCIDeviceDiscoveryListener {
+ class DBTDeviceDiscoveryListener {
public:
- virtual void deviceAdded(HCIAdapter const &a, std::shared_ptr<HCIDevice> device) = 0;
- virtual void deviceUpdated(HCIAdapter const &a, std::shared_ptr<HCIDevice> device) = 0;
- virtual void deviceRemoved(HCIAdapter const &a, std::shared_ptr<HCIDevice> device) = 0;
- virtual ~HCIDeviceDiscoveryListener() {}
+ virtual void deviceAdded(DBTAdapter const &a, std::shared_ptr<DBTDevice> device) = 0;
+ virtual void deviceUpdated(DBTAdapter const &a, std::shared_ptr<DBTDevice> device) = 0;
+ virtual void deviceRemoved(DBTAdapter const &a, std::shared_ptr<DBTDevice> device) = 0;
+ virtual ~DBTDeviceDiscoveryListener() {}
};
/** Alternative method to DeviceDiscoveryListener to set a callback */
- typedef std::function<void(HCIAdapter const &a, std::shared_ptr<HCIDevice> device)> DeviceDiscoveryCallback;
+ typedef std::function<void(DBTAdapter const &a, std::shared_ptr<DBTDevice> device)> DBTDeviceDiscoveryCallback;
- class HCIDevice : public HCIObject
+ class DBTDevice : public DBTObject
{
- friend HCIAdapter; // managing us: ctor and update(..) during discovery
+ friend DBTAdapter; // managing us: ctor and update(..) during discovery
private:
static const int to_connect_ms = 5000;
- HCIAdapter const & adapter;
+ DBTAdapter const & adapter;
uint64_t ts_update;
std::string name;
int8_t rssi = 0;
@@ -160,7 +160,7 @@ namespace direct_bt {
std::shared_ptr<ManufactureSpecificData> msd = nullptr;
std::vector<std::shared_ptr<uuid_t>> services;
- HCIDevice(HCIAdapter const & adapter, EInfoReport const & r);
+ DBTDevice(DBTAdapter const & adapter, EInfoReport const & r);
void addService(std::shared_ptr<uuid_t> const &uuid);
void addServices(std::vector<std::shared_ptr<uuid_t>> const & services);
@@ -172,20 +172,20 @@ namespace direct_bt {
/** Device mac address */
const EUI48 mac;
- ~HCIDevice();
+ ~DBTDevice();
std::string get_java_class() const override {
return java_class();
}
static std::string java_class() {
- return std::string(JAVA_DBT_PACKAGE "Device");
+ return std::string(JAVA_DBT_PACKAGE "DBTDevice");
}
/** Returns the managing adapter */
- HCIAdapter const & getAdapter() const { return adapter; }
+ DBTAdapter const & getAdapter() const { return adapter; }
/** Returns the shares reference of this instance, managed by the adapter */
- std::shared_ptr<HCIDevice> getSharedInstance() const;
+ std::shared_ptr<DBTDevice> getSharedInstance() const;
uint64_t getCreationTimestamp() const { return ts_creation; }
uint64_t getUpdateTimestamp() const { return ts_update; }
@@ -219,7 +219,7 @@ namespace direct_bt {
* and usual connection latency, interval etc.
* </p>
*/
- uint16_t le_connect(HCISession& s,
+ uint16_t le_connect(DBTSession& s,
const uint8_t peer_mac_type=HCIADDR_LE_PUBLIC, const uint8_t own_mac_type=HCIADDR_LE_PUBLIC,
const uint16_t interval=0x0004, const uint16_t window=0x0004,
const uint16_t min_interval=0x000F, const uint16_t max_interval=0x000F,
@@ -228,44 +228,44 @@ namespace direct_bt {
const uint8_t initiator_filter=0);
};
- inline bool operator<(const HCIDevice& lhs, const HCIDevice& rhs)
+ inline bool operator<(const DBTDevice& lhs, const DBTDevice& rhs)
{ return lhs.mac < rhs.mac; }
- inline bool operator==(const HCIDevice& lhs, const HCIDevice& rhs)
+ inline bool operator==(const DBTDevice& lhs, const DBTDevice& rhs)
{ return lhs.mac == rhs.mac; }
- inline bool operator!=(const HCIDevice& lhs, const HCIDevice& rhs)
+ inline bool operator!=(const DBTDevice& lhs, const DBTDevice& rhs)
{ return !(lhs == rhs); }
// *************************************************
// *************************************************
// *************************************************
- class HCIAdapter : public HCIObject
+ class DBTAdapter : public DBTObject
{
private:
/** Returns index >= 0 if found, otherwise -1 */
- static int findDevice(std::vector<std::shared_ptr<HCIDevice>> const & devices, EUI48 const & mac);
+ static int findDevice(std::vector<std::shared_ptr<DBTDevice>> const & devices, EUI48 const & mac);
MgmtHandler& mgmt;
std::shared_ptr<const AdapterInfo> adapterInfo;
- std::shared_ptr<HCISession> session;
- std::vector<std::shared_ptr<HCIDevice>> scannedDevices; // all devices scanned
- std::vector<std::shared_ptr<HCIDevice>> discoveredDevices; // matching all requirements for export
- std::shared_ptr<HCIDeviceDiscoveryListener> deviceDiscoveryListener = nullptr;
+ std::shared_ptr<DBTSession> session;
+ std::vector<std::shared_ptr<DBTDevice>> scannedDevices; // all devices scanned
+ std::vector<std::shared_ptr<DBTDevice>> discoveredDevices; // matching all requirements for export
+ std::shared_ptr<DBTDeviceDiscoveryListener> deviceDiscoveryListener = nullptr;
bool validateDevInfo();
- friend bool HCISession::close();
- void sessionClosing(HCISession& s);
+ friend bool DBTSession::close();
+ void sessionClosing(DBTSession& s);
- friend std::shared_ptr<HCIDevice> HCIDevice::getSharedInstance() const;
+ friend std::shared_ptr<DBTDevice> DBTDevice::getSharedInstance() const;
int findScannedDeviceIdx(EUI48 const & mac) const;
- std::shared_ptr<HCIDevice> findScannedDevice (EUI48 const & mac) const;
- bool addScannedDevice(std::shared_ptr<HCIDevice> const &device);
+ std::shared_ptr<DBTDevice> findScannedDevice (EUI48 const & mac) const;
+ bool addScannedDevice(std::shared_ptr<DBTDevice> const &device);
- bool addDiscoveredDevice(std::shared_ptr<HCIDevice> const &device);
+ bool addDiscoveredDevice(std::shared_ptr<DBTDevice> const &device);
protected:
@@ -275,25 +275,25 @@ namespace direct_bt {
/**
* Using the default adapter device
*/
- HCIAdapter();
+ DBTAdapter();
/**
* @param[in] mac address
*/
- HCIAdapter(EUI48 &mac);
+ DBTAdapter(EUI48 &mac);
/**
* @param[in] dev_id an already identified HCI device id
*/
- HCIAdapter(const int dev_id);
+ DBTAdapter(const int dev_id);
- ~HCIAdapter();
+ ~DBTAdapter();
std::string get_java_class() const override {
return java_class();
}
static std::string java_class() {
- return std::string(JAVA_DBT_PACKAGE "Adapter");
+ return std::string(JAVA_DBT_PACKAGE "DBTAdapter");
}
bool hasDevId() const { return 0 <= dev_id; }
@@ -306,19 +306,19 @@ namespace direct_bt {
* Returns a reference to the newly opened session
* if successful, otherwise nullptr is returned.
*/
- std::shared_ptr<HCISession> open();
+ std::shared_ptr<DBTSession> open();
/**
* Returns the {@link #open()} session or {@code nullptr} if closed.
*/
- std::shared_ptr<HCISession> getOpenSession() { return session; }
+ std::shared_ptr<DBTSession> getOpenSession() { return session; }
// device discovery aka device scanning
/**
* Replaces the HCIDeviceDiscoveryListener with the given instance, returning the replaced one.
*/
- std::shared_ptr<HCIDeviceDiscoveryListener> setDeviceDiscoveryListener(std::shared_ptr<HCIDeviceDiscoveryListener> l);
+ std::shared_ptr<DBTDeviceDiscoveryListener> setDeviceDiscoveryListener(std::shared_ptr<DBTDeviceDiscoveryListener> l);
/**
* Starts a new discovery session.
@@ -330,14 +330,14 @@ namespace direct_bt {
* and usual discovery intervals etc.
* </p>
*/
- bool startDiscovery(HCISession& s, uint8_t own_mac_type=HCIADDR_LE_PUBLIC,
+ bool startDiscovery(DBTSession& s, uint8_t own_mac_type=HCIADDR_LE_PUBLIC,
uint16_t interval=0x0004, uint16_t window=0x0004);
/**
* Closes the discovery session.
* @return true if no error, otherwise false.
*/
- void stopDiscovery(HCISession& s);
+ void stopDiscovery(DBTSession& s);
/**
* Discovery devices up until 'timeoutMS' in milliseconds
@@ -369,20 +369,20 @@ namespace direct_bt {
* <br>
* Default value is: 'EInfoReport::Element::NAME',
* while 'EInfoReport::Element::BDADDR|EInfoReport::Element::RSSI' is implicit
- * and guarantedd by the AD protocol.
+ * and guaranteed by the AD protocol.
* </p>
*
* @return number of successfully scanned devices matching above criteria
* or -1 if an error has occurred.
*/
- int discoverDevices(HCISession& s,
+ int discoverDevices(DBTSession& s,
const int waitForDeviceCount=1,
const EUI48 &waitForDevice=EUI48_ANY_DEVICE,
const int timeoutMS=HCI_TO_SEND_REQ_POLL_MS,
const uint32_t ad_type_req=static_cast<uint32_t>(EInfoReport::Element::NAME));
/** Returns discovered devices from a discovery */
- std::vector<std::shared_ptr<HCIDevice>> getDiscoveredDevices() { return discoveredDevices; }
+ std::vector<std::shared_ptr<DBTDevice>> getDiscoveredDevices() { return discoveredDevices; }
/** Discards all discovered devices. Returns number of removed discovered devices. */
int removeDiscoveredDevices();
@@ -391,13 +391,13 @@ namespace direct_bt {
int findDiscoveredDeviceIdx(EUI48 const & mac) const;
/** Returns shared HCIDevice if found, otherwise nullptr */
- std::shared_ptr<HCIDevice> findDiscoveredDevice (EUI48 const & mac) const;
+ std::shared_ptr<DBTDevice> findDiscoveredDevice (EUI48 const & mac) const;
- std::shared_ptr<HCIDevice> getDiscoveredDevice(int index) const { return discoveredDevices.at(index); }
+ std::shared_ptr<DBTDevice> getDiscoveredDevice(int index) const { return discoveredDevices.at(index); }
std::string toString() const;
};
} // namespace direct_bt
-#endif /* HCITYPES_HPP_ */
+#endif /* DBT_TYPES_HPP_ */
diff --git a/api/direct_bt/GATTHandler.hpp b/api/direct_bt/GATTHandler.hpp
index 7f4a2c9d..ae83c663 100644
--- a/api/direct_bt/GATTHandler.hpp
+++ b/api/direct_bt/GATTHandler.hpp
@@ -38,7 +38,7 @@
#include "UUID.hpp"
#include "BTTypes.hpp"
-#include "HCITypes.hpp"
+#include "DBTTypes.hpp"
#include "L2CAPComm.hpp"
#include "ATTPDUTypes.hpp"
#include "GATTTypes.hpp"
@@ -57,13 +57,13 @@ namespace direct_bt {
class GATTNotificationListener {
public:
- virtual void notificationReceived(std::shared_ptr<HCIDevice> dev, GATTCharacterisicsDeclRef charDecl,
+ virtual void notificationReceived(std::shared_ptr<DBTDevice> dev, GATTCharacterisicsDeclRef charDecl,
std::shared_ptr<const AttHandleValueRcv> charValue) = 0;
virtual ~GATTNotificationListener() {}
};
class GATTIndicationListener {
public:
- virtual void indicationReceived(std::shared_ptr<HCIDevice> dev, GATTCharacterisicsDeclRef charDecl,
+ virtual void indicationReceived(std::shared_ptr<DBTDevice> dev, GATTCharacterisicsDeclRef charDecl,
std::shared_ptr<const AttHandleValueRcv> charValue, const bool confirmationSent) = 0;
virtual ~GATTIndicationListener() {}
};
@@ -168,7 +168,7 @@ namespace direct_bt {
attPDURing(ATTPDU_RING_CAPACITY), l2capReaderRunning(false), l2capReaderShallStop(false),
serverMTU(DEFAULT_MIN_ATT_MTU), usedMTU(DEFAULT_MIN_ATT_MTU) {}
- GATTHandler(std::shared_ptr<HCIDevice> device, const int timeoutMS)
+ GATTHandler(std::shared_ptr<DBTDevice> device, const int timeoutMS)
: rbuffer(ClientMaxMTU), state(Disconnected),
l2cap(new L2CAPComm(device, L2CAP_PSM_UNDEF, L2CAP_CID_ATT)), timeoutMS(timeoutMS),
attPDURing(ATTPDU_RING_CAPACITY), l2capReaderRunning(false), l2capReaderShallStop(false),
diff --git a/api/direct_bt/JavaAccess.hpp b/api/direct_bt/JavaUplink.hpp
index 86c7251e..86c7251e 100644
--- a/api/direct_bt/JavaAccess.hpp
+++ b/api/direct_bt/JavaUplink.hpp
diff --git a/api/direct_bt/L2CAPComm.hpp b/api/direct_bt/L2CAPComm.hpp
index 152ac58d..94eef5aa 100644
--- a/api/direct_bt/L2CAPComm.hpp
+++ b/api/direct_bt/L2CAPComm.hpp
@@ -37,7 +37,7 @@
#include "UUID.hpp"
#include "BTTypes.hpp"
-#include "HCITypes.hpp"
+#include "DBTTypes.hpp"
namespace direct_bt {
@@ -57,7 +57,7 @@ namespace direct_bt {
static int l2cap_close_dev(int dd);
State state;
- std::shared_ptr<HCIDevice> device = nullptr;
+ std::shared_ptr<DBTDevice> device = nullptr;
const uint16_t psm;
const uint16_t cid;
const bool pubaddr;
@@ -66,11 +66,11 @@ namespace direct_bt {
volatile bool interruptReadFlag; // for forced disconnect
public:
- L2CAPComm(std::shared_ptr<HCIDevice> device, const uint16_t psm, const uint16_t cid, const bool pubaddr=true, const bool blocking=true)
+ L2CAPComm(std::shared_ptr<DBTDevice> device, const uint16_t psm, const uint16_t cid, const bool pubaddr=true, const bool blocking=true)
: state(Disconnected), device(device), psm(psm), cid(cid), pubaddr(pubaddr), blocking(blocking), _dd(-1), interruptReadFlag(false) {}
~L2CAPComm() { disconnect(); }
- std::shared_ptr<HCIDevice> getDevice() { return device; }
+ std::shared_ptr<DBTDevice> getDevice() { return device; }
State getState() const { return state; }
std::string getStateString() const { return getStateString(state); }
diff --git a/api/direct_bt/MgmtComm.hpp b/api/direct_bt/MgmtComm.hpp
index a022a8d9..cf07dc3d 100644
--- a/api/direct_bt/MgmtComm.hpp
+++ b/api/direct_bt/MgmtComm.hpp
@@ -35,7 +35,7 @@
#include "BTIoctl.hpp"
#include "OctetTypes.hpp"
#include "HCIComm.hpp"
-#include "JavaAccess.hpp"
+#include "JavaUplink.hpp"
namespace direct_bt {
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 26edd814..356658c0 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,9 +1,13 @@
-include_directories(
- ${tinyb_LIB_INCLUDE_DIRS}
- ${GLIB2_INCLUDE_DIRS}
- ${GIO_INCLUDE_DIRS}
- ${GIO-UNIX_INCLUDE_DIRS}
-)
+include_directories(${PROJECT_SOURCE_DIR}/api)
+
+#include_directories(
+# ${PROJECT_SOURCE_DIR}/api
+# ${direct_bt_LIB_INCLUDE_DIRS}
+# ${tinyb_LIB_INCLUDE_DIRS}
+# ${GLIB2_INCLUDE_DIRS}
+# ${GIO_INCLUDE_DIRS}
+# ${GIO-UNIX_INCLUDE_DIRS}
+#)
add_executable (hellotinyb tinyb/hellotinyb.cpp)
set_target_properties(hellotinyb
@@ -45,8 +49,6 @@ set_target_properties(list_mfg
PROPERTIES
CXX_STANDARD 11)
-include_directories(${PROJECT_SOURCE_DIR}/api)
-
target_link_libraries (hellotinyb tinyb)
target_link_libraries (checkinit tinyb)
target_link_libraries (asynctinyb tinyb)
diff --git a/examples/direct_bt_scanner/dbt_scanner.cpp b/examples/direct_bt_scanner/dbt_scanner.cpp
index 055aa7e1..fcce3a22 100644
--- a/examples/direct_bt_scanner/dbt_scanner.cpp
+++ b/examples/direct_bt_scanner/dbt_scanner.cpp
@@ -24,10 +24,10 @@
*/
#include <direct_bt/BTAddress.hpp>
-#include <direct_bt/HCITypes.hpp>
#include <direct_bt/ATTPDUTypes.hpp>
#include <direct_bt/GATTHandler.hpp>
#include <direct_bt/GATTNumbers.hpp>
+#include <direct_bt/DBTTypes.hpp>
#include <cinttypes>
extern "C" {
@@ -36,18 +36,18 @@ extern "C" {
using namespace direct_bt;
-class DeviceDiscoveryListener : public direct_bt::HCIDeviceDiscoveryListener {
- void deviceAdded(direct_bt::HCIAdapter const &a, std::shared_ptr<direct_bt::HCIDevice> device) override {
+class DeviceDiscoveryListener : public direct_bt::DBTDeviceDiscoveryListener {
+ void deviceAdded(direct_bt::DBTAdapter const &a, std::shared_ptr<direct_bt::DBTDevice> device) override {
fprintf(stderr, "****** ADDED__: %s\n", device->toString().c_str());
fprintf(stderr, "Status HCIAdapter:\n");
fprintf(stderr, "%s\n", a.toString().c_str());
}
- void deviceUpdated(direct_bt::HCIAdapter const &a, std::shared_ptr<direct_bt::HCIDevice> device) override {
+ void deviceUpdated(direct_bt::DBTAdapter const &a, std::shared_ptr<direct_bt::DBTDevice> device) override {
fprintf(stderr, "****** UPDATED: %s\n", device->toString().c_str());
fprintf(stderr, "Status HCIAdapter:\n");
fprintf(stderr, "%s\n", a.toString().c_str());
}
- void deviceRemoved(direct_bt::HCIAdapter const &a, std::shared_ptr<direct_bt::HCIDevice> device) override {
+ void deviceRemoved(direct_bt::DBTAdapter const &a, std::shared_ptr<direct_bt::DBTDevice> device) override {
fprintf(stderr, "****** REMOVED: %s\n", device->toString().c_str());
fprintf(stderr, "Status HCIAdapter:\n");
fprintf(stderr, "%s\n", a.toString().c_str());
@@ -57,7 +57,7 @@ class DeviceDiscoveryListener : public direct_bt::HCIDeviceDiscoveryListener {
static const uuid16_t _TEMPERATURE_MEASUREMENT(GattCharacteristicType::TEMPERATURE_MEASUREMENT);
class MyGATTNotificationListener : public direct_bt::GATTNotificationListener {
- void notificationReceived(std::shared_ptr<HCIDevice> dev,
+ void notificationReceived(std::shared_ptr<DBTDevice> dev,
GATTCharacterisicsDeclRef charDecl, std::shared_ptr<const AttHandleValueRcv> charValue) override {
const int64_t tR = direct_bt::getCurrentMilliseconds();
fprintf(stderr, "****** GATT Notify (td %" PRIu64 " ms, dev-discovered %" PRIu64 " ms): From %s\n",
@@ -69,7 +69,7 @@ class MyGATTNotificationListener : public direct_bt::GATTNotificationListener {
}
};
class MyGATTIndicationListener : public direct_bt::GATTIndicationListener {
- void indicationReceived(std::shared_ptr<HCIDevice> dev,
+ void indicationReceived(std::shared_ptr<DBTDevice> dev,
GATTCharacterisicsDeclRef charDecl, std::shared_ptr<const AttHandleValueRcv> charValue,
const bool confirmationSent) override
{
@@ -126,7 +126,7 @@ int main(int argc, char *argv[])
getchar();
}
- direct_bt::HCIAdapter adapter; // default
+ direct_bt::DBTAdapter adapter; // default
if( !adapter.hasDevId() ) {
fprintf(stderr, "Default adapter not available.\n");
exit(1);
@@ -138,11 +138,11 @@ int main(int argc, char *argv[])
fprintf(stderr, "Adapter: device %s, address %s\n",
adapter.getName().c_str(), adapter.getAddressString().c_str());
- adapter.setDeviceDiscoveryListener(std::shared_ptr<direct_bt::HCIDeviceDiscoveryListener>(new DeviceDiscoveryListener()));
+ adapter.setDeviceDiscoveryListener(std::shared_ptr<direct_bt::DBTDeviceDiscoveryListener>(new DeviceDiscoveryListener()));
const int64_t t0 = direct_bt::getCurrentMilliseconds();
- std::shared_ptr<direct_bt::HCISession> session = adapter.open();
+ std::shared_ptr<direct_bt::DBTSession> session = adapter.open();
while( ok && !done && nullptr != session ) {
ok = adapter.startDiscovery(*session);
@@ -160,11 +160,11 @@ int main(int argc, char *argv[])
if( ok && 0 < deviceCount ) {
const uint64_t t1 = direct_bt::getCurrentMilliseconds();
- std::vector<std::shared_ptr<direct_bt::HCIDevice>> discoveredDevices = adapter.getDiscoveredDevices();
+ std::vector<std::shared_ptr<direct_bt::DBTDevice>> discoveredDevices = adapter.getDiscoveredDevices();
int i=0, j=0, k=0;
for(auto it = discoveredDevices.begin(); it != discoveredDevices.end(); it++) {
i++;
- std::shared_ptr<direct_bt::HCIDevice> device = *it;
+ std::shared_ptr<direct_bt::DBTDevice> device = *it;
const uint64_t lup = device->getLastUpdateAge(t1);
if( 2000 > lup ) {
// less than 2s old ..
diff --git a/examples/java/AsyncTinyB.java b/examples/java/AsyncTinyB.java
index 28c492b5..f70b890a 100644
--- a/examples/java/AsyncTinyB.java
+++ b/examples/java/AsyncTinyB.java
@@ -7,6 +7,7 @@ import org.tinyb.BluetoothGattCharacteristic;
import org.tinyb.BluetoothGattService;
import org.tinyb.BluetoothManager;
+import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.TimeUnit;
public class AsyncTinyB {
@@ -45,7 +46,15 @@ public class AsyncTinyB {
* library is through the BluetoothManager. There can be only one BluetoothManager at one time, and the
* reference to it is obtained through the getBluetoothManager method.
*/
- final BluetoothManager manager = BluetoothFactory.getDBusBluetoothManager();
+ final BluetoothManager manager;
+ try {
+ manager = BluetoothFactory.getDBusBluetoothManager();
+ } catch (BluetoothException | NoSuchMethodException | SecurityException
+ | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException | ClassNotFoundException e) {
+ System.err.println("Failed to initialized "+BluetoothFactory.DBusImplementationID);
+ throw new RuntimeException(e);
+ }
/*
* The manager will try to initialize a BluetoothAdapter if any adapter is present in the system. To initialize
diff --git a/examples/java/HelloTinyB.java b/examples/java/HelloTinyB.java
index 4e8a2d0d..77435de6 100644
--- a/examples/java/HelloTinyB.java
+++ b/examples/java/HelloTinyB.java
@@ -1,3 +1,4 @@
+import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
@@ -30,8 +31,7 @@ public class HelloTinyB {
* getDevices method. We can the look through the list of devices to find the device with the MAC which we provided
* as a parameter. We continue looking until we find it, or we try 15 times (1 minutes).
*/
- static BluetoothDevice getDevice(final String address) throws InterruptedException {
- final BluetoothManager manager = BluetoothFactory.getDBusBluetoothManager();
+ static BluetoothDevice getDevice(final BluetoothManager manager, final String address) throws InterruptedException {
BluetoothDevice sensor = null;
for (int i = 0; (i < 15) && running; ++i) {
final List<BluetoothDevice> list = manager.getDevices();
@@ -113,7 +113,15 @@ public class HelloTinyB {
* library is through the BluetoothManager. There can be only one BluetoothManager at one time, and the
* reference to it is obtained through the getBluetoothManager method.
*/
- final BluetoothManager manager = BluetoothFactory.getDBusBluetoothManager();
+ final BluetoothManager manager;
+ try {
+ manager = BluetoothFactory.getDBusBluetoothManager();
+ } catch (BluetoothException | NoSuchMethodException | SecurityException
+ | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException | ClassNotFoundException e) {
+ System.err.println("Failed to initialized "+BluetoothFactory.DBusImplementationID);
+ throw new RuntimeException(e);
+ }
/*
* The manager will try to initialize a BluetoothAdapter if any adapter is present in the system. To initialize
@@ -122,7 +130,7 @@ public class HelloTinyB {
final boolean discoveryStarted = manager.startDiscovery();
System.out.println("The discovery started: " + (discoveryStarted ? "true" : "false"));
- final BluetoothDevice sensor = getDevice(args[0]);
+ final BluetoothDevice sensor = getDevice(manager, args[0]);
/*
* After we find the device we can stop looking for other devices.
diff --git a/examples/java/Notification.java b/examples/java/Notification.java
index 069e013d..c39a0a9e 100644
--- a/examples/java/Notification.java
+++ b/examples/java/Notification.java
@@ -22,11 +22,13 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import org.tinyb.BluetoothDevice;
+import org.tinyb.BluetoothException;
import org.tinyb.BluetoothFactory;
import org.tinyb.BluetoothGattCharacteristic;
import org.tinyb.BluetoothGattService;
@@ -105,7 +107,15 @@ public class Notification {
* library is through the BluetoothManager. There can be only one BluetoothManager at one time, and the
* reference to it is obtained through the getBluetoothManager method.
*/
- final BluetoothManager manager = BluetoothFactory.getDBusBluetoothManager();
+ final BluetoothManager manager;
+ try {
+ manager = BluetoothFactory.getDBusBluetoothManager();
+ } catch (BluetoothException | NoSuchMethodException | SecurityException
+ | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException | ClassNotFoundException e) {
+ System.err.println("Failed to initialized "+BluetoothFactory.DBusImplementationID);
+ throw new RuntimeException(e);
+ }
/*
* The manager will try to initialize a BluetoothAdapter if any adapter is present in the system. To initialize
diff --git a/examples/java/ScannerTinyB00.java b/examples/java/ScannerTinyB00.java
index db9c2b38..c5ec4790 100644
--- a/examples/java/ScannerTinyB00.java
+++ b/examples/java/ScannerTinyB00.java
@@ -45,7 +45,7 @@ public class ScannerTinyB00 {
static long TO_DISCOVER = 60000;
public static void main(final String[] args) throws InterruptedException {
- String factoryImplClassName = BluetoothFactory.DBusFactoryImplClassName;
+ int factory = 0;
String mac = null;
int mode = 0;
boolean forever = false;
@@ -58,7 +58,7 @@ public class ScannerTinyB00 {
} else if( arg.equals("-mode") ) {
mode = Integer.valueOf(args[++i]).intValue();
} else if( arg.equals("-factory") ) {
- factoryImplClassName = args[++i];
+ factory = Integer.valueOf(args[++i]).intValue();
} else if( arg.equals("-forever") ) {
forever = true;
}
@@ -69,6 +69,7 @@ public class ScannerTinyB00 {
System.exit(-1);
}
+ final BluetoothFactory.ImplementationIdentifier implID = 0 == factory ? BluetoothFactory.DirectBTImplementationID : BluetoothFactory.DBusImplementationID;
final boolean useAdapter = mode/10 > 0;
mode = mode %10;
@@ -76,11 +77,11 @@ public class ScannerTinyB00 {
{
BluetoothManager _manager = null;
try {
- _manager = BluetoothFactory.getBluetoothManager(factoryImplClassName);
+ _manager = BluetoothFactory.getBluetoothManager( implID );
} catch (BluetoothException | NoSuchMethodException | SecurityException
| IllegalAccessException | IllegalArgumentException
| InvocationTargetException | ClassNotFoundException e) {
- System.err.println("Unable to instantiate BluetoothManager via factory "+factoryImplClassName);
+ System.err.println("Unable to instantiate BluetoothManager via "+implID);
e.printStackTrace();
System.exit(-1);
}
diff --git a/examples/java/ScannerTinyB01.java b/examples/java/ScannerTinyB01.java
index 449ab765..f6cd5a87 100644
--- a/examples/java/ScannerTinyB01.java
+++ b/examples/java/ScannerTinyB01.java
@@ -47,7 +47,7 @@ public class ScannerTinyB01 {
static long TO_DISCOVER = 60000;
public static void main(final String[] args) throws InterruptedException {
- String factoryImplClassName = BluetoothFactory.DirectBTFactoryImplClassName;
+ int factory = 0;
int mode = 0;
boolean forever = false;
final String mac;
@@ -61,7 +61,7 @@ public class ScannerTinyB01 {
} else if( arg.equals("-mode") ) {
mode = Integer.valueOf(args[++i]).intValue();
} else if( arg.equals("-factory") ) {
- factoryImplClassName = args[++i];
+ factory = Integer.valueOf(args[++i]).intValue();
} else if( arg.equals("-forever") ) {
forever = true;
}
@@ -74,15 +74,16 @@ public class ScannerTinyB01 {
mac = _mac;
}
+ final BluetoothFactory.ImplementationIdentifier implID = 0 == factory ? BluetoothFactory.DirectBTImplementationID : BluetoothFactory.DBusImplementationID;
final BluetoothManager manager;
{
BluetoothManager _manager = null;
try {
- _manager = BluetoothFactory.getBluetoothManager(factoryImplClassName);
+ _manager = BluetoothFactory.getBluetoothManager( implID );
} catch (BluetoothException | NoSuchMethodException | SecurityException
| IllegalAccessException | IllegalArgumentException
| InvocationTargetException | ClassNotFoundException e) {
- System.err.println("Unable to instantiate BluetoothManager via factory "+factoryImplClassName);
+ System.err.println("Unable to instantiate BluetoothManager via "+implID);
e.printStackTrace();
System.exit(-1);
}
diff --git a/java/direct_bt/tinyb/Adapter.java b/java/direct_bt/tinyb/DBTAdapter.java
index b953c318..1c32bc7c 100644
--- a/java/direct_bt/tinyb/Adapter.java
+++ b/java/direct_bt/tinyb/DBTAdapter.java
@@ -41,13 +41,13 @@ import org.tinyb.BluetoothType;
import org.tinyb.BluetoothDeviceDiscoveryListener;
import org.tinyb.TransportType;
-public class Adapter extends DBTObject implements BluetoothAdapter
+public class DBTAdapter extends DBTObject implements BluetoothAdapter
{
private final String address;
private final String name;
private final DiscoveryThread discoveryThread;
- /* pp */ Adapter(final long nativeInstance, final String address, final String name)
+ /* pp */ DBTAdapter(final long nativeInstance, final String address, final String name)
{
super(nativeInstance, compHash(address, name));
this.address = address;
@@ -66,10 +66,10 @@ public class Adapter extends DBTObject implements BluetoothAdapter
@Override
public boolean equals(final Object obj)
{
- if (obj == null || !(obj instanceof Device)) {
+ if (obj == null || !(obj instanceof DBTDevice)) {
return false;
}
- final Adapter other = (Adapter)obj;
+ final DBTAdapter other = (DBTAdapter)obj;
return address.equals(other.address) && name.equals(other.name);
}
@@ -94,7 +94,7 @@ public class Adapter extends DBTObject implements BluetoothAdapter
@Override
public BluetoothDevice find(final String name, final String address, final long timeoutMS) {
- final BluetoothManager manager = Manager.getBluetoothManager();
+ final BluetoothManager manager = DBTManager.getBluetoothManager();
return (BluetoothDevice) manager.find(BluetoothType.DEVICE, name, address, this, timeoutMS);
}
diff --git a/java/direct_bt/tinyb/Device.java b/java/direct_bt/tinyb/DBTDevice.java
index f3a90d6b..2946f532 100644
--- a/java/direct_bt/tinyb/Device.java
+++ b/java/direct_bt/tinyb/DBTDevice.java
@@ -36,15 +36,15 @@ import org.tinyb.BluetoothNotification;
import org.tinyb.BluetoothType;
import org.tinyb.BluetoothUtils;
-public class Device extends DBTObject implements BluetoothDevice
+public class DBTDevice extends DBTObject implements BluetoothDevice
{
- private final Adapter adapter;
+ private final DBTAdapter adapter;
private final String address;
private final String name;
private final long ts_creation;
long ts_update;
- /* pp */ Device(final long nativeInstance, final Adapter adptr, final String address, final String name, final long ts_creation)
+ /* pp */ DBTDevice(final long nativeInstance, final DBTAdapter adptr, final String address, final String name, final long ts_creation)
{
super(nativeInstance, compHash(address, name));
this.adapter = adptr;
@@ -58,10 +58,10 @@ public class Device extends DBTObject implements BluetoothDevice
@Override
public boolean equals(final Object obj)
{
- if (obj == null || !(obj instanceof Device)) {
+ if (obj == null || !(obj instanceof DBTDevice)) {
return false;
}
- final Device other = (Device)obj;
+ final DBTDevice other = (DBTDevice)obj;
return address.equals(other.address) && name.equals(other.name);
}
@@ -82,7 +82,7 @@ public class Device extends DBTObject implements BluetoothDevice
@Override
public BluetoothGattService find(final String UUID, final long timeoutMS) {
- final BluetoothManager manager = Manager.getBluetoothManager();
+ final BluetoothManager manager = DBTManager.getBluetoothManager();
return (BluetoothGattService) manager.find(BluetoothType.GATT_SERVICE,
null, UUID, this, timeoutMS);
}
@@ -227,7 +227,7 @@ public class Device extends DBTObject implements BluetoothDevice
public native String getModalias();
@Override
- public native Adapter getAdapter();
+ public native DBTAdapter getAdapter();
@Override
public native Map<Short, byte[]> getManufacturerData();
diff --git a/java/direct_bt/tinyb/GattCharacteristic.java b/java/direct_bt/tinyb/DBTGattCharacteristic.java
index 801dac33..6c79e188 100644
--- a/java/direct_bt/tinyb/GattCharacteristic.java
+++ b/java/direct_bt/tinyb/DBTGattCharacteristic.java
@@ -36,11 +36,11 @@ import org.tinyb.BluetoothManager;
import org.tinyb.BluetoothNotification;
import org.tinyb.BluetoothType;
-public class GattCharacteristic extends DBTObject implements BluetoothGattCharacteristic
+public class DBTGattCharacteristic extends DBTObject implements BluetoothGattCharacteristic
{
private final String uuid;
- /* pp */ GattCharacteristic(final long nativeInstance, final String uuid)
+ /* pp */ DBTGattCharacteristic(final long nativeInstance, final String uuid)
{
super(nativeInstance, uuid.hashCode());
this.uuid = uuid;
@@ -49,10 +49,10 @@ public class GattCharacteristic extends DBTObject implements BluetoothGattCharac
@Override
public boolean equals(final Object obj)
{
- if (obj == null || !(obj instanceof GattCharacteristic)) {
+ if (obj == null || !(obj instanceof DBTGattCharacteristic)) {
return false;
}
- final GattCharacteristic other = (GattCharacteristic)obj;
+ final DBTGattCharacteristic other = (DBTGattCharacteristic)obj;
return uuid.equals(other.uuid);
}
@@ -65,12 +65,12 @@ public class GattCharacteristic extends DBTObject implements BluetoothGattCharac
static BluetoothType class_type() { return BluetoothType.GATT_CHARACTERISTIC; }
@Override
- public final GattCharacteristic clone()
+ public BluetoothGattCharacteristic clone()
{ throw new UnsupportedOperationException(); } // FIXME
@Override
public BluetoothGattDescriptor find(final String UUID, final long timeoutMS) {
- final BluetoothManager manager = Manager.getBluetoothManager();
+ final BluetoothManager manager = DBTManager.getBluetoothManager();
return (BluetoothGattDescriptor) manager.find(BluetoothType.GATT_DESCRIPTOR,
null, UUID, this, timeoutMS);
}
@@ -111,7 +111,7 @@ public class GattCharacteristic extends DBTObject implements BluetoothGattCharac
@Override
public native List<BluetoothGattDescriptor> getDescriptors();
- private native void init(GattCharacteristic obj);
+ private native void init(DBTGattCharacteristic obj);
@Override
protected native void deleteImpl();
diff --git a/java/direct_bt/tinyb/GattDescriptor.java b/java/direct_bt/tinyb/DBTGattDescriptor.java
index 5b0d2898..3bd8711f 100644
--- a/java/direct_bt/tinyb/GattDescriptor.java
+++ b/java/direct_bt/tinyb/DBTGattDescriptor.java
@@ -30,11 +30,11 @@ import org.tinyb.BluetoothGattDescriptor;
import org.tinyb.BluetoothNotification;
import org.tinyb.BluetoothType;
-public class GattDescriptor extends DBTObject implements BluetoothGattDescriptor
+public class DBTGattDescriptor extends DBTObject implements BluetoothGattDescriptor
{
private final String uuid;
- /* pp */ GattDescriptor(final long nativeInstance, final String uuid)
+ /* pp */ DBTGattDescriptor(final long nativeInstance, final String uuid)
{
super(nativeInstance, uuid.hashCode());
this.uuid = uuid;
@@ -43,10 +43,10 @@ public class GattDescriptor extends DBTObject implements BluetoothGattDescriptor
@Override
public boolean equals(final Object obj)
{
- if (obj == null || !(obj instanceof GattDescriptor)) {
+ if (obj == null || !(obj instanceof DBTGattDescriptor)) {
return false;
}
- final GattDescriptor other = (GattDescriptor)obj;
+ final DBTGattDescriptor other = (DBTGattDescriptor)obj;
return uuid.equals(other.uuid);
}
@@ -59,7 +59,7 @@ public class GattDescriptor extends DBTObject implements BluetoothGattDescriptor
static BluetoothType class_type() { return BluetoothType.GATT_DESCRIPTOR; }
@Override
- public final GattDescriptor clone()
+ public final BluetoothGattDescriptor clone()
{ throw new UnsupportedOperationException(); } // FIXME
/* D-Bus method calls: */
@@ -79,7 +79,7 @@ public class GattDescriptor extends DBTObject implements BluetoothGattDescriptor
/* D-Bus property accessors: */
@Override
- public native GattCharacteristic getCharacteristic();
+ public native DBTGattCharacteristic getCharacteristic();
@Override
public native byte[] getValue();
diff --git a/java/direct_bt/tinyb/GattService.java b/java/direct_bt/tinyb/DBTGattService.java
index 8377c806..17fd1a7c 100644
--- a/java/direct_bt/tinyb/GattService.java
+++ b/java/direct_bt/tinyb/DBTGattService.java
@@ -32,11 +32,11 @@ import org.tinyb.BluetoothGattService;
import org.tinyb.BluetoothManager;
import org.tinyb.BluetoothType;
-public class GattService extends DBTObject implements BluetoothGattService
+public class DBTGattService extends DBTObject implements BluetoothGattService
{
private final String uuid;
- /* pp */ GattService(final long nativeInstance, final String uuid)
+ /* pp */ DBTGattService(final long nativeInstance, final String uuid)
{
super(nativeInstance, uuid.hashCode());
this.uuid = uuid;
@@ -45,10 +45,10 @@ public class GattService extends DBTObject implements BluetoothGattService
@Override
public boolean equals(final Object obj)
{
- if (obj == null || !(obj instanceof GattService)) {
+ if (obj == null || !(obj instanceof DBTGattService)) {
return false;
}
- final GattService other = (GattService)obj;
+ final DBTGattService other = (DBTGattService)obj;
return uuid.equals(other.uuid);
}
@@ -61,13 +61,13 @@ public class GattService extends DBTObject implements BluetoothGattService
static BluetoothType class_type() { return BluetoothType.GATT_SERVICE; }
@Override
- public final GattService clone()
+ public final BluetoothGattService clone()
{ throw new UnsupportedOperationException(); } // FIXME
@Override
public BluetoothGattCharacteristic find(final String UUID, final long timeoutMS) {
- final BluetoothManager manager = Manager.getBluetoothManager();
- return (GattCharacteristic) manager.find(BluetoothType.GATT_CHARACTERISTIC,
+ final BluetoothManager manager = DBTManager.getBluetoothManager();
+ return (DBTGattCharacteristic) manager.find(BluetoothType.GATT_CHARACTERISTIC,
null, UUID, this, timeoutMS);
}
@@ -79,7 +79,7 @@ public class GattService extends DBTObject implements BluetoothGattService
/* D-Bus property accessors: */
@Override
- public native Device getDevice();
+ public native DBTDevice getDevice();
@Override
public native boolean getPrimary();
diff --git a/java/direct_bt/tinyb/Manager.java b/java/direct_bt/tinyb/DBTManager.java
index 99ea2cce..e5f17ad6 100644
--- a/java/direct_bt/tinyb/Manager.java
+++ b/java/direct_bt/tinyb/DBTManager.java
@@ -36,10 +36,10 @@ import org.tinyb.BluetoothObject;
import org.tinyb.BluetoothManager;
import org.tinyb.BluetoothType;
-public class Manager implements BluetoothManager
+public class DBTManager implements BluetoothManager
{
private long nativeInstance;
- private static Manager inst;
+ private static DBTManager inst;
private final List<BluetoothAdapter> adapters = new ArrayList<BluetoothAdapter>();
public BluetoothType getBluetoothType() { return BluetoothType.NONE; }
@@ -113,11 +113,11 @@ public class Manager implements BluetoothManager
* Returns an opened default adapter instance!
* @throws BluetoothException in case adapter is invalid or could not have been opened.
*/
- private native Adapter getDefaultAdapterImpl() throws BluetoothException;
+ private native DBTAdapter getDefaultAdapterImpl() throws BluetoothException;
private native void initImpl() throws BluetoothException;
private native void deleteImpl();
- private Manager()
+ private DBTManager()
{
initImpl();
try {
@@ -134,7 +134,7 @@ public class Manager implements BluetoothManager
{
if (inst == null)
{
- inst = new Manager();
+ inst = new DBTManager();
}
return inst;
}
diff --git a/java/direct_bt/tinyb/NativeDownlink.java b/java/direct_bt/tinyb/DBTNativeDownlink.java
index 72e4e137..28708a85 100644
--- a/java/direct_bt/tinyb/NativeDownlink.java
+++ b/java/direct_bt/tinyb/DBTNativeDownlink.java
@@ -27,22 +27,16 @@ package direct_bt.tinyb;
import org.tinyb.BluetoothFactory;
-public abstract class NativeDownlink
+public abstract class DBTNativeDownlink
{
protected long nativeInstance;
private boolean isValid;
static {
- try {
- System.loadLibrary(BluetoothFactory.JavaNativeLibBasename);
- } catch (final Throwable e) {
- System.err.println("Failed to load native library "+BluetoothFactory.JavaNativeLibBasename);
- e.printStackTrace();
- throw e; // fwd exception - end here
- }
+ BluetoothFactory.checkInitialized();
}
- protected NativeDownlink(final long nativeInstance)
+ protected DBTNativeDownlink(final long nativeInstance)
{
this.nativeInstance = nativeInstance;
isValid = true;
diff --git a/java/direct_bt/tinyb/DBTObject.java b/java/direct_bt/tinyb/DBTObject.java
index 93b10245..0380bb53 100644
--- a/java/direct_bt/tinyb/DBTObject.java
+++ b/java/direct_bt/tinyb/DBTObject.java
@@ -28,7 +28,7 @@ package direct_bt.tinyb;
import org.tinyb.BluetoothObject;
import org.tinyb.BluetoothType;
-public abstract class DBTObject extends NativeDownlink implements BluetoothObject
+public abstract class DBTObject extends DBTNativeDownlink implements BluetoothObject
{
private final int hashValue;
diff --git a/java/jni/direct_bt/DBTAdapter.cxx b/java/jni/direct_bt/DBTAdapter.cxx
index 3f634dc2..ed63c8b4 100644
--- a/java/jni/direct_bt/DBTAdapter.cxx
+++ b/java/jni/direct_bt/DBTAdapter.cxx
@@ -23,7 +23,7 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include "direct_bt_tinyb_Adapter.h"
+#include "direct_bt_tinyb_DBTAdapter.h"
// #define VERBOSE_ON 1
#include <dbt_debug.hpp>
@@ -32,14 +32,14 @@
#include "helper_base.hpp"
#include "helper_dbt.hpp"
-#include "direct_bt/HCITypes.hpp"
+#include "direct_bt/DBTTypes.hpp"
using namespace direct_bt;
-static const std::string _deviceClazzCtorArgs("(JLdirect_bt/tinyb/Adapter;Ljava/lang/String;Ljava/lang/String;J)V");
+static const std::string _deviceClazzCtorArgs("(JLdirect_bt/tinyb/DBTAdapter;Ljava/lang/String;Ljava/lang/String;J)V");
static const std::string _deviceDiscoveryMethodArgs("(Lorg/tinyb/BluetoothAdapter;Lorg/tinyb/BluetoothDevice;)V");
-class DeviceDiscoveryCallbackListener : public HCIDeviceDiscoveryListener {
+class DeviceDiscoveryCallbackListener : public DBTDeviceDiscoveryListener {
public:
/**
package org.tinyb;
@@ -60,24 +60,24 @@ class DeviceDiscoveryCallbackListener : public HCIDeviceDiscoveryListener {
jmethodID mDeviceUpdated = nullptr;
jmethodID mDeviceRemoved = nullptr;
- DeviceDiscoveryCallbackListener(JNIEnv *env, HCIAdapter *adapter, jobject deviceDiscoveryListener) {
+ DeviceDiscoveryCallbackListener(JNIEnv *env, DBTAdapter *adapter, jobject deviceDiscoveryListener) {
adapterObjRef = adapter->getJavaObject();
JavaGlobalObj::check(adapterObjRef, E_FILE_LINE);
{
- jclass deviceClazz = search_class(*jni_env, HCIDevice::java_class().c_str());
+ jclass deviceClazz = search_class(*jni_env, DBTDevice::java_class().c_str());
if( nullptr == deviceClazz ) {
- throw InternalError("HCIDevice::java_class not found: "+HCIDevice::java_class(), E_FILE_LINE);
+ throw InternalError("DBTDevice::java_class not found: "+DBTDevice::java_class(), E_FILE_LINE);
}
deviceClazzRef = std::unique_ptr<JNIGlobalRef>(new JNIGlobalRef(deviceClazz));
env->DeleteLocalRef(deviceClazz);
}
deviceClazzCtor = search_method(*jni_env, deviceClazzRef->getClass(), "<init>", _deviceClazzCtorArgs.c_str(), false);
if( nullptr == deviceClazzCtor ) {
- throw InternalError("HCIDevice::java_class ctor not found: "+HCIDevice::java_class()+".<init>"+_deviceClazzCtorArgs, E_FILE_LINE);
+ throw InternalError("DBTDevice::java_class ctor not found: "+DBTDevice::java_class()+".<init>"+_deviceClazzCtorArgs, E_FILE_LINE);
}
deviceClazzTSUpdateField = jni_env->GetFieldID(deviceClazzRef->getClass(), "ts_update", "J");
if( nullptr == deviceClazzTSUpdateField ) {
- throw InternalError("HCIDevice::java_class field not found: "+HCIDevice::java_class()+".ts_update", E_FILE_LINE);
+ throw InternalError("DBTDevice::java_class field not found: "+DBTDevice::java_class()+".ts_update", E_FILE_LINE);
}
listenerObjRef = std::unique_ptr<JNIGlobalRef>(new JNIGlobalRef(deviceDiscoveryListener));
@@ -104,13 +104,14 @@ class DeviceDiscoveryCallbackListener : public HCIDeviceDiscoveryListener {
exception_check_raise_and_throw(env, E_FILE_LINE);
}
- void deviceAdded(HCIAdapter const &a, std::shared_ptr<HCIDevice> device) override {
+ void deviceAdded(DBTAdapter const &a, std::shared_ptr<DBTDevice> device) override {
try {
#ifdef VERBOSE_ON
fprintf(stderr, "****** Native Adapter Device ADDED__: %s\n", device->toString().c_str());
- fprintf(stderr, "Status HCIAdapter:\n");
+ fprintf(stderr, "Status DBTAdapter:\n");
fprintf(stderr, "%s\n", a.toString().c_str());
#endif
+ (void)a;
// Device(final long nativeInstance, final Adapter adptr, final String address, final String name)
const jstring addr = from_string_to_jstring(*jni_env, device->getAddressString());
@@ -126,13 +127,14 @@ class DeviceDiscoveryCallbackListener : public HCIDeviceDiscoveryListener {
exception_check_raise_and_throw(*jni_env, E_FILE_LINE);
} CATCH_EXCEPTION_AND_RAISE_JAVA(*jni_env, e)
}
- void deviceUpdated(HCIAdapter const &a, std::shared_ptr<HCIDevice> device) override {
+ void deviceUpdated(DBTAdapter const &a, std::shared_ptr<DBTDevice> device) override {
try {
#ifdef VERBOSE_ON
fprintf(stderr, "****** Native Adapter Device UPDATED: %s\n", device->toString().c_str());
- fprintf(stderr, "Status HCIAdapter:\n");
+ fprintf(stderr, "Status DBTAdapter:\n");
fprintf(stderr, "%s\n", a.toString().c_str());
#endif
+ (void)a;
std::shared_ptr<JavaAnonObj> jDeviceRef = device->getJavaObject();
JavaGlobalObj::check(jDeviceRef, E_FILE_LINE);
jni_env->SetLongField(JavaGlobalObj::GetObject(jDeviceRef), deviceClazzTSUpdateField, (jlong)device->getUpdateTimestamp());
@@ -140,13 +142,14 @@ class DeviceDiscoveryCallbackListener : public HCIDeviceDiscoveryListener {
exception_check_raise_and_throw(*jni_env, E_FILE_LINE);
} CATCH_EXCEPTION_AND_RAISE_JAVA(*jni_env, e)
}
- void deviceRemoved(HCIAdapter const &a, std::shared_ptr<HCIDevice> device) override {
+ void deviceRemoved(DBTAdapter const &a, std::shared_ptr<DBTDevice> device) override {
try {
#ifdef VERBOSE_ON
fprintf(stderr, "****** DBTAdapter Device REMOVED: %s\n", device->toString().c_str());
- fprintf(stderr, "Status HCIAdapter:\n");
+ fprintf(stderr, "Status DBTAdapter:\n");
fprintf(stderr, "%s\n", a.toString().c_str());
#endif
+ (void)a;
std::shared_ptr<JavaAnonObj> jDeviceRef = device->getJavaObject();
JavaGlobalObj::check(jDeviceRef, E_FILE_LINE);
jni_env->SetLongField(JavaGlobalObj::GetObject(jDeviceRef), deviceClazzTSUpdateField, (jlong)device->getUpdateTimestamp());
@@ -156,33 +159,33 @@ class DeviceDiscoveryCallbackListener : public HCIDeviceDiscoveryListener {
}
};
-void Java_direct_1bt_tinyb_Adapter_initImpl(JNIEnv *env, jobject obj, jobject deviceDiscoveryListener)
+void Java_direct_1bt_tinyb_DBTAdapter_initImpl(JNIEnv *env, jobject obj, jobject deviceDiscoveryListener)
{
// org.tinyb.BluetoothDeviceDiscoveryListener
try {
- HCIAdapter *adapter = getInstance<HCIAdapter>(env, obj);
+ DBTAdapter *adapter = getInstance<DBTAdapter>(env, obj);
JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
// set our callback discovery listener.
DeviceDiscoveryCallbackListener *l = new DeviceDiscoveryCallbackListener(env, adapter, deviceDiscoveryListener);
- adapter->setDeviceDiscoveryListener(std::shared_ptr<HCIDeviceDiscoveryListener>(l));
+ adapter->setDeviceDiscoveryListener(std::shared_ptr<DBTDeviceDiscoveryListener>(l));
} CATCH_EXCEPTION_AND_RAISE_JAVA(env, e)
}
-void Java_direct_1bt_tinyb_Adapter_deleteImpl(JNIEnv *env, jobject obj)
+void Java_direct_1bt_tinyb_DBTAdapter_deleteImpl(JNIEnv *env, jobject obj)
{
try {
- HCIAdapter *adapter = getInstance<HCIAdapter>(env, obj);
- DBG_PRINT("Java_direct_1bt_tinyb_Adapter_deleteImpl %s", adapter->toString().c_str());
+ DBTAdapter *adapter = getInstance<DBTAdapter>(env, obj);
+ DBG_PRINT("Java_direct_1bt_tinyb_DBTAdapter_deleteImpl %s", adapter->toString().c_str());
delete adapter;
} CATCH_EXCEPTION_AND_RAISE_JAVA(env, e)
}
-jboolean Java_direct_1bt_tinyb_Adapter_startDiscoveryImpl(JNIEnv *env, jobject obj)
+jboolean Java_direct_1bt_tinyb_DBTAdapter_startDiscoveryImpl(JNIEnv *env, jobject obj)
{
try {
- HCIAdapter *adapter = getInstance<HCIAdapter>(env, obj);
- std::shared_ptr<direct_bt::HCISession> session = adapter->getOpenSession();
+ DBTAdapter *adapter = getInstance<DBTAdapter>(env, obj);
+ std::shared_ptr<direct_bt::DBTSession> session = adapter->getOpenSession();
if( nullptr == session ) {
throw BluetoothException("No adapter session: "+adapter->toString(), E_FILE_LINE);
}
@@ -194,11 +197,11 @@ jboolean Java_direct_1bt_tinyb_Adapter_startDiscoveryImpl(JNIEnv *env, jobject o
return JNI_FALSE;
}
-jboolean Java_direct_1bt_tinyb_Adapter_stopDiscoveryImpl(JNIEnv *env, jobject obj)
+jboolean Java_direct_1bt_tinyb_DBTAdapter_stopDiscoveryImpl(JNIEnv *env, jobject obj)
{
try {
- HCIAdapter *adapter = getInstance<HCIAdapter>(env, obj);
- std::shared_ptr<direct_bt::HCISession> session = adapter->getOpenSession();
+ DBTAdapter *adapter = getInstance<DBTAdapter>(env, obj);
+ std::shared_ptr<direct_bt::DBTSession> session = adapter->getOpenSession();
if( nullptr == session ) {
throw BluetoothException("No adapter session: "+adapter->toString(), E_FILE_LINE);
}
@@ -212,11 +215,11 @@ jboolean Java_direct_1bt_tinyb_Adapter_stopDiscoveryImpl(JNIEnv *env, jobject ob
return JNI_FALSE;
}
-jint Java_direct_1bt_tinyb_Adapter_discoverAnyDeviceImpl(JNIEnv *env, jobject obj, jint timeoutMS)
+jint Java_direct_1bt_tinyb_DBTAdapter_discoverAnyDeviceImpl(JNIEnv *env, jobject obj, jint timeoutMS)
{
try {
- HCIAdapter *adapter = getInstance<HCIAdapter>(env, obj);
- std::shared_ptr<direct_bt::HCISession> session = adapter->getOpenSession();
+ DBTAdapter *adapter = getInstance<DBTAdapter>(env, obj);
+ std::shared_ptr<direct_bt::DBTSession> session = adapter->getOpenSession();
if( nullptr == session ) {
throw BluetoothException("No adapter session: "+adapter->toString(), E_FILE_LINE);
}
@@ -228,30 +231,30 @@ jint Java_direct_1bt_tinyb_Adapter_discoverAnyDeviceImpl(JNIEnv *env, jobject ob
return 0;
}
-jobject Java_direct_1bt_tinyb_Adapter_getDiscoveredDevicesImpl(JNIEnv *env, jobject obj)
+jobject Java_direct_1bt_tinyb_DBTAdapter_getDiscoveredDevicesImpl(JNIEnv *env, jobject obj)
{
try {
- HCIAdapter *adapter = getInstance<HCIAdapter>(env, obj);
+ DBTAdapter *adapter = getInstance<DBTAdapter>(env, obj);
/**
- std::function<jobject(JNIEnv*, jclass, jmethodID, HCIDevice*)> ctor_device = [&](JNIEnv *env, jclass clazz, jmethodID clazz_ctor, HCIDevice *elem) {
+ std::function<jobject(JNIEnv*, jclass, jmethodID, DBTDevice*)> ctor_device = [&](JNIEnv *env, jclass clazz, jmethodID clazz_ctor, DBTDevice *elem) {
// Device(final long nativeInstance, final Adapter adptr, final String address, final String name)
jstring addr = from_string_to_jstring(env, elem->getAddressString());
jstring name = from_string_to_jstring(env, elem->getName());
jobject object = env->NewObject(clazz, clazz_ctor, (jlong)elem, obj, addr, name);
return object;
};
- return convert_vector_to_jobject<HCIDevice>(env, array, "(JLdirect_bt/tinyb/Adapter;Ljava/lang/String;Ljava/lang/String;)V", ctor_device);
+ return convert_vector_to_jobject<DBTDevice>(env, array, "(JLdirect_bt/tinyb/Adapter;Ljava/lang/String;Ljava/lang/String;)V", ctor_device);
*/
- std::vector<std::shared_ptr<HCIDevice>> array = adapter->getDiscoveredDevices();
+ std::vector<std::shared_ptr<DBTDevice>> array = adapter->getDiscoveredDevices();
return convert_vector_to_jobject(env, array);
} CATCH_EXCEPTION_AND_RAISE_JAVA(env, e)
return nullptr;
}
-jint Java_direct_1bt_tinyb_Adapter_removeDevicesImpl(JNIEnv *env, jobject obj)
+jint Java_direct_1bt_tinyb_DBTAdapter_removeDevicesImpl(JNIEnv *env, jobject obj)
{
try {
- HCIAdapter *adapter = getInstance<HCIAdapter>(env, obj);
+ DBTAdapter *adapter = getInstance<DBTAdapter>(env, obj);
return adapter->removeDiscoveredDevices();
} CATCH_EXCEPTION_AND_RAISE_JAVA(env, e)
return 0;
diff --git a/java/jni/direct_bt/DBTDevice.cxx b/java/jni/direct_bt/DBTDevice.cxx
index b2887b55..232e768b 100644
--- a/java/jni/direct_bt/DBTDevice.cxx
+++ b/java/jni/direct_bt/DBTDevice.cxx
@@ -23,54 +23,54 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include "direct_bt_tinyb_Device.h"
+#include "direct_bt_tinyb_DBTDevice.h"
#include "JNIMem.hpp"
#include "helper_base.hpp"
#include "helper_dbt.hpp"
-#include "direct_bt/HCITypes.hpp"
+#include "direct_bt/DBTTypes.hpp"
using namespace direct_bt;
-void Java_direct_1bt_tinyb_Device_initImpl(JNIEnv *env, jobject obj)
+void Java_direct_1bt_tinyb_DBTDevice_initImpl(JNIEnv *env, jobject obj)
{
try {
- HCIDevice *device = getInstance<HCIDevice>(env, obj);
+ DBTDevice *device = getInstance<DBTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
} CATCH_EXCEPTION_AND_RAISE_JAVA(env, e)
}
-void Java_direct_1bt_tinyb_Device_deleteImpl(JNIEnv *env, jobject obj)
+void Java_direct_1bt_tinyb_DBTDevice_deleteImpl(JNIEnv *env, jobject obj)
{
try {
- HCIDevice *device = getInstance<HCIDevice>(env, obj);
+ DBTDevice *device = getInstance<DBTDevice>(env, obj);
delete device;
} CATCH_EXCEPTION_AND_RAISE_JAVA(env, e)
}
-jshort Java_direct_1bt_tinyb_Device_getRSSI(JNIEnv *env, jobject obj)
+jshort Java_direct_1bt_tinyb_DBTDevice_getRSSI(JNIEnv *env, jobject obj)
{
try {
- HCIDevice *device = getInstance<HCIDevice>(env, obj);
+ DBTDevice *device = getInstance<DBTDevice>(env, obj);
return device->getRSSI();
} CATCH_EXCEPTION_AND_RAISE_JAVA(env, e)
return 0;
}
-jshort Java_direct_1bt_tinyb_Device_getTxPower(JNIEnv *env, jobject obj)
+jshort Java_direct_1bt_tinyb_DBTDevice_getTxPower(JNIEnv *env, jobject obj)
{
try {
- HCIDevice *device = getInstance<HCIDevice>(env, obj);
+ DBTDevice *device = getInstance<DBTDevice>(env, obj);
return device->getTxPower();
} CATCH_EXCEPTION_AND_RAISE_JAVA(env, e)
return 0;
}
-jboolean Java_direct_1bt_tinyb_Device_getConnected(JNIEnv *env, jobject obj)
+jboolean Java_direct_1bt_tinyb_DBTDevice_getConnected(JNIEnv *env, jobject obj)
{
try {
- HCIDevice *device = getInstance<HCIDevice>(env, obj);
+ DBTDevice *device = getInstance<DBTDevice>(env, obj);
(void) device;
return JNI_TRUE; // FIXME
} CATCH_EXCEPTION_AND_RAISE_JAVA(env, e)
diff --git a/java/jni/direct_bt/DBTGattCharacteristic.cxx b/java/jni/direct_bt/DBTGattCharacteristic.cxx
index cae33960..c19701a3 100644
--- a/java/jni/direct_bt/DBTGattCharacteristic.cxx
+++ b/java/jni/direct_bt/DBTGattCharacteristic.cxx
@@ -23,12 +23,12 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include "direct_bt_tinyb_GattCharacteristic.h"
+#include "direct_bt_tinyb_DBTGattCharacteristic.h"
#include "JNIMem.hpp"
#include "helper_base.hpp"
-#include "direct_bt/HCITypes.hpp"
+#include "direct_bt/DBTTypes.hpp"
using namespace direct_bt;
diff --git a/java/jni/direct_bt/DBTGattDescriptor.cxx b/java/jni/direct_bt/DBTGattDescriptor.cxx
index 59410d92..d90c559b 100644
--- a/java/jni/direct_bt/DBTGattDescriptor.cxx
+++ b/java/jni/direct_bt/DBTGattDescriptor.cxx
@@ -23,12 +23,12 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include "direct_bt_tinyb_GattDescriptor.h"
+#include "direct_bt_tinyb_DBTGattDescriptor.h"
#include "JNIMem.hpp"
#include "helper_base.hpp"
-#include "direct_bt/HCITypes.hpp"
+#include "direct_bt/DBTTypes.hpp"
using namespace direct_bt;
diff --git a/java/jni/direct_bt/DBTGattService.cxx b/java/jni/direct_bt/DBTGattService.cxx
index 6e0fe141..84ce946d 100644
--- a/java/jni/direct_bt/DBTGattService.cxx
+++ b/java/jni/direct_bt/DBTGattService.cxx
@@ -23,12 +23,12 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include "direct_bt_tinyb_GattService.h"
+#include "direct_bt_tinyb_DBTGattService.h"
#include "JNIMem.hpp"
#include "helper_base.hpp"
-#include "direct_bt/HCITypes.hpp"
+#include "direct_bt/DBTTypes.hpp"
using namespace direct_bt;
diff --git a/java/jni/direct_bt/DBTManager.cxx b/java/jni/direct_bt/DBTManager.cxx
index 0c01272d..fab3451f 100644
--- a/java/jni/direct_bt/DBTManager.cxx
+++ b/java/jni/direct_bt/DBTManager.cxx
@@ -23,7 +23,7 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include "direct_bt_tinyb_Manager.h"
+#include "direct_bt_tinyb_DBTManager.h"
// #define VERBOSE_ON 1
#include <dbt_debug.hpp>
@@ -32,22 +32,22 @@
#include "helper_base.hpp"
#include "helper_dbt.hpp"
-#include "direct_bt/HCITypes.hpp"
+#include "direct_bt/DBTTypes.hpp"
using namespace direct_bt;
-void Java_direct_1bt_tinyb_Manager_initImpl(JNIEnv *env, jobject obj)
+void Java_direct_1bt_tinyb_DBTManager_initImpl(JNIEnv *env, jobject obj)
{
try {
MgmtHandler *manager = &MgmtHandler::get(); // special: static singleton
setInstance<MgmtHandler>(env, obj, manager);
manager->setJavaObject( std::shared_ptr<JavaAnonObj>( new JavaGlobalObj(obj) ) );
JavaGlobalObj::check(manager->getJavaObject(), E_FILE_LINE);
- DBG_PRINT("Java_direct_1bt_tinyb_Manager_init: Manager %s", manager->toString().c_str());
+ DBG_PRINT("Java_direct_1bt_tinyb_DBTManager_init: Manager %s", manager->toString().c_str());
} CATCH_EXCEPTION_AND_RAISE_JAVA(env, e)
}
-void Java_direct_1bt_tinyb_Manager_deleteImpl(JNIEnv *env, jobject obj)
+void Java_direct_1bt_tinyb_DBTManager_deleteImpl(JNIEnv *env, jobject obj)
{
try {
MgmtHandler *manager = getInstance<MgmtHandler>(env, obj); // special: static singleton
@@ -59,13 +59,13 @@ void Java_direct_1bt_tinyb_Manager_deleteImpl(JNIEnv *env, jobject obj)
static const std::string _adapterClazzCtorArgs("(JLjava/lang/String;Ljava/lang/String;)V");
-jobject Java_direct_1bt_tinyb_Manager_getDefaultAdapterImpl(JNIEnv *env, jobject obj)
+jobject Java_direct_1bt_tinyb_DBTManager_getDefaultAdapterImpl(JNIEnv *env, jobject obj)
{
try {
MgmtHandler *manager = getInstance<MgmtHandler>(env, obj);
- DBG_PRINT("Java_direct_1bt_tinyb_Manager_getDefaultAdapterImpl: Manager %s", manager->toString().c_str());
+ DBG_PRINT("Java_direct_1bt_tinyb_DBTManager_getDefaultAdapterImpl: Manager %s", manager->toString().c_str());
int defAdapterIdx = manager->getDefaultAdapterIdx();
- HCIAdapter * adapter = new HCIAdapter(defAdapterIdx);
+ DBTAdapter * adapter = new DBTAdapter(defAdapterIdx);
if( !adapter->isValid() ) {
delete adapter;
throw BluetoothException("Invalid default adapter "+std::to_string(defAdapterIdx), E_FILE_LINE);
@@ -74,7 +74,7 @@ jobject Java_direct_1bt_tinyb_Manager_getDefaultAdapterImpl(JNIEnv *env, jobject
delete adapter;
throw BluetoothException("Invalid default adapter dev-id "+std::to_string(defAdapterIdx), E_FILE_LINE);
}
- std::shared_ptr<direct_bt::HCISession> session = adapter->open();
+ std::shared_ptr<direct_bt::DBTSession> session = adapter->open();
if( nullptr == session ) {
delete adapter;
throw BluetoothException("Couldn't open default adapter "+std::to_string(defAdapterIdx), E_FILE_LINE);
@@ -85,11 +85,11 @@ jobject Java_direct_1bt_tinyb_Manager_getDefaultAdapterImpl(JNIEnv *env, jobject
const jstring name = from_string_to_jstring(env, adapter->getName());
const jclass clazz = search_class(env, *adapter);
if( nullptr == clazz ) {
- throw InternalError("Adapter class not found: "+HCIAdapter::java_class(), E_FILE_LINE);
+ throw InternalError("Adapter class not found: "+DBTAdapter::java_class(), E_FILE_LINE);
}
const jmethodID clazz_ctor = search_method(env, clazz, "<init>", _adapterClazzCtorArgs.c_str(), false);
if( nullptr == clazz_ctor ) {
- throw InternalError("Adapter ctor not found: "+HCIAdapter::java_class()+".<init>"+_adapterClazzCtorArgs, E_FILE_LINE);
+ throw InternalError("Adapter ctor not found: "+DBTAdapter::java_class()+".<init>"+_adapterClazzCtorArgs, E_FILE_LINE);
}
exception_check_raise_and_throw(env, E_FILE_LINE);
jobject jAdapter = env->NewObject(clazz, clazz_ctor, (jlong)adapter, addr, name);
@@ -98,7 +98,7 @@ jobject Java_direct_1bt_tinyb_Manager_getDefaultAdapterImpl(JNIEnv *env, jobject
std::shared_ptr<JavaAnonObj> jAdapterRef = adapter->getJavaObject();
JavaGlobalObj::check(jAdapterRef, E_FILE_LINE);
- DBG_PRINT("Java_direct_1bt_tinyb_Manager_getDefaultAdapterImpl: New Adapter %s", adapter->toString().c_str());
+ DBG_PRINT("Java_direct_1bt_tinyb_DBTManager_getDefaultAdapterImpl: New Adapter %s", adapter->toString().c_str());
return JavaGlobalObj::GetObject(jAdapterRef);
} CATCH_EXCEPTION_AND_RAISE_JAVA(env, e)
return NULL;
diff --git a/java/jni/direct_bt/DBTNativeDownlink.cxx b/java/jni/direct_bt/DBTNativeDownlink.cxx
index 201d0728..ddad1cec 100644
--- a/java/jni/direct_bt/DBTNativeDownlink.cxx
+++ b/java/jni/direct_bt/DBTNativeDownlink.cxx
@@ -23,7 +23,7 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include "direct_bt_tinyb_NativeDownlink.h"
+#include "direct_bt_tinyb_DBTNativeDownlink.h"
// #define VERBOSE_ON 1
#include <dbt_debug.hpp>
@@ -32,11 +32,11 @@
#include "helper_base.hpp"
#include "helper_dbt.hpp"
-#include "direct_bt/HCITypes.hpp"
+#include "direct_bt/DBTTypes.hpp"
using namespace direct_bt;
-void Java_direct_1bt_tinyb_NativeDownlink_initNativeJavaObject(JNIEnv *env, jobject obj, jlong nativeInstance)
+void Java_direct_1bt_tinyb_DBTNativeDownlink_initNativeJavaObject(JNIEnv *env, jobject obj, jlong nativeInstance)
{
try {
JavaUplink *javaUplink = castInstance<JavaUplink>(nativeInstance);
@@ -46,12 +46,12 @@ void Java_direct_1bt_tinyb_NativeDownlink_initNativeJavaObject(JNIEnv *env, jobj
} CATCH_EXCEPTION_AND_RAISE_JAVA(env, e)
}
-void Java_direct_1bt_tinyb_NativeDownlink_clearNativeJavaObject(JNIEnv *env, jobject obj, jlong nativeInstance)
+void Java_direct_1bt_tinyb_DBTNativeDownlink_clearNativeJavaObject(JNIEnv *env, jobject obj, jlong nativeInstance)
{
(void)obj;
try {
JavaUplink *javaUplink = castInstance<JavaUplink>(nativeInstance);
- DBG_PRINT("Java_direct_1bt_tinyb_NativeDownlink_clearNativeJavaObject %s", javaUplink->toString().c_str());
+ DBG_PRINT("Java_direct_1bt_tinyb_DBTNativeDownlink_clearNativeJavaObject %s", javaUplink->toString().c_str());
javaUplink->setJavaObject(nullptr);
} CATCH_EXCEPTION_AND_RAISE_JAVA(env, e)
}
diff --git a/java/jni/direct_bt/DBTObject.cxx b/java/jni/direct_bt/DBTObject.cxx
index 74f40e8a..25b578a0 100644
--- a/java/jni/direct_bt/DBTObject.cxx
+++ b/java/jni/direct_bt/DBTObject.cxx
@@ -28,7 +28,7 @@
#include "JNIMem.hpp"
#include "helper_base.hpp"
-#include "direct_bt/HCITypes.hpp"
+#include "direct_bt/DBTTypes.hpp"
using namespace direct_bt;
diff --git a/java/jni/direct_bt/helper_dbt.hpp b/java/jni/direct_bt/helper_dbt.hpp
index 2f3d265f..5598c011 100644
--- a/java/jni/direct_bt/helper_dbt.hpp
+++ b/java/jni/direct_bt/helper_dbt.hpp
@@ -29,7 +29,7 @@
#include "JNIMem.hpp"
#include "helper_base.hpp"
-#include "direct_bt/JavaAccess.hpp"
+#include "direct_bt/JavaUplink.hpp"
#include "direct_bt/BasicTypes.hpp"
namespace direct_bt {
diff --git a/java/manifest.txt.in b/java/manifest.txt.in
index bac86421..b61ce601 100644
--- a/java/manifest.txt.in
+++ b/java/manifest.txt.in
@@ -12,7 +12,7 @@ Package-Version: @VERSION_SHORT@
Specification-Title: TinyB-2
Specification-Vendor: ZAFENA AB
Specification-Version: @VERSION_API@
-Implementation-Title: TinyB-2
+Implementation-Title: TinyB-2 with Direct-BT
Implementation-Vendor: ZAFENA AB
Implementation-Version: @VERSION@
Implementation-Commit: @VERSION_SHA1@
@@ -28,6 +28,6 @@ Sealed: true
Name: tinyb/dbus/
Sealed: true
-Name: tinyb/hci/
+Name: direct_bt/tinyb/
Sealed: true
diff --git a/java/org/tinyb/BluetoothFactory.java b/java/org/tinyb/BluetoothFactory.java
index 38306a16..0c5f4fb3 100644
--- a/java/org/tinyb/BluetoothFactory.java
+++ b/java/org/tinyb/BluetoothFactory.java
@@ -36,25 +36,62 @@ import java.util.jar.Attributes;
import java.util.jar.Manifest;
public class BluetoothFactory {
+
+ /**
+ * Identifier names, allowing {@link BluetoothFactory#getBluetoothManager(ImplementationIdentifier)}
+ * to initialize the required native libraries and to instantiate the root {@link BluetoothManager} instance.
+ */
+ public static class ImplementationIdentifier {
+ /** Fully qualified class name for the {@link BluetoothManager} implementation */
+ public final String BluetoothManagerClassName;
+ /** Native library basename for the implementation native library */
+ public final String ImplementationNativeLibraryBasename;
+ /** Native library basename for the Java binding native library */
+ public final String JavaNativeLibraryBasename;
+
+ public ImplementationIdentifier(final String BluetoothManagerClassName,
+ final String ImplementationNativeLibraryBasename,
+ final String JavaNativeLibraryBasename) {
+ this.BluetoothManagerClassName = BluetoothManagerClassName;
+ this.ImplementationNativeLibraryBasename = ImplementationNativeLibraryBasename;
+ this.JavaNativeLibraryBasename = JavaNativeLibraryBasename;
+ }
+
+ @Override
+ public String toString() {
+ return "ImplementationIdentifier[class "+BluetoothManagerClassName+
+ ", implLib "+ImplementationNativeLibraryBasename+
+ ", javaLib "+JavaNativeLibraryBasename+"]";
+ }
+ }
+
/**
- * Name of the native implementation native library basename: {@value}
+ * {@link ImplementationIdentifier} for D-Bus implementation: {@value}
+ * <p>
+ * This value is exposed for convenience, user implementations are welcome.
+ * </p>
*/
- public static final String ImplNativeLibBasename = "direct_bt"; // "tinyb";
+ public static final ImplementationIdentifier DBusImplementationID = new ImplementationIdentifier("tinyb.dbus.DBusManager", "tinyb", "javatinyb");
/**
- * Name of the Jave native library basename: {@value}
+ * {@link ImplementationIdentifier} for direct_bt implementation: {@value}
+ * <p>
+ * This value is exposed for convenience, user implementations are welcome.
+ * </p>
*/
- public static final String JavaNativeLibBasename = "javadirect_bt"; // "javatinyb";
+ public static final ImplementationIdentifier DirectBTImplementationID = new ImplementationIdentifier("direct_bt.tinyb.DBTManager", "direct_bt", "javadirect_bt");
/**
* Manifest's {@link Attributes.Name#SPECIFICATION_VERSION} or {@code null} if not available.
*/
- public static final String APIVersion;
+ public static final String getAPIVersion() { return APIVersion; }
+ private static String APIVersion;
/**
* Manifest's {@link Attributes.Name#IMPLEMENTATION_VERSION} or {@code null} if not available.
*/
- public static final String ImplVersion;
+ public static final String getImplVersion() { return ImplVersion; }
+ private static String ImplVersion;
static final boolean VERBOSE;
@@ -63,20 +100,39 @@ public class BluetoothFactory {
final String v = System.getProperty("org.tinyb.verbose", "false");
VERBOSE = Boolean.valueOf(v);
}
+ }
+
+ private static ImplementationIdentifier initializedID = null;
+
+ public static synchronized void checkInitialized() {
+ if( null == initializedID ) {
+ throw new IllegalStateException("BluetoothFactory not initialized.");
+ }
+ }
+
+ private static synchronized void initLibrary(final ImplementationIdentifier id) {
+ if( null != initializedID ) {
+ if( id != initializedID ) {
+ throw new IllegalStateException("BluetoothFactory already initialized with "+initializedID+", can't override by "+id);
+ }
+ return;
+ }
+
try {
- System.loadLibrary(ImplNativeLibBasename);
+ System.loadLibrary(id.ImplementationNativeLibraryBasename);
} catch (final Throwable e) {
- System.err.println("Failed to load native library "+ImplNativeLibBasename);
+ System.err.println("Failed to load native library "+id.ImplementationNativeLibraryBasename);
e.printStackTrace();
throw e; // fwd exception - end here
}
try {
- System.loadLibrary(JavaNativeLibBasename);
+ System.loadLibrary(id.JavaNativeLibraryBasename);
} catch (final Throwable e) {
- System.err.println("Failed to load native library "+JavaNativeLibBasename);
+ System.err.println("Failed to load native library "+id.JavaNativeLibraryBasename);
e.printStackTrace();
throw e; // fwd exception - end here
}
+
try {
final Manifest manifest = getManifest(BluetoothFactory.class.getClassLoader(), new String[] { "org.tinyb" } );
final Attributes mfAttributes = null != manifest ? manifest.getMainAttributes() : null;
@@ -101,9 +157,12 @@ public class BluetoothFactory {
}
}
}
+ initializedID = id; // initialized!
+
APIVersion = JAPIVersion;
ImplVersion = null != mfAttributes ? mfAttributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION) : null;
if( VERBOSE ) {
+ System.err.println("tinyb2 loaded "+id);
System.err.println("tinyb2 java api version "+JAPIVersion);
System.err.println("tinyb2 native api version "+NAPIVersion);
if( null != mfAttributes ) {
@@ -129,56 +188,47 @@ public class BluetoothFactory {
}
}
- /**
- * Fully qualified factory class name for D-Bus implementation: {@value}
- * <p>
- * This value is exposed for convenience, user implementations are welcome.
- * </p>
- */
- public static final String DBusFactoryImplClassName = "tinyb.dbus.DBusManager";
-
- /**
- * Fully qualified factory class name for direct_bt implementation: {@value}
- * <p>
- * This value is exposed for convenience, user implementations are welcome.
- * </p>
- */
- public static final String DirectBTFactoryImplClassName = "direct_bt.tinyb.Manager";
+ private static synchronized BluetoothManager getBluetoothManager(final Class<?> factoryImplClass)
+ throws BluetoothException, NoSuchMethodException, SecurityException,
+ IllegalAccessException, IllegalArgumentException, InvocationTargetException
+ {
+ final Method m = factoryImplClass.getMethod("getBluetoothManager");
+ return (BluetoothManager)m.invoke(null);
+ }
/**
* Returns an initialized BluetoothManager instance using the given {@code factoryImplClass}.
* <p>
* The {@code factoryImplClass} must provide the static method
* <pre>
- * public static BluetoothManager getBluetoothManager() throws BluetoothException { .. }
+ * public static synchronized BluetoothManager getBluetoothManager() throws BluetoothException { .. }
* </pre>
* </p>
- * @param factoryImplClass the factory implementation class
+ * @param id the fully qualified factory implementation class name
* @throws BluetoothException
* @throws NoSuchMethodException
* @throws SecurityException
* @throws IllegalAccessException
* @throws IllegalArgumentException
* @throws InvocationTargetException
- * @see #getBluetoothManager(String)
+ * @throws ClassNotFoundException
+ * @see {@link #DBusFactoryImplClassName}
+ * @see {@link #DirectBTFactoryImplClassName}
*/
- public static synchronized BluetoothManager getBluetoothManager(final Class<?> factoryImplClass)
+ public static synchronized BluetoothManager getBluetoothManager(final ImplementationIdentifier id)
throws BluetoothException, NoSuchMethodException, SecurityException,
- IllegalAccessException, IllegalArgumentException, InvocationTargetException
+ IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException
{
- final Method m = factoryImplClass.getMethod("getBluetoothManager");
- return (BluetoothManager)m.invoke(null);
+ initLibrary(id);
+ final Class<?> factoryImpl = Class.forName(id.BluetoothManagerClassName);
+ return getBluetoothManager(factoryImpl);
}
/**
- * Returns an initialized BluetoothManager instance using the given {@code factoryImplClass}.
+ * Returns an initialized BluetoothManager instance using a D-Bus implementation.
* <p>
- * The {@code factoryImplClass} must provide the static method
- * <pre>
- * public static synchronized BluetoothManager getBluetoothManager() throws BluetoothException { .. }
- * </pre>
+ * Issues {@link #getBluetoothManager(ImplementationIdentifier)} using {@link #DBusImplementationID}.
* </p>
- * @param factoryImplClass the fully qualified factory implementation class name
* @throws BluetoothException
* @throws NoSuchMethodException
* @throws SecurityException
@@ -186,24 +236,32 @@ public class BluetoothFactory {
* @throws IllegalArgumentException
* @throws InvocationTargetException
* @throws ClassNotFoundException
- * @see {@link #DBusFactoryImplClassName}
- * @see {@link #DirectBTFactoryImplClassName}
*/
- public static synchronized BluetoothManager getBluetoothManager(final String factoryImplClassName)
+ public static synchronized BluetoothManager getDBusBluetoothManager()
throws BluetoothException, NoSuchMethodException, SecurityException,
IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException
{
- final Class<?> factoryImpl = Class.forName(factoryImplClassName);
- return getBluetoothManager(factoryImpl);
+ return getBluetoothManager(DBusImplementationID);
}
/**
- * Returns an initialized BluetoothManager instance using a D-Bus implementation.
+ * Returns an initialized BluetoothManager instance using the DirectBT implementation.
+ * <p>
+ * Issues {@link #getBluetoothManager(ImplementationIdentifier)} using {@link #DirectBTImplementationID}.
+ * </p>
* @throws BluetoothException
+ * @throws NoSuchMethodException
+ * @throws SecurityException
+ * @throws IllegalAccessException
+ * @throws IllegalArgumentException
+ * @throws InvocationTargetException
+ * @throws ClassNotFoundException
*/
- public static synchronized BluetoothManager getDBusBluetoothManager() throws BluetoothException
+ public static synchronized BluetoothManager getDirectBTBluetoothManager()
+ throws BluetoothException, NoSuchMethodException, SecurityException,
+ IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException
{
- return tinyb.dbus.DBusManager.getBluetoothManager();
+ return getBluetoothManager(DirectBTImplementationID);
}
private static final boolean debug = false;
diff --git a/java/tinyb/dbus/DBusObject.java b/java/tinyb/dbus/DBusObject.java
index 66cdde30..b714d4c2 100644
--- a/java/tinyb/dbus/DBusObject.java
+++ b/java/tinyb/dbus/DBusObject.java
@@ -38,13 +38,7 @@ public class DBusObject implements BluetoothObject
private boolean isValid;
static {
- try {
- System.loadLibrary(BluetoothFactory.JavaNativeLibBasename);
- } catch (final Throwable e) {
- System.err.println("Failed to load native library "+BluetoothFactory.JavaNativeLibBasename);
- e.printStackTrace();
- throw e; // fwd exception - end here
- }
+ BluetoothFactory.checkInitialized();
}
static BluetoothType class_type() { return BluetoothType.NONE; }
diff --git a/src/direct_bt/HCIAdapter.cpp b/src/direct_bt/HCIAdapter.cpp
index da9db337..e29cb651 100644
--- a/src/direct_bt/HCIAdapter.cpp
+++ b/src/direct_bt/HCIAdapter.cpp
@@ -34,12 +34,12 @@
// #define VERBOSE_ON 1
#include <dbt_debug.hpp>
+#include <DBTTypes.hpp>
#include "BTIoctl.hpp"
#include "HCIIoctl.hpp"
#include "HCIComm.hpp"
-#include "HCITypes.hpp"
extern "C" {
#include <inttypes.h>
@@ -53,9 +53,9 @@ using namespace direct_bt;
// *************************************************
// *************************************************
-std::atomic_int HCISession::name_counter(0);
+std::atomic_int DBTSession::name_counter(0);
-void HCISession::disconnect(const uint8_t reason) {
+void DBTSession::disconnect(const uint8_t reason) {
connectedDevice = nullptr;
if( !hciComm.isLEConnected() ) {
@@ -67,7 +67,7 @@ void HCISession::disconnect(const uint8_t reason) {
}
}
-bool HCISession::close()
+bool DBTSession::close()
{
if( !hciComm.isOpen() ) {
DBG_PRINT("HCISession::close: Not open");
@@ -83,7 +83,7 @@ bool HCISession::close()
// *************************************************
// *************************************************
-bool HCIAdapter::validateDevInfo() {
+bool DBTAdapter::validateDevInfo() {
if( !mgmt.isOpen() || 0 > dev_id ) {
return false;
}
@@ -92,31 +92,31 @@ bool HCIAdapter::validateDevInfo() {
return true;
}
-void HCIAdapter::sessionClosing(HCISession& s)
+void DBTAdapter::sessionClosing(DBTSession& s)
{
stopDiscovery(s);
session = nullptr;
}
-HCIAdapter::HCIAdapter()
+DBTAdapter::DBTAdapter()
: mgmt(MgmtHandler::get()), dev_id(mgmt.getDefaultAdapterIdx())
{
valid = validateDevInfo();
}
-HCIAdapter::HCIAdapter(EUI48 &mac)
+DBTAdapter::DBTAdapter(EUI48 &mac)
: mgmt(MgmtHandler::get()), dev_id(mgmt.findAdapterIdx(mac))
{
valid = validateDevInfo();
}
-HCIAdapter::HCIAdapter(const int dev_id)
+DBTAdapter::DBTAdapter(const int dev_id)
: mgmt(MgmtHandler::get()), dev_id(dev_id)
{
valid = validateDevInfo();
}
-HCIAdapter::~HCIAdapter() {
+DBTAdapter::~DBTAdapter() {
DBG_PRINT("HCIAdapter::dtor: %s", toString().c_str());
deviceDiscoveryListener = nullptr;
@@ -125,29 +125,29 @@ HCIAdapter::~HCIAdapter() {
session = nullptr;
}
-std::shared_ptr<HCISession> HCIAdapter::open()
+std::shared_ptr<DBTSession> DBTAdapter::open()
{
if( !valid ) {
return nullptr;
}
- HCISession * s = new HCISession( *this, dev_id, HCI_CHANNEL_RAW );
+ DBTSession * s = new DBTSession( *this, dev_id, HCI_CHANNEL_RAW );
if( !s->isOpen() ) {
delete s;
perror("Could not open device");
return nullptr;
}
- session = std::shared_ptr<HCISession>( s );
+ session = std::shared_ptr<DBTSession>( s );
return session;
}
-std::shared_ptr<HCIDeviceDiscoveryListener> HCIAdapter::setDeviceDiscoveryListener(std::shared_ptr<HCIDeviceDiscoveryListener> l)
+std::shared_ptr<DBTDeviceDiscoveryListener> DBTAdapter::setDeviceDiscoveryListener(std::shared_ptr<DBTDeviceDiscoveryListener> l)
{
- std::shared_ptr<HCIDeviceDiscoveryListener> o = deviceDiscoveryListener;
+ std::shared_ptr<DBTDeviceDiscoveryListener> o = deviceDiscoveryListener;
deviceDiscoveryListener = l;
return o;
}
-bool HCIAdapter::startDiscovery(HCISession &session, uint8_t own_mac_type,
+bool DBTAdapter::startDiscovery(DBTSession &session, uint8_t own_mac_type,
uint16_t interval, uint16_t window)
{
if( !session.isOpen() ) {
@@ -161,7 +161,7 @@ bool HCIAdapter::startDiscovery(HCISession &session, uint8_t own_mac_type,
return true;
}
-void HCIAdapter::stopDiscovery(HCISession& session) {
+void DBTAdapter::stopDiscovery(DBTSession& session) {
if( !session.isOpen() ) {
DBG_PRINT("HCIAdapter::stopDiscovery: Not open");
return;
@@ -170,9 +170,9 @@ void HCIAdapter::stopDiscovery(HCISession& session) {
session.hciComm.le_disable_scan();
}
-int HCIAdapter::findDevice(std::vector<std::shared_ptr<HCIDevice>> const & devices, EUI48 const & mac) {
+int DBTAdapter::findDevice(std::vector<std::shared_ptr<DBTDevice>> const & devices, EUI48 const & mac) {
auto begin = devices.begin();
- auto it = std::find_if(begin, devices.end(), [&](std::shared_ptr<HCIDevice> const& p) {
+ auto it = std::find_if(begin, devices.end(), [&](std::shared_ptr<DBTDevice> const& p) {
return p->mac == mac;
});
if ( it == std::end(devices) ) {
@@ -182,11 +182,11 @@ int HCIAdapter::findDevice(std::vector<std::shared_ptr<HCIDevice>> const & devic
}
}
-int HCIAdapter::findScannedDeviceIdx(EUI48 const & mac) const {
+int DBTAdapter::findScannedDeviceIdx(EUI48 const & mac) const {
return findDevice(scannedDevices, mac);
}
-std::shared_ptr<HCIDevice> HCIAdapter::findScannedDevice (EUI48 const & mac) const {
+std::shared_ptr<DBTDevice> DBTAdapter::findScannedDevice (EUI48 const & mac) const {
const int idx = findDevice(scannedDevices, mac);
if( 0 <= idx ) {
return scannedDevices.at(idx);
@@ -194,7 +194,7 @@ std::shared_ptr<HCIDevice> HCIAdapter::findScannedDevice (EUI48 const & mac) con
return nullptr;
}
-bool HCIAdapter::addScannedDevice(std::shared_ptr<HCIDevice> const &device) {
+bool DBTAdapter::addScannedDevice(std::shared_ptr<DBTDevice> const &device) {
if( 0 > findDevice(scannedDevices, device->mac) ) {
scannedDevices.push_back(device);
return true;
@@ -202,11 +202,11 @@ bool HCIAdapter::addScannedDevice(std::shared_ptr<HCIDevice> const &device) {
return false;
}
-int HCIAdapter::findDiscoveredDeviceIdx(EUI48 const & mac) const {
+int DBTAdapter::findDiscoveredDeviceIdx(EUI48 const & mac) const {
return findDevice(discoveredDevices, mac);
}
-std::shared_ptr<HCIDevice> HCIAdapter::findDiscoveredDevice (EUI48 const & mac) const {
+std::shared_ptr<DBTDevice> DBTAdapter::findDiscoveredDevice (EUI48 const & mac) const {
const int idx = findDevice(discoveredDevices, mac);
if( 0 <= idx ) {
return discoveredDevices.at(idx);
@@ -214,7 +214,7 @@ std::shared_ptr<HCIDevice> HCIAdapter::findDiscoveredDevice (EUI48 const & mac)
return nullptr;
}
-bool HCIAdapter::addDiscoveredDevice(std::shared_ptr<HCIDevice> const &device) {
+bool DBTAdapter::addDiscoveredDevice(std::shared_ptr<DBTDevice> const &device) {
if( 0 > findDiscoveredDeviceIdx(device->mac) ) {
discoveredDevices.push_back(device);
return true;
@@ -222,7 +222,7 @@ bool HCIAdapter::addDiscoveredDevice(std::shared_ptr<HCIDevice> const &device) {
return false;
}
-int HCIAdapter::removeDiscoveredDevices() {
+int DBTAdapter::removeDiscoveredDevices() {
// also need to flush scannedDevices, old data
scannedDevices.clear();
int res = discoveredDevices.size();
@@ -230,12 +230,12 @@ int HCIAdapter::removeDiscoveredDevices() {
return res;
}
-std::string HCIAdapter::toString() const {
+std::string DBTAdapter::toString() const {
std::string out("Adapter["+getAddressString()+", '"+getName()+"', id="+std::to_string(dev_id)+", "+javaObjectToString()+"]");
if(discoveredDevices.size() > 0 ) {
out.append("\n");
for(auto it = discoveredDevices.begin(); it != discoveredDevices.end(); it++) {
- std::shared_ptr<HCIDevice> p = *it;
+ std::shared_ptr<DBTDevice> p = *it;
out.append(" ").append(p->toString()).append("\n");
}
}
@@ -244,7 +244,7 @@ std::string HCIAdapter::toString() const {
// *************************************************
-int HCIAdapter::discoverDevices(HCISession& session,
+int DBTAdapter::discoverDevices(DBTSession& session,
const int waitForDeviceCount,
const EUI48 &waitForDevice,
const int timeoutMS,
@@ -365,10 +365,10 @@ int HCIAdapter::discoverDevices(HCISession& session,
DBG_PRINT("HCIAdapter::discovery[%d] %d/%d: %s", loop-1, i, num_reports, ad_report->toString().c_str());
int idx = findDevice(scannedDevices, ad_report->getAddress());
- std::shared_ptr<HCIDevice> dev;
+ std::shared_ptr<DBTDevice> dev;
if( 0 > idx ) {
// new device
- dev = std::shared_ptr<HCIDevice>(new HCIDevice(*this, *ad_report));
+ dev = std::shared_ptr<DBTDevice>(new DBTDevice(*this, *ad_report));
scannedDevices.push_back(dev);
} else {
// existing device
diff --git a/src/direct_bt/HCIDevice.cpp b/src/direct_bt/HCIDevice.cpp
index 4ef9354d..baa97d5f 100644
--- a/src/direct_bt/HCIDevice.cpp
+++ b/src/direct_bt/HCIDevice.cpp
@@ -24,6 +24,7 @@
*/
#include <dbt_debug.hpp>
+#include <DBTTypes.hpp>
#include <cstring>
#include <string>
#include <memory>
@@ -34,12 +35,11 @@
#include <algorithm>
#include "HCIComm.hpp"
-#include "HCITypes.hpp"
using namespace direct_bt;
-HCIDevice::HCIDevice(HCIAdapter const & a, EInfoReport const & r)
+DBTDevice::DBTDevice(DBTAdapter const & a, EInfoReport const & r)
: adapter(a), ts_creation(r.getTimestamp()), mac(r.getAddress())
{
if( !r.isSet(EInfoReport::Element::BDADDR) ) {
@@ -48,26 +48,26 @@ HCIDevice::HCIDevice(HCIAdapter const & a, EInfoReport const & r)
update(r);
}
-HCIDevice::~HCIDevice() {
+DBTDevice::~DBTDevice() {
services.clear();
msd = nullptr;
}
-std::shared_ptr<HCIDevice> HCIDevice::getSharedInstance() const {
- const std::shared_ptr<HCIDevice> myself = adapter.findDiscoveredDevice(mac);
+std::shared_ptr<DBTDevice> DBTDevice::getSharedInstance() const {
+ const std::shared_ptr<DBTDevice> myself = adapter.findDiscoveredDevice(mac);
if( nullptr == myself ) {
throw InternalError("HCIDevice: Not present in HCIAdapter: "+toString(), E_FILE_LINE);
}
return myself;
}
-void HCIDevice::addService(std::shared_ptr<uuid_t> const &uuid)
+void DBTDevice::addService(std::shared_ptr<uuid_t> const &uuid)
{
if( 0 > findService(uuid) ) {
services.push_back(uuid);
}
}
-void HCIDevice::addServices(std::vector<std::shared_ptr<uuid_t>> const & services)
+void DBTDevice::addServices(std::vector<std::shared_ptr<uuid_t>> const & services)
{
for(size_t j=0; j<services.size(); j++) {
const std::shared_ptr<uuid_t> uuid = services.at(j);
@@ -75,7 +75,7 @@ void HCIDevice::addServices(std::vector<std::shared_ptr<uuid_t>> const & service
}
}
-int HCIDevice::findService(std::shared_ptr<uuid_t> const &uuid) const
+int DBTDevice::findService(std::shared_ptr<uuid_t> const &uuid) const
{
auto begin = services.begin();
auto it = std::find_if(begin, services.end(), [&](std::shared_ptr<uuid_t> const& p) {
@@ -88,7 +88,7 @@ int HCIDevice::findService(std::shared_ptr<uuid_t> const &uuid) const
}
}
-std::string HCIDevice::toString() const {
+std::string DBTDevice::toString() const {
const uint64_t t0 = getCurrentMilliseconds();
std::string msdstr = nullptr != msd ? msd->toString() : "MSD[null]";
std::string out("Device["+getAddressString()+", '"+getName()+
@@ -108,7 +108,7 @@ std::string HCIDevice::toString() const {
return out;
}
-void HCIDevice::update(EInfoReport const & data) {
+void DBTDevice::update(EInfoReport const & data) {
ts_update = data.getTimestamp();
if( data.isSet(EInfoReport::Element::NAME) ) {
if( !name.length() || data.getName().length() > name.length() ) {
@@ -132,7 +132,7 @@ void HCIDevice::update(EInfoReport const & data) {
addServices(data.getServices());
}
-uint16_t HCIDevice::le_connect(HCISession &session,
+uint16_t DBTDevice::le_connect(DBTSession &session,
uint8_t peer_mac_type, uint8_t own_mac_type,
uint16_t interval, uint16_t window,
uint16_t min_interval, uint16_t max_interval,
diff --git a/src/direct_bt/MgmtComm.cpp b/src/direct_bt/MgmtComm.cpp
index d4ac14ef..e6dc13c2 100644
--- a/src/direct_bt/MgmtComm.cpp
+++ b/src/direct_bt/MgmtComm.cpp
@@ -40,7 +40,7 @@
#include "MgmtComm.hpp"
#include "HCIIoctl.hpp"
#include "HCIComm.hpp"
-#include "HCITypes.hpp"
+#include <DBTTypes.hpp>
extern "C" {
#include <inttypes.h>
diff --git a/test/direct_bt/test_attpdu01.cpp b/test/direct_bt/test_attpdu01.cpp
index 1e6c30ce..194824ef 100644
--- a/test/direct_bt/test_attpdu01.cpp
+++ b/test/direct_bt/test_attpdu01.cpp
@@ -7,7 +7,7 @@
#include <direct_bt/UUID.hpp>
// #include <direct_bt/BTAddress.hpp>
-// #include <direct_bt/HCITypes.hpp>
+// #include <direct_bt/DBTTypes.hpp>
#include <direct_bt/ATTPDUTypes.hpp>
// #include <direct_bt/GATTHandler.hpp>
// #include <direct_bt/GATTIoctl.hpp>