aboutsummaryrefslogtreecommitdiff
path: root/Bluetooth.h
diff options
context:
space:
mode:
Diffstat (limited to 'Bluetooth.h')
-rw-r--r--Bluetooth.h77
1 files changed, 77 insertions, 0 deletions
diff --git a/Bluetooth.h b/Bluetooth.h
new file mode 100644
index 0000000..2e2f2ef
--- /dev/null
+++ b/Bluetooth.h
@@ -0,0 +1,77 @@
+#ifndef BLUETOOTH_H
+#define BLUETOOTH_H
+
+#include <string>
+#include <stdexcept>
+
+// For now
+#include <boost/log/core.hpp>
+#include <boost/log/trivial.hpp>
+
+#define D BOOST_LOG_TRIVIAL(debug)
+#define I BOOST_LOG_TRIVIAL(info)
+#define W BOOST_LOG_TRIVIAL(warning)
+
+namespace trygvis {
+ using namespace std;
+
+ class BluetoothAdapter;
+ class BluetoothDevice;
+
+ class BluetoothException : public runtime_error {
+ public:
+ BluetoothException(const BluetoothAdapter *adapter, string const &what) :
+ adapter(adapter), device(nullptr), runtime_error(what) {
+ }
+ BluetoothException(const BluetoothAdapter *adapter, const BluetoothDevice *device, string const &what) :
+ adapter(adapter), device(device), runtime_error(what) {
+ }
+
+ 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;
+ };
+
+ string str() const;
+
+ bool operator==(Mac& other) const;
+
+ void copy(uint8_t &_0, uint8_t &_1, uint8_t &_2, uint8_t &_3, uint8_t &_4, uint8_t &_5) const;
+ static Mac *parseMac(string s);
+
+ private:
+ uint8_t bytes[6];
+ };
+
+ class BluetoothDevice {
+ public:
+ virtual Mac const &mac() = 0;
+ virtual void connect() = 0;
+ virtual void disconnect() = 0;
+ virtual BluetoothAdapter& adapter() = 0;
+ };
+
+ class BluetoothAdapter {
+ public:
+ BluetoothAdapter() {};
+ virtual ~BluetoothAdapter();
+
+ virtual void stopScan() = 0;
+ virtual void runScan(void (callback)(BluetoothDevice &device)) = 0;
+ };
+
+// BluetoothAdapter &getDevice(int hciDevice);
+ BluetoothAdapter *getDevice(int hciDevice);
+}
+
+#endif