aboutsummaryrefslogtreecommitdiff
path: root/ble/BluetoothImpl.h
diff options
context:
space:
mode:
Diffstat (limited to 'ble/BluetoothImpl.h')
-rw-r--r--ble/BluetoothImpl.h45
1 files changed, 33 insertions, 12 deletions
diff --git a/ble/BluetoothImpl.h b/ble/BluetoothImpl.h
index 967c2e7..204b051 100644
--- a/ble/BluetoothImpl.h
+++ b/ble/BluetoothImpl.h
@@ -2,9 +2,10 @@
#define BLUETOOTH_IMPL_H
#include "ble/Bluetooth.h"
-#include "log.h"
#include <boost/uuid/uuid_io.hpp>
#include <cstring>
+#include <log4cplus/logger.h>
+#include <log4cplus/loggingmacros.h>
#define BLUETOOTH_UUID_INITIALIZER \
{ \
@@ -15,17 +16,36 @@
0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb \
};
+#define LOG_DEBUG(body) LOG4CPLUS_DEBUG(logger, body)
+#define LOG_INFO(body) LOG4CPLUS_INFO(logger, body)
+#define LOG_WARN(body) LOG4CPLUS_WARN(logger, body)
+
namespace trygvis {
namespace bluetooth {
+// Utility typedefs
typedef boost::uuids::uuid uuid_t;
template<class t>
using o = boost::optional<t>;
+using namespace log4cplus;
+
+// Logging
+
+class LogSetup {
+public:
+ LogSetup(std::string name) : logger(Logger::getInstance(LOG4CPLUS_TEXT(name))) {
+ }
+
+protected:
+ Logger logger;
+};
+
+// Shared classes
-class DefaultBluetoothGattCharacteristic : public BluetoothGattCharacteristic {
+class DefaultBluetoothGattCharacteristic : LogSetup, public BluetoothGattCharacteristic {
public:
DefaultBluetoothGattCharacteristic(BluetoothGattService &service, uint16_t handle, uuid_t uuid, uint8_t properties, uint16_t valueHandle)
- : service(service), handle(handle), uuid(uuid), properties(properties), valueHandle(valueHandle) {
+ : LogSetup("DefaultBluetoothGattCharacteristic"), service(service), handle(handle), uuid(uuid), properties(properties), valueHandle(valueHandle) {
}
virtual ~DefaultBluetoothGattCharacteristic() {
@@ -63,11 +83,9 @@ class DefaultBluetoothGattService : public BluetoothGattService {
public:
DefaultBluetoothGattService(BluetoothDevice &device, const uuid_t uuid, const uint16_t handle, const uint16_t endGroupHandle)
: device(device), uuid(uuid), handle(handle), endGroupHandle(endGroupHandle) {
- DF;
}
virtual ~DefaultBluetoothGattService() {
- DF;
removeCharacteristics();
}
@@ -113,7 +131,6 @@ protected:
vector<BluetoothGattCharacteristic *> characteristics;
void removeCharacteristics() {
- DF;
for (auto &c: characteristics) {
delete c;
}
@@ -122,7 +139,7 @@ protected:
};
template<class _D>
-class DefaultBluetoothGatt : public BluetoothGatt {
+class DefaultBluetoothGatt : protected LogSetup, public BluetoothGatt {
public:
virtual _D &getDevice() const {
return device;
@@ -147,12 +164,10 @@ public:
}
protected:
- DefaultBluetoothGatt(_D &device) : device(device) {
- DF;
+ DefaultBluetoothGatt(_D &device) : LogSetup("BluetoothGatt"), device(device) {
}
virtual ~DefaultBluetoothGatt() {
- DF;
removeServices();
}
@@ -182,11 +197,9 @@ public:
protected:
DefaultBluetoothDevice(A &adapter, Mac &mac) :
adapter(adapter), mac(mac) {
- DF;
}
virtual ~DefaultBluetoothDevice() {
- DF;
removeServices();
}
@@ -202,6 +215,14 @@ protected:
vector<BluetoothGattService *> services;
};
+class DefaultBluetoothAdapter : protected LogSetup, public BluetoothAdapter {
+public:
+protected:
+ DefaultBluetoothAdapter() :
+ LogSetup("BluetoothAdapter") {
+ }
+};
+
BluetoothAdapter &getAdapterImpl(int hciDevice);
void shutdownImpl();