aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-02-21 10:37:25 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2015-02-21 10:37:25 +0100
commita76e09808905d280282a81958cb4c68f71f18ca4 (patch)
tree52719f5d59bbdeee52188c9094850c80e24eaa67
parent7c9f266cdb37e215279208198dfe009dc66c5daa (diff)
downloadble-toys-a76e09808905d280282a81958cb4c68f71f18ca4.tar.gz
ble-toys-a76e09808905d280282a81958cb4c68f71f18ca4.tar.bz2
ble-toys-a76e09808905d280282a81958cb4c68f71f18ca4.tar.xz
ble-toys-a76e09808905d280282a81958cb4c68f71f18ca4.zip
o Consistence reference usage.
-rw-r--r--apps/sm-get-value.cpp2
-rw-r--r--ble/Bluetooth.h2
-rw-r--r--ble/BluetoothImpl.h12
-rw-r--r--ble/LinuxBluetooth.cpp11
4 files changed, 17 insertions, 10 deletions
diff --git a/apps/sm-get-value.cpp b/apps/sm-get-value.cpp
index 9e6ae2c..4d84c45 100644
--- a/apps/sm-get-value.cpp
+++ b/apps/sm-get-value.cpp
@@ -64,6 +64,8 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
}
+// auto bytes = gatt.readValue(c);
+
gatt.disconnect();
return EXIT_SUCCESS;
} catch (std::runtime_error ex) {
diff --git a/ble/Bluetooth.h b/ble/Bluetooth.h
index 1dd5022..d6be783 100644
--- a/ble/Bluetooth.h
+++ b/ble/Bluetooth.h
@@ -122,7 +122,7 @@ public:
virtual ~BluetoothGatt();
-// virtual BluetoothDevice &getDevice() = 0;
+ virtual BluetoothDevice &getDevice() const = 0;
virtual void connect() = 0;
diff --git a/ble/BluetoothImpl.h b/ble/BluetoothImpl.h
index 7801771..ef9a733 100644
--- a/ble/BluetoothImpl.h
+++ b/ble/BluetoothImpl.h
@@ -133,7 +133,7 @@ public:
}
protected:
- DefaultBluetoothDevice(A adapter, Mac &mac) :
+ DefaultBluetoothDevice(A &adapter, Mac &mac) :
adapter(adapter), mac(mac) {
DF;
}
@@ -150,13 +150,18 @@ protected:
services.clear();
}
- A adapter;
+ A &adapter;
Mac &mac;
vector<BluetoothGattService *> services;
};
+template<class _D>
class DefaultBluetoothGatt : public BluetoothGatt {
public:
+ virtual _D &getDevice() const {
+ return device;
+ }
+
virtual const vector<BluetoothGattService *> getServices() const {
return services;
};
@@ -176,7 +181,7 @@ public:
}
protected:
- DefaultBluetoothGatt() {
+ DefaultBluetoothGatt(_D &device) : device(device) {
DF;
}
@@ -192,6 +197,7 @@ protected:
services.clear();
}
+ _D &device;
vector<BluetoothGattService *> services;
};
diff --git a/ble/LinuxBluetooth.cpp b/ble/LinuxBluetooth.cpp
index a5d092b..d62bf23 100644
--- a/ble/LinuxBluetooth.cpp
+++ b/ble/LinuxBluetooth.cpp
@@ -55,21 +55,21 @@ private:
class LinuxBluetoothDevice : public DefaultBluetoothDevice<LinuxBluetoothAdapter> {
public:
LinuxBluetoothDevice(LinuxBluetoothAdapter &adapter, Mac &mac);
+
~LinuxBluetoothDevice();
BluetoothGatt &connectGatt() override;
private:
- LinuxBluetoothGatt* gatt;
+ LinuxBluetoothGatt *gatt;
int l2cap;
};
-class LinuxBluetoothGatt : public DefaultBluetoothGatt {
+class LinuxBluetoothGatt : public DefaultBluetoothGatt<LinuxBluetoothDevice> {
public:
LinuxBluetoothGatt(LinuxBluetoothDevice &device, int l2cap);
- ~LinuxBluetoothGatt();
-// LinuxBluetoothDevice &getDevice() override;
+ ~LinuxBluetoothGatt();
void connect() override;
@@ -84,7 +84,6 @@ private:
ByteBuffer writeAndRead(ByteBuffer &out, shared_ptr<uint8_t> buffer, size_t size);
- LinuxBluetoothDevice &device;
int l2cap;
};
@@ -131,7 +130,7 @@ BluetoothGatt &LinuxBluetoothDevice::connectGatt() {
// -----------------------------------------------------------------------
LinuxBluetoothGatt::LinuxBluetoothGatt(LinuxBluetoothDevice &device, int l2cap) :
- device(device), l2cap(l2cap) {
+ DefaultBluetoothGatt(device), l2cap(l2cap) {
}
LinuxBluetoothGatt::~LinuxBluetoothGatt() {