From 0d0543e4daeb1c6b01d4799736026b6f3aef9779 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 15 Feb 2015 23:29:17 +0100 Subject: valgrind tests --- Bluetooth.h | 177 +++++++++++++++++++++++++++++++----------------------------- 1 file changed, 91 insertions(+), 86 deletions(-) (limited to 'Bluetooth.h') diff --git a/Bluetooth.h b/Bluetooth.h index 15ef171..7ed7b8c 100644 --- a/Bluetooth.h +++ b/Bluetooth.h @@ -21,125 +21,130 @@ #define UUID_SECONDARY_SERVICE 0x2801 namespace trygvis { - using namespace std; +namespace bluetooth { +using namespace std; + +class BluetoothAdapter; + +class BluetoothDevice; + +class BluetoothException : public runtime_error { +public: + BluetoothException(const BluetoothAdapter *adapter, string const &what) : + runtime_error(what), adapter(adapter), device(nullptr) { + } + + BluetoothException(const BluetoothDevice *device, string const &what) : + runtime_error(what), adapter(nullptr), device(device) { + } + + BluetoothException(string const &what) : + runtime_error(what), adapter(nullptr), device(nullptr) { + } + + const BluetoothAdapter *adapter; + const BluetoothDevice *device; +}; + +class Mac { +public: + Mac(uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5) { + bytes[0] = _0; + bytes[1] = _1; + bytes[2] = _2; + bytes[3] = _3; + bytes[4] = _4; + bytes[5] = _5; + }; - class BluetoothAdapter; + string str() const; - class BluetoothDevice; + bool operator==(Mac &other) const; - class BluetoothException : public runtime_error { - public: - BluetoothException(const BluetoothAdapter *adapter, string const &what) : - runtime_error(what), adapter(adapter), device(nullptr) { - } + bool operator!=(Mac &other) const; - BluetoothException(const BluetoothDevice *device, string const &what) : - runtime_error(what), adapter(nullptr), device(device) { - } + void copy(uint8_t &_0, uint8_t &_1, uint8_t &_2, uint8_t &_3, uint8_t &_4, uint8_t &_5) const; - BluetoothException(string const &what) : - runtime_error(what), adapter(nullptr), device(nullptr) { - } + static Mac parseMac(string s) throw(BluetoothException); - const BluetoothAdapter *adapter; - const BluetoothDevice *device; - }; + friend bool operator<(const Mac &a, const Mac &b); - class Mac { - public: - Mac(uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5) { - bytes[0] = _0; - bytes[1] = _1; - bytes[2] = _2; - bytes[3] = _3; - bytes[4] = _4; - bytes[5] = _5; - }; +private: + uint8_t bytes[6]; +}; - string str() const; +class BluetoothDevice { +public: + virtual Mac const &mac() = 0; - bool operator==(Mac &other) const; + virtual BluetoothAdapter &adapter() = 0; - bool operator!=(Mac &other) const; + virtual void connect() = 0; - void copy(uint8_t &_0, uint8_t &_1, uint8_t &_2, uint8_t &_3, uint8_t &_4, uint8_t &_5) const; + virtual void disconnect() = 0; - static Mac *parseMac(string s) throw(BluetoothException); + virtual void discoverServices() = 0; +}; - friend bool operator<(const Mac &a, const Mac &b); - private: - uint8_t bytes[6]; - }; +class BluetoothAdapter { +public: + virtual void stopScan() = 0; - class BluetoothDevice { - public: - virtual Mac const &mac() = 0; + virtual void runScan(void (callback)(BluetoothDevice &device)) = 0; - virtual BluetoothAdapter &adapter() = 0; + virtual BluetoothDevice &getDevice(Mac &mac) = 0; - virtual void connect() = 0; +protected: + BluetoothAdapter(); - virtual void disconnect() = 0; + virtual ~BluetoothAdapter(); +}; - virtual void discoverServices() = 0; - }; +enum AttPduType { + ERROR = 0x00, + READ_BY_GROUP_TYPE_REQ = 0x10, + READ_BY_GROUP_TYPE_RES = 0x11 +}; - class BluetoothAdapter { - public: - BluetoothAdapter() { - }; +class AttributeData; - virtual ~BluetoothAdapter(); +class AttPdu { +public: + AttPdu(ByteBuffer &bytes); - virtual void stopScan() = 0; + AttPdu(ByteBuffer &bytes, AttPduType type); - virtual void runScan(void (callback)(BluetoothDevice &device)) = 0; + AttPduType getType(); - virtual BluetoothDevice &getDevice(Mac& mac) = 0; - }; + static vector parseReadByGroupType(ByteBuffer &bytes); - enum AttPduType { - ERROR = 0x00, - READ_BY_GROUP_TYPE_REQ = 0x10, - READ_BY_GROUP_TYPE_RES = 0x11 - }; + static void makeReadByGroupType(ByteBuffer &bytes, uint16_t startHandle, uint16_t endHandle, uint16_t uuid); - class AttributeData; +private: + static void checkType(ByteBuffer &bytes, AttPduType type); - class AttPdu { - public: - AttPdu(ByteBuffer &bytes); + ByteBuffer &bytes; +}; - AttPdu(ByteBuffer &bytes, AttPduType type); +class AttributeData { +public: + ~AttributeData(); - AttPduType getType(); + static AttributeData fromByteBuffer(ByteBuffer &value, uint8_t length); - static vector parseReadByGroupType(ByteBuffer &bytes); + const uint16_t handle; + const uint16_t groupEndHandle; + const ByteBuffer value; - static void makeReadByGroupType(ByteBuffer &bytes, uint16_t startHandle, uint16_t endHandle, uint16_t uuid); +private: + AttributeData(uint16_t handle, uint16_t groupEndHandle, ByteBuffer value); +}; - private: - static void checkType(ByteBuffer &bytes, AttPduType type); +BluetoothAdapter &getAdapter(int hciDevice); - ByteBuffer &bytes; - }; +void shutdown(); - class AttributeData { - public: - ~AttributeData(); - - static AttributeData fromByteBuffer(ByteBuffer &value, uint8_t length); - - const uint16_t handle; - const uint16_t groupEndHandle; - const ByteBuffer value; - - private: - AttributeData(uint16_t handle, uint16_t groupEndHandle, ByteBuffer value); - }; - -// BluetoothAdapter &getAdapter(int hciDevice); - BluetoothAdapter *getAdapter(int hciDevice); +} } #endif -- cgit v1.2.3