summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/bluez
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@theqtcompany.com>2015-10-28 08:52:04 +0100
committerChristian Kandeler <christian.kandeler@theqtcompany.com>2015-11-12 10:44:16 +0000
commiteb59027d32c7904a129b16c786df1dc2097ab9c9 (patch)
tree1ac3e31e00082df536b59a6289a676b8a0127917 /src/bluetooth/bluez
parent0738b5963165bd013278a6ac4c083817e5bba7d3 (diff)
Bluetooth: Introduce convenience "put data" function for quint* types.
Users can just call the function regardless of the concrete type, and it will do the right thing with regards to casting and edianness. This will come in handy when implementing GATT server functionality, where lots of generic packet creation needs to happen. Change-Id: Id6315bc1fd628bdfb84c1b91c7c8b50925f24d32 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/bluetooth/bluez')
-rw-r--r--src/bluetooth/bluez/bluez_data_p.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/bluetooth/bluez/bluez_data_p.h b/src/bluetooth/bluez/bluez_data_p.h
index 3722b80d..5d6a90ef 100644
--- a/src/bluetooth/bluez/bluez_data_p.h
+++ b/src/bluetooth/bluez/bluez_data_p.h
@@ -191,6 +191,20 @@ static inline void ntoh128(const quint128 *src, quint128 *dst)
#error "Unknown byte order"
#endif
+inline quint8 hostToBt(quint8 val) { return val; }
+inline quint16 hostToBt(quint16 val) { return htobs(val); }
+inline quint32 hostToBt(quint32 val) { return htobl(val); }
+inline quint64 hostToBt(quint64 val) { return htobll(val); }
+
+template<typename T> inline void putBtData(T src, void *dst)
+{
+ bt_put_unaligned(hostToBt(src), reinterpret_cast<T *>(dst));
+}
+template<> inline void putBtData(quint128 src, void *dst)
+{
+ btoh128(&src, reinterpret_cast<quint128 *>(dst));
+}
+
#define hton128(x, y) ntoh128(x, y)
// HCI related