aboutsummaryrefslogtreecommitdiff
path: root/include/ble/misc.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/ble/misc.h')
-rw-r--r--include/ble/misc.h15
1 files changed, 12 insertions, 3 deletions
diff --git a/include/ble/misc.h b/include/ble/misc.h
index 089c3a1..4ba3309 100644
--- a/include/ble/misc.h
+++ b/include/ble/misc.h
@@ -1,5 +1,7 @@
#pragma once
+#include <experimental/optional>
+
#include <cstring>
#include <cctype>
#include <stdexcept>
@@ -7,6 +9,9 @@
namespace trygvis {
namespace bluetooth {
+template<typename T>
+using o = std::experimental::optional<T>;
+
class BluetoothAdapter;
class BluetoothDevice;
@@ -31,7 +36,7 @@ struct Uuid {
Uuid(uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5, uint8_t b6, uint8_t b7,
uint8_t b8, uint8_t b9, uint8_t b10, uint8_t b11, uint8_t b12, uint8_t b13, uint8_t b14, uint8_t b15) noexcept : value{
- b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15} {}
+ b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15} {}
bool operator==(const Uuid &other) {
return std::memcmp(value, other.value, 16) == 0;
@@ -48,20 +53,24 @@ struct Uuid {
static Uuid fromShort(uint8_t b2, uint8_t b3) {
return {0x00, 0x00, b2, b3, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb};
}
+
+ static o<Uuid> fromString(const std::string &str);
};
struct ShortUuid {
private:
public:
- explicit ShortUuid(uint16_t value) : value(value) {}
+ explicit ShortUuid(uint16_t value) noexcept : value(value) {}
- Uuid toLong()
+ Uuid toLong() const noexcept
{
auto b2 = static_cast<uint8_t>(value >> 8);
auto b3 = static_cast<uint8_t>(value & 0xff);
return Uuid::fromShort(b2, b3);
}
+ std::string str() const noexcept;
+
uint16_t value;
};