aboutsummaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2021-09-18 16:57:08 +0200
committerSven Gothel <[email protected]>2021-09-18 16:57:08 +0200
commit162e04122b733e9860ad8d9d6e8772de9e63cd01 (patch)
tree13edadf41331328fdc4ccb93fa649a2f94bc84b8 /api
parent7406c239f55b8e820be3a5cae88b7ecd53de76c7 (diff)
Moved EUI48, EUI48Sub (C++/Java) and uuid_t, *Octets (C++) to jaulib for general use.
Notable, the java classes EUI48, EUI48Sub and BasicTypes are included in direct_bt's jar file to avoid any inconvenience. Hence BTUtils's byte[s]HexString(..) simply uses jaulib's BasicTypes s' implementation.
Diffstat (limited to 'api')
-rw-r--r--api/direct_bt/ATTPDUTypes.hpp56
-rw-r--r--api/direct_bt/BTAddress.hpp294
-rw-r--r--api/direct_bt/BTDevice.hpp12
-rw-r--r--api/direct_bt/BTGattChar.hpp22
-rw-r--r--api/direct_bt/BTGattDesc.hpp16
-rw-r--r--api/direct_bt/BTGattHandler.hpp14
-rw-r--r--api/direct_bt/BTGattService.hpp8
-rw-r--r--api/direct_bt/BTManager.hpp4
-rw-r--r--api/direct_bt/BTTypes0.hpp30
-rw-r--r--api/direct_bt/BTTypes1.hpp8
-rw-r--r--api/direct_bt/GattNumbers.hpp28
-rw-r--r--api/direct_bt/GattTypes.hpp4
-rw-r--r--api/direct_bt/HCIHandler.hpp4
-rw-r--r--api/direct_bt/HCITypes.hpp6
-rw-r--r--api/direct_bt/L2CAPComm.hpp2
-rw-r--r--api/direct_bt/MgmtTypes.hpp10
-rw-r--r--api/direct_bt/OctetTypes.hpp675
-rw-r--r--api/direct_bt/SMPHandler.hpp4
-rw-r--r--api/direct_bt/SMPTypes.hpp4
-rw-r--r--api/direct_bt/UUID.hpp242
-rw-r--r--api/direct_bt/linux_kernel_types.hpp5
21 files changed, 140 insertions, 1308 deletions
diff --git a/api/direct_bt/ATTPDUTypes.hpp b/api/direct_bt/ATTPDUTypes.hpp
index 78b68cd9..b56d8ac4 100644
--- a/api/direct_bt/ATTPDUTypes.hpp
+++ b/api/direct_bt/ATTPDUTypes.hpp
@@ -36,11 +36,11 @@
#include <atomic>
#include <jau/basic_types.hpp>
+#include <jau/octets.hpp>
+#include <jau/uuid.hpp>
-#include "UUID.hpp"
#include "BTTypes0.hpp"
-#include "OctetTypes.hpp"
/**
* - - - - - - - - - - - - - - -
@@ -432,7 +432,7 @@ namespace direct_bt {
public:
/** actual received PDU */
- POctets pdu;
+ jau::POctets pdu;
/** flags a request PDU, i.e. a command etc, initiated by a GATT client */
const bool is_request;
@@ -753,7 +753,7 @@ namespace direct_bt {
class AttReadRsp: public AttPDUMsg
{
private:
- const TOctetSlice view;
+ const jau::TOctetSlice view;
constexpr static jau::nsize_t pdu_value_offset = 1;
@@ -770,7 +770,7 @@ namespace direct_bt {
constexpr uint8_t const * getValuePtr() const noexcept { return pdu.get_ptr_nc( pdu_value_offset ); }
- constexpr TOctetSlice const & getValue() const noexcept { return view; }
+ constexpr jau::TOctetSlice const & getValue() const noexcept { return view; }
constexpr_cxx20 std::string getName() const noexcept override {
return "AttReadRsp";
@@ -836,7 +836,7 @@ namespace direct_bt {
class AttReadBlobRsp: public AttPDUMsg
{
private:
- const TOctetSlice view;
+ const jau::TOctetSlice view;
constexpr static jau::nsize_t pdu_value_offset = 1;
@@ -853,7 +853,7 @@ namespace direct_bt {
constexpr uint8_t const * getValuePtr() const noexcept { return pdu.get_ptr_nc( pdu_value_offset ); }
- constexpr TOctetSlice const & getValue() const noexcept { return view; }
+ constexpr jau::TOctetSlice const & getValue() const noexcept { return view; }
constexpr_cxx20 std::string getName() const noexcept override {
return "AttReadBlobRsp";
@@ -881,12 +881,12 @@ namespace direct_bt {
class AttWriteReq : public AttPDUMsg
{
private:
- const TOctetSlice view;
+ const jau::TOctetSlice view;
constexpr static jau::nsize_t pdu_value_offset = 1 + 2;
public:
- AttWriteReq(const uint16_t handle, const TROOctets & value)
+ AttWriteReq(const uint16_t handle, const jau::TROOctets & value)
: AttPDUMsg(Opcode::WRITE_REQ, 1+2+value.getSize()), view(pdu, getPDUValueOffset(), getPDUValueSize())
{
pdu.put_uint16_nc(1, handle);
@@ -902,7 +902,7 @@ namespace direct_bt {
constexpr uint8_t const * getValuePtr() const noexcept { return pdu.get_ptr_nc( pdu_value_offset ); }
- constexpr TOctetSlice const & getValue() const noexcept { return view; }
+ constexpr jau::TOctetSlice const & getValue() const noexcept { return view; }
constexpr_cxx20 std::string getName() const noexcept override {
return "AttWriteReq";
@@ -953,12 +953,12 @@ namespace direct_bt {
class AttWriteCmd : public AttPDUMsg
{
private:
- const TOctetSlice view;
+ const jau::TOctetSlice view;
constexpr static jau::nsize_t pdu_value_offset = 1 + 2;
public:
- AttWriteCmd(const uint16_t handle, const TROOctets & value)
+ AttWriteCmd(const uint16_t handle, const jau::TROOctets & value)
: AttPDUMsg(Opcode::WRITE_CMD, 1+2+value.getSize()), view(pdu, getPDUValueOffset(), getPDUValueSize())
{
pdu.put_uint16_nc(1, handle);
@@ -974,7 +974,7 @@ namespace direct_bt {
constexpr uint8_t const * getValuePtr() const noexcept { return pdu.get_ptr_nc( pdu_value_offset ); }
- constexpr TOctetSlice const & getValue() const noexcept { return view; }
+ constexpr jau::TOctetSlice const & getValue() const noexcept { return view; }
constexpr_cxx20 std::string getName() const noexcept override {
return "AttWriteCmd";
@@ -1005,7 +1005,7 @@ namespace direct_bt {
class AttHandleValueRcv: public AttPDUMsg
{
private:
- const TOctetSlice view;
+ const jau::TOctetSlice view;
constexpr static jau::nsize_t pdu_value_offset = 1 + 2;
@@ -1022,7 +1022,7 @@ namespace direct_bt {
constexpr uint8_t const * getValuePtr() const noexcept { return pdu.get_ptr_nc( pdu_value_offset ); }
- TOctetSlice const & getValue() const noexcept { return view; }
+ jau::TOctetSlice const & getValue() const noexcept { return view; }
bool isNotification() const noexcept {
return Opcode::HANDLE_VALUE_NTF == getOpcode();
@@ -1136,15 +1136,15 @@ namespace direct_bt {
class AttReadByNTypeReq : public AttPDUMsg
{
private:
- constexpr_cxx20 uuid_t::TypeSize getUUIFormat() const {
- return uuid_t::toTypeSize(this->getPDUValueSize());
+ constexpr_cxx20 jau::uuid_t::TypeSize getUUIFormat() const {
+ return jau::uuid_t::toTypeSize(this->getPDUValueSize());
}
public:
- AttReadByNTypeReq(const bool groupTypeReq, const uint16_t startHandle, const uint16_t endHandle, const uuid_t & uuid)
+ AttReadByNTypeReq(const bool groupTypeReq, const uint16_t startHandle, const uint16_t endHandle, const jau::uuid_t & uuid)
: AttPDUMsg(groupTypeReq ? Opcode::READ_BY_GROUP_TYPE_REQ : Opcode::READ_BY_TYPE_REQ, 1+2+2+uuid.getTypeSizeInt())
{
- if( uuid.getTypeSize() != uuid_t::TypeSize::UUID16_SZ && uuid.getTypeSize()!= uuid_t::TypeSize::UUID128_SZ ) {
+ if( uuid.getTypeSize() != jau::uuid_t::TypeSize::UUID16_SZ && uuid.getTypeSize()!= jau::uuid_t::TypeSize::UUID128_SZ ) {
throw jau::IllegalArgumentException("Only UUID16 and UUID128 allowed: "+uuid.toString(), E_FILE_LINE);
}
pdu.put_uint16_nc(1, startHandle);
@@ -1163,7 +1163,7 @@ namespace direct_bt {
return "AttReadByNTypeReq";
}
- std::unique_ptr<const uuid_t> getNType() const {
+ std::unique_ptr<const jau::uuid_t> getNType() const {
return pdu.get_uuid( getPDUValueOffset(), getUUIFormat() );
}
@@ -1202,7 +1202,7 @@ namespace direct_bt {
*/
class Element {
private:
- const TOctetSlice view;
+ const jau::TOctetSlice view;
public:
Element(const AttReadByTypeRsp & p, const jau::nsize_t idx)
@@ -1301,7 +1301,7 @@ namespace direct_bt {
*/
class Element {
private:
- const TOctetSlice view;
+ const jau::TOctetSlice view;
public:
Element(const AttReadByGroupTypeRsp & p, const jau::nsize_t idx)
@@ -1436,12 +1436,12 @@ namespace direct_bt {
class AttFindInfoRsp: public AttElementList
{
private:
- uuid_t::TypeSize getUUIFormat() const {
+ jau::uuid_t::TypeSize getUUIFormat() const {
const int f = pdu.get_uint8_nc(1);
if( 0x01 == f ) {
- return uuid_t::TypeSize::UUID16_SZ;
+ return jau::uuid_t::TypeSize::UUID16_SZ;
} else if( 0x02 == f ) {
- return uuid_t::TypeSize::UUID128_SZ;
+ return jau::uuid_t::TypeSize::UUID128_SZ;
}
throw AttValueException("PDUFindInfoRsp: Invalid format "+std::to_string(f)+", not UUID16 (1) or UUID128 (2)", E_FILE_LINE);
}
@@ -1453,7 +1453,7 @@ namespace direct_bt {
class Element {
public:
const uint16_t handle;
- const std::unique_ptr<const uuid_t> uuid;
+ const std::unique_ptr<const jau::uuid_t> uuid;
Element(const AttFindInfoRsp & p, const jau::nsize_t idx)
: handle( p.getElementHandle(idx) ), uuid( p.getElementValue(idx) )
@@ -1483,7 +1483,7 @@ namespace direct_bt {
* </p>
*/
jau::nsize_t getElementValueSize() const override {
- return uuid_t::number(getUUIFormat());
+ return jau::uuid_t::number(getUUIFormat());
}
jau::nsize_t getElementCount() const override {
@@ -1498,7 +1498,7 @@ namespace direct_bt {
return pdu.get_uint16( getElementPDUOffset(elementIdx) );
}
- std::unique_ptr<const uuid_t> getElementValue(const jau::nsize_t elementIdx) const {
+ std::unique_ptr<const jau::uuid_t> getElementValue(const jau::nsize_t elementIdx) const {
return pdu.get_uuid( getElementPDUOffset(elementIdx) + 2, getUUIFormat() );
}
diff --git a/api/direct_bt/BTAddress.hpp b/api/direct_bt/BTAddress.hpp
index ec094d1a..593ee254 100644
--- a/api/direct_bt/BTAddress.hpp
+++ b/api/direct_bt/BTAddress.hpp
@@ -33,6 +33,10 @@
#include <jau/packed_attribute.hpp>
#include <jau/ordered_atomic.hpp>
+#include <jau/eui48.hpp>
+
+using jau::EUI48;
+using jau::EUI48Sub;
namespace direct_bt {
@@ -154,263 +158,6 @@ namespace direct_bt {
HCILEOwnAddressType to_HCILEOwnAddressType(const BDAddressType addrType) noexcept;
std::string to_string(const HCILEOwnAddressType type) noexcept;
- /**
- * A 48 bit EUI-48 sub-identifier, see EUI48.
- */
- struct EUI48Sub {
- /** EUI48 MAC address matching any device, i.e. `0:0:0:0:0:0`. */
- static const EUI48Sub ANY_DEVICE;
- /** EUI48 MAC address matching all device, i.e. `ff:ff:ff:ff:ff:ff`. */
- static const EUI48Sub ALL_DEVICE;
- /** EUI48 MAC address matching local device, i.e. `0:0:0:ff:ff:ff`. */
- static const EUI48Sub LOCAL_DEVICE;
-
- /**
- * The <= 6 byte EUI48 sub-address.
- */
- uint8_t b[6]; // == sizeof(EUI48)
-
- /**
- * The actual length in bytes of the EUI48 sub-address, less or equal 6 bytes.
- */
- jau::nsize_t length;
-
- constexpr EUI48Sub() noexcept : b{0}, length{0} { }
- EUI48Sub(const uint8_t * b_, const jau::nsize_t len_) noexcept;
-
- /**
- * Fills given EUI48Sub instance via given string representation.
- * <p>
- * Implementation is consistent with EUI48Sub::toString().
- * </p>
- * @param str a string of less or equal of 17 characters representing less or equal of 6 bytes as hexadecimal numbers separated via colon,
- * e.g. `01:02:03:0A:0B:0C`, `01:02:03:0A`, `:`, (empty).
- * @param dest EUI48Sub to set its value
- * @param errmsg error parsing message if returning false
- * @return true if successful, otherwise false
- * @see EUI48Sub::EUI48Sub
- * @see EUI48Sub::toString()
- */
- static bool scanEUI48Sub(const std::string& str, EUI48Sub& dest, std::string& errmsg);
-
- /**
- * Construct a sub EUI48 via given string representation.
- * <p>
- * Implementation is consistent with EUI48Sub::toString().
- * </p>
- * @param str a string of less or equal of 17 characters representing less or equal of 6 bytes as hexadecimal numbers separated via colon,
- * e.g. `01:02:03:0A:0B:0C`, `01:02:03:0A`, `:`, (empty).
- * @see EUI48Sub::scanEUI48Sub()
- * @see EUI48Sub::toString()
- * @throws jau::IllegalArgumentException if given string doesn't comply with EUI48
- */
- EUI48Sub(const std::string& str);
-
- constexpr EUI48Sub(const EUI48Sub &o) noexcept = default;
- EUI48Sub(EUI48Sub &&o) noexcept = default;
- constexpr EUI48Sub& operator=(const EUI48Sub &o) noexcept = default;
- EUI48Sub& operator=(EUI48Sub &&o) noexcept = default;
-
- constexpr std::size_t hash_code() const noexcept {
- // 31 * x == (x << 5) - x
- std::size_t h = length;
- for(jau::nsize_t i=0; i<length; i++) {
- h = ( ( h << 5 ) - h ) + b[i];
- }
- return h;
- }
-
- /**
- * Method clears the underlying byte array {@link #b} and sets length to zero.
- */
- void clear() {
- b[0] = 0; b[1] = 0; b[2] = 0;
- b[3] = 0; b[4] = 0; b[5] = 0;
- length = 0;
- }
-
- /**
- * Find index of needle within haystack.
- * @param haystack_b haystack data
- * @param haystack_length haystack length
- * @param needle_b needle data
- * @param needle_length needle length
- * @return index of first element of needle within haystack or -1 if not found. If the needle length is zero, 0 (found) is returned.
- */
- static jau::snsize_t indexOf(const uint8_t haystack_b[], const jau::nsize_t haystack_length,
- const uint8_t needle_b[], const jau::nsize_t needle_length) noexcept;
-
- /**
- * Finds the index of given EUI48Sub needle within this instance haystack.
- * @param needle
- * @return index of first element of needle within this instance haystack or -1 if not found. If the needle length is zero, 0 (found) is returned.
- */
- jau::snsize_t indexOf(const EUI48Sub& needle) const noexcept {
- return indexOf(b, length, needle.b, needle.length);
- }
-
- /**
- * Returns true, if given EUI48Sub needle is contained in this instance haystack.
- * <p>
- * If the sub is zero, true is returned.
- * </p>
- */
- bool contains(const EUI48Sub& needle) const noexcept {
- return 0 <= indexOf(needle);
- }
-
- /**
- * Returns the EUI48 sub-string representation,
- * less or equal 17 characters representing less or equal 6 bytes as upper case hexadecimal numbers separated via colon,
- * e.g. `01:02:03:0A:0B:0C`, `01:02:03:0A`, `:`, (empty).
- */
- std::string toString() const noexcept;
- };
- inline std::string to_string(const EUI48Sub& a) noexcept { return a.toString(); }
-
- inline bool operator==(const EUI48Sub& lhs, const EUI48Sub& rhs) noexcept {
- if( &lhs == &rhs ) {
- return true;
- }
- if( lhs.length != rhs.length ) {
- return false;
- }
- return !memcmp(&lhs.b, &rhs.b, lhs.length);
- }
-
- inline bool operator!=(const EUI48Sub& lhs, const EUI48Sub& rhs) noexcept
- { return !(lhs == rhs); }
-
-
- /**
- * A packed 48 bit EUI-48 identifier, formerly known as MAC-48
- * or simply network device MAC address (Media Access Control address).
- */
- __pack ( struct EUI48 {
- /** EUI48 MAC address matching any device, i.e. `0:0:0:0:0:0`. */
- static const EUI48 ANY_DEVICE;
- /** EUI48 MAC address matching all device, i.e. `ff:ff:ff:ff:ff:ff`. */
- static const EUI48 ALL_DEVICE;
- /** EUI48 MAC address matching local device, i.e. `0:0:0:ff:ff:ff`. */
- static const EUI48 LOCAL_DEVICE;
-
- /**
- * The 6 byte EUI48 address.
- */
- uint8_t b[6]; // == sizeof(EUI48)
-
- constexpr EUI48() noexcept : b{0} { }
- EUI48(const uint8_t * b_) noexcept;
-
- /**
- * Fills given EUI48 instance via given string representation.
- * <p>
- * Implementation is consistent with EUI48::toString().
- * </p>
- * @param str a string of exactly 17 characters representing 6 bytes as hexadecimal numbers separated via colon `01:02:03:0A:0B:0C`.
- * @param dest EUI48 to set its value
- * @param errmsg error parsing message if returning false
- * @return true if successful, otherwise false
- * @see EUI48::EUI48
- * @see EUI48::toString()
- */
- static bool scanEUI48(const std::string& str, EUI48& dest, std::string& errmsg);
-
- /**
- * Construct instance via given string representation.
- * <p>
- * Implementation is consistent with EUI48::toString().
- * </p>
- * @param str a string of exactly 17 characters representing 6 bytes as hexadecimal numbers separated via colon `01:02:03:0A:0B:0C`.
- * @see EUI48::scanEUI48()
- * @see EUI48::toString()
- * @throws jau::IllegalArgumentException if given string doesn't comply with EUI48
- */
- EUI48(const std::string& str);
-
- constexpr EUI48(const EUI48 &o) noexcept = default;
- EUI48(EUI48 &&o) noexcept = default;
- constexpr EUI48& operator=(const EUI48 &o) noexcept = default;
- EUI48& operator=(EUI48 &&o) noexcept = default;
-
- constexpr std::size_t hash_code() const noexcept {
- // 31 * x == (x << 5) - x
- std::size_t h = b[0];
- h = ( ( h << 5 ) - h ) + b[1];
- h = ( ( h << 5 ) - h ) + b[2];
- h = ( ( h << 5 ) - h ) + b[3];
- h = ( ( h << 5 ) - h ) + b[4];
- h = ( ( h << 5 ) - h ) + b[5];
- return h;
- }
-
- /**
- * Method clears the underlying byte array {@link #b}.
- */
- void clear() {
- b[0] = 0; b[1] = 0; b[2] = 0;
- b[3] = 0; b[4] = 0; b[5] = 0;
- }
-
- /**
- * Returns the BLERandomAddressType.
- * <p>
- * If ::BDAddressType is ::BDAddressType::BDADDR_LE_RANDOM,
- * method shall return a valid value other than ::BLERandomAddressType::UNDEFINED.
- * </p>
- * <p>
- * If BDAddressType is not ::BDAddressType::BDADDR_LE_RANDOM,
- * method shall return ::BLERandomAddressType::UNDEFINED.
- * </p>
- * @since 2.2.0
- */
- BLERandomAddressType getBLERandomAddressType(const BDAddressType addressType) const noexcept;
-
- /**
- * Finds the index of given EUI48Sub needle within this instance haystack.
- * @param needle
- * @return index of first element of needle within this instance haystack or -1 if not found. If the needle length is zero, 0 (found) is returned.
- */
- jau::snsize_t indexOf(const EUI48Sub& needle) const noexcept {
- return EUI48Sub::indexOf(b, sizeof(b), needle.b, needle.length);
- }
-
- /**
- * Returns true, if given EUI48Sub needle is contained in this instance haystack.
- * <p>
- * If the sub is zero, true is returned.
- * </p>
- */
- bool contains(const EUI48Sub& needle) const noexcept {
- return 0 <= indexOf(needle);
- }
-
- /**
- * Returns the EUI48 string representation,
- * exactly 17 characters representing 6 bytes as upper case hexadecimal numbers separated via colon `01:02:03:0A:0B:0C`.
- * @see EUI48::EUI48()
- */
- std::string toString() const noexcept;
- } );
- inline std::string to_string(const EUI48& a) noexcept { return a.toString(); }
-
- inline bool operator==(const EUI48& lhs, const EUI48& rhs) noexcept {
- if( &lhs == &rhs ) {
- return true;
- }
- //return !memcmp(&lhs, &rhs, sizeof(EUI48));
- const uint8_t * a = lhs.b;
- const uint8_t * b = rhs.b;
- return a[0] == b[0] &&
- a[1] == b[1] &&
- a[2] == b[2] &&
- a[3] == b[3] &&
- a[4] == b[4] &&
- a[5] == b[5];
- }
-
- inline bool operator!=(const EUI48& lhs, const EUI48& rhs) noexcept
- { return !(lhs == rhs); }
/**
* Unique Bluetooth EUI48 address and ::BDAddressType tuple.
@@ -431,14 +178,14 @@ namespace direct_bt {
*/
static const BDAddressAndType ANY_DEVICE;
- EUI48 address;
+ jau::EUI48 address;
BDAddressType type;
private:
jau::relaxed_atomic_size_t hash = 0; // default 0, cache
public:
- BDAddressAndType(const EUI48 & address_, BDAddressType type_)
+ BDAddressAndType(const jau::EUI48 & address_, BDAddressType type_)
: address(address_), type(type_) {}
constexpr BDAddressAndType() noexcept : address(), type{BDAddressType::BDADDR_UNDEFINED} { }
@@ -473,6 +220,20 @@ namespace direct_bt {
/**
* Returns the BLERandomAddressType.
* <p>
+ * If ::BDAddressType is ::BDAddressType::BDADDR_LE_RANDOM,
+ * method shall return a valid value other than ::BLERandomAddressType::UNDEFINED.
+ * </p>
+ * <p>
+ * If BDAddressType is not ::BDAddressType::BDADDR_LE_RANDOM,
+ * method shall return ::BLERandomAddressType::UNDEFINED.
+ * </p>
+ * @since 2.2.0
+ */
+ static BLERandomAddressType getBLERandomAddressType(const jau::EUI48& address, const BDAddressType addressType) noexcept;
+
+ /**
+ * Returns the BLERandomAddressType.
+ * <p>
* If type is ::BDAddressType::BDADDR_LE_RANDOM},
* method shall return a valid value other than ::BLERandomAddressType::UNDEFINED.
* </p>
@@ -483,9 +244,10 @@ namespace direct_bt {
* @since 2.0.0
*/
BLERandomAddressType getBLERandomAddressType() const noexcept {
- return address.getBLERandomAddressType(type);
+ return getBLERandomAddressType(address, type);
}
+
/**
* Returns true if both devices match, i.e. equal address
* and equal type or at least one type is {@link BDAddressType#BDADDR_UNDEFINED}.
@@ -549,18 +311,6 @@ namespace direct_bt {
// injecting specialization of std::hash to namespace std of our types above
namespace std
{
- template<> struct hash<direct_bt::EUI48Sub> {
- std::size_t operator()(direct_bt::EUI48Sub const& a) const noexcept {
- return a.hash_code();
- }
- };
-
- template<> struct hash<direct_bt::EUI48> {
- std::size_t operator()(direct_bt::EUI48 const& a) const noexcept {
- return a.hash_code();
- }
- };
-
template<> struct hash<direct_bt::BDAddressAndType> {
std::size_t operator()(direct_bt::BDAddressAndType const& a) const noexcept {
return a.hash_code();
diff --git a/api/direct_bt/BTDevice.hpp b/api/direct_bt/BTDevice.hpp
index 3e306238..eecf0c1d 100644
--- a/api/direct_bt/BTDevice.hpp
+++ b/api/direct_bt/BTDevice.hpp
@@ -88,7 +88,7 @@ namespace direct_bt {
jau::relaxed_atomic_uint16 hciConnHandle;
jau::ordered_atomic<LE_Features, std::memory_order_relaxed> le_features;
std::shared_ptr<ManufactureSpecificData> advMSD = nullptr;
- jau::darray<std::shared_ptr<const uuid_t>> advServices;
+ jau::darray<std::shared_ptr<const jau::uuid_t>> advServices;
#if SMP_SUPPORTED_BY_OS
std::shared_ptr<SMPHandler> smpHandler = nullptr;
std::recursive_mutex mtx_smpHandler;
@@ -144,14 +144,14 @@ namespace direct_bt {
}
/** Add advertised service (GAP discovery) */
- bool addAdvService(std::shared_ptr<const uuid_t> const &uuid) noexcept;
+ bool addAdvService(std::shared_ptr<const jau::uuid_t> const &uuid) noexcept;
/** Add advertised service (GAP discovery) */
- bool addAdvServices(jau::darray<std::shared_ptr<const uuid_t>> const & services) noexcept;
+ bool addAdvServices(jau::darray<std::shared_ptr<const jau::uuid_t>> const & services) noexcept;
/**
* Find advertised service (GAP discovery) index
* @return index >= 0 if found, otherwise -1
*/
- int findAdvService(std::shared_ptr<const uuid_t> const &uuid) const noexcept;
+ int findAdvService(const jau::uuid_t& uuid) const noexcept;
EIRDataType update(EInfoReport const & data) noexcept;
EIRDataType update(GattGenericAccessSvc const &data, const uint64_t timestamp) noexcept;
@@ -332,7 +332,7 @@ namespace direct_bt {
* use {@link #getGattService()}.
* </p>
*/
- jau::darray<std::shared_ptr<const uuid_t>> getAdvertisedServices() const noexcept;
+ jau::darray<std::shared_ptr<const jau::uuid_t>> getAdvertisedServices() const noexcept;
std::string toString() const noexcept override { return toString(false); }
@@ -905,7 +905,7 @@ namespace direct_bt {
* Implementation calls getGattService().
* </p>
*/
- std::shared_ptr<BTGattService> findGattService(std::shared_ptr<uuid_t> const &uuid);
+ std::shared_ptr<BTGattService> findGattService(const jau::uuid_t& uuid);
/** Returns the shared GenericAccess instance, retrieved by {@link #getGattService()} or nullptr if not available. */
std::shared_ptr<GattGenericAccessSvc> getGattGenericAccess();
diff --git a/api/direct_bt/BTGattChar.hpp b/api/direct_bt/BTGattChar.hpp
index 44dd48b3..944ecceb 100644
--- a/api/direct_bt/BTGattChar.hpp
+++ b/api/direct_bt/BTGattChar.hpp
@@ -35,10 +35,10 @@
#include <atomic>
#include <jau/java_uplink.hpp>
+#include <jau/octets.hpp>
+#include <jau/uuid.hpp>
-#include "UUID.hpp"
#include "BTTypes0.hpp"
-#include "OctetTypes.hpp"
#include "ATTPDUTypes.hpp"
#include "BTTypes1.hpp"
@@ -129,7 +129,7 @@ namespace direct_bt {
* @param timestamp the indication monotonic timestamp, see getCurrentMilliseconds()
*/
virtual void notificationReceived(BTGattCharRef charDecl,
- const TROOctets& charValue, const uint64_t timestamp) = 0;
+ const jau::TROOctets& charValue, const uint64_t timestamp) = 0;
/**
* Called from native BLE stack, initiated by a received indication associated
@@ -140,7 +140,7 @@ namespace direct_bt {
* @param confirmationSent if true, the native stack has sent the confirmation, otherwise user is required to do so.
*/
virtual void indicationReceived(BTGattCharRef charDecl,
- const TROOctets& charValue, const uint64_t timestamp,
+ const jau::TROOctets& charValue, const uint64_t timestamp,
const bool confirmationSent) = 0;
virtual ~Listener() noexcept {}
@@ -186,7 +186,7 @@ namespace direct_bt {
const uint16_t value_handle;
/* Characteristics Value Type UUID */
- std::unique_ptr<const uuid_t> value_type;
+ std::unique_ptr<const jau::uuid_t> value_type;
/** List of Characteristic Descriptions as shared reference */
jau::darray<BTGattDescRef> descriptorList;
@@ -195,7 +195,7 @@ namespace direct_bt {
int clientCharConfigIndex = -1;
BTGattChar(const BTGattServiceRef & service_, const uint16_t service_handle_, const uint16_t handle_,
- const PropertyBitVal properties_, const uint16_t value_handle_, std::unique_ptr<const uuid_t> && value_type_) noexcept
+ const PropertyBitVal properties_, const uint16_t value_handle_, std::unique_ptr<const jau::uuid_t> && value_type_) noexcept
: wbr_service(service_), service_handle(service_handle_), handle(handle_),
properties(properties_), value_handle(value_handle_), value_type(std::move(value_type_)) {}
@@ -382,7 +382,7 @@ namespace direct_bt {
* If the BTDevice's BTGattHandler is null, i.e. not connected, an IllegalStateException is thrown.
* </p>
*/
- bool readValue(POctets & res, int expectedLength=-1);
+ bool readValue(jau::POctets & res, int expectedLength=-1);
/**
* BT Core Spec v5.2: Vol 3, Part G GATT: 4.9.3 Write Characteristic Value
@@ -393,7 +393,7 @@ namespace direct_bt {
* If the BTDevice's BTGattHandler is null, i.e. not connected, an IllegalStateException is thrown.
* </p>
*/
- bool writeValue(const TROOctets & value);
+ bool writeValue(const jau::TROOctets & value);
/**
* BT Core Spec v5.2: Vol 3, Part G GATT: 4.9.1 Write Characteristic Value Without Response
@@ -404,7 +404,7 @@ namespace direct_bt {
* If the BTDevice's BTGattHandler is null, i.e. not connected, an IllegalStateException is thrown.
* </p>
*/
- bool writeValueNoResp(const TROOctets & value);
+ bool writeValueNoResp(const jau::TROOctets & value);
};
typedef std::shared_ptr<BTGattChar> BTGattCharRef;
@@ -458,7 +458,7 @@ namespace direct_bt {
* @param timestamp the indication monotonic timestamp, see getCurrentMilliseconds()
*/
virtual void notificationReceived(BTGattCharRef charDecl,
- const TROOctets& charValue, const uint64_t timestamp) = 0;
+ const jau::TROOctets& charValue, const uint64_t timestamp) = 0;
/**
* Called from native BLE stack, initiated by a received indication associated
@@ -469,7 +469,7 @@ namespace direct_bt {
* @param confirmationSent if true, the native stack has sent the confirmation, otherwise user is required to do so.
*/
virtual void indicationReceived(BTGattCharRef charDecl,
- const TROOctets& charValue, const uint64_t timestamp,
+ const jau::TROOctets& charValue, const uint64_t timestamp,
const bool confirmationSent) = 0;
virtual ~BTGattCharListener() noexcept {}
diff --git a/api/direct_bt/BTGattDesc.hpp b/api/direct_bt/BTGattDesc.hpp
index 81e11145..24667782 100644
--- a/api/direct_bt/BTGattDesc.hpp
+++ b/api/direct_bt/BTGattDesc.hpp
@@ -26,6 +26,8 @@
#ifndef BT_GATT_DESCRIPTOR_HPP_
#define BT_GATT_DESCRIPTOR_HPP_
+#include <jau/octets.hpp>
+#include <jau/uuid.hpp>
#include <cstring>
#include <string>
#include <memory>
@@ -34,9 +36,7 @@
#include <mutex>
#include <atomic>
-#include "UUID.hpp"
#include "BTTypes0.hpp"
-#include "OctetTypes.hpp"
#include "ATTPDUTypes.hpp"
#include "BTTypes1.hpp"
@@ -67,9 +67,9 @@ namespace direct_bt {
std::string toShortString() const noexcept;
public:
- static const uuid16_t TYPE_EXT_PROP;
- static const uuid16_t TYPE_USER_DESC;
- static const uuid16_t TYPE_CCC_DESC;
+ static const jau::uuid16_t TYPE_EXT_PROP;
+ static const jau::uuid16_t TYPE_USER_DESC;
+ static const jau::uuid16_t TYPE_CCC_DESC;
/**
* Following UUID16 GATT profile attribute types are listed under:
@@ -99,7 +99,7 @@ namespace direct_bt {
};
/** Type of descriptor */
- std::unique_ptr<const uuid_t> type;
+ std::unique_ptr<const jau::uuid_t> type;
/**
* Characteristic Descriptor Handle
@@ -110,9 +110,9 @@ namespace direct_bt {
const uint16_t handle;
/* Characteristics Descriptor's Value */
- POctets value;
+ jau::POctets value;
- BTGattDesc(const BTGattCharRef & characteristic, std::unique_ptr<const uuid_t> && type_,
+ BTGattDesc(const BTGattCharRef & characteristic, std::unique_ptr<const jau::uuid_t> && type_,
const uint16_t handle_) noexcept
: wbr_char(characteristic), type(std::move(type_)), handle(handle_), value(/* intentional zero sized */) {}
diff --git a/api/direct_bt/BTGattHandler.hpp b/api/direct_bt/BTGattHandler.hpp
index 14258a3e..16c8d8ac 100644
--- a/api/direct_bt/BTGattHandler.hpp
+++ b/api/direct_bt/BTGattHandler.hpp
@@ -38,8 +38,8 @@
#include <jau/environment.hpp>
#include <jau/ringbuffer.hpp>
#include <jau/cow_darray.hpp>
+#include <jau/uuid.hpp>
-#include "UUID.hpp"
#include "BTTypes0.hpp"
#include "L2CAPComm.hpp"
#include "ATTPDUTypes.hpp"
@@ -170,7 +170,7 @@ namespace direct_bt {
const std::string deviceString;
std::recursive_mutex mtx_command;
- POctets rbuffer;
+ jau::POctets rbuffer;
jau::sc_atomic_bool is_connected; // reflects state
jau::relaxed_atomic_bool has_ioerror; // reflects state
@@ -383,7 +383,7 @@ namespace direct_bt {
* if required until the response returns zero.
* </p>
*/
- bool readValue(const uint16_t handle, POctets & res, int expectedLength=-1);
+ bool readValue(const uint16_t handle, jau::POctets & res, int expectedLength=-1);
/**
* BT Core Spec v5.2: Vol 3, Part G GATT: 4.8.1 Read Characteristic Value
@@ -402,7 +402,7 @@ namespace direct_bt {
* if required until the response returns zero.
* </p>
*/
- bool readCharacteristicValue(const BTGattChar & c, POctets & res, int expectedLength=-1);
+ bool readCharacteristicValue(const BTGattChar & c, jau::POctets & res, int expectedLength=-1);
/**
* BT Core Spec v5.2: Vol 3, Part G GATT: 4.12.1 Read Characteristic Descriptor
@@ -426,7 +426,7 @@ namespace direct_bt {
/**
* Generic write GATT value and long value
*/
- bool writeValue(const uint16_t handle, const TROOctets & value, const bool withResponse);
+ bool writeValue(const uint16_t handle, const jau::TROOctets & value, const bool withResponse);
/**
* BT Core Spec v5.2: Vol 3, Part G GATT: 4.12.3 Write Characteristic Descriptors
@@ -442,12 +442,12 @@ namespace direct_bt {
/**
* BT Core Spec v5.2: Vol 3, Part G GATT: 4.9.3 Write Characteristic Value
*/
- bool writeCharacteristicValue(const BTGattChar & c, const TROOctets & value);
+ bool writeCharacteristicValue(const BTGattChar & c, const jau::TROOctets & value);
/**
* BT Core Spec v5.2: Vol 3, Part G GATT: 4.9.1 Write Characteristic Value Without Response
*/
- bool writeCharacteristicValueNoResp(const BTGattChar & c, const TROOctets & value);
+ bool writeCharacteristicValueNoResp(const BTGattChar & c, const jau::TROOctets & value);
/**
* BT Core Spec v5.2: Vol 3, Part G GATT: 3.3.3.3 Client Characteristic Configuration
diff --git a/api/direct_bt/BTGattService.hpp b/api/direct_bt/BTGattService.hpp
index cfbe090f..17dcef51 100644
--- a/api/direct_bt/BTGattService.hpp
+++ b/api/direct_bt/BTGattService.hpp
@@ -36,10 +36,10 @@
#include <jau/java_uplink.hpp>
#include <jau/darray.hpp>
+#include <jau/octets.hpp>
+#include <jau/uuid.hpp>
-#include "UUID.hpp"
#include "BTTypes0.hpp"
-#include "OctetTypes.hpp"
#include "ATTPDUTypes.hpp"
#include "BTTypes1.hpp"
@@ -91,13 +91,13 @@ namespace direct_bt {
const uint16_t endHandle;
/** Service type UUID */
- std::unique_ptr<const uuid_t> type;
+ std::unique_ptr<const jau::uuid_t> type;
/** List of Characteristic Declarations as shared reference */
jau::darray<BTGattCharRef> characteristicList;
BTGattService(const std::shared_ptr<BTGattHandler> &handler_, const bool isPrimary_,
- const uint16_t startHandle_, const uint16_t endHandle_, std::unique_ptr<const uuid_t> && type_) noexcept
+ const uint16_t startHandle_, const uint16_t endHandle_, std::unique_ptr<const jau::uuid_t> && type_) noexcept
: wbr_handler(handler_), isPrimary(isPrimary_), startHandle(startHandle_), endHandle(endHandle_), type(std::move(type_)), characteristicList() {
characteristicList.reserve(10);
}
diff --git a/api/direct_bt/BTManager.hpp b/api/direct_bt/BTManager.hpp
index d0c621ff..313571b0 100644
--- a/api/direct_bt/BTManager.hpp
+++ b/api/direct_bt/BTManager.hpp
@@ -39,10 +39,10 @@
#include <jau/java_uplink.hpp>
#include <jau/darray.hpp>
#include <jau/cow_darray.hpp>
+#include <jau/octets.hpp>
#include "BTTypes0.hpp"
#include "BTIoctl.hpp"
-#include "OctetTypes.hpp"
#include "HCIComm.hpp"
#include "MgmtTypes.hpp"
#include "BTAdapter.hpp"
@@ -219,7 +219,7 @@ namespace direct_bt {
const MgmtEnv & env;
- POctets rbuffer;
+ jau::POctets rbuffer;
HCIComm comm;
jau::ringbuffer<std::unique_ptr<MgmtEvent>, std::nullptr_t, jau::nsize_t> mgmtEventRing;
diff --git a/api/direct_bt/BTTypes0.hpp b/api/direct_bt/BTTypes0.hpp
index 6e07cc9f..73643d8d 100644
--- a/api/direct_bt/BTTypes0.hpp
+++ b/api/direct_bt/BTTypes0.hpp
@@ -33,10 +33,10 @@
#include <jau/basic_types.hpp>
#include <jau/darray.hpp>
+#include <jau/octets.hpp>
+#include <jau/uuid.hpp>
-#include "OctetTypes.hpp"
#include "BTAddress.hpp"
-#include "UUID.hpp"
namespace direct_bt {
@@ -755,7 +755,7 @@ namespace direct_bt {
private:
uint16_t company;
std::string companyName;
- POctets data;
+ jau::POctets data;
public:
ManufactureSpecificData(uint16_t const company) noexcept;
@@ -769,7 +769,7 @@ namespace direct_bt {
constexpr uint16_t getCompany() const noexcept { return company; }
const std::string& getCompanyName() const noexcept { return companyName; }
- const TROOctets& getData() const noexcept { return data; }
+ const jau::TROOctets& getData() const noexcept { return data; }
std::string toString() const noexcept;
};
@@ -885,7 +885,7 @@ namespace direct_bt {
EAD_Event_Type ead_type = EAD_Event_Type::NONE;
uint8_t ad_address_type = 0;
BDAddressType addressType = BDAddressType::BDADDR_UNDEFINED;
- EUI48 address;
+ jau::EUI48 address;
GAPFlags flags = GAPFlags::NONE;
std::string name;
@@ -893,11 +893,11 @@ namespace direct_bt {
int8_t rssi = 127; // The core spec defines 127 as the "not available" value
int8_t tx_power = 127; // The core spec defines 127 as the "not available" value
std::shared_ptr<ManufactureSpecificData> msd = nullptr;
- jau::darray<std::shared_ptr<const uuid_t>> services;
+ jau::darray<std::shared_ptr<const jau::uuid_t>> services;
uint32_t device_class = 0;
AppearanceCat appearance = AppearanceCat::UNKNOWN;
- POctets hash;
- POctets randomizer;
+ jau::POctets hash;
+ jau::POctets randomizer;
uint16_t did_source = 0;
uint16_t did_vendor = 0;
uint16_t did_product = 0;
@@ -921,7 +921,7 @@ namespace direct_bt {
void setEvtType(AD_PDU_Type et) noexcept { evt_type = et; set(EIRDataType::EVT_TYPE); }
void setExtEvtType(EAD_Event_Type eadt) noexcept { ead_type = eadt; set(EIRDataType::EXT_EVT_TYPE); }
void setAddressType(BDAddressType at) noexcept;
- void setAddress(EUI48 const &a) noexcept { address = a; set(EIRDataType::BDADDR); }
+ void setAddress(jau::EUI48 const &a) noexcept { address = a; set(EIRDataType::BDADDR); }
void setRSSI(int8_t v) noexcept { rssi = v; set(EIRDataType::RSSI); }
void setFlags(GAPFlags f) noexcept { flags = f; set(EIRDataType::FLAGS); }
@@ -929,8 +929,8 @@ namespace direct_bt {
void setShortName(const std::string& name_short_) noexcept;
void setManufactureSpecificData(const ManufactureSpecificData& msd_) noexcept;
- void addService(const std::shared_ptr<const uuid_t>& uuid) noexcept;
- void addService(const uuid_t& uuid) noexcept;
+ void addService(const std::shared_ptr<const jau::uuid_t>& uuid) noexcept;
+ void addService(const jau::uuid_t& uuid) noexcept;
void setDeviceClass(uint32_t c) noexcept { device_class= c; set(EIRDataType::DEVICE_CLASS); }
void setAppearance(AppearanceCat a) noexcept { appearance= a; set(EIRDataType::APPEARANCE); }
void setHash(const uint8_t * h) noexcept { hash.resize(16); memcpy(hash.get_wptr(), h, 16); set(EIRDataType::HASH); }
@@ -1037,19 +1037,19 @@ namespace direct_bt {
GAPFlags getFlags() const noexcept { return flags; }
uint8_t getADAddressType() const noexcept { return ad_address_type; }
BDAddressType getAddressType() const noexcept { return addressType; }
- EUI48 const & getAddress() const noexcept { return address; }
+ jau::EUI48 const & getAddress() const noexcept { return address; }
std::string const & getName() const noexcept { return name; }
std::string const & getShortName() const noexcept{ return name_short; }
int8_t getRSSI() const noexcept { return rssi; }
int8_t getTxPower() const noexcept { return tx_power; }
std::shared_ptr<ManufactureSpecificData> getManufactureSpecificData() const noexcept { return msd; }
- jau::darray<std::shared_ptr<const uuid_t>> getServices() const noexcept { return services; }
+ jau::darray<std::shared_ptr<const jau::uuid_t>> getServices() const noexcept { return services; }
uint32_t getDeviceClass() const noexcept { return device_class; }
AppearanceCat getAppearance() const noexcept { return appearance; }
- const TROOctets & getHash() const noexcept { return hash; }
- const TROOctets & getRandomizer() const noexcept { return randomizer; }
+ const jau::TROOctets & getHash() const noexcept { return hash; }
+ const jau::TROOctets & getRandomizer() const noexcept { return randomizer; }
uint16_t getDeviceIDSource() const noexcept { return did_source; }
uint16_t getDeviceIDVendor() const noexcept { return did_vendor; }
uint16_t getDeviceIDProduct() const noexcept { return did_product; }
diff --git a/api/direct_bt/BTTypes1.hpp b/api/direct_bt/BTTypes1.hpp
index d2336b6f..2c2adf83 100644
--- a/api/direct_bt/BTTypes1.hpp
+++ b/api/direct_bt/BTTypes1.hpp
@@ -31,8 +31,8 @@
#include <jau/java_uplink.hpp>
#include <jau/basic_types.hpp>
+#include <jau/uuid.hpp>
-#include "UUID.hpp"
#include "BTAddress.hpp"
#include "BTTypes0.hpp"
@@ -74,7 +74,7 @@ namespace direct_bt {
class ConnectionInfo
{
private:
- EUI48 address;
+ jau::EUI48 address;
BDAddressType addressType;
int8_t rssi;
int8_t tx_power;
@@ -83,10 +83,10 @@ namespace direct_bt {
public:
static jau::nsize_t minimumDataSize() noexcept { return 6 + 1 + 1 + 1 + 1; }
- ConnectionInfo(const EUI48 &address_, BDAddressType addressType_, int8_t rssi_, int8_t tx_power_, int8_t max_tx_power_) noexcept
+ ConnectionInfo(const jau::EUI48 &address_, BDAddressType addressType_, int8_t rssi_, int8_t tx_power_, int8_t max_tx_power_) noexcept
: address(address_), addressType(addressType_), rssi(rssi_), tx_power(tx_power_), max_tx_power(max_tx_power_) {}
- const EUI48 getAddress() const noexcept { return address; }
+ const jau::EUI48 getAddress() const noexcept { return address; }
BDAddressType getAddressType() const noexcept { return addressType; }
int8_t getRSSI() const noexcept { return rssi; }
int8_t getTxPower() const noexcept { return tx_power; }
diff --git a/api/direct_bt/GattNumbers.hpp b/api/direct_bt/GattNumbers.hpp
index 97726ff3..e5fea80b 100644
--- a/api/direct_bt/GattNumbers.hpp
+++ b/api/direct_bt/GattNumbers.hpp
@@ -30,9 +30,9 @@
#include <jau/basic_types.hpp>
#include <jau/darray.hpp>
+#include <jau/octets.hpp>
+#include <jau/uuid.hpp>
-#include "UUID.hpp"
-#include "OctetTypes.hpp"
#include "BTTypes0.hpp"
#include "ieee11073/DataTypes.hpp"
@@ -230,7 +230,7 @@ const GattCharacteristicSpec * findGattCharSpec(const uint16_t uuid16) noexcept;
/**
* Converts a GATT Name (not null-terminated) UTF8 to a null-terminated C++ string
*/
-std::string GattNameToString(const TROOctets &v) noexcept;
+std::string GattNameToString(const jau::TROOctets &v) noexcept;
/**
* <i>Peripheral Preferred Connection Parameters</i> is a GATT Characteristic.
@@ -248,9 +248,9 @@ struct GattPeriphalPreferredConnectionParameters {
/** mandatory [10..3200] */
const uint16_t connectionSupervisionTimeoutMultiplier;
- static std::shared_ptr<GattPeriphalPreferredConnectionParameters> get(const TROOctets &source) noexcept;
+ static std::shared_ptr<GattPeriphalPreferredConnectionParameters> get(const jau::TROOctets &source) noexcept;
- GattPeriphalPreferredConnectionParameters(const TROOctets &source) noexcept;
+ GattPeriphalPreferredConnectionParameters(const jau::TROOctets &source) noexcept;
std::string toString() const noexcept;
};
@@ -293,12 +293,12 @@ struct GattPnP_ID {
const uint16_t product_id;
const uint16_t product_version;
- static std::shared_ptr<GattPnP_ID> get(const TROOctets &source) noexcept;
+ static std::shared_ptr<GattPnP_ID> get(const jau::TROOctets &source) noexcept;
GattPnP_ID() noexcept
: vendor_id_source(0), vendor_id(0), product_id(0), product_version(0) {}
- GattPnP_ID(const TROOctets &source) noexcept;
+ GattPnP_ID(const jau::TROOctets &source) noexcept;
GattPnP_ID(const uint8_t vendor_id_source_, const uint16_t vendor_id_, const uint16_t product_id_, const uint16_t product_version_) noexcept
: vendor_id_source(vendor_id_source_), vendor_id(vendor_id_), product_id(product_id_), product_version(product_version_) {}
@@ -315,7 +315,7 @@ struct GattPnP_ID {
class GattDeviceInformationSvc {
public:
/** Optional */
- const POctets systemID;
+ const jau::POctets systemID;
/** Optional */
const std::string modelNumber;
/** Optional */
@@ -329,13 +329,13 @@ class GattDeviceInformationSvc {
/** Optional */
const std::string manufacturer;
/** Optional */
- const POctets regulatoryCertDataList;
+ const jau::POctets regulatoryCertDataList;
/** Optional */
const std::shared_ptr<GattPnP_ID> pnpID;
- GattDeviceInformationSvc(const POctets &systemID_, const std::string &modelNumber_, const std::string &serialNumber_,
+ GattDeviceInformationSvc(const jau::POctets &systemID_, const std::string &modelNumber_, const std::string &serialNumber_,
const std::string &firmwareRevision_, const std::string &hardwareRevision_, const std::string &softwareRevision_,
- const std::string &manufacturer_, const POctets &regulatoryCertDataList_, const std::shared_ptr<GattPnP_ID> &pnpID_) noexcept
+ const std::string &manufacturer_, const jau::POctets &regulatoryCertDataList_, const std::shared_ptr<GattPnP_ID> &pnpID_) noexcept
: systemID(systemID_), modelNumber(modelNumber_), serialNumber(serialNumber_), firmwareRevision(firmwareRevision_),
hardwareRevision(hardwareRevision_), softwareRevision(softwareRevision_), manufacturer(manufacturer_),
regulatoryCertDataList(regulatoryCertDataList_), pnpID(pnpID_) {}
@@ -371,10 +371,10 @@ class GattTemperatureMeasurement {
/** Temperature Type, if HAS_TEMP_TYPE is set: Format ????. 1 byte (!?). */
const uint8_t temperature_type;
- static std::shared_ptr<GattTemperatureMeasurement> get(const TROOctets &source) noexcept;
+ static std::shared_ptr<GattTemperatureMeasurement> get(const jau::TROOctets &source) noexcept;
- static std::shared_ptr<GattTemperatureMeasurement> get(const TOctetSlice &source) noexcept {
- const TROOctets o(source.get_ptr(0), source.getSize());
+ static std::shared_ptr<GattTemperatureMeasurement> get(const jau::TOctetSlice &source) noexcept {
+ const jau::TROOctets o(source.get_ptr(0), source.getSize());
return get(o);
}
diff --git a/api/direct_bt/GattTypes.hpp b/api/direct_bt/GattTypes.hpp
index 6b681c81..6703e7ec 100644
--- a/api/direct_bt/GattTypes.hpp
+++ b/api/direct_bt/GattTypes.hpp
@@ -35,10 +35,10 @@
#include <atomic>
#include <jau/java_uplink.hpp>
+#include <jau/octets.hpp>
+#include <jau/uuid.hpp>
-#include "UUID.hpp"
#include "BTTypes0.hpp"
-#include "OctetTypes.hpp"
#include "ATTPDUTypes.hpp"
/* Only to resolve high level service and characteristic names */
diff --git a/api/direct_bt/HCIHandler.hpp b/api/direct_bt/HCIHandler.hpp
index d1b5138c..5d435f88 100644
--- a/api/direct_bt/HCIHandler.hpp
+++ b/api/direct_bt/HCIHandler.hpp
@@ -38,10 +38,10 @@
#include <jau/environment.hpp>
#include <jau/ringbuffer.hpp>
#include <jau/java_uplink.hpp>
+#include <jau/octets.hpp>
#include "BTTypes0.hpp"
#include "BTIoctl.hpp"
-#include "OctetTypes.hpp"
#include "HCIComm.hpp"
#include "HCITypes.hpp"
#include "MgmtTypes.hpp"
@@ -225,7 +225,7 @@ namespace direct_bt {
static MgmtEvent::Opcode translate(HCIEventType evt, HCIMetaEventType met) noexcept;
const uint16_t dev_id;
- POctets rbuffer;
+ jau::POctets rbuffer;
HCIComm comm;
hci_ufilter filter_mask;
std::atomic<uint32_t> metaev_filter_mask;
diff --git a/api/direct_bt/HCITypes.hpp b/api/direct_bt/HCITypes.hpp
index 7a7df001..d65dfd57 100644
--- a/api/direct_bt/HCITypes.hpp
+++ b/api/direct_bt/HCITypes.hpp
@@ -34,10 +34,10 @@
#include <mutex>
#include <jau/basic_types.hpp>
+#include <jau/octets.hpp>
#include "BTTypes0.hpp"
#include "BTIoctl.hpp"
-#include "OctetTypes.hpp"
#include "HCIIoctl.hpp"
#include "SMPTypes.hpp"
@@ -489,7 +489,7 @@ namespace direct_bt {
template<typename T> friend class HCIStructCmdCompleteMetaEvtWrap;
protected:
- POctets pdu;
+ jau::POctets pdu;
inline static void checkPacketType(const HCIPacketType type) {
switch(type) {
@@ -545,7 +545,7 @@ namespace direct_bt {
constexpr jau::nsize_t getTotalSize() const noexcept { return pdu.getSize(); }
/** Return the underlying octets read only */
- TROOctets & getPDU() noexcept { return pdu; }
+ jau::TROOctets & getPDU() noexcept { return pdu; }
HCIPacketType getPacketType() noexcept { return static_cast<HCIPacketType>(pdu.get_uint8_nc(0)); }
diff --git a/api/direct_bt/L2CAPComm.hpp b/api/direct_bt/L2CAPComm.hpp
index 40e9a85e..f05a8446 100644
--- a/api/direct_bt/L2CAPComm.hpp
+++ b/api/direct_bt/L2CAPComm.hpp
@@ -35,8 +35,8 @@
#include <atomic>
#include <jau/environment.hpp>
+#include <jau/uuid.hpp>
-#include "UUID.hpp"
#include "BTTypes0.hpp"
/**
diff --git a/api/direct_bt/MgmtTypes.hpp b/api/direct_bt/MgmtTypes.hpp
index 5c66e307..475791d2 100644
--- a/api/direct_bt/MgmtTypes.hpp
+++ b/api/direct_bt/MgmtTypes.hpp
@@ -34,11 +34,11 @@
#include <jau/function_def.hpp>
#include <jau/cow_darray.hpp>
+#include <jau/octets.hpp>
#include <jau/packed_attribute.hpp>
#include "BTTypes0.hpp"
#include "BTIoctl.hpp"
-#include "OctetTypes.hpp"
#include "HCIComm.hpp"
#include "BTTypes1.hpp"
@@ -304,7 +304,7 @@ namespace direct_bt {
class MgmtMsg
{
protected:
- POctets pdu;
+ jau::POctets pdu;
uint64_t ts_creation;
virtual std::string baseString() const noexcept {
@@ -358,7 +358,7 @@ namespace direct_bt {
jau::nsize_t getTotalSize() const noexcept { return pdu.getSize(); }
/** Return the underlying octets read only */
- TROOctets & getPDU() noexcept { return pdu; }
+ jau::TROOctets & getPDU() noexcept { return pdu; }
uint16_t getIntOpcode() const noexcept { return pdu.get_uint16_nc(0); }
uint16_t getDevID() const noexcept { return pdu.get_uint16_nc(2); }
@@ -802,7 +802,7 @@ namespace direct_bt {
public:
MgmtPinCodeReplyCmd(const uint16_t dev_id, const BDAddressAndType& addressAndType,
- const uint8_t pin_len, const TROOctets &pin_code)
+ const uint8_t pin_len, const jau::TROOctets &pin_code)
: MgmtCommand(Opcode::PIN_CODE_REPLY, dev_id, 6+1+1+16)
{
pdu.put_eui48_nc(MGMT_HEADER_SIZE, addressAndType.address);
@@ -813,7 +813,7 @@ namespace direct_bt {
const EUI48& getAddress() const noexcept { return *reinterpret_cast<const EUI48 *>( pdu.get_ptr_nc(MGMT_HEADER_SIZE + 0) ); } // mgmt_addr_info
BDAddressType getAddressType() const noexcept { return static_cast<BDAddressType>(pdu.get_uint8_nc(MGMT_HEADER_SIZE+6)); } // mgmt_addr_info
uint8_t getPinLength() const noexcept { return pdu.get_uint8_nc(MGMT_HEADER_SIZE+6+1); }
- TROOctets getPinCode() const noexcept { return POctets(pdu.get_ptr_nc(MGMT_HEADER_SIZE+6+1+1), getPinLength()); }
+ jau::TROOctets getPinCode() const noexcept { return jau::POctets(pdu.get_ptr_nc(MGMT_HEADER_SIZE+6+1+1), getPinLength()); }
};
/**
diff --git a/api/direct_bt/OctetTypes.hpp b/api/direct_bt/OctetTypes.hpp
deleted file mode 100644
index 96ab6a49..00000000
--- a/api/direct_bt/OctetTypes.hpp
+++ /dev/null
@@ -1,675 +0,0 @@
-/*
- * Author: Sven Gothel <[email protected]>
- * Copyright (c) 2020 Gothel Software e.K.
- * Copyright (c) 2020 ZAFENA AB
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#ifndef OCTET_TYPES_HPP_
-#define OCTET_TYPES_HPP_
-
-#include <cstring>
-#include <string>
-#include <memory>
-#include <cstdint>
-#include <algorithm>
-
-#include <mutex>
-#include <atomic>
-
-#include <jau/basic_types.hpp>
-
-#include "UUID.hpp"
-#include "BTAddress.hpp"
-
-// #define TRACE_MEM 1
-#ifdef TRACE_MEM
- #define TRACE_PRINT(...) { fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); fflush(stderr); }
-#else
- #define TRACE_PRINT(...)
-#endif
-
-namespace direct_bt {
-
- /**
- * Transient read only octet data, i.e. non persistent passthrough, owned by caller.
- * <p>
- * Either ATT value (Vol 3, Part F 3.2.4) or PDU data.
- * </p>
- */
- class TROOctets
- {
- private:
- /** Used memory size <= capacity, maybe zero. */
- jau::nsize_t _size;
- /** Non-null memory pointer. Actual capacity known by owner. */
- uint8_t * _data;
-
- protected:
- static inline void checkPtr(uint8_t *d, jau::nsize_t s) {
- if( nullptr == d && 0 < s ) {
- throw jau::IllegalArgumentException("TROOctets::setData: nullptr with size "+std::to_string(s)+" > 0", E_FILE_LINE);
- }
- }
-
- constexpr uint8_t * data() noexcept { return _data; }
-
- /**
- * @param d a non nullptr memory, otherwise throws exception
- * @param s used memory size, may be zero
- */
- inline void setData(uint8_t *d, jau::nsize_t s) {
- TRACE_PRINT("POctets setData: %d bytes @ %p -> %d bytes @ %p",
- _size, _data, s, d);
- checkPtr(d, s);
- _size = s;
- _data = d;
- }
- constexpr void setSize(jau::nsize_t s) noexcept { _size = s; }
-
- public:
- /**
- * Transient passthrough read-only memory, w/o ownership ..
- * @param source a non nullptr memory, otherwise throws exception. Actual capacity known by owner.
- * @param len readable size of the memory, may be zero
- */
- TROOctets(const uint8_t *source, const jau::nsize_t len)
- : _size( len ), _data( const_cast<uint8_t *>(source) ) {
- checkPtr(_data, _size);
- }
-
- TROOctets(const TROOctets &o) noexcept = default;
- TROOctets(TROOctets &&o) noexcept = default;
- TROOctets& operator=(const TROOctets &o) noexcept = default;
- TROOctets& operator=(TROOctets &&o) noexcept = default;
-
- virtual ~TROOctets() noexcept {}
-
- inline void check_range(const jau::nsize_t i, const jau::nsize_t count, const char *file, int line) const {
- if( i+count > _size ) {
- throw jau::IndexOutOfBoundsException(i, count, _size, file, line);
- }
- }
- #define check_range(I,C) check_range((I), (C), E_FILE_LINE)
-
- constexpr bool is_range_valid(const jau::nsize_t i, const jau::nsize_t count) const noexcept {
- return i+count <= _size;
- }
-
- /** Returns the used memory size for read and write operations, may be zero. */
- constexpr jau::nsize_t getSize() const noexcept { return _size; }
-
- uint8_t get_uint8(const jau::nsize_t i) const {
- check_range(i, 1);
- return _data[i];
- }
- constexpr uint8_t get_uint8_nc(const jau::nsize_t i) const noexcept {
- return _data[i];
- }
-
- int8_t get_int8(const jau::nsize_t i) const {
- check_range(i, 1);
- return jau::get_int8(_data, i);
- }
- constexpr int8_t get_int8_nc(const jau::nsize_t i) const noexcept {
- return jau::get_int8(_data, i);
- }
-
- uint16_t get_uint16(const jau::nsize_t i) const {
- check_range(i, 2);
- return jau::get_uint16(_data, i, true /* littleEndian */);
- }
- constexpr uint16_t get_uint16_nc(const jau::nsize_t i) const noexcept {
- return jau::get_uint16(_data, i, true /* littleEndian */);
- }
-
- uint32_t get_uint32(const jau::nsize_t i) const {
- check_range(i, 4);
- return jau::get_uint32(_data, i, true /* littleEndian */);
- }
- constexpr uint32_t get_uint32_nc(const jau::nsize_t i) const noexcept {
- return jau::get_uint32(_data, i, true /* littleEndian */);
- }
-
- EUI48 get_eui48(const jau::nsize_t i) const {
- check_range(i, sizeof(EUI48));
- return EUI48(_data+i);
- }
- inline EUI48 get_eui48_nc(const jau::nsize_t i) const noexcept {
- return EUI48(_data+i);
- }
-
- uint64_t get_uint64(const jau::nsize_t i) const {
- check_range(i, 8);
- return jau::get_uint64(_data, i, true /* littleEndian */);
- }
- constexpr uint64_t get_uint64_nc(const jau::nsize_t i) const noexcept {
- return jau::get_uint64(_data, i, true /* littleEndian */);
- }
-
- jau::uint128_t get_uint128(const jau::nsize_t i) const {
- check_range(i, 8);
- return jau::get_uint128(_data, i, true /* littleEndian */);
- }
- constexpr jau::uint128_t get_uint128_nc(const jau::nsize_t i) const noexcept {
- return jau::get_uint128(_data, i, true /* littleEndian */);
- }
-
- jau::uint192_t get_uint192(const jau::nsize_t i) const {
- check_range(i, 8);
- return jau::get_uint192(_data, i, true /* littleEndian */);
- }
- constexpr jau::uint192_t get_uint192_nc(const jau::nsize_t i) const noexcept {
- return jau::get_uint192(_data, i, true /* littleEndian */);
- }
-
- jau::uint256_t get_uint256(const jau::nsize_t i) const {
- check_range(i, 8);
- return jau::get_uint256(_data, i, true /* littleEndian */);
- }
- constexpr jau::uint256_t get_uint256_nc(const jau::nsize_t i) const noexcept {
- return jau::get_uint256(_data, i, true /* littleEndian */);
- }
-
- /** Assumes a null terminated string */
- std::string get_string(const jau::nsize_t i) const {
- check_range(i, 1); // minimum size
- return std::string( (const char*)(_data+i) );
- }
- /** Assumes a null terminated string */
- constexpr_cxx20 std::string get_string_nc(const jau::nsize_t i) const noexcept {
- return std::string( (const char*)(_data+i) );
- }
-
- /** Assumes a string with defined length, not necessarily null terminated */
- inline std::string get_string(const jau::nsize_t i, const jau::nsize_t length) const {
- check_range(i, length);
- return std::string( (const char*)(_data+i), length );
- }
-
- uuid16_t get_uuid16(const jau::nsize_t i) const {
- return uuid16_t(get_uint16(i));
- }
- inline uuid16_t get_uuid16_nc(const jau::nsize_t i) const noexcept {
- return uuid16_t(get_uint16_nc(i));
- }
-
- uuid128_t get_uuid128(const jau::nsize_t i) const {
- check_range(i, uuid_t::number(uuid_t::TypeSize::UUID128_SZ));
- return direct_bt::get_uuid128(_data, i, true /* littleEndian */);
- }
- inline uuid128_t get_uuid128_nc(const jau::nsize_t i) const noexcept {
- return direct_bt::get_uuid128(_data, i, true /* littleEndian */);
- }
-
- std::unique_ptr<const uuid_t> get_uuid(const jau::nsize_t i, const uuid_t::TypeSize tsize) const {
- check_range(i, uuid_t::number(tsize));
- return uuid_t::create(tsize, _data, i, true /* littleEndian */);
- }
-
- constexpr uint8_t const * get_ptr() const noexcept { return _data; }
- uint8_t const * get_ptr(const jau::nsize_t i) const {
- check_range(i, 1);
- return _data + i;
- }
- constexpr uint8_t const * get_ptr_nc(const jau::nsize_t i) const noexcept {
- return _data + i;
- }
-
- bool operator==(const TROOctets& rhs) const noexcept {
- return _size == rhs._size && 0 == std::memcmp(_data, rhs._data, _size);
- }
- bool operator!=(const TROOctets& rhs) const noexcept {
- return !(*this == rhs);
- }
-
- std::string toString() const noexcept {
- return "size "+std::to_string(_size)+", ro: "+jau::bytesHexString(_data, 0, _size, true /* lsbFirst */);
- }
- };
-
- /**
- * Transient octet data, i.e. non persistent passthrough, owned by caller.
- * <p>
- * Either ATT value (Vol 3, Part F 3.2.4) or PDU data.
- * </p>
- */
- class TOctets : public TROOctets
- {
- public:
- /** Transient passthrough r/w memory, w/o ownership ..*/
- TOctets(uint8_t *source, const jau::nsize_t len)
- : TROOctets(source, len) {}
-
- TOctets(const TOctets &o) noexcept = default;
- TOctets(TOctets &&o) noexcept = default;
- TOctets& operator=(const TOctets &o) noexcept = default;
- TOctets& operator=(TOctets &&o) noexcept = default;
-
- virtual ~TOctets() noexcept override {}
-
- void put_int8(const jau::nsize_t i, const int8_t v) {
- check_range(i, 1);
- data()[i] = static_cast<uint8_t>(v);
- }
- constexpr void put_int8_nc(const jau::nsize_t i, const int8_t v) noexcept {
- data()[i] = static_cast<uint8_t>(v);
- }
-
- void put_uint8(const jau::nsize_t i, const uint8_t v) {
- check_range(i, 1);
- data()[i] = v;
- }
- constexpr void put_uint8_nc(const jau::nsize_t i, const uint8_t v) noexcept {
- data()[i] = v;
- }
-
- void put_uint16(const jau::nsize_t i, const uint16_t v) {
- check_range(i, 2);
- jau::put_uint16(data(), i, v, true /* littleEndian */);
- }
- constexpr void put_uint16_nc(const jau::nsize_t i, const uint16_t v) noexcept {
- jau::put_uint16(data(), i, v, true /* littleEndian */);
- }
-
- void put_uint32(const jau::nsize_t i, const uint32_t v) {
- check_range(i, 4);
- jau::put_uint32(data(), i, v, true /* littleEndian */);
- }
- constexpr void put_uint32_nc(const jau::nsize_t i, const uint32_t v) noexcept {
- jau::put_uint32(data(), i, v, true /* littleEndian */);
- }
-
- void put_eui48(const jau::nsize_t i, const EUI48 & v) {
- check_range(i, sizeof(v.b));
- memcpy(data() + i, v.b, sizeof(v.b));
- }
- void put_eui48_nc(const jau::nsize_t i, const EUI48 & v) noexcept {
- memcpy(data() + i, v.b, sizeof(v.b));
- }
-
- void put_uint64(const jau::nsize_t i, const uint64_t & v) {
- check_range(i, 8);
- jau::put_uint64(data(), i, v, true /* littleEndian */);
- }
- constexpr void put_uint64_nc(const jau::nsize_t i, const uint64_t & v) noexcept {
- jau::put_uint64(data(), i, v, true /* littleEndian */);
- }
-
- void put_uint128(const jau::nsize_t i, const jau::uint128_t & v) {
- check_range(i, 8);
- jau::put_uint128(data(), i, v, true /* littleEndian */);
- }
- constexpr void put_uint128_nc(const jau::nsize_t i, const jau::uint128_t & v) noexcept {
- jau::put_uint128(data(), i, v, true /* littleEndian */);
- }
-
- void put_uint192(const jau::nsize_t i, const jau::uint192_t & v) {
- check_range(i, 8);
- jau::put_uint192(data(), i, v, true /* littleEndian */);
- }
- constexpr void put_uint192_nc(const jau::nsize_t i, const jau::uint192_t & v) noexcept {
- jau::put_uint192(data(), i, v, true /* littleEndian */);
- }
-
- void put_uint256(const jau::nsize_t i, const jau::uint256_t & v) {
- check_range(i, 8);
- jau::put_uint256(data(), i, v, true /* littleEndian */);
- }
- constexpr void put_uint256_nc(const jau::nsize_t i, const jau::uint256_t & v) noexcept {
- jau::put_uint256(data(), i, v, true /* littleEndian */);
- }
-
- void put_octets(const jau::nsize_t i, const TROOctets & v) {
- check_range(i, v.getSize());
- memcpy(data() + i, v.get_ptr(), v.getSize());
- }
- void put_octets_nc(const jau::nsize_t i, const TROOctets & v) noexcept {
- memcpy(data() + i, v.get_ptr(), v.getSize());
- }
-
- void put_bytes(const jau::nsize_t i, const uint8_t *source, const jau::nsize_t byte_count) {
- check_range(i, byte_count);
- memcpy(data() + i, source, byte_count);
- }
- void put_bytes_nc(const jau::nsize_t i, const uint8_t *source, const jau::nsize_t byte_count) noexcept {
- memcpy(data() + i, source, byte_count);
- }
-
- void put_string(const jau::nsize_t i, const std::string & v, const jau::nsize_t max_len, const bool includeEOS) {
- const jau::nsize_t size1 = v.size() + ( includeEOS ? 1 : 0 );
- const jau::nsize_t size = std::min(size1, max_len);
- check_range(i, size);
- memcpy(data() + i, v.c_str(), size);
- if( size < size1 && includeEOS ) {
- *(data() + i + size - 1) = 0; // ensure EOS
- }
- }
- void put_string_nc(const jau::nsize_t i, const std::string & v, const jau::nsize_t max_len, const bool includeEOS) noexcept {
- const jau::nsize_t size1 = v.size() + ( includeEOS ? 1 : 0 );
- const jau::nsize_t size = std::min(size1, max_len);
- memcpy(data() + i, v.c_str(), size);
- if( size < size1 && includeEOS ) {
- *(data() + i + size - 1) = 0; // ensure EOS
- }
- }
-
- void put_uuid(const jau::nsize_t i, const uuid_t & v) {
- check_range(i, v.getTypeSizeInt());
- v.put(data(), i, true /* littleEndian */);
- }
- void put_uuid_nc(const jau::nsize_t i, const uuid_t & v) noexcept {
- v.put(data(), i, true /* littleEndian */);
- }
-
- inline uint8_t * get_wptr() noexcept { return data(); }
-
- uint8_t * get_wptr(const jau::nsize_t i) {
- check_range(i, 1);
- return data() + i;
- }
- inline uint8_t * get_wptr_nc(const jau::nsize_t i) noexcept {
- return data() + i;
- }
-
- std::string toString() const noexcept {
- return "size "+std::to_string(getSize())+", rw: "+jau::bytesHexString(get_ptr(), 0, getSize(), true /* lsbFirst */);
- }
- };
-
- class TOctetSlice
- {
- private:
- const TOctets & parent;
- jau::nsize_t const offset;
- jau::nsize_t const size;
-
- public:
- TOctetSlice(const TOctets &buffer_, const jau::nsize_t offset_, const jau::nsize_t size_)
- : parent(buffer_), offset(offset_), size(size_)
- {
- if( offset_+size > buffer_.getSize() ) {
- throw jau::IndexOutOfBoundsException(offset_, size, buffer_.getSize(), E_FILE_LINE);
- }
- }
-
- constexpr jau::nsize_t getSize() const noexcept { return size; }
- constexpr jau::nsize_t getOffset() const noexcept { return offset; }
- const TOctets& getParent() const noexcept { return parent; }
-
- uint8_t get_uint8(const jau::nsize_t i) const {
- return parent.get_uint8(offset+i);
- }
- constexpr uint8_t get_uint8_nc(const jau::nsize_t i) const noexcept {
- return parent.get_uint8_nc(offset+i);
- }
-
- uint16_t get_uint16(const jau::nsize_t i) const {
- return parent.get_uint16(offset+i);
- }
- constexpr uint16_t get_uint16_nc(const jau::nsize_t i) const noexcept {
- return parent.get_uint16_nc(offset+i);
- }
-
- uint8_t const * get_ptr(const jau::nsize_t i) const {
- return parent.get_ptr(offset+i);
- }
- constexpr uint8_t const * get_ptr_nc(const jau::nsize_t i) const noexcept {
- return parent.get_ptr_nc(offset+i);
- }
-
- std::string toString() const noexcept {
- return "offset "+std::to_string(offset)+", size "+std::to_string(size)+": "+jau::bytesHexString(parent.get_ptr(), offset, size, true /* lsbFirst */);
- }
- };
-
- /**
- * Persistent octet data, i.e. owned memory allocation.
- * <p>
- * GATT value (Vol 3, Part F 3.2.4)
- * </p>
- */
- class POctets : public TOctets
- {
- private:
- jau::nsize_t capacity;
-
- void freeData() {
- uint8_t * ptr = data();
- if( nullptr != ptr ) {
- TRACE_PRINT("POctets release: %p", ptr);
- free(ptr);
- } // else: zero sized POctets w/ nullptr are supported
- }
-
- static uint8_t * allocData(const jau::nsize_t size) {
- if( size <= 0 ) {
- return nullptr;
- }
- uint8_t * m = static_cast<uint8_t*>( std::malloc(size) );
- if( nullptr == m ) {
- throw jau::OutOfMemoryError("allocData size "+std::to_string(size)+" -> nullptr", E_FILE_LINE);
- }
- return m;
- }
-
- public:
- /** Returns the memory capacity, never zero, greater or equal {@link #getSize()}. */
- constexpr jau::nsize_t getCapacity() const noexcept { return capacity; }
-
- /** Intentional zero sized POctets instance. */
- POctets()
- : TOctets(nullptr, 0), capacity(0)
- {
- TRACE_PRINT("POctets ctor0: zero-sized");
- }
-
- /** Takes ownership (malloc and copy, free) ..*/
- POctets(const uint8_t *_source, const jau::nsize_t size_)
- : TOctets( allocData(size_), size_),
- capacity( size_ )
- {
- std::memcpy(data(), _source, size_);
- TRACE_PRINT("POctets ctor1: %p", data());
- }
-
- /** New buffer (malloc, free) */
- POctets(const jau::nsize_t _capacity, const jau::nsize_t size_)
- : TOctets( allocData(_capacity), size_),
- capacity( _capacity )
- {
- if( capacity < getSize() ) {
- throw jau::IllegalArgumentException("capacity "+std::to_string(capacity)+" < size "+std::to_string(getSize()), E_FILE_LINE);
- }
- TRACE_PRINT("POctets ctor2: %p", data());
- }
-
- /** New buffer (malloc, free) */
- POctets(const jau::nsize_t size)
- : POctets(size, size)
- {
- TRACE_PRINT("POctets ctor3: %p", data());
- }
-
- POctets(const POctets &_source)
- : TOctets( allocData(_source.getSize()), _source.getSize()),
- capacity( _source.getSize() )
- {
- std::memcpy(data(), _source.get_ptr(), _source.getSize());
- TRACE_PRINT("POctets ctor-cpy0: %p", data());
- }
-
- POctets(POctets &&o) noexcept
- : TOctets( o.data(), o.getSize() ),
- capacity( o.getCapacity() )
- {
- // moved origin data references
- // purge origin
- o.setData(nullptr, 0);
- o.capacity = 0;
- TRACE_PRINT("POctets ctor-move0: %p", data());
- }
-
- POctets& operator=(const POctets &_source) {
- if( this == &_source ) {
- return *this;
- }
- freeData();
- setData(allocData(_source.getSize()), _source.getSize());
- capacity = _source.getSize();
- std::memcpy(data(), _source.get_ptr(), _source.getSize());
- TRACE_PRINT("POctets assign0: %p", data());
- return *this;
- }
-
- POctets& operator=(POctets &&o) noexcept {
- // move origin data references
- setData(o.data(), o.getSize());
- capacity = o.capacity;
- // purge origin
- o.setData(nullptr, 0);
- o.capacity = 0;
- TRACE_PRINT("POctets assign-move0: %p", data());
- return *this;
- }
-
- virtual ~POctets() noexcept override {
- freeData();
- setData(nullptr, 0);
- capacity=0;
- }
-
- /** Makes a persistent POctets by copying the data from TROOctets. */
- POctets(const TROOctets & _source)
- : TOctets( allocData(_source.getSize()), _source.getSize()),
- capacity( _source.getSize() )
- {
- std::memcpy(data(), _source.get_ptr(), _source.getSize());
- TRACE_PRINT("POctets ctor-cpy1: %p", data());
- }
-
- POctets& operator=(const TROOctets &_source) {
- if( static_cast<TROOctets *>(this) == &_source ) {
- return *this;
- }
- freeData();
- setData(allocData(_source.getSize()), _source.getSize());
- capacity = _source.getSize();
- std::memcpy(data(), _source.get_ptr(), _source.getSize());
- TRACE_PRINT("POctets assign1: %p", data());
- return *this;
- }
-
- /** Makes a persistent POctets by copying the data from TOctetSlice. */
- POctets(const TOctetSlice & _source)
- : TOctets( allocData(_source.getSize()), _source.getSize()),
- capacity( _source.getSize() )
- {
- std::memcpy(data(), _source.getParent().get_ptr() + _source.getOffset(), _source.getSize());
- TRACE_PRINT("POctets ctor-cpy2: %p", data());
- }
-
- POctets& operator=(const TOctetSlice &_source) {
- freeData();
- setData(allocData(_source.getSize()), _source.getSize());
- capacity = _source.getSize();
- std::memcpy(data(), _source.get_ptr(0), _source.getSize());
- TRACE_PRINT("POctets assign2: %p", data());
- return *this;
- }
-
- POctets & resize(const jau::nsize_t newSize, const jau::nsize_t newCapacity) {
- if( newCapacity < newSize ) {
- throw jau::IllegalArgumentException("newCapacity "+std::to_string(newCapacity)+" < newSize "+std::to_string(newSize), E_FILE_LINE);
- }
- if( newCapacity != capacity ) {
- if( newSize > getSize() ) {
- recapacity(newCapacity);
- setSize(newSize);
- } else {
- setSize(newSize);
- recapacity(newCapacity);
- }
- } else {
- setSize(newSize);
- }
- return *this;
- }
-
- POctets & resize(const jau::nsize_t newSize) {
- if( capacity < newSize ) {
- throw jau::IllegalArgumentException("capacity "+std::to_string(capacity)+" < newSize "+std::to_string(newSize), E_FILE_LINE);
- }
- setSize(newSize);
- return *this;
- }
-
- POctets & recapacity(const jau::nsize_t newCapacity) {
- if( newCapacity < getSize() ) {
- throw jau::IllegalArgumentException("newCapacity "+std::to_string(newCapacity)+" < size "+std::to_string(getSize()), E_FILE_LINE);
- }
- if( newCapacity == capacity ) {
- return *this;
- }
- uint8_t* data2 = allocData(newCapacity);
- if( getSize() > 0 ) {
- memcpy(data2, get_ptr(), getSize());
- }
- TRACE_PRINT("POctets recapacity: %p -> %p", data(), data2);
- free(data());
- setData(data2, getSize());
- capacity = newCapacity;
- return *this;
- }
-
- POctets & operator+=(const TROOctets &b) {
- if( 0 < b.getSize() ) {
- const jau::nsize_t newSize = getSize() + b.getSize();
- if( capacity < newSize ) {
- recapacity( newSize );
- }
- memcpy(data()+getSize(), b.get_ptr(), b.getSize());
- setSize(newSize);
- }
- return *this;
- }
- POctets & operator+=(const TOctetSlice &b) {
- if( 0 < b.getSize() ) {
- const jau::nsize_t newSize = getSize() + b.getSize();
- if( capacity < newSize ) {
- recapacity( newSize );
- }
- memcpy(data()+getSize(), b.getParent().get_ptr()+b.getOffset(), b.getSize());
- setSize(newSize);
- }
- return *this;
- }
-
- std::string toString() const {
- return "size "+std::to_string(getSize())+", capacity "+std::to_string(getCapacity())+", "+jau::bytesHexString(get_ptr(), 0, getSize(), true /* lsbFirst */);
- }
- };
-
-
-}
-
-
-#endif /* OCTET_TYPES_HPP_ */
diff --git a/api/direct_bt/SMPHandler.hpp b/api/direct_bt/SMPHandler.hpp
index 06f14420..2ffaa7b8 100644
--- a/api/direct_bt/SMPHandler.hpp
+++ b/api/direct_bt/SMPHandler.hpp
@@ -39,8 +39,8 @@
#include <jau/function_def.hpp>
#include <jau/darray.hpp>
#include <jau/cow_darray.hpp>
+#include <jau/uuid.hpp>
-#include "UUID.hpp"
#include "BTTypes0.hpp"
#include "L2CAPComm.hpp"
#include "SMPTypes.hpp"
@@ -192,7 +192,7 @@ namespace direct_bt {
const std::string deviceString;
std::recursive_mutex mtx_command;
- POctets rbuffer;
+ jau::POctets rbuffer;
L2CAPComm l2cap;
jau::sc_atomic_bool is_connected; // reflects state
diff --git a/api/direct_bt/SMPTypes.hpp b/api/direct_bt/SMPTypes.hpp
index dc472c12..cc5e6d03 100644
--- a/api/direct_bt/SMPTypes.hpp
+++ b/api/direct_bt/SMPTypes.hpp
@@ -34,8 +34,8 @@
#include <mutex>
#include <jau/basic_types.hpp>
+#include <jau/octets.hpp>
-#include "OctetTypes.hpp"
#include "BTTypes0.hpp"
/**
@@ -700,7 +700,7 @@ namespace direct_bt {
}
/** actual received PDU */
- POctets pdu;
+ jau::POctets pdu;
/** creation timestamp in milliseconds */
uint64_t ts_creation;
diff --git a/api/direct_bt/UUID.hpp b/api/direct_bt/UUID.hpp
deleted file mode 100644
index 01c29a50..00000000
--- a/api/direct_bt/UUID.hpp
+++ /dev/null
@@ -1,242 +0,0 @@
-/*
- * Author: Sven Gothel <[email protected]>
- * Copyright (c) 2020 Gothel Software e.K.
- * Copyright (c) 2020 ZAFENA AB
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#ifndef UUID_HPP_
-#define UUID_HPP_
-
-#include <cstring>
-#include <string>
-#include <memory>
-#include <cstdint>
-#include <vector>
-
-#include <jau/basic_types.hpp>
-
-namespace direct_bt {
-
-class uuid128_t; // forward
-
-/**
- * Bluetooth UUID <https://www.bluetooth.com/specifications/assigned-numbers/service-discovery/>
- * <p>
- * Bluetooth is LSB or Little-Endian!
- * </p>
- * <p>
- * BASE_UUID '00000000-0000-1000-8000-00805F9B34FB'
- * </p>
- */
-extern uuid128_t BT_BASE_UUID;
-
-class uuid_t {
-public:
- /** Underlying integer value present octet count */
- enum class TypeSize : jau::nsize_t {
- UUID16_SZ=2, UUID32_SZ=4, UUID128_SZ=16
- };
- static constexpr jau::nsize_t number(const TypeSize rhs) noexcept {
- return static_cast<jau::nsize_t>(rhs);
- }
-
-private:
- TypeSize type;
-
-protected:
- uuid_t(TypeSize const type_) : type(type_) {}
-
-public:
- static TypeSize toTypeSize(const jau::nsize_t size);
- static std::unique_ptr<uuid_t> create(TypeSize const t, uint8_t const * const buffer, jau::nsize_t const byte_offset, bool const littleEndian);
- static std::unique_ptr<uuid_t> create(const std::string& str);
-
- virtual ~uuid_t() noexcept {}
-
- uuid_t(const uuid_t &o) noexcept = default;
- uuid_t(uuid_t &&o) noexcept = default;
- uuid_t& operator=(const uuid_t &o) noexcept = default;
- uuid_t& operator=(uuid_t &&o) noexcept = default;
-
- std::unique_ptr<uuid_t> clone() const noexcept;
-
- virtual bool operator==(uuid_t const &o) const noexcept {
- if( this == &o ) {
- return true;
- }
- return type == o.type;
- }
- bool operator!=(uuid_t const &o) const noexcept
- { return !(*this == o); }
-
- TypeSize getTypeSize() const noexcept { return type; }
- jau::nsize_t getTypeSizeInt() const noexcept { return uuid_t::number(type); }
-
- uuid128_t toUUID128(uuid128_t const & base_uuid=BT_BASE_UUID, jau::nsize_t const uuid32_le_octet_index=12) const noexcept;
-
- /** returns the pointer to the uuid data of size getTypeSize() */
- virtual const uint8_t * data() const noexcept = 0;
- virtual std::string toString() const noexcept = 0;
- virtual std::string toUUID128String(uuid128_t const & base_uuid=BT_BASE_UUID, jau::nsize_t const le_octet_index=12) const noexcept = 0;
- virtual jau::nsize_t put(uint8_t * const buffer, jau::nsize_t const byte_offset, bool const littleEndian) const noexcept = 0;
-};
-
-class uuid16_t : public uuid_t {
-public:
- uint16_t value;
-
- uuid16_t(uint16_t const v) noexcept
- : uuid_t(TypeSize::UUID16_SZ), value(v) { }
-
- uuid16_t(const std::string& str);
-
- uuid16_t(uint8_t const * const buffer, jau::nsize_t const byte_offset, bool const littleEndian) noexcept
- : uuid_t(TypeSize::UUID16_SZ), value(jau::get_uint16(buffer, byte_offset, littleEndian)) { }
-
- uuid16_t(const uuid16_t &o) noexcept = default;
- uuid16_t(uuid16_t &&o) noexcept = default;
- uuid16_t& operator=(const uuid16_t &o) noexcept = default;
- uuid16_t& operator=(uuid16_t &&o) noexcept = default;
-
- bool operator==(uuid_t const &o) const noexcept override {
- if( this == &o ) {
- return true;
- }
- return getTypeSize() == o.getTypeSize() && value == static_cast<uuid16_t const *>(&o)->value;
- }
-
- const uint8_t * data() const noexcept override { return static_cast<uint8_t*>(static_cast<void*>(const_cast<uint16_t*>(&value))); }
- std::string toString() const noexcept override;
- std::string toUUID128String(uuid128_t const & base_uuid=BT_BASE_UUID, jau::nsize_t const le_octet_index=12) const noexcept override;
-
- jau::nsize_t put(uint8_t * const buffer, jau::nsize_t const byte_offset, bool const littleEndian) const noexcept override {
- jau::put_uint16(buffer, byte_offset, value, littleEndian);
- return 2;
- }
-};
-
-class uuid32_t : public uuid_t {
-public:
- uint32_t value;
-
- uuid32_t(uint32_t const v) noexcept
- : uuid_t(TypeSize::UUID32_SZ), value(v) {}
-
- uuid32_t(const std::string& str);
-
- uuid32_t(uint8_t const * const buffer, jau::nsize_t const byte_offset, bool const littleEndian) noexcept
- : uuid_t(TypeSize::UUID32_SZ), value(jau::get_uint32(buffer, byte_offset, littleEndian)) { }
-
- uuid32_t(const uuid32_t &o) noexcept = default;
- uuid32_t(uuid32_t &&o) noexcept = default;
- uuid32_t& operator=(const uuid32_t &o) noexcept = default;
- uuid32_t& operator=(uuid32_t &&o) noexcept = default;
-
- bool operator==(uuid_t const &o) const noexcept override {
- if( this == &o ) {
- return true;
- }
- return getTypeSize() == o.getTypeSize() && value == static_cast<uuid32_t const *>(&o)->value;
- }
-
- const uint8_t * data() const noexcept override { return static_cast<uint8_t*>(static_cast<void*>(const_cast<uint32_t*>(&value))); }
- std::string toString() const noexcept override;
- std::string toUUID128String(uuid128_t const & base_uuid=BT_BASE_UUID, jau::nsize_t const le_octet_index=12) const noexcept override;
-
- jau::nsize_t put(uint8_t * const buffer, jau::nsize_t const byte_offset, bool const littleEndian) const noexcept override {
- jau::put_uint32(buffer, byte_offset, value, littleEndian);
- return 4;
- }
-};
-
-class uuid128_t : public uuid_t {
-public:
- jau::uint128_t value;
-
- uuid128_t() noexcept : uuid_t(TypeSize::UUID128_SZ) { bzero(value.data, sizeof(value)); }
-
- uuid128_t(jau::uint128_t const v) noexcept
- : uuid_t(TypeSize::UUID128_SZ), value(v) {}
-
- uuid128_t(const std::string& str);
-
- uuid128_t(uint8_t const * const buffer, jau::nsize_t const byte_offset, bool const littleEndian) noexcept
- : uuid_t(TypeSize::UUID128_SZ), value(jau::get_uint128(buffer, byte_offset, littleEndian)) { }
-
- uuid128_t(uuid16_t const & uuid16, uuid128_t const & base_uuid=BT_BASE_UUID, jau::nsize_t const uuid16_le_octet_index=12) noexcept;
-
- uuid128_t(uuid32_t const & uuid32, uuid128_t const & base_uuid=BT_BASE_UUID, jau::nsize_t const uuid32_le_octet_index=12) noexcept;
-
- uuid128_t(const uuid128_t &o) noexcept = default;
- uuid128_t(uuid128_t &&o) noexcept = default;
- uuid128_t& operator=(const uuid128_t &o) noexcept = default;
- uuid128_t& operator=(uuid128_t &&o) noexcept = default;
-
- bool operator==(uuid_t const &o) const noexcept override {
- if( this == &o ) {
- return true;
- }
- return getTypeSize() == o.getTypeSize() && value == static_cast<uuid128_t const *>(&o)->value;
- }
-
- const uint8_t * data() const noexcept override { return value.data; }
- std::string toString() const noexcept override;
- std::string toUUID128String(uuid128_t const & base_uuid=BT_BASE_UUID, jau::nsize_t const le_octet_index=12) const noexcept override {
- (void)base_uuid;
- (void)le_octet_index;
- return toString();
- }
-
- jau::nsize_t put(uint8_t * const buffer, jau::nsize_t const byte_offset, bool const littleEndian) const noexcept override {
- jau::put_uint128(buffer, byte_offset, value, littleEndian);
- return 16;
- }
-};
-
-inline uuid16_t get_uuid16(uint8_t const * buffer, jau::nsize_t const byte_offset) noexcept
-{
- return uuid16_t(jau::get_uint16(buffer, byte_offset));
-}
-inline uuid16_t get_uuid16(uint8_t const * buffer, jau::nsize_t const byte_offset, bool littleEndian) noexcept
-{
- return uuid16_t(jau::get_uint16(buffer, byte_offset, littleEndian));
-}
-inline uuid32_t get_uuid32(uint8_t const * buffer, jau::nsize_t const byte_offset) noexcept
-{
- return uuid32_t(jau::get_uint32(buffer, byte_offset));
-}
-inline uuid32_t get_uuid32(uint8_t const * buffer, jau::nsize_t const byte_offset, bool littleEndian) noexcept
-{
- return uuid32_t(jau::get_uint32(buffer, byte_offset, littleEndian));
-}
-inline uuid128_t get_uuid128(uint8_t const * buffer, jau::nsize_t const byte_offset) noexcept
-{
- return uuid128_t(jau::get_uint128(buffer, byte_offset));
-}
-inline uuid128_t get_uuid128(uint8_t const * buffer, jau::nsize_t const byte_offset, bool littleEndian) noexcept
-{
- return uuid128_t(jau::get_uint128(buffer, byte_offset, littleEndian));
-}
-
-} /* namespace direct_bt */
-
-#endif /* UUID_HPP_ */
diff --git a/api/direct_bt/linux_kernel_types.hpp b/api/direct_bt/linux_kernel_types.hpp
index 247fddb3..6bc88680 100644
--- a/api/direct_bt/linux_kernel_types.hpp
+++ b/api/direct_bt/linux_kernel_types.hpp
@@ -27,8 +27,7 @@
#define LINUX_KERNEL_TYPES_HPP_
#include <jau/packed_attribute.hpp>
-
-#include "BTAddress.hpp"
+#include <jau/eui48.hpp>
#if defined(__linux__)
/* <sys/param.h> defines __u64 _le64 and _be64 on aarch64 */
@@ -52,6 +51,6 @@ typedef uint32_t __be32;
typedef uint64_t __be64;
#endif
-typedef direct_bt::EUI48 bdaddr_t;
+typedef jau::EUI48 bdaddr_t;
#endif /* LINUX_KERNEL_TYPES_HPP_ */