diff options
author | Sven Gothel <[email protected]> | 2020-10-20 08:18:11 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-10-20 08:18:11 +0200 |
commit | bc5b9519034edfa7a24a6667d183f3a3b01f3867 (patch) | |
tree | d18e96cef8286dfc6bc20e1f8e8e71b360aba1fd | |
parent | aa43800a7722940ac1a902b088a6900e29efd0c9 (diff) |
Small footprint compromise: Use jau::nsize_t and jau::snsize_t where appropriate
Revises commit 1f6e924fe05ed45bfa4d0d901af2c4df6c1abab5
Use jau::nsize_t and jau::snsize_t where appropriate
- OctetTypes.hpp: TROOctets*
- ATTPDUTypes.hpp: AttPDUMsg*
- HCITypes.hpp: HCIPacket*
- HCIComm.hpp: HCIComm
- L2CAPComm.hpp: L2CAPComm
- MgmtTypes.hpp: MgmtCommand*, MgmtEvent*
- UUID.hpp: uuid_t
- DBTManager, GATTHandler, HCIHandler
- HCIComm.hpp: HCIComm
- BTTypes.hpp
- DBTTypes.hpp
-rw-r--r-- | api/direct_bt/ATTPDUTypes.hpp | 152 | ||||
-rw-r--r-- | api/direct_bt/BTTypes.hpp | 4 | ||||
-rw-r--r-- | api/direct_bt/DBTTypes.hpp | 2 | ||||
-rw-r--r-- | api/direct_bt/HCIComm.hpp | 4 | ||||
-rw-r--r-- | api/direct_bt/HCIHandler.hpp | 4 | ||||
-rw-r--r-- | api/direct_bt/HCITypes.hpp | 58 | ||||
-rw-r--r-- | api/direct_bt/L2CAPComm.hpp | 4 | ||||
-rw-r--r-- | api/direct_bt/MgmtTypes.hpp | 140 | ||||
-rw-r--r-- | api/direct_bt/OctetTypes.hpp | 146 | ||||
-rw-r--r-- | api/direct_bt/UUID.hpp | 48 | ||||
-rw-r--r-- | src/direct_bt/ATTPDUTypes.cpp | 2 | ||||
-rw-r--r-- | src/direct_bt/BTTypes.cpp | 14 | ||||
-rw-r--r-- | src/direct_bt/DBTManager.cpp | 10 | ||||
-rw-r--r-- | src/direct_bt/GATTHandler.cpp | 6 | ||||
-rw-r--r-- | src/direct_bt/GATTNumbers.cpp | 10 | ||||
-rw-r--r-- | src/direct_bt/HCIComm.cpp | 8 | ||||
-rw-r--r-- | src/direct_bt/HCIHandler.cpp | 8 | ||||
-rw-r--r-- | src/direct_bt/HCITypes.cpp | 2 | ||||
-rw-r--r-- | src/direct_bt/L2CAPComm.cpp | 12 | ||||
-rw-r--r-- | src/direct_bt/MgmtTypes.cpp | 6 | ||||
-rw-r--r-- | src/direct_bt/UUID.cpp | 32 |
21 files changed, 336 insertions, 336 deletions
diff --git a/api/direct_bt/ATTPDUTypes.hpp b/api/direct_bt/ATTPDUTypes.hpp index b5ac98ae..c77f6f07 100644 --- a/api/direct_bt/ATTPDUTypes.hpp +++ b/api/direct_bt/ATTPDUTypes.hpp @@ -353,18 +353,18 @@ namespace direct_bt { * Returned memory reference is managed by caller (delete etc) * </p> */ - static std::shared_ptr<const AttPDUMsg> getSpecialized(const uint8_t * buffer, size_t const buffer_size) noexcept; + static std::shared_ptr<const AttPDUMsg> getSpecialized(const uint8_t * buffer, jau::nsize_t const buffer_size) noexcept; /** Persistent memory, w/ ownership ..*/ - AttPDUMsg(const uint8_t* source, const size_t size) - : pdu(source, std::max<size_t>(1, size)), ts_creation(jau::getCurrentMilliseconds()) + AttPDUMsg(const uint8_t* source, const jau::nsize_t size) + : pdu(source, std::max<jau::nsize_t>(1, size)), ts_creation(jau::getCurrentMilliseconds()) { pdu.check_range(0, getPDUMinSize()); } /** Persistent memory, w/ ownership ..*/ - AttPDUMsg(const Opcode opc, const size_t size) - : pdu(std::max<size_t>(1, size)), ts_creation(jau::getCurrentMilliseconds()) + AttPDUMsg(const Opcode opc, const jau::nsize_t size) + : pdu(std::max<jau::nsize_t>(1, size)), ts_creation(jau::getCurrentMilliseconds()) { pdu.put_uint8_nc(0, opc); pdu.check_range(0, getPDUMinSize()); @@ -407,7 +407,7 @@ namespace direct_bt { * This auth-signature comes at the very last of the PDU. * </p> */ - size_t getAuthSigSize() const noexcept { + jau::nsize_t getAuthSigSize() const noexcept { return getOpAuthSigFlag() ? 12 : 0; } @@ -427,7 +427,7 @@ namespace direct_bt { * Note that the optional auth-signature is at the end of the PDU. * </p> */ - size_t getPDUParamSize() const noexcept { + jau::nsize_t getPDUParamSize() const noexcept { return pdu.getSize() - getAuthSigSize() - 1 /* opcode */; } @@ -449,7 +449,7 @@ namespace direct_bt { * conveniently. * </p> */ - virtual size_t getPDUValueOffset() const noexcept { return 1; /* default: opcode */ } + virtual jau::nsize_t getPDUValueOffset() const noexcept { return 1; /* default: opcode */ } /** * Returns this PDU's minimum size, i.e. @@ -458,7 +458,7 @@ namespace direct_bt { * </pre> * Value is excluded as it might be flexible. */ - size_t getPDUMinSize() const noexcept { + jau::nsize_t getPDUMinSize() const noexcept { return getPDUValueOffset() + getAuthSigSize(); } @@ -477,7 +477,7 @@ namespace direct_bt { * value-size := pdu.size - getAuthSigSize() - value-offset * </pre> */ - size_t getPDUValueSize() const noexcept { return getPDUParamSize() - getPDUValueOffset() + 1; } + jau::nsize_t getPDUValueSize() const noexcept { return getPDUParamSize() - getPDUValueOffset() + 1; } /** * Returns the theoretical maximum value size of a PDU. @@ -485,7 +485,7 @@ namespace direct_bt { * ATT_MTU - getAuthSigSize() - value-offset * </pre> */ - size_t getMaxPDUValueSize(const size_t mtu) const noexcept { + jau::nsize_t getMaxPDUValueSize(const jau::nsize_t mtu) const noexcept { return mtu - getAuthSigSize() - getPDUValueOffset(); } @@ -507,12 +507,12 @@ namespace direct_bt { class AttPDUUndefined: public AttPDUMsg { public: - AttPDUUndefined(const uint8_t* source, const size_t length) : AttPDUMsg(source, length) { + AttPDUUndefined(const uint8_t* source, const jau::nsize_t length) : AttPDUMsg(source, length) { checkOpcode(ATT_PDU_UNDEFINED); } /** opcode */ - size_t getPDUValueOffset() const noexcept override { return 1; } + jau::nsize_t getPDUValueOffset() const noexcept override { return 1; } std::string getName() const noexcept override { return "AttPDUUndefined"; @@ -552,12 +552,12 @@ namespace direct_bt { static std::string getPlainErrorString(const ErrorCode errorCode) noexcept; - AttErrorRsp(const uint8_t* source, const size_t length) : AttPDUMsg(source, length) { + AttErrorRsp(const uint8_t* source, const jau::nsize_t length) : AttPDUMsg(source, length) { checkOpcode(ATT_ERROR_RSP); } /** opcode + reqOpcodeCause + handleCause + errorCode */ - size_t getPDUValueOffset() const noexcept override { return 1 + 1 + 2 + 1; } + jau::nsize_t getPDUValueOffset() const noexcept override { return 1 + 1 + 2 + 1; } uint8_t getRequestedOpcodeCause() const noexcept { return pdu.get_uint8_nc(1); @@ -599,7 +599,7 @@ namespace direct_bt { class AttExchangeMTU: public AttPDUMsg { public: - AttExchangeMTU(const uint8_t* source, const size_t length) : AttPDUMsg(source, length) { + AttExchangeMTU(const uint8_t* source, const jau::nsize_t length) : AttPDUMsg(source, length) { checkOpcode(ATT_EXCHANGE_MTU_RSP); } @@ -610,7 +610,7 @@ namespace direct_bt { } /** opcode + mtu-size */ - size_t getPDUValueOffset() const noexcept override { return 1+2; } + jau::nsize_t getPDUValueOffset() const noexcept override { return 1+2; } uint16_t getMTUSize() const noexcept { return pdu.get_uint16_nc(1); @@ -646,7 +646,7 @@ namespace direct_bt { } /** opcode + handle */ - size_t getPDUValueOffset() const noexcept override { return 1+2; } + jau::nsize_t getPDUValueOffset() const noexcept override { return 1+2; } uint16_t getHandle() const noexcept { return pdu.get_uint16_nc( 1 ); @@ -684,13 +684,13 @@ namespace direct_bt { public: static bool instanceOf(); - AttReadRsp(const uint8_t* source, const size_t length) + AttReadRsp(const uint8_t* source, const jau::nsize_t length) : AttPDUMsg(source, length), view(pdu, getPDUValueOffset(), getPDUValueSize()) { checkOpcode(ATT_READ_RSP); } /** opcode */ - size_t getPDUValueOffset() const noexcept override { return 1; } + jau::nsize_t getPDUValueOffset() const noexcept override { return 1; } uint8_t const * getValuePtr() const noexcept { return pdu.get_ptr_nc(getPDUValueOffset()); } @@ -727,7 +727,7 @@ namespace direct_bt { } /** opcode + handle + value_offset */ - size_t getPDUValueOffset() const noexcept override { return 1 + 2 + 2; } + jau::nsize_t getPDUValueOffset() const noexcept override { return 1 + 2 + 2; } uint16_t getHandle() const noexcept { return pdu.get_uint16_nc( 1 ); @@ -769,13 +769,13 @@ namespace direct_bt { public: static bool instanceOf(); - AttReadBlobRsp(const uint8_t* source, const size_t length) + AttReadBlobRsp(const uint8_t* source, const jau::nsize_t length) : AttPDUMsg(source, length), view(pdu, getPDUValueOffset(), getPDUValueSize()) { checkOpcode(ATT_READ_BLOB_RSP); } /** opcode */ - size_t getPDUValueOffset() const noexcept override { return 1; } + jau::nsize_t getPDUValueOffset() const noexcept override { return 1; } uint8_t const * getValuePtr() const noexcept { return pdu.get_ptr_nc(getPDUValueOffset()); } @@ -814,13 +814,13 @@ namespace direct_bt { : AttPDUMsg(ATT_WRITE_REQ, 1+2+value.getSize()), view(pdu, getPDUValueOffset(), getPDUValueSize()) { pdu.put_uint16_nc(1, handle); - for(size_t i=0; i<value.getSize(); i++) { + for(jau::nsize_t i=0; i<value.getSize(); i++) { pdu.put_uint8_nc(3+i, value.get_uint8_nc(i)); } } /** opcode + handle */ - size_t getPDUValueOffset() const noexcept override { return 1 + 2; } + jau::nsize_t getPDUValueOffset() const noexcept override { return 1 + 2; } uint16_t getHandle() const noexcept { return pdu.get_uint16_nc( 1 ); @@ -853,13 +853,13 @@ namespace direct_bt { class AttWriteRsp : public AttPDUMsg { public: - AttWriteRsp(const uint8_t* source, const size_t length) + AttWriteRsp(const uint8_t* source, const jau::nsize_t length) : AttPDUMsg(source, length) { checkOpcode(ATT_WRITE_RSP); } /** opcode */ - size_t getPDUValueOffset() const noexcept override { return 1; } + jau::nsize_t getPDUValueOffset() const noexcept override { return 1; } std::string getName() const noexcept override { return "AttWriteRsp"; @@ -886,13 +886,13 @@ namespace direct_bt { : AttPDUMsg(ATT_WRITE_CMD, 1+2+value.getSize()), view(pdu, getPDUValueOffset(), getPDUValueSize()) { pdu.put_uint16_nc(1, handle); - for(size_t i=0; i<value.getSize(); i++) { + for(jau::nsize_t i=0; i<value.getSize(); i++) { pdu.put_uint8_nc(3+i, value.get_uint8_nc(i)); } } /** opcode + handle */ - size_t getPDUValueOffset() const noexcept override { return 1 + 2; } + jau::nsize_t getPDUValueOffset() const noexcept override { return 1 + 2; } uint16_t getHandle() const noexcept { return pdu.get_uint16_nc( 1 ); @@ -934,13 +934,13 @@ namespace direct_bt { const TOctetSlice view; public: - AttHandleValueRcv(const uint8_t* source, const size_t length) + AttHandleValueRcv(const uint8_t* source, const jau::nsize_t length) : AttPDUMsg(source, length), view(pdu, getPDUValueOffset(), getPDUValueSize()) { checkOpcode(ATT_HANDLE_VALUE_NTF, ATT_HANDLE_VALUE_IND); } /** opcode + handle */ - size_t getPDUValueOffset() const noexcept override { return 1+2; } + jau::nsize_t getPDUValueOffset() const noexcept override { return 1+2; } uint16_t getHandle() const noexcept { return pdu.get_uint16_nc(1); @@ -987,7 +987,7 @@ namespace direct_bt { } /** opcode */ - size_t getPDUValueOffset() const noexcept override { return 1; } + jau::nsize_t getPDUValueOffset() const noexcept override { return 1; } std::string getName() const noexcept override { return "AttHandleValueCfm"; @@ -997,17 +997,17 @@ namespace direct_bt { class AttElementList : public AttPDUMsg { protected: - AttElementList(const uint8_t* source, const size_t length) + AttElementList(const uint8_t* source, const jau::nsize_t length) : AttPDUMsg(source, length) {} virtual std::string addValueString() const { return ""; } - virtual std::string elementString(const size_t idx) const { (void)idx; return "not implemented"; } + virtual std::string elementString(const jau::nsize_t idx) const { (void)idx; return "not implemented"; } std::string valueString() const noexcept override { std::string res = "size "+std::to_string(getPDUValueSize())+", "+addValueString()+"elements[count "+std::to_string(getElementCount())+", "+ "size [total "+std::to_string(getElementTotalSize())+", value "+std::to_string(getElementValueSize())+"]: "; - const size_t count = getElementCount(); - for(size_t i=0; i<count; i++) { + const jau::nsize_t count = getElementCount(); + for(jau::nsize_t i=0; i<count; i++) { res += std::to_string(i)+"["+elementString(i)+"],"; } res += "]"; @@ -1017,15 +1017,15 @@ namespace direct_bt { public: virtual ~AttElementList() noexcept override {} - virtual size_t getElementTotalSize() const = 0; - virtual size_t getElementValueSize() const = 0; - virtual size_t getElementCount() const = 0; + virtual jau::nsize_t getElementTotalSize() const = 0; + virtual jau::nsize_t getElementValueSize() const = 0; + virtual jau::nsize_t getElementCount() const = 0; - size_t getElementPDUOffset(const size_t elementIdx) const { + jau::nsize_t getElementPDUOffset(const jau::nsize_t elementIdx) const { return getPDUValueOffset() + elementIdx * getElementTotalSize(); } - uint8_t const * getElementPtr(const size_t elementIdx) const { + uint8_t const * getElementPtr(const jau::nsize_t elementIdx) const { return pdu.get_ptr(getElementPDUOffset(elementIdx)); } @@ -1079,7 +1079,7 @@ namespace direct_bt { } /** opcode + handle-start + handle-end */ - size_t getPDUValueOffset() const noexcept override { return 1 + 2 + 2; } + jau::nsize_t getPDUValueOffset() const noexcept override { return 1 + 2 + 2; } uint16_t getStartHandle() const noexcept { return pdu.get_uint16_nc( 1 ); @@ -1135,7 +1135,7 @@ namespace direct_bt { const TOctetSlice view; public: - Element(const AttReadByTypeRsp & p, const size_t idx) + Element(const AttReadByTypeRsp & p, const jau::nsize_t idx) : view(p.pdu, p.getElementPDUOffset(idx), p.getElementTotalSize()) {} uint16_t getHandle() const noexcept { @@ -1146,7 +1146,7 @@ namespace direct_bt { return view.get_ptr_nc(2 /* handle size */); } - size_t getValueSize() const noexcept { return view.getSize() - 2 /* handle size */; } + jau::nsize_t getValueSize() const noexcept { return view.getSize() - 2 /* handle size */; } std::string toString() const { return "handle "+jau::uint16HexString(getHandle(), true)+ @@ -1154,7 +1154,7 @@ namespace direct_bt { } }; - AttReadByTypeRsp(const uint8_t* source, const size_t length) + AttReadByTypeRsp(const uint8_t* source, const jau::nsize_t length) : AttElementList(source, length) { checkOpcode(ATT_READ_BY_TYPE_RSP); @@ -1166,10 +1166,10 @@ namespace direct_bt { } /** opcode + element-size */ - size_t getPDUValueOffset() const noexcept override { return 1 + 1; } + jau::nsize_t getPDUValueOffset() const noexcept override { return 1 + 1; } /** Returns size of each element, i.e. handle-value pair. */ - size_t getElementTotalSize() const noexcept override { + jau::nsize_t getElementTotalSize() const noexcept override { return pdu.get_uint8_nc(1); } @@ -1179,23 +1179,23 @@ namespace direct_bt { * element := { uint16_t handle, uint8_t value[value-size] } * </p> */ - size_t getElementValueSize() const noexcept override { + jau::nsize_t getElementValueSize() const noexcept override { return getElementTotalSize() - 2; } - size_t getElementCount() const noexcept override { + jau::nsize_t getElementCount() const noexcept override { return getPDUValueSize() / getElementTotalSize(); } - Element getElement(const size_t elementIdx) const { + Element getElement(const jau::nsize_t elementIdx) const { return Element(*this, elementIdx); } - uint16_t getElementHandle(const size_t elementIdx) const { + uint16_t getElementHandle(const jau::nsize_t elementIdx) const { return pdu.get_uint16( getElementPDUOffset(elementIdx) ); } - uint8_t * getElementValuePtr(const size_t elementIdx) { + uint8_t * getElementValuePtr(const jau::nsize_t elementIdx) { return pdu.get_wptr() + getElementPDUOffset(elementIdx) + 2 /* handle size */; } @@ -1204,7 +1204,7 @@ namespace direct_bt { } protected: - std::string elementString(const size_t idx) const override { + std::string elementString(const jau::nsize_t idx) const override { return getElement(idx).toString(); } }; @@ -1238,7 +1238,7 @@ namespace direct_bt { const TOctetSlice view; public: - Element(const AttReadByGroupTypeRsp & p, const size_t idx) + Element(const AttReadByGroupTypeRsp & p, const jau::nsize_t idx) : view(p.pdu, p.getElementPDUOffset(idx), p.getElementTotalSize()) {} uint16_t getStartHandle() const noexcept { @@ -1253,10 +1253,10 @@ namespace direct_bt { return view.get_ptr_nc(4 /* handle size */); } - size_t getValueSize() const noexcept { return view.getSize() - 4 /* handle size */; } + jau::nsize_t getValueSize() const noexcept { return view.getSize() - 4 /* handle size */; } }; - AttReadByGroupTypeRsp(const uint8_t* source, const size_t length) + AttReadByGroupTypeRsp(const uint8_t* source, const jau::nsize_t length) : AttElementList(source, length) { checkOpcode(ATT_READ_BY_GROUP_TYPE_RSP); @@ -1268,10 +1268,10 @@ namespace direct_bt { } /** opcode + element-size */ - size_t getPDUValueOffset() const noexcept override { return 1 + 1; } + jau::nsize_t getPDUValueOffset() const noexcept override { return 1 + 1; } /** Returns size of each element, i.e. handle-value triple. */ - size_t getElementTotalSize() const noexcept override { + jau::nsize_t getElementTotalSize() const noexcept override { return pdu.get_uint8_nc(1); } @@ -1281,27 +1281,27 @@ namespace direct_bt { * element := { uint16_t startHandle, uint16_t endHandle, uint8_t value[value-size] } * </p> */ - size_t getElementValueSize() const noexcept override { + jau::nsize_t getElementValueSize() const noexcept override { return getElementTotalSize() - 4; } - size_t getElementCount() const noexcept override { + jau::nsize_t getElementCount() const noexcept override { return getPDUValueSize() / getElementTotalSize(); } - Element getElement(const size_t elementIdx) const { + Element getElement(const jau::nsize_t elementIdx) const { return Element(*this, elementIdx); } - uint16_t getElementStartHandle(const size_t elementIdx) const { + uint16_t getElementStartHandle(const jau::nsize_t elementIdx) const { return pdu.get_uint16( getElementPDUOffset(elementIdx) ); } - uint16_t getElementEndHandle(const size_t elementIdx) const { + uint16_t getElementEndHandle(const jau::nsize_t elementIdx) const { return pdu.get_uint16( getElementPDUOffset(elementIdx) + 2 /* 1 handle size */ ); } - uint8_t * getElementValuePtr(const size_t elementIdx) { + uint8_t * getElementValuePtr(const jau::nsize_t elementIdx) { return pdu.get_wptr() + getElementPDUOffset(elementIdx) + 4 /* 2 handle size */; } @@ -1310,7 +1310,7 @@ namespace direct_bt { } protected: - std::string elementString(const size_t idx) const override { + std::string elementString(const jau::nsize_t idx) const override { Element e = getElement(idx); return "handle ["+jau::uint16HexString(e.getStartHandle(), true)+".."+jau::uint16HexString(e.getEndHandle(), true)+ "], data "+jau::bytesHexString(e.getValuePtr(), 0, e.getValueSize(), true /* lsbFirst */, true /* leading0X */); @@ -1338,7 +1338,7 @@ namespace direct_bt { } /** opcode + handle_start + handle_end */ - size_t getPDUValueOffset() const noexcept override { return 1 + 2 + 2; } + jau::nsize_t getPDUValueOffset() const noexcept override { return 1 + 2 + 2; } uint16_t getStartHandle() const noexcept { return pdu.get_uint16_nc( 1 ); @@ -1399,12 +1399,12 @@ namespace direct_bt { const uint16_t handle; const std::shared_ptr<const uuid_t> uuid; - Element(const AttFindInfoRsp & p, const size_t idx) + Element(const AttFindInfoRsp & p, const jau::nsize_t idx) : handle( p.getElementHandle(idx) ), uuid( p.getElementValue(idx) ) { } }; - AttFindInfoRsp(const uint8_t* source, const size_t length) : AttElementList(source, length) { + AttFindInfoRsp(const uint8_t* source, const jau::nsize_t length) : AttElementList(source, length) { checkOpcode(ATT_FIND_INFORMATION_RSP); if( getPDUValueSize() % getElementTotalSize() != 0 ) { throw AttValueException("PDUFindInfoRsp: Invalid packet size: pdu-value-size "+std::to_string(getPDUValueSize())+ @@ -1413,10 +1413,10 @@ namespace direct_bt { } /** opcode + format */ - size_t getPDUValueOffset() const noexcept override { return 1 + 1; } + jau::nsize_t getPDUValueOffset() const noexcept override { return 1 + 1; } /** Returns size of each element, i.e. handle-value tuple. */ - size_t getElementTotalSize() const override { + jau::nsize_t getElementTotalSize() const override { return 2 + getElementValueSize(); } @@ -1426,23 +1426,23 @@ namespace direct_bt { * element := { uint16_t handle, UUID value }, with a UUID of UUID16 or UUID128 * </p> */ - size_t getElementValueSize() const override { + jau::nsize_t getElementValueSize() const override { return uuid_t::number(getUUIFormat()); } - size_t getElementCount() const override { + jau::nsize_t getElementCount() const override { return getPDUValueSize() / getElementTotalSize(); } - Element getElement(const size_t elementIdx) const { + Element getElement(const jau::nsize_t elementIdx) const { return Element(*this, elementIdx); } - uint16_t getElementHandle(const size_t elementIdx) const { + uint16_t getElementHandle(const jau::nsize_t elementIdx) const { return pdu.get_uint16( getElementPDUOffset(elementIdx) ); } - std::shared_ptr<const uuid_t> getElementValue(const size_t elementIdx) const { + std::shared_ptr<const uuid_t> getElementValue(const jau::nsize_t elementIdx) const { return pdu.get_uuid( getElementPDUOffset(elementIdx) + 2, getUUIFormat() ); } @@ -1453,7 +1453,7 @@ namespace direct_bt { protected: std::string addValueString() const override { return "format "+std::to_string(pdu.get_uint8_nc(1))+", "; } - std::string elementString(const size_t idx) const override { + std::string elementString(const jau::nsize_t idx) const override { Element e = getElement(idx); return "handle "+jau::uint16HexString(e.handle, true)+ ", uuid "+e.uuid.get()->toString(); diff --git a/api/direct_bt/BTTypes.hpp b/api/direct_bt/BTTypes.hpp index 959bdfae..93854ad9 100644 --- a/api/direct_bt/BTTypes.hpp +++ b/api/direct_bt/BTTypes.hpp @@ -444,7 +444,7 @@ namespace direct_bt { POctets data; ManufactureSpecificData(uint16_t const company) noexcept; - ManufactureSpecificData(uint16_t const company, uint8_t const * const data, size_t const data_len) noexcept; + ManufactureSpecificData(uint16_t const company, uint8_t const * const data, jau::nsize_t const data_len) noexcept; std::string toString() const noexcept; }; @@ -578,7 +578,7 @@ namespace direct_bt { * https://www.bluetooth.com/specifications/archived-specifications/ * </p> */ - static std::vector<std::shared_ptr<EInfoReport>> read_ad_reports(uint8_t const * data, size_t const data_length) noexcept; + static std::vector<std::shared_ptr<EInfoReport>> read_ad_reports(uint8_t const * data, jau::nsize_t const data_length) noexcept; /** * Reads the Extended Inquiry Response (EIR) or Advertising Data (AD) segments diff --git a/api/direct_bt/DBTTypes.hpp b/api/direct_bt/DBTTypes.hpp index 93d66fb7..bec4bd41 100644 --- a/api/direct_bt/DBTTypes.hpp +++ b/api/direct_bt/DBTTypes.hpp @@ -100,7 +100,7 @@ namespace direct_bt { int8_t max_tx_power; public: - static size_t minimumDataSize() noexcept { return 6 + 1 + 1 + 1 + 1; } + 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 : address(address_), addressType(addressType_), rssi(rssi_), tx_power(tx_power_), max_tx_power(max_tx_power_) {} diff --git a/api/direct_bt/HCIComm.hpp b/api/direct_bt/HCIComm.hpp index 4c66ff75..d840d849 100644 --- a/api/direct_bt/HCIComm.hpp +++ b/api/direct_bt/HCIComm.hpp @@ -84,10 +84,10 @@ namespace direct_bt { inline std::recursive_mutex & mutex_write() noexcept { return mtx_write; } /** Generic read w/ own timeoutMS, w/o locking suitable for a unique ringbuffer sink. */ - ssize_t read(uint8_t* buffer, const size_t capacity, const int32_t timeoutMS) noexcept; + jau::snsize_t read(uint8_t* buffer, const jau::nsize_t capacity, const int32_t timeoutMS) noexcept; /** Generic write, locking {@link #mutex_write()}. */ - ssize_t write(const uint8_t* buffer, const size_t size) noexcept; + jau::snsize_t write(const uint8_t* buffer, const jau::nsize_t size) noexcept; private: static inline void setu32_bit(int nr, void *addr) noexcept diff --git a/api/direct_bt/HCIHandler.hpp b/api/direct_bt/HCIHandler.hpp index 6943542c..45c88594 100644 --- a/api/direct_bt/HCIHandler.hpp +++ b/api/direct_bt/HCIHandler.hpp @@ -182,8 +182,8 @@ namespace direct_bt { */ class HCIHandler { public: - enum DefaultsSizeT : size_t { - HCI_MAX_MTU = static_cast<size_t>(HCIConstSizeT::PACKET_MAX_SIZE) + enum DefaultsSizeT : jau::nsize_t { + HCI_MAX_MTU = static_cast<jau::nsize_t>(HCIConstSizeT::PACKET_MAX_SIZE) }; static const pid_t pidSelf; diff --git a/api/direct_bt/HCITypes.hpp b/api/direct_bt/HCITypes.hpp index 823b3d2b..8b229334 100644 --- a/api/direct_bt/HCITypes.hpp +++ b/api/direct_bt/HCITypes.hpp @@ -197,7 +197,7 @@ namespace direct_bt { } std::string getHCIStatusCodeString(const HCIStatusCode ec) noexcept; - enum class HCIConstSizeT : size_t { + enum class HCIConstSizeT : jau::nsize_t { /** HCIPacketType::COMMAND header size including HCIPacketType */ COMMAND_HDR_SIZE = 1+3, /** HCIPacketType::ACLDATA header size including HCIPacketType */ @@ -209,8 +209,8 @@ namespace direct_bt { /** Total packet size, guaranteed to be handled by adapter. */ PACKET_MAX_SIZE = 255 }; - constexpr size_t number(const HCIConstSizeT rhs) noexcept { - return static_cast<size_t>(rhs); + constexpr jau::nsize_t number(const HCIConstSizeT rhs) noexcept { + return static_cast<jau::nsize_t>(rhs); } enum class HCIPacketType : uint8_t { @@ -440,7 +440,7 @@ namespace direct_bt { } public: - HCIPacket(const HCIPacketType type, const size_t total_packet_size) + HCIPacket(const HCIPacketType type, const jau::nsize_t total_packet_size) : pdu(total_packet_size) { if( 0 == total_packet_size ) { @@ -450,7 +450,7 @@ namespace direct_bt { } /** Persistent memory, w/ ownership ..*/ - HCIPacket(const uint8_t *packet_data, const size_t total_packet_size) + HCIPacket(const uint8_t *packet_data, const jau::nsize_t total_packet_size) : pdu(packet_data, total_packet_size) { if( 0 == total_packet_size ) { @@ -461,7 +461,7 @@ namespace direct_bt { virtual ~HCIPacket() noexcept {} - inline size_t getTotalSize() const noexcept { return pdu.getSize(); } + inline jau::nsize_t getTotalSize() const noexcept { return pdu.getSize(); } /** Return the underlying octets read only */ TROOctets & getPDU() noexcept { return pdu; } @@ -496,7 +496,7 @@ namespace direct_bt { return "opcode="+jau::uint16HexString(number(getOpcode()))+" "+getOpcodeString(); } virtual std::string valueString() const noexcept { - const size_t psz = getParamSize(); + const jau::nsize_t psz = getParamSize(); const std::string ps = psz > 0 ? jau::bytesHexString(getParam(), 0, psz, true /* lsbFirst */, true /* leading0X */) : ""; return "param[size "+std::to_string(getParamSize())+", data "+ps+"], tsz "+std::to_string(getTotalSize()); } @@ -504,7 +504,7 @@ namespace direct_bt { public: /** Enabling manual construction of command without given value. */ - HCICommand(const HCIOpcode opc, const size_t param_size) + HCICommand(const HCIOpcode opc, const jau::nsize_t param_size) : HCIPacket(HCIPacketType::COMMAND, number(HCIConstSizeT::COMMAND_HDR_SIZE)+param_size) { checkOpcode(opc, HCIOpcode::SPECIAL, HCIOpcode::LE_START_ENC); @@ -514,7 +514,7 @@ namespace direct_bt { } /** Enabling manual construction of command with given value. */ - HCICommand(const HCIOpcode opc, const uint8_t* param, const size_t param_size) + HCICommand(const HCIOpcode opc, const uint8_t* param, const jau::nsize_t param_size) : HCICommand(opc, param_size) { if( param_size > 0 ) { @@ -526,7 +526,7 @@ namespace direct_bt { HCIOpcode getOpcode() const noexcept { return static_cast<HCIOpcode>( pdu.get_uint16_nc(1) ); } std::string getOpcodeString() const noexcept { return getHCIOpcodeString(getOpcode()); } - size_t getParamSize() const noexcept { return pdu.get_uint8_nc(3); } + jau::nsize_t getParamSize() const noexcept { return pdu.get_uint8_nc(3); } const uint8_t* getParam() const noexcept { return pdu.get_ptr_nc(number(HCIConstSizeT::COMMAND_HDR_SIZE)); } std::string toString() const noexcept { @@ -613,13 +613,13 @@ namespace direct_bt { return "event="+jau::uint8HexString(number(getEventType()))+" "+getEventTypeString(); } virtual std::string valueString() const noexcept { - const size_t d_sz_base = getBaseParamSize(); - const size_t d_sz = getParamSize(); + const jau::nsize_t d_sz_base = getBaseParamSize(); + const jau::nsize_t d_sz = getParamSize(); const std::string d_str = d_sz > 0 ? jau::bytesHexString(getParam(), 0, d_sz, true /* lsbFirst */, true /* leading0X */) : ""; return "data[size "+std::to_string(d_sz)+"/"+std::to_string(d_sz_base)+", data "+d_str+"], tsz "+std::to_string(getTotalSize()); } - size_t getBaseParamSize() const noexcept { return pdu.get_uint8_nc(2); } + jau::nsize_t getBaseParamSize() const noexcept { return pdu.get_uint8_nc(2); } public: @@ -629,13 +629,13 @@ namespace direct_bt { * Returned memory reference is managed by caller (delete etc) * </p> */ - static std::shared_ptr<HCIEvent> getSpecialized(const uint8_t * buffer, size_t const buffer_size) noexcept; + static std::shared_ptr<HCIEvent> getSpecialized(const uint8_t * buffer, jau::nsize_t const buffer_size) noexcept; /** Persistent memory, w/ ownership ..*/ - HCIEvent(const uint8_t* buffer, const size_t buffer_len, const size_t exp_param_size) + HCIEvent(const uint8_t* buffer, const jau::nsize_t buffer_len, const jau::nsize_t exp_param_size) : HCIPacket(buffer, buffer_len), ts_creation(jau::getCurrentMilliseconds()) { - const size_t baseParamSize = getBaseParamSize(); + const jau::nsize_t baseParamSize = getBaseParamSize(); pdu.check_range(0, number(HCIConstSizeT::EVENT_HDR_SIZE)+baseParamSize); if( exp_param_size > baseParamSize ) { throw jau::IndexOutOfBoundsException(exp_param_size, baseParamSize, E_FILE_LINE); @@ -644,7 +644,7 @@ namespace direct_bt { } /** Enabling manual construction of event without given value. */ - HCIEvent(const HCIEventType evt, const size_t param_size=0) + HCIEvent(const HCIEventType evt, const jau::nsize_t param_size=0) : HCIPacket(HCIPacketType::EVENT, number(HCIConstSizeT::EVENT_HDR_SIZE)+param_size), ts_creation(jau::getCurrentMilliseconds()) { checkEventType(evt, HCIEventType::INQUIRY_COMPLETE, HCIEventType::AMP_Receiver_Report); @@ -653,7 +653,7 @@ namespace direct_bt { } /** Enabling manual construction of event with given value. */ - HCIEvent(const HCIEventType evt, const uint8_t* param, const size_t param_size) + HCIEvent(const HCIEventType evt, const uint8_t* param, const jau::nsize_t param_size) : HCIEvent(evt, param_size) { if( param_size > 0 ) { @@ -676,7 +676,7 @@ namespace direct_bt { std::string getMetaEventTypeString() const noexcept { return getHCIMetaEventTypeString(getMetaEventType()); } bool isMetaEvent(HCIMetaEventType t) const noexcept { return t == getMetaEventType(); } - virtual size_t getParamSize() const noexcept { return getBaseParamSize(); } + virtual jau::nsize_t getParamSize() const noexcept { return getBaseParamSize(); } virtual const uint8_t* getParam() const noexcept { return pdu.get_ptr_nc(number(HCIConstSizeT::EVENT_HDR_SIZE)); } virtual bool validate(const HCICommand & cmd) const noexcept { (void)cmd; return true; } @@ -733,7 +733,7 @@ namespace direct_bt { } public: - HCIDisconnectionCompleteEvent(const uint8_t* buffer, const size_t buffer_len) + HCIDisconnectionCompleteEvent(const uint8_t* buffer, const jau::nsize_t buffer_len) : HCIEvent(buffer, buffer_len, 4) { checkEventType(getEventType(), HCIEventType::DISCONN_COMPLETE); @@ -767,7 +767,7 @@ namespace direct_bt { } public: - HCICommandCompleteEvent(const uint8_t* buffer, const size_t buffer_len) + HCICommandCompleteEvent(const uint8_t* buffer, const jau::nsize_t buffer_len) : HCIEvent(buffer, buffer_len, 3) { checkEventType(getEventType(), HCIEventType::CMD_COMPLETE); @@ -786,10 +786,10 @@ namespace direct_bt { */ HCIOpcode getOpcode() const noexcept { return static_cast<HCIOpcode>( pdu.get_uint16_nc(number(HCIConstSizeT::EVENT_HDR_SIZE)+1) ); } - size_t getReturnParamSize() const noexcept { return getParamSize() - 3; } + jau::nsize_t getReturnParamSize() const noexcept { return getParamSize() - 3; } const uint8_t* getReturnParam() const { return pdu.get_ptr(number(HCIConstSizeT::EVENT_HDR_SIZE)+3); } - HCIStatusCode getReturnStatus(const size_t returnParamOffset=0) const { - const size_t returnParamSize = getReturnParamSize(); + HCIStatusCode getReturnStatus(const jau::nsize_t returnParamOffset=0) const { + const jau::nsize_t returnParamSize = getReturnParamSize(); if( returnParamSize < returnParamOffset + 1 /* status size */ ) { return HCIStatusCode::UNKNOWN; } @@ -821,7 +821,7 @@ namespace direct_bt { } public: - HCICommandStatusEvent(const uint8_t* buffer, const size_t buffer_len) + HCICommandStatusEvent(const uint8_t* buffer, const jau::nsize_t buffer_len) : HCIEvent(buffer, buffer_len, 4) { checkEventType(getEventType(), HCIEventType::CMD_STATUS); @@ -871,21 +871,21 @@ namespace direct_bt { public: /** Passing through preset buffer of this type */ - HCIMetaEvent(const uint8_t* buffer, const size_t buffer_len, const size_t exp_meta_param_size) + HCIMetaEvent(const uint8_t* buffer, const jau::nsize_t buffer_len, const jau::nsize_t exp_meta_param_size) : HCIEvent(buffer, buffer_len, 1+exp_meta_param_size) { checkEventType(getEventType(), HCIEventType::LE_META); } /** Enabling manual construction of event without given value. */ - HCIMetaEvent(const HCIMetaEventType mc, const size_t meta_param_size) + HCIMetaEvent(const HCIMetaEventType mc, const jau::nsize_t meta_param_size) : HCIEvent(HCIEventType::LE_META, 1+meta_param_size) { pdu.put_uint8_nc(number(HCIConstSizeT::EVENT_HDR_SIZE), number(mc)); } /** Enabling manual construction of event with given value. */ - HCIMetaEvent(const HCIMetaEventType mc, const uint8_t * meta_param, const size_t meta_param_size) + HCIMetaEvent(const HCIMetaEventType mc, const uint8_t * meta_param, const jau::nsize_t meta_param_size) : HCIMetaEvent(mc, meta_param_size) { if( meta_param_size > 0 ) { @@ -895,7 +895,7 @@ namespace direct_bt { HCIMetaEventType getMetaEventType() const noexcept override { return static_cast<HCIMetaEventType>( pdu.get_uint8_nc(number(HCIConstSizeT::EVENT_HDR_SIZE)) ); } - size_t getParamSize() const noexcept override { return HCIEvent::getParamSize()-1; } + jau::nsize_t getParamSize() const noexcept override { return HCIEvent::getParamSize()-1; } const uint8_t* getParam() const noexcept override { return HCIEvent::getParam()+1; } }; diff --git a/api/direct_bt/L2CAPComm.hpp b/api/direct_bt/L2CAPComm.hpp index 7734334c..496287b6 100644 --- a/api/direct_bt/L2CAPComm.hpp +++ b/api/direct_bt/L2CAPComm.hpp @@ -165,10 +165,10 @@ namespace direct_bt { std::recursive_mutex & mutex_write() { return mtx_write; } /** Generic read, w/o locking suitable for a unique ringbuffer sink. Using L2CAPEnv::L2CAP_READER_POLL_TIMEOUT.*/ - ssize_t read(uint8_t* buffer, const size_t capacity); + jau::snsize_t read(uint8_t* buffer, const jau::nsize_t capacity); /** Generic write, locking {@link #mutex_write()}. */ - ssize_t write(const uint8_t *buffer, const size_t length); + jau::snsize_t write(const uint8_t *buffer, const jau::nsize_t length); }; } // namespace direct_bt diff --git a/api/direct_bt/MgmtTypes.hpp b/api/direct_bt/MgmtTypes.hpp index cad4c851..a2429553 100644 --- a/api/direct_bt/MgmtTypes.hpp +++ b/api/direct_bt/MgmtTypes.hpp @@ -68,7 +68,7 @@ namespace direct_bt { }; - enum MgmtSizeConst : size_t { + enum MgmtSizeConst : jau::nsize_t { MGMT_HEADER_SIZE = 6 }; @@ -196,7 +196,7 @@ namespace direct_bt { return "opcode="+jau::uint16HexString(static_cast<uint16_t>(getOpcode()))+" "+getOpcodeString()+", devID "+jau::uint16HexString(getDevID()); } virtual std::string valueString() const noexcept { - const size_t psz = getParamSize(); + const jau::nsize_t psz = getParamSize(); const std::string ps = psz > 0 ? jau::bytesHexString(getParam(), 0, psz, true /* lsbFirst */, true /* leading0X */) : ""; return "param[size "+std::to_string(getParamSize())+", data "+ps+"], tsz "+std::to_string(getTotalSize()); } @@ -221,7 +221,7 @@ namespace direct_bt { } virtual ~MgmtCommand() noexcept {} - size_t getTotalSize() const noexcept { return pdu.getSize(); } + jau::nsize_t getTotalSize() const noexcept { return pdu.getSize(); } /** Return the underlying octets read only */ TROOctets & getPDU() noexcept { return pdu; } @@ -441,8 +441,8 @@ namespace direct_bt { class MgmtLoadConnParamCmd : public MgmtCommand { private: - void checkParamIdx(const size_t idx) const { - const size_t pc = getParamCount(); + void checkParamIdx(const jau::nsize_t idx) const { + const jau::nsize_t pc = getParamCount(); if( idx >= pc ) { throw jau::IndexOutOfBoundsException(idx, pc, E_FILE_LINE); } @@ -450,9 +450,9 @@ namespace direct_bt { protected: std::string valueString() const noexcept override { - const size_t paramCount = getParamCount(); + const jau::nsize_t paramCount = getParamCount(); std::string ps = "count "+std::to_string(paramCount)+": "; - for(size_t i=0; i<paramCount; i++) { + for(jau::nsize_t i=0; i<paramCount; i++) { if( 0 < i ) { ps.append(", "); } @@ -467,7 +467,7 @@ namespace direct_bt { MgmtLoadConnParamCmd(const uint16_t dev_id, const MgmtConnParam & connParam) : MgmtCommand(MgmtOpcode::LOAD_CONN_PARAM, dev_id, 2 + 15) { - size_t offset = MGMT_HEADER_SIZE; + jau::nsize_t offset = MGMT_HEADER_SIZE; pdu.put_uint16_nc(offset, 1); offset+= 2; pdu.put_eui48_nc(offset, connParam.address); offset+=6; @@ -481,7 +481,7 @@ namespace direct_bt { MgmtLoadConnParamCmd(const uint16_t dev_id, std::vector<std::shared_ptr<MgmtConnParam>> connParams) : MgmtCommand(MgmtOpcode::LOAD_CONN_PARAM, dev_id, 2 + connParams.size() * 15) { - size_t offset = MGMT_HEADER_SIZE; + jau::nsize_t offset = MGMT_HEADER_SIZE; pdu.put_uint16_nc(offset, connParams.size()); offset+= 2; for(auto it = connParams.begin(); it != connParams.end(); ++it) { @@ -497,12 +497,12 @@ namespace direct_bt { } uint16_t getParamCount() const noexcept { return pdu.get_uint16_nc(MGMT_HEADER_SIZE); } - const EUI48 getAddress(size_t idx) const { checkParamIdx(idx); return EUI48(pdu.get_ptr(MGMT_HEADER_SIZE + 2 + 15*idx)); } // mgmt_addr_info - BDAddressType getAddressType(size_t idx) const { checkParamIdx(idx); return static_cast<BDAddressType>(pdu.get_uint8(MGMT_HEADER_SIZE + 2 + 15*idx + 6)); } // mgmt_addr_info - uint16_t getMinInterval(size_t idx) const { checkParamIdx(idx); return pdu.get_uint16(MGMT_HEADER_SIZE + 2 + 15*idx + 6 + 1); } - uint16_t getMaxInterval(size_t idx) const { checkParamIdx(idx); return pdu.get_uint16(MGMT_HEADER_SIZE + 2 + 15*idx + 6 + 1 + 2); } - uint16_t getLatency(size_t idx) const { checkParamIdx(idx); return pdu.get_uint16(MGMT_HEADER_SIZE + 2 + 15*idx + 6 + 1 + 2 + 2); } - uint16_t getTimeout(size_t idx) const { checkParamIdx(idx); return pdu.get_uint16(MGMT_HEADER_SIZE + 2 + 15*idx + 6 + 1 + 2 + 2 + 2); } + const EUI48 getAddress(jau::nsize_t idx) const { checkParamIdx(idx); return EUI48(pdu.get_ptr(MGMT_HEADER_SIZE + 2 + 15*idx)); } // mgmt_addr_info + BDAddressType getAddressType(jau::nsize_t idx) const { checkParamIdx(idx); return static_cast<BDAddressType>(pdu.get_uint8(MGMT_HEADER_SIZE + 2 + 15*idx + 6)); } // mgmt_addr_info + uint16_t getMinInterval(jau::nsize_t idx) const { checkParamIdx(idx); return pdu.get_uint16(MGMT_HEADER_SIZE + 2 + 15*idx + 6 + 1); } + uint16_t getMaxInterval(jau::nsize_t idx) const { checkParamIdx(idx); return pdu.get_uint16(MGMT_HEADER_SIZE + 2 + 15*idx + 6 + 1 + 2); } + uint16_t getLatency(jau::nsize_t idx) const { checkParamIdx(idx); return pdu.get_uint16(MGMT_HEADER_SIZE + 2 + 15*idx + 6 + 1 + 2 + 2); } + uint16_t getTimeout(jau::nsize_t idx) const { checkParamIdx(idx); return pdu.get_uint16(MGMT_HEADER_SIZE + 2 + 15*idx + 6 + 1 + 2 + 2 + 2); } }; /** @@ -584,7 +584,7 @@ namespace direct_bt { " "+getOpcodeString()+", devID "+jau::uint16HexString(getDevID(), true); } virtual std::string valueString() const { - const size_t d_sz = getDataSize(); + const jau::nsize_t d_sz = getDataSize(); const std::string d_str = d_sz > 0 ? jau::bytesHexString(getData(), 0, d_sz, true /* lsbFirst */, true /* leading0X */) : ""; return "data[size "+std::to_string(d_sz)+", data "+d_str+"], tsz "+std::to_string(getTotalSize()); } @@ -597,13 +597,13 @@ namespace direct_bt { * Returned memory reference is managed by caller (delete etc) * </p> */ - static std::shared_ptr<MgmtEvent> getSpecialized(const uint8_t * buffer, size_t const buffer_size) noexcept; + static std::shared_ptr<MgmtEvent> getSpecialized(const uint8_t * buffer, jau::nsize_t const buffer_size) noexcept; /** Persistent memory, w/ ownership ..*/ - MgmtEvent(const uint8_t* buffer, const size_t buffer_len, const size_t exp_param_size) + MgmtEvent(const uint8_t* buffer, const jau::nsize_t buffer_len, const jau::nsize_t exp_param_size) : pdu(buffer, buffer_len), ts_creation(jau::getCurrentMilliseconds()) { - const size_t paramSize = getParamSize(); + const jau::nsize_t paramSize = getParamSize(); pdu.check_range(0, MGMT_HEADER_SIZE+paramSize); if( exp_param_size > paramSize ) { throw jau::IndexOutOfBoundsException(exp_param_size, paramSize, E_FILE_LINE); @@ -629,7 +629,7 @@ namespace direct_bt { } virtual ~MgmtEvent() noexcept {} - size_t getTotalSize() const noexcept { return pdu.getSize(); } + jau::nsize_t getTotalSize() const noexcept { return pdu.getSize(); } uint64_t getTimestamp() const noexcept { return ts_creation; } Opcode getOpcode() const noexcept { return static_cast<Opcode>( pdu.get_uint16_nc(0) ); } @@ -637,8 +637,8 @@ namespace direct_bt { uint16_t getDevID() const noexcept { return pdu.get_uint16_nc(2); } uint16_t getParamSize() const noexcept { return pdu.get_uint16_nc(4); } - virtual size_t getDataOffset() const noexcept { return MGMT_HEADER_SIZE; } - virtual size_t getDataSize() const noexcept { return getParamSize(); } + virtual jau::nsize_t getDataOffset() const noexcept { return MGMT_HEADER_SIZE; } + virtual jau::nsize_t getDataSize() const noexcept { return getParamSize(); } virtual const uint8_t* getData() const noexcept { return getDataSize()>0 ? pdu.get_ptr_nc(getDataOffset()) : nullptr; } virtual bool validate(const MgmtCommand &req) const noexcept { @@ -659,7 +659,7 @@ namespace direct_bt { ", status "+jau::uint8HexString(static_cast<uint8_t>(getStatus()), true)+" "+getMgmtStatusString(getStatus()); } - MgmtEvtCmdComplete(const uint8_t* buffer, const size_t buffer_len, const size_t exp_param_size) + MgmtEvtCmdComplete(const uint8_t* buffer, const jau::nsize_t buffer_len, const jau::nsize_t exp_param_size) : MgmtEvent(buffer, buffer_len, 3+exp_param_size) { checkOpcode(getOpcode(), Opcode::CMD_COMPLETE); @@ -671,7 +671,7 @@ namespace direct_bt { return static_cast<MgmtOpcode>( jau::get_uint16(data, MGMT_HEADER_SIZE, true /* littleEndian */) ); } - MgmtEvtCmdComplete(const uint8_t* buffer, const size_t buffer_len) + MgmtEvtCmdComplete(const uint8_t* buffer, const jau::nsize_t buffer_len) : MgmtEvent(buffer, buffer_len, 3) { checkOpcode(getOpcode(), Opcode::CMD_COMPLETE); @@ -682,8 +682,8 @@ namespace direct_bt { MgmtOpcode getReqOpcode() const noexcept { return static_cast<MgmtOpcode>( pdu.get_uint16_nc(MGMT_HEADER_SIZE) ); } MgmtStatus getStatus() const noexcept { return static_cast<MgmtStatus>( pdu.get_uint8_nc(MGMT_HEADER_SIZE+2) ); } - size_t getDataOffset() const noexcept override { return MGMT_HEADER_SIZE+3; } - size_t getDataSize() const noexcept override { return getParamSize()-3; } + jau::nsize_t getDataOffset() const noexcept override { return MGMT_HEADER_SIZE+3; } + jau::nsize_t getDataSize() const noexcept override { return getParamSize()-3; } const uint8_t* getData() const noexcept override { return getDataSize()>0 ? pdu.get_ptr_nc(getDataOffset()) : nullptr; } bool validate(const MgmtCommand &req) const noexcept override { @@ -717,7 +717,7 @@ namespace direct_bt { } public: - MgmtEvtCmdStatus(const uint8_t* buffer, const size_t buffer_len) + MgmtEvtCmdStatus(const uint8_t* buffer, const jau::nsize_t buffer_len) : MgmtEvent(buffer, buffer_len, 3) { checkOpcode(getOpcode(), Opcode::CMD_STATUS); @@ -725,8 +725,8 @@ namespace direct_bt { MgmtOpcode getReqOpcode() const noexcept { return static_cast<MgmtOpcode>( pdu.get_uint16_nc(MGMT_HEADER_SIZE) ); } MgmtStatus getStatus() const noexcept { return static_cast<MgmtStatus>( pdu.get_uint8_nc(MGMT_HEADER_SIZE+2) ); } - size_t getDataOffset() const noexcept override { return MGMT_HEADER_SIZE+3; } - size_t getDataSize() const noexcept override { return 0; } + jau::nsize_t getDataOffset() const noexcept override { return MGMT_HEADER_SIZE+3; } + jau::nsize_t getDataSize() const noexcept override { return 0; } const uint8_t* getData() const noexcept override { return nullptr; } bool validate(const MgmtCommand &req) const noexcept override { @@ -745,7 +745,7 @@ namespace direct_bt { } public: - MgmtEvtDiscovering(const uint8_t* buffer, const size_t buffer_len) + MgmtEvtDiscovering(const uint8_t* buffer, const jau::nsize_t buffer_len) : MgmtEvent(buffer, buffer_len, 2) { checkOpcode(getOpcode(), Opcode::DISCOVERING); @@ -761,8 +761,8 @@ namespace direct_bt { ScanType getScanType() const noexcept { return static_cast<ScanType>( pdu.get_uint8_nc(MGMT_HEADER_SIZE) ); } bool getEnabled() const noexcept { return 0 != pdu.get_uint8_nc(MGMT_HEADER_SIZE+1); } - size_t getDataOffset() const noexcept override { return MGMT_HEADER_SIZE+2; } - size_t getDataSize() const noexcept override { return 0; } + jau::nsize_t getDataOffset() const noexcept override { return MGMT_HEADER_SIZE+2; } + jau::nsize_t getDataSize() const noexcept override { return 0; } const uint8_t* getData() const noexcept override { return nullptr; } }; @@ -779,15 +779,15 @@ namespace direct_bt { } public: - MgmtEvtNewSettings(const uint8_t* buffer, const size_t buffer_len) + MgmtEvtNewSettings(const uint8_t* buffer, const jau::nsize_t buffer_len) : MgmtEvent(buffer, buffer_len, 4) { checkOpcode(getOpcode(), Opcode::NEW_SETTINGS); } AdapterSetting getSettings() const noexcept { return static_cast<AdapterSetting>( pdu.get_uint32_nc(MGMT_HEADER_SIZE) ); } - size_t getDataOffset() const noexcept override { return MGMT_HEADER_SIZE+4; } - size_t getDataSize() const noexcept override { return getParamSize()-4; } + jau::nsize_t getDataOffset() const noexcept override { return MGMT_HEADER_SIZE+4; } + jau::nsize_t getDataSize() const noexcept override { return getParamSize()-4; } const uint8_t* getData() const noexcept override { return getDataSize()>0 ? pdu.get_ptr_nc(getDataOffset()) : nullptr; } }; @@ -813,7 +813,7 @@ namespace direct_bt { } public: - MgmtEvtNewConnectionParam(const uint8_t* buffer, const size_t buffer_len) + MgmtEvtNewConnectionParam(const uint8_t* buffer, const jau::nsize_t buffer_len) : MgmtEvent(buffer, buffer_len, 16) { checkOpcode(getOpcode(), Opcode::NEW_CONN_PARAM); @@ -827,8 +827,8 @@ namespace direct_bt { uint16_t getLatency() const noexcept { return pdu.get_uint16_nc(MGMT_HEADER_SIZE+12); } uint16_t getTimeout() const noexcept { return pdu.get_uint16_nc(MGMT_HEADER_SIZE+14); } - size_t getDataOffset() const noexcept override { return MGMT_HEADER_SIZE+16; } - size_t getDataSize() const noexcept override { return getParamSize()-16; } + jau::nsize_t getDataOffset() const noexcept override { return MGMT_HEADER_SIZE+16; } + jau::nsize_t getDataSize() const noexcept override { return getParamSize()-16; } const uint8_t* getData() const noexcept override { return getDataSize()>0 ? pdu.get_ptr_nc(getDataOffset()) : nullptr; } }; @@ -857,7 +857,7 @@ namespace direct_bt { } public: - MgmtEvtDeviceFound(const uint8_t* buffer, const size_t buffer_len) + MgmtEvtDeviceFound(const uint8_t* buffer, const jau::nsize_t buffer_len) : MgmtEvent(buffer, buffer_len, 14) { checkOpcode(getOpcode(), Opcode::DEVICE_FOUND); @@ -884,8 +884,8 @@ namespace direct_bt { uint32_t getFlags() const noexcept { return pdu.get_uint32_nc(MGMT_HEADER_SIZE+8); } uint16_t getEIRSize() const noexcept { return pdu.get_uint16_nc(MGMT_HEADER_SIZE+12); } - size_t getDataOffset() const noexcept override { return MGMT_HEADER_SIZE+14; } - size_t getDataSize() const noexcept override { return getParamSize()-14; } + jau::nsize_t getDataOffset() const noexcept override { return MGMT_HEADER_SIZE+14; } + jau::nsize_t getDataSize() const noexcept override { return getParamSize()-14; } const uint8_t* getData() const noexcept override { return getDataSize()>0 ? pdu.get_ptr_nc(getDataOffset()) : nullptr; } }; @@ -910,7 +910,7 @@ namespace direct_bt { } public: - MgmtEvtDeviceConnected(const uint8_t* buffer, const size_t buffer_len) + MgmtEvtDeviceConnected(const uint8_t* buffer, const jau::nsize_t buffer_len) : MgmtEvent(buffer, buffer_len, 13), hci_conn_handle(0xffff) { checkOpcode(getOpcode(), Opcode::DEVICE_CONNECTED); @@ -933,8 +933,8 @@ namespace direct_bt { uint32_t getFlags() const noexcept { return pdu.get_uint32_nc(MGMT_HEADER_SIZE+7); } uint16_t getEIRSize() const noexcept { return pdu.get_uint16_nc(MGMT_HEADER_SIZE+11); } - size_t getDataOffset() const noexcept override { return MGMT_HEADER_SIZE+13; } - size_t getDataSize() const noexcept override { return getParamSize()-13; } + jau::nsize_t getDataOffset() const noexcept override { return MGMT_HEADER_SIZE+13; } + jau::nsize_t getDataSize() const noexcept override { return getParamSize()-13; } const uint8_t* getData() const noexcept override { return getDataSize()>0 ? pdu.get_ptr_nc(getDataOffset()) : nullptr; } }; @@ -956,7 +956,7 @@ namespace direct_bt { } public: - MgmtEvtDeviceConnectFailed(const uint8_t* buffer, const size_t buffer_len) + MgmtEvtDeviceConnectFailed(const uint8_t* buffer, const jau::nsize_t buffer_len) : MgmtEvent(buffer, buffer_len, 8), hciStatus(HCIStatusCode::UNKNOWN) { checkOpcode(getOpcode(), Opcode::CONNECT_FAILED); @@ -976,8 +976,8 @@ namespace direct_bt { /** Return the root reason in non reduced HCIStatusCode space, if available. Otherwise this value will be HCIStatusCode::UNKNOWN. */ HCIStatusCode getHCIStatus() const noexcept { return hciStatus; } - size_t getDataOffset() const noexcept override { return MGMT_HEADER_SIZE+8; } - size_t getDataSize() const noexcept override { return getParamSize()-8; } + jau::nsize_t getDataOffset() const noexcept override { return MGMT_HEADER_SIZE+8; } + jau::nsize_t getDataSize() const noexcept override { return getParamSize()-8; } const uint8_t* getData() const noexcept override { return getDataSize()>0 ? pdu.get_ptr_nc(getDataOffset()) : nullptr; } }; @@ -1027,7 +1027,7 @@ namespace direct_bt { } public: - MgmtEvtDeviceDisconnected(const uint8_t* buffer, const size_t buffer_len) + MgmtEvtDeviceDisconnected(const uint8_t* buffer, const jau::nsize_t buffer_len) : MgmtEvent(buffer, buffer_len, 8), hciReason(HCIStatusCode::UNKNOWN), hci_conn_handle(0xffff) { checkOpcode(getOpcode(), Opcode::DEVICE_DISCONNECTED); @@ -1058,8 +1058,8 @@ namespace direct_bt { /** Returns the disconnected HCI connection handle, assuming creation occurred via HCIHandler */ uint16_t getHCIHandle() const noexcept { return hci_conn_handle; } - size_t getDataOffset() const noexcept override { return MGMT_HEADER_SIZE+8; } - size_t getDataSize() const noexcept override { return getParamSize()-8; } + jau::nsize_t getDataOffset() const noexcept override { return MGMT_HEADER_SIZE+8; } + jau::nsize_t getDataSize() const noexcept override { return getParamSize()-8; } const uint8_t* getData() const noexcept override { return getDataSize()>0 ? pdu.get_ptr_nc(getDataOffset()) : nullptr; } }; @@ -1079,7 +1079,7 @@ namespace direct_bt { } public: - MgmtEvtPinCodeRequest(const uint8_t* buffer, const size_t buffer_len) + MgmtEvtPinCodeRequest(const uint8_t* buffer, const jau::nsize_t buffer_len) : MgmtEvent(buffer, buffer_len, 8) { checkOpcode(getOpcode(), Opcode::PIN_CODE_REQUEST); @@ -1089,8 +1089,8 @@ namespace direct_bt { uint8_t getSecure() const noexcept { return pdu.get_uint8_nc(MGMT_HEADER_SIZE+7); } - size_t getDataOffset() const noexcept override { return MGMT_HEADER_SIZE+8; } - size_t getDataSize() const noexcept override { return getParamSize()-8; } + jau::nsize_t getDataOffset() const noexcept override { return MGMT_HEADER_SIZE+8; } + jau::nsize_t getDataSize() const noexcept override { return getParamSize()-8; } const uint8_t* getData() const noexcept override { return getDataSize()>0 ? pdu.get_ptr_nc(getDataOffset()) : nullptr; } }; @@ -1110,7 +1110,7 @@ namespace direct_bt { } public: - MgmtEvtDeviceWhitelistAdded(const uint8_t* buffer, const size_t buffer_len) + MgmtEvtDeviceWhitelistAdded(const uint8_t* buffer, const jau::nsize_t buffer_len) : MgmtEvent(buffer, buffer_len, 8) { checkOpcode(getOpcode(), Opcode::DEVICE_WHITELIST_ADDED); @@ -1120,8 +1120,8 @@ namespace direct_bt { uint8_t getAction() const noexcept { return pdu.get_uint8_nc(MGMT_HEADER_SIZE+7); } - size_t getDataOffset() const noexcept override { return MGMT_HEADER_SIZE+8; } - size_t getDataSize() const noexcept override { return getParamSize()-8; } + jau::nsize_t getDataOffset() const noexcept override { return MGMT_HEADER_SIZE+8; } + jau::nsize_t getDataSize() const noexcept override { return getParamSize()-8; } const uint8_t* getData() const noexcept override { return getDataSize()>0 ? pdu.get_ptr_nc(getDataOffset()) : nullptr; } }; @@ -1137,7 +1137,7 @@ namespace direct_bt { } public: - MgmtEvtAdressInfoMeta(const Opcode opc, const uint8_t* buffer, const size_t buffer_len) + MgmtEvtAdressInfoMeta(const Opcode opc, const uint8_t* buffer, const jau::nsize_t buffer_len) : MgmtEvent(buffer, buffer_len, 7) { checkOpcode(getOpcode(), opc); @@ -1148,8 +1148,8 @@ namespace direct_bt { const EUI48 getAddress() const noexcept { return EUI48(pdu.get_ptr_nc(MGMT_HEADER_SIZE)); } // mgmt_addr_info BDAddressType getAddressType() const noexcept { return static_cast<BDAddressType>(pdu.get_uint8_nc(MGMT_HEADER_SIZE+6)); } // mgmt_addr_info - size_t getDataOffset() const noexcept override { return MGMT_HEADER_SIZE+7; } - size_t getDataSize() const noexcept override { return getParamSize()-7; } + jau::nsize_t getDataOffset() const noexcept override { return MGMT_HEADER_SIZE+7; } + jau::nsize_t getDataSize() const noexcept override { return getParamSize()-7; } const uint8_t* getData() const noexcept override { return getDataSize()>0 ? pdu.get_ptr_nc(getDataOffset()) : nullptr; } }; @@ -1159,7 +1159,7 @@ namespace direct_bt { class MgmtEvtDeviceWhitelistRemoved : public MgmtEvtAdressInfoMeta { public: - MgmtEvtDeviceWhitelistRemoved(const uint8_t* buffer, const size_t buffer_len) + MgmtEvtDeviceWhitelistRemoved(const uint8_t* buffer, const jau::nsize_t buffer_len) : MgmtEvtAdressInfoMeta(Opcode::DEVICE_WHITELIST_REMOVED, buffer, buffer_len) { } }; @@ -1170,7 +1170,7 @@ namespace direct_bt { class MgmtEvtDeviceUnpaired : public MgmtEvtAdressInfoMeta { public: - MgmtEvtDeviceUnpaired(const uint8_t* buffer, const size_t buffer_len) + MgmtEvtDeviceUnpaired(const uint8_t* buffer, const jau::nsize_t buffer_len) : MgmtEvtAdressInfoMeta(Opcode::DEVICE_UNPAIRED, buffer, buffer_len) { } }; @@ -1181,7 +1181,7 @@ namespace direct_bt { class MgmtEvtDeviceBlocked : public MgmtEvtAdressInfoMeta { public: - MgmtEvtDeviceBlocked(const uint8_t* buffer, const size_t buffer_len) + MgmtEvtDeviceBlocked(const uint8_t* buffer, const jau::nsize_t buffer_len) : MgmtEvtAdressInfoMeta(Opcode::DEVICE_BLOCKED, buffer, buffer_len) { } }; @@ -1192,7 +1192,7 @@ namespace direct_bt { class MgmtEvtDeviceUnblocked : public MgmtEvtAdressInfoMeta { public: - MgmtEvtDeviceUnblocked(const uint8_t* buffer, const size_t buffer_len) + MgmtEvtDeviceUnblocked(const uint8_t* buffer, const jau::nsize_t buffer_len) : MgmtEvtAdressInfoMeta(Opcode::DEVICE_UNBLOCKED, buffer, buffer_len) { } }; @@ -1203,7 +1203,7 @@ namespace direct_bt { class MgmtEvtUserPasskeyRequest: public MgmtEvtAdressInfoMeta { public: - MgmtEvtUserPasskeyRequest(const uint8_t* buffer, const size_t buffer_len) + MgmtEvtUserPasskeyRequest(const uint8_t* buffer, const jau::nsize_t buffer_len) : MgmtEvtAdressInfoMeta(Opcode::USER_PASSKEY_REQUEST, buffer, buffer_len) { } }; @@ -1220,10 +1220,10 @@ namespace direct_bt { } public: - static size_t namesDataSize() noexcept { return MgmtConstU16::MGMT_MAX_NAME_LENGTH + MgmtConstU16::MGMT_MAX_SHORT_NAME_LENGTH; } - static size_t getRequiredTotalSize() noexcept { return MGMT_HEADER_SIZE + namesDataSize(); } + static jau::nsize_t namesDataSize() noexcept { return MgmtConstU16::MGMT_MAX_NAME_LENGTH + MgmtConstU16::MGMT_MAX_SHORT_NAME_LENGTH; } + static jau::nsize_t getRequiredTotalSize() noexcept { return MGMT_HEADER_SIZE + namesDataSize(); } - MgmtEvtLocalNameChanged(const uint8_t* buffer, const size_t buffer_len) + MgmtEvtLocalNameChanged(const uint8_t* buffer, const jau::nsize_t buffer_len) : MgmtEvent(buffer, buffer_len, namesDataSize()) { checkOpcode(getOpcode(), Opcode::LOCAL_NAME_CHANGED); @@ -1252,10 +1252,10 @@ namespace direct_bt { } public: - static size_t infoDataSize() noexcept { return 20 + MgmtConstU16::MGMT_MAX_NAME_LENGTH + MgmtConstU16::MGMT_MAX_SHORT_NAME_LENGTH; } - static size_t getRequiredTotalSize() noexcept { return MGMT_HEADER_SIZE + 3 + infoDataSize(); } + static jau::nsize_t infoDataSize() noexcept { return 20 + MgmtConstU16::MGMT_MAX_NAME_LENGTH + MgmtConstU16::MGMT_MAX_SHORT_NAME_LENGTH; } + static jau::nsize_t getRequiredTotalSize() noexcept { return MGMT_HEADER_SIZE + 3 + infoDataSize(); } - MgmtEvtAdapterInfo(const uint8_t* buffer, const size_t buffer_len) + MgmtEvtAdapterInfo(const uint8_t* buffer, const jau::nsize_t buffer_len) : MgmtEvtCmdComplete(buffer, buffer_len, infoDataSize()) { } diff --git a/api/direct_bt/OctetTypes.hpp b/api/direct_bt/OctetTypes.hpp index 7a6cfac2..0e30dc0c 100644 --- a/api/direct_bt/OctetTypes.hpp +++ b/api/direct_bt/OctetTypes.hpp @@ -60,12 +60,12 @@ namespace direct_bt { { private: /** Used memory size <= capacity, maybe zero. */ - size_t _size; + jau::nsize_t _size; /** Non-null memory pointer. Actual capacity known by owner. */ uint8_t * _data; protected: - static inline void checkPtr(uint8_t *d, size_t s) { + 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); } @@ -77,14 +77,14 @@ namespace direct_bt { * @param d a non nullptr memory, otherwise throws exception * @param s used memory size, may be zero */ - inline void setData(uint8_t *d, size_t s) { + 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; } - inline void setSize(size_t s) noexcept { _size = s; } + inline void setSize(jau::nsize_t s) noexcept { _size = s; } public: /** @@ -92,7 +92,7 @@ namespace direct_bt { * @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 size_t len) + TROOctets(const uint8_t *source, const jau::nsize_t len) : _size( len ), _data( const_cast<uint8_t *>(source) ) { checkPtr(_data, _size); } @@ -104,102 +104,102 @@ namespace direct_bt { virtual ~TROOctets() noexcept {} - inline void check_range(const size_t i, const size_t count, const char *file, int line) const { + 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) - inline bool is_range_valid(const size_t i, const size_t count) const noexcept { + inline 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. */ - inline size_t getSize() const noexcept { return _size; } + inline jau::nsize_t getSize() const noexcept { return _size; } - uint8_t get_uint8(const size_t i) const { + uint8_t get_uint8(const jau::nsize_t i) const { check_range(i, 1); return _data[i]; } - inline uint8_t get_uint8_nc(const size_t i) const noexcept { + inline uint8_t get_uint8_nc(const jau::nsize_t i) const noexcept { return _data[i]; } - int8_t get_int8(const size_t i) const { + int8_t get_int8(const jau::nsize_t i) const { check_range(i, 1); return jau::get_int8(_data, i); } - inline int8_t get_int8_nc(const size_t i) const noexcept { + inline int8_t get_int8_nc(const jau::nsize_t i) const noexcept { return jau::get_int8(_data, i); } - uint16_t get_uint16(const size_t i) const { + uint16_t get_uint16(const jau::nsize_t i) const { check_range(i, 2); return jau::get_uint16(_data, i, true /* littleEndian */); } - inline uint16_t get_uint16_nc(const size_t i) const noexcept { + inline 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 size_t i) const { + uint32_t get_uint32(const jau::nsize_t i) const { check_range(i, 4); return jau::get_uint32(_data, i, true /* littleEndian */); } - inline uint32_t get_uint32_nc(const size_t i) const noexcept { + inline uint32_t get_uint32_nc(const jau::nsize_t i) const noexcept { return jau::get_uint32(_data, i, true /* littleEndian */); } - EUI48 get_eui48(const size_t i) const { + EUI48 get_eui48(const jau::nsize_t i) const { check_range(i, sizeof(EUI48)); return EUI48(_data+i); } - inline EUI48 get_eui48_nc(const size_t i) const noexcept { + inline EUI48 get_eui48_nc(const jau::nsize_t i) const noexcept { return EUI48(_data+i); } /** Assumes a null terminated string */ - std::string get_string(const size_t i) const { + 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 */ - inline std::string get_string_nc(const size_t i) const noexcept { + inline 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 */ - std::string get_string(const size_t i, const size_t length) const { + 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 size_t i) const { + uuid16_t get_uuid16(const jau::nsize_t i) const { return uuid16_t(get_uint16(i)); } - inline uuid16_t get_uuid16_nc(const size_t i) const noexcept { + 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 size_t i) const { + uuid128_t get_uuid128(const jau::nsize_t i) const { check_range(i, uuid_t::number(uuid_t::TypeSize::UUID128_SZ)); return uuid128_t(jau::get_uint128(_data, i, true /* littleEndian */)); } - inline uuid128_t get_uuid128_nc(const size_t i) const noexcept { + inline uuid128_t get_uuid128_nc(const jau::nsize_t i) const noexcept { return uuid128_t(jau::get_uint128(_data, i, true /* littleEndian */)); } - std::shared_ptr<const uuid_t> get_uuid(const size_t i, const uuid_t::TypeSize tsize) const { + std::shared_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 */); } inline uint8_t const * get_ptr() const noexcept { return _data; } - uint8_t const * get_ptr(const size_t i) const { + uint8_t const * get_ptr(const jau::nsize_t i) const { check_range(i, 1); return _data + i; } - inline uint8_t const * get_ptr_nc(const size_t i) const noexcept { + inline uint8_t const * get_ptr_nc(const jau::nsize_t i) const noexcept { return _data + i; } @@ -225,7 +225,7 @@ namespace direct_bt { { public: /** Transient passthrough r/w memory, w/o ownership ..*/ - TOctets(uint8_t *source, const size_t len) + TOctets(uint8_t *source, const jau::nsize_t len) : TROOctets(source, len) {} TOctets(const TOctets &o) noexcept = default; @@ -235,86 +235,86 @@ namespace direct_bt { virtual ~TOctets() noexcept override {} - void put_int8(const size_t i, const int8_t v) { + void put_int8(const jau::nsize_t i, const int8_t v) { check_range(i, 1); data()[i] = static_cast<uint8_t>(v); } - void put_int8_nc(const size_t i, const int8_t v) noexcept { + 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 size_t i, const uint8_t v) { + void put_uint8(const jau::nsize_t i, const uint8_t v) { check_range(i, 1); data()[i] = v; } - void put_uint8_nc(const size_t i, const uint8_t v) noexcept { + void put_uint8_nc(const jau::nsize_t i, const uint8_t v) noexcept { data()[i] = v; } - void put_uint16(const size_t i, const uint16_t 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 */); } - void put_uint16_nc(const size_t i, const uint16_t v) noexcept { + 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 size_t i, const uint32_t v) { + void put_uint32(const jau::nsize_t i, const uint32_t v) { check_range(i, 4); jau::put_uint32(data(), i, v, true /* littleEndian */); } - void put_uint32_nc(const size_t i, const uint32_t v) noexcept { + 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 size_t i, const EUI48 & v) { + 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 size_t i, const EUI48 & v) noexcept { + void put_eui48_nc(const jau::nsize_t i, const EUI48 & v) noexcept { memcpy(data() + i, v.b, sizeof(v.b)); } - void put_octets(const size_t i, const TROOctets & v) { + 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 size_t i, const TROOctets & v) noexcept { + void put_octets_nc(const jau::nsize_t i, const TROOctets & v) noexcept { memcpy(data() + i, v.get_ptr(), v.getSize()); } - void put_string(const size_t i, const std::string & v, const size_t max_len, const bool includeEOS) { - const size_t size1 = v.size() + ( includeEOS ? 1 : 0 ); - const size_t size = std::min(size1, max_len); + 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 size_t i, const std::string & v, const size_t max_len, const bool includeEOS) noexcept { - const size_t size1 = v.size() + ( includeEOS ? 1 : 0 ); - const size_t size = std::min(size1, max_len); + 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 size_t i, const uuid_t & v) { + void put_uuid(const jau::nsize_t i, const uuid_t & v) { check_range(i, v.getTypeSizeInt()); direct_bt::put_uuid(data(), i, v, true /* littleEndian */); } - void put_uuid_nc(const size_t i, const uuid_t & v) noexcept { + void put_uuid_nc(const jau::nsize_t i, const uuid_t & v) noexcept { direct_bt::put_uuid(data(), i, v, true /* littleEndian */); } inline uint8_t * get_wptr() noexcept { return data(); } - uint8_t * get_wptr(const size_t i) { + uint8_t * get_wptr(const jau::nsize_t i) { check_range(i, 1); return data() + i; } - uint8_t * get_wptr_nc(const size_t i) noexcept { + uint8_t * get_wptr_nc(const jau::nsize_t i) noexcept { return data() + i; } @@ -327,11 +327,11 @@ namespace direct_bt { { private: const TOctets & parent; - size_t const offset; - size_t const size; + jau::nsize_t const offset; + jau::nsize_t const size; public: - TOctetSlice(const TOctets &buffer_, const size_t offset_, const size_t size_) + 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() ) { @@ -339,28 +339,28 @@ namespace direct_bt { } } - size_t getSize() const noexcept { return size; } - size_t getOffset() const noexcept { return offset; } + jau::nsize_t getSize() const noexcept { return size; } + jau::nsize_t getOffset() const noexcept { return offset; } const TOctets& getParent() const noexcept { return parent; } - uint8_t get_uint8(const size_t i) const { + uint8_t get_uint8(const jau::nsize_t i) const { return parent.get_uint8(offset+i); } - inline uint8_t get_uint8_nc(const size_t i) const noexcept { + inline uint8_t get_uint8_nc(const jau::nsize_t i) const noexcept { return parent.get_uint8_nc(offset+i); } - uint16_t get_uint16(const size_t i) const { + uint16_t get_uint16(const jau::nsize_t i) const { return parent.get_uint16(offset+i); } - inline uint16_t get_uint16_nc(const size_t i) const noexcept { + inline 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 size_t i) const { + uint8_t const * get_ptr(const jau::nsize_t i) const { return parent.get_ptr(offset+i); } - inline uint8_t const * get_ptr_nc(const size_t i) const noexcept { + inline uint8_t const * get_ptr_nc(const jau::nsize_t i) const noexcept { return parent.get_ptr_nc(offset+i); } @@ -378,7 +378,7 @@ namespace direct_bt { class POctets : public TOctets { private: - size_t capacity; + jau::nsize_t capacity; void freeData() { uint8_t * ptr = data(); @@ -388,7 +388,7 @@ namespace direct_bt { } // else: zero sized POctets w/ nullptr are supported } - static uint8_t * allocData(const size_t size) { + static uint8_t * allocData(const jau::nsize_t size) { if( size <= 0 ) { return nullptr; } @@ -401,7 +401,7 @@ namespace direct_bt { public: /** Returns the memory capacity, never zero, greater or equal {@link #getSize()}. */ - inline size_t getCapacity() const noexcept { return capacity; } + inline jau::nsize_t getCapacity() const noexcept { return capacity; } /** Intentional zero sized POctets instance. */ POctets() @@ -411,7 +411,7 @@ namespace direct_bt { } /** Takes ownership (malloc and copy, free) ..*/ - POctets(const uint8_t *_source, const size_t size_) + POctets(const uint8_t *_source, const jau::nsize_t size_) : TOctets( allocData(size_), size_), capacity( size_ ) { @@ -420,7 +420,7 @@ namespace direct_bt { } /** New buffer (malloc, free) */ - POctets(const size_t _capacity, const size_t size_) + POctets(const jau::nsize_t _capacity, const jau::nsize_t size_) : TOctets( allocData(_capacity), size_), capacity( _capacity ) { @@ -431,7 +431,7 @@ namespace direct_bt { } /** New buffer (malloc, free) */ - POctets(const size_t size) + POctets(const jau::nsize_t size) : POctets(size, size) { TRACE_PRINT("POctets ctor3: %p", data()); @@ -524,7 +524,7 @@ namespace direct_bt { return *this; } - POctets & resize(const size_t newSize, const size_t newCapacity) { + 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); } @@ -542,7 +542,7 @@ namespace direct_bt { return *this; } - POctets & resize(const size_t newSize) { + 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); } @@ -550,7 +550,7 @@ namespace direct_bt { return *this; } - POctets & recapacity(const size_t newCapacity) { + 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); } @@ -570,7 +570,7 @@ namespace direct_bt { POctets & operator+=(const TROOctets &b) { if( 0 < b.getSize() ) { - const size_t newSize = getSize() + b.getSize(); + const jau::nsize_t newSize = getSize() + b.getSize(); if( capacity < newSize ) { recapacity( newSize ); } @@ -581,7 +581,7 @@ namespace direct_bt { } POctets & operator+=(const TOctetSlice &b) { if( 0 < b.getSize() ) { - const size_t newSize = getSize() + b.getSize(); + const jau::nsize_t newSize = getSize() + b.getSize(); if( capacity < newSize ) { recapacity( newSize ); } diff --git a/api/direct_bt/UUID.hpp b/api/direct_bt/UUID.hpp index 02adb1e7..407a601f 100644 --- a/api/direct_bt/UUID.hpp +++ b/api/direct_bt/UUID.hpp @@ -52,11 +52,11 @@ extern uuid128_t BT_BASE_UUID; class uuid_t { public: /** Underlying integer value present octet count */ - enum class TypeSize : int { + enum class TypeSize : jau::nsize_t { UUID16_SZ=2, UUID32_SZ=4, UUID128_SZ=16 }; - static constexpr size_t number(const TypeSize rhs) noexcept { - return static_cast<size_t>(rhs); + static constexpr jau::nsize_t number(const TypeSize rhs) noexcept { + return static_cast<jau::nsize_t>(rhs); } private: @@ -66,8 +66,8 @@ protected: uuid_t(TypeSize const type_) : type(type_) {} public: - static TypeSize toTypeSize(const int size); - static std::shared_ptr<const uuid_t> create(TypeSize const t, uint8_t const * const buffer, int const byte_offset, bool const littleEndian); + static TypeSize toTypeSize(const jau::nsize_t size); + static std::shared_ptr<const uuid_t> create(TypeSize const t, uint8_t const * const buffer, jau::nsize_t const byte_offset, bool const littleEndian); virtual ~uuid_t() noexcept {} @@ -86,13 +86,13 @@ public: { return !(*this == o); } TypeSize getTypeSize() const noexcept { return type; } - size_t getTypeSizeInt() const noexcept { return uuid_t::number(type); } + jau::nsize_t getTypeSizeInt() const noexcept { return uuid_t::number(type); } - uuid128_t toUUID128(uuid128_t const & base_uuid=BT_BASE_UUID, int const uuid32_le_octet_index=12) const noexcept; + 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 { return nullptr; } virtual std::string toString() const noexcept { return ""; } - virtual std::string toUUID128String(uuid128_t const & base_uuid=BT_BASE_UUID, int const le_octet_index=12) const noexcept; + virtual std::string toUUID128String(uuid128_t const & base_uuid=BT_BASE_UUID, jau::nsize_t const le_octet_index=12) const noexcept; }; class uuid16_t : public uuid_t { @@ -102,7 +102,7 @@ public: uuid16_t(uint16_t const v) noexcept : uuid_t(TypeSize::UUID16_SZ), value(v) { } - uuid16_t(uint8_t const * const buffer, int const byte_offset, bool const littleEndian) noexcept + 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; @@ -119,7 +119,7 @@ public: 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, int const le_octet_index=12) 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; }; class uuid32_t : public uuid_t { @@ -129,7 +129,7 @@ public: uuid32_t(uint32_t const v) noexcept : uuid_t(TypeSize::UUID32_SZ), value(v) {} - uuid32_t(uint8_t const * const buffer, int const byte_offset, bool const littleEndian) noexcept + 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; @@ -146,7 +146,7 @@ public: 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, int const le_octet_index=12) 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; }; class uuid128_t : public uuid_t { @@ -160,12 +160,12 @@ public: uuid128_t(const std::string str); - uuid128_t(uint8_t const * const buffer, int const byte_offset, bool const littleEndian) noexcept + 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, int const uuid16_le_octet_index=12) noexcept; + 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, int const uuid32_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; @@ -181,14 +181,14 @@ public: 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, int const le_octet_index=12) 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(); } }; -inline void put_uuid(uint8_t * buffer, int const byte_offset, const uuid_t &v) noexcept +inline void put_uuid(uint8_t * buffer, jau::nsize_t const byte_offset, const uuid_t &v) noexcept { switch(v.getTypeSize()) { case uuid_t::TypeSize::UUID16_SZ: @@ -202,7 +202,7 @@ inline void put_uuid(uint8_t * buffer, int const byte_offset, const uuid_t &v) n break; } } -inline void put_uuid(uint8_t * buffer, int const byte_offset, const uuid_t &v, bool littleEndian) noexcept +inline void put_uuid(uint8_t * buffer, jau::nsize_t const byte_offset, const uuid_t &v, bool littleEndian) noexcept { switch(v.getTypeSize()) { case uuid_t::TypeSize::UUID16_SZ: @@ -217,27 +217,27 @@ inline void put_uuid(uint8_t * buffer, int const byte_offset, const uuid_t &v, b } } -inline uuid16_t get_uuid16(uint8_t const * buffer, int const byte_offset) noexcept +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, int const byte_offset, bool littleEndian) noexcept +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, int const byte_offset) noexcept +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, int const byte_offset, bool littleEndian) noexcept +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, int const byte_offset) noexcept +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, int const byte_offset, bool littleEndian) noexcept +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)); } diff --git a/src/direct_bt/ATTPDUTypes.cpp b/src/direct_bt/ATTPDUTypes.cpp index 97f33bfd..295cfe9d 100644 --- a/src/direct_bt/ATTPDUTypes.cpp +++ b/src/direct_bt/ATTPDUTypes.cpp @@ -115,7 +115,7 @@ std::string AttErrorRsp::getPlainErrorString(const ErrorCode errorCode) noexcept return "Error Reserved for future use"; } -std::shared_ptr<const AttPDUMsg> AttPDUMsg::getSpecialized(const uint8_t * buffer, size_t const buffer_size) noexcept { +std::shared_ptr<const AttPDUMsg> AttPDUMsg::getSpecialized(const uint8_t * buffer, jau::nsize_t const buffer_size) noexcept { const uint8_t opc = *buffer; const AttPDUMsg * res; switch( opc ) { diff --git a/src/direct_bt/BTTypes.cpp b/src/direct_bt/BTTypes.cpp index 88b50032..d37b15cf 100644 --- a/src/direct_bt/BTTypes.cpp +++ b/src/direct_bt/BTTypes.cpp @@ -374,7 +374,7 @@ ManufactureSpecificData::ManufactureSpecificData(uint16_t const company_) noexce : company(company_), companyName(std::string(bt_compidtostr(company_))), data(/* intentional zero sized */) { } -ManufactureSpecificData::ManufactureSpecificData(uint16_t const company_, uint8_t const * const data_, size_t const data_len) noexcept +ManufactureSpecificData::ManufactureSpecificData(uint16_t const company_, uint8_t const * const data_, jau::nsize_t const data_len) noexcept : company(company_), companyName(std::string(bt_compidtostr(company_))), data(data_, data_len) { } @@ -696,8 +696,8 @@ int EInfoReport::read_data(uint8_t const * data, uint8_t const data_length) noex return count; } -std::vector<std::shared_ptr<EInfoReport>> EInfoReport::read_ad_reports(uint8_t const * data, size_t const data_length) noexcept { - size_t const num_reports = (size_t) data[0]; +std::vector<std::shared_ptr<EInfoReport>> EInfoReport::read_ad_reports(uint8_t const * data, jau::nsize_t const data_length) noexcept { + jau::nsize_t const num_reports = (jau::nsize_t) data[0]; std::vector<std::shared_ptr<EInfoReport>> ad_reports; if( 0 == num_reports || num_reports > 0x19 ) { @@ -707,9 +707,9 @@ std::vector<std::shared_ptr<EInfoReport>> EInfoReport::read_ad_reports(uint8_t c uint8_t const *limes = data + data_length; uint8_t const *i_octets = data + 1; uint8_t ad_data_len[0x19]; - const size_t segment_count = 6; - size_t read_segments = 0; - size_t i; + const jau::nsize_t segment_count = 6; + jau::nsize_t read_segments = 0; + jau::nsize_t i; const uint64_t timestamp = jau::getCurrentMilliseconds(); for(i = 0; i < num_reports && i_octets < limes; i++) { @@ -742,7 +742,7 @@ std::vector<std::shared_ptr<EInfoReport>> EInfoReport::read_ad_reports(uint8_t c i_octets++; read_segments++; } - const size_t bytes_left = static_cast<size_t>(limes - i_octets); + const jau::nsize_t bytes_left = static_cast<jau::nsize_t>(limes - i_octets); if( segment_count != read_segments ) { WARN_PRINT("AD-Reports: Incomplete %zu reports within %zu bytes: Segment read %zu < %zu, data-ptr %zu bytes to limes\n", diff --git a/src/direct_bt/DBTManager.cpp b/src/direct_bt/DBTManager.cpp index dcff5ea9..111ef4b1 100644 --- a/src/direct_bt/DBTManager.cpp +++ b/src/direct_bt/DBTManager.cpp @@ -89,7 +89,7 @@ void DBTManager::mgmtReaderThreadImpl() noexcept { } while( !mgmtReaderShallStop ) { - ssize_t len; + jau::snsize_t len; if( !comm.isOpen() ) { // not open ERR_PRINT("DBTManager::reader: Not connected"); @@ -99,10 +99,10 @@ void DBTManager::mgmtReaderThreadImpl() noexcept { len = comm.read(rbuffer.get_wptr(), rbuffer.getSize(), env.MGMT_READER_THREAD_POLL_TIMEOUT); if( 0 < len ) { - const size_t len2 = static_cast<size_t>(len); - const size_t paramSize = len2 >= MGMT_HEADER_SIZE ? rbuffer.get_uint16_nc(4) : 0; + const jau::nsize_t len2 = static_cast<jau::nsize_t>(len); + const jau::nsize_t paramSize = len2 >= MGMT_HEADER_SIZE ? rbuffer.get_uint16_nc(4) : 0; if( len2 < MGMT_HEADER_SIZE + paramSize ) { - WARN_PRINT("DBTManager::reader: length mismatch %zu < MGMT_HEADER_SIZE(%zu) + %zu", len2, MGMT_HEADER_SIZE, paramSize); + WARN_PRINT("DBTManager::reader: length mismatch %zu < MGMT_HEADER_SIZE(%u) + %u", len2, MGMT_HEADER_SIZE, paramSize); continue; // discard data } std::shared_ptr<MgmtEvent> event = MgmtEvent::getSpecialized(rbuffer.get_ptr(), len2); @@ -411,7 +411,7 @@ next1: const uint16_t num_adapter = jau::get_uint16(data, 0, true /* littleEndian */); WORDY_PRINT("Bluetooth %d adapter", num_adapter); - const size_t expDataSize = 2 + num_adapter * 2; + const jau::nsize_t expDataSize = 2 + num_adapter * 2; if( res->getDataSize() < expDataSize ) { ERR_PRINT("Insufficient data for %d adapter indices: res %s", num_adapter, res->toString().c_str()); goto fail; diff --git a/src/direct_bt/GATTHandler.cpp b/src/direct_bt/GATTHandler.cpp index 9ab4c31e..977f224c 100644 --- a/src/direct_bt/GATTHandler.cpp +++ b/src/direct_bt/GATTHandler.cpp @@ -198,7 +198,7 @@ void GATTHandler::l2capReaderThreadImpl() { } while( !l2capReaderShallStop ) { - ssize_t len; + jau::snsize_t len; if( !validateConnected() ) { ERR_PRINT("GATTHandler::reader: Invalid IO state -> Stop"); l2capReaderShallStop = true; @@ -207,7 +207,7 @@ void GATTHandler::l2capReaderThreadImpl() { len = l2cap.read(rbuffer.get_wptr(), rbuffer.getSize()); if( 0 < len ) { - std::shared_ptr<const AttPDUMsg> attPDU = AttPDUMsg::getSpecialized(rbuffer.get_ptr(), static_cast<size_t>(len)); + std::shared_ptr<const AttPDUMsg> attPDU = AttPDUMsg::getSpecialized(rbuffer.get_ptr(), static_cast<jau::nsize_t>(len)); const AttPDUMsg::Opcode opc = attPDU->getOpcode(); if( AttPDUMsg::Opcode::ATT_HANDLE_VALUE_NTF == opc ) { @@ -262,7 +262,7 @@ void GATTHandler::l2capReaderThreadImpl() { attPDURing.putBlocking( attPDU ); } } else if( ETIMEDOUT != errno && !l2capReaderShallStop ) { // expected exits - IRQ_PRINT("GATTHandler::reader: l2cap read error -> Stop; l2cap.read %zd", len); + IRQ_PRINT("GATTHandler::reader: l2cap read error -> Stop; l2cap.read %d", len); l2capReaderShallStop = true; has_ioerror = true; } diff --git a/src/direct_bt/GATTNumbers.cpp b/src/direct_bt/GATTNumbers.cpp index 6fec1bd9..80fba5da 100644 --- a/src/direct_bt/GATTNumbers.cpp +++ b/src/direct_bt/GATTNumbers.cpp @@ -347,7 +347,7 @@ const GattCharacteristicSpec * direct_bt::findGattCharSpec(const uint16_t uuid16 /********************************************************/ std::string direct_bt::GattNameToString(const TROOctets &v) noexcept { - const size_t str_len = v.getSize(); + const jau::nsize_t str_len = v.getSize(); if( 0 == str_len ) { return std::string(); // empty } @@ -364,7 +364,7 @@ GattPeriphalPreferredConnectionParameters::GattPeriphalPreferredConnectionParame } std::shared_ptr<GattPeriphalPreferredConnectionParameters> GattPeriphalPreferredConnectionParameters::get(const TROOctets &source) noexcept { - const size_t reqSize = 8; + const jau::nsize_t reqSize = 8; if( source.getSize() < reqSize ) { ERR_PRINT("GattPeriphalPreferredConnectionParameters: Insufficient data, less than %d bytes in %s", reqSize, source.toString().c_str()); return nullptr; @@ -389,7 +389,7 @@ GattPnP_ID::GattPnP_ID(const TROOctets &source) noexcept product_id(source.get_uint16(3)), product_version(source.get_uint16(5)) {} std::shared_ptr<GattPnP_ID> GattPnP_ID::get(const TROOctets &source) noexcept { - const size_t reqSize = 7; + const jau::nsize_t reqSize = 7; if( source.getSize() < reqSize ) { ERR_PRINT("GattPnP_ID: Insufficient data, less than %d bytes in %s", reqSize, source.toString().c_str()); return nullptr; @@ -412,8 +412,8 @@ std::string GattDeviceInformationSvc::toString() const noexcept { } std::shared_ptr<GattTemperatureMeasurement> GattTemperatureMeasurement::get(const TROOctets &source) noexcept { - const size_t size = source.getSize(); - size_t reqSize = 1 + 4; // max size = 13 + const jau::nsize_t size = source.getSize(); + jau::nsize_t reqSize = 1 + 4; // max size = 13 if( reqSize > size ) { // min size: flags + temperatureValue ERR_PRINT("GattTemperatureMeasurement: Insufficient data, less than %d bytes in %s", reqSize, source.toString().c_str()); diff --git a/src/direct_bt/HCIComm.cpp b/src/direct_bt/HCIComm.cpp index a99125e9..34de0752 100644 --- a/src/direct_bt/HCIComm.cpp +++ b/src/direct_bt/HCIComm.cpp @@ -138,8 +138,8 @@ void HCIComm::close() noexcept { DBG_PRINT("HCIComm::close: End: dd %d", socket_descriptor.load()); } -ssize_t HCIComm::read(uint8_t* buffer, const size_t capacity, const int32_t timeoutMS) noexcept { - ssize_t len = 0; +jau::snsize_t HCIComm::read(uint8_t* buffer, const jau::nsize_t capacity, const int32_t timeoutMS) noexcept { + jau::snsize_t len = 0; if( 0 > socket_descriptor ) { goto errout; } @@ -180,9 +180,9 @@ errout: return -1; } -ssize_t HCIComm::write(const uint8_t* buffer, const size_t size) noexcept { +jau::snsize_t HCIComm::write(const uint8_t* buffer, const jau::nsize_t size) noexcept { const std::lock_guard<std::recursive_mutex> lock(mtx_write); // RAII-style acquire and relinquish via destructor - ssize_t len = 0; + jau::snsize_t len = 0; if( 0 > socket_descriptor ) { goto errout; } diff --git a/src/direct_bt/HCIHandler.cpp b/src/direct_bt/HCIHandler.cpp index 017c9155..5caa8d41 100644 --- a/src/direct_bt/HCIHandler.cpp +++ b/src/direct_bt/HCIHandler.cpp @@ -260,7 +260,7 @@ void HCIHandler::hciReaderThreadImpl() noexcept { } while( !hciReaderShallStop ) { - ssize_t len; + jau::snsize_t len; if( !comm.isOpen() ) { // not open ERR_PRINT("HCIHandler::reader: Not connected"); @@ -270,10 +270,10 @@ void HCIHandler::hciReaderThreadImpl() noexcept { len = comm.read(rbuffer.get_wptr(), rbuffer.getSize(), env.HCI_READER_THREAD_POLL_TIMEOUT); if( 0 < len ) { - const size_t len2 = static_cast<size_t>(len); - const size_t paramSize = len2 >= number(HCIConstSizeT::EVENT_HDR_SIZE) ? rbuffer.get_uint8_nc(2) : 0; + const jau::nsize_t len2 = static_cast<jau::nsize_t>(len); + const jau::nsize_t paramSize = len2 >= number(HCIConstSizeT::EVENT_HDR_SIZE) ? rbuffer.get_uint8_nc(2) : 0; if( len2 < number(HCIConstSizeT::EVENT_HDR_SIZE) + paramSize ) { - WARN_PRINT("HCIHandler::reader: length mismatch %zu < EVENT_HDR_SIZE(%zu) + %zu", + WARN_PRINT("HCIHandler::reader: length mismatch %u < EVENT_HDR_SIZE(%u) + %u", len2, number(HCIConstSizeT::EVENT_HDR_SIZE), paramSize); continue; // discard data } diff --git a/src/direct_bt/HCITypes.cpp b/src/direct_bt/HCITypes.cpp index ce334788..4a16e181 100644 --- a/src/direct_bt/HCITypes.cpp +++ b/src/direct_bt/HCITypes.cpp @@ -272,7 +272,7 @@ std::string getHCIMetaEventTypeString(const HCIMetaEventType op) noexcept { return "Unknown HCIMetaType"; } -std::shared_ptr<HCIEvent> HCIEvent::getSpecialized(const uint8_t * buffer, size_t const buffer_size) noexcept { +std::shared_ptr<HCIEvent> HCIEvent::getSpecialized(const uint8_t * buffer, jau::nsize_t const buffer_size) noexcept { const HCIPacketType pc = static_cast<HCIPacketType>( jau::get_uint8(buffer, 0) ); if( HCIPacketType::EVENT != pc ) { return nullptr; diff --git a/src/direct_bt/L2CAPComm.cpp b/src/direct_bt/L2CAPComm.cpp index ca83109e..b3493fc6 100644 --- a/src/direct_bt/L2CAPComm.cpp +++ b/src/direct_bt/L2CAPComm.cpp @@ -215,10 +215,10 @@ bool L2CAPComm::disconnect() noexcept { return true; } -ssize_t L2CAPComm::read(uint8_t* buffer, const size_t capacity) { +jau::snsize_t L2CAPComm::read(uint8_t* buffer, const jau::nsize_t capacity) { const int32_t timeoutMS = env.L2CAP_READER_POLL_TIMEOUT; - ssize_t len = 0; - ssize_t err_res = 0; + jau::snsize_t len = 0; + jau::snsize_t err_res = 0; tid_read = pthread_self(); // temporary safe tid to allow interruption @@ -280,10 +280,10 @@ errout: return err_res; } -ssize_t L2CAPComm::write(const uint8_t * buffer, const size_t length) { +jau::snsize_t L2CAPComm::write(const uint8_t * buffer, const jau::nsize_t length) { const std::lock_guard<std::recursive_mutex> lock(mtx_write); // RAII-style acquire and relinquish via destructor - ssize_t len = 0; - ssize_t err_res = 0; + jau::snsize_t len = 0; + jau::snsize_t err_res = 0; if( 0 > socket_descriptor ) { err_res = -1; // invalid socket_descriptor or capacity diff --git a/src/direct_bt/MgmtTypes.cpp b/src/direct_bt/MgmtTypes.cpp index ee4e15fe..cf37e1d6 100644 --- a/src/direct_bt/MgmtTypes.cpp +++ b/src/direct_bt/MgmtTypes.cpp @@ -230,7 +230,7 @@ std::string MgmtEvent::getOpcodeString(const Opcode opc) noexcept { return "Unknown Opcode"; } -std::shared_ptr<MgmtEvent> MgmtEvent::getSpecialized(const uint8_t * buffer, size_t const buffer_size) noexcept { +std::shared_ptr<MgmtEvent> MgmtEvent::getSpecialized(const uint8_t * buffer, jau::nsize_t const buffer_size) noexcept { const MgmtEvent::Opcode opc = static_cast<MgmtEvent::Opcode>( jau::get_uint16(buffer, 0, true /* littleEndian */) ); MgmtEvent * res; switch( opc ) { @@ -287,7 +287,7 @@ std::shared_ptr<ConnectionInfo> MgmtEvtCmdComplete::toConnectionInfo() const noe ERR_PRINT("No Success: %s", toString().c_str()); return nullptr; } - const size_t min_size = ConnectionInfo::minimumDataSize(); + const jau::nsize_t min_size = ConnectionInfo::minimumDataSize(); if( getDataSize() < min_size ) { ERR_PRINT("Data size < %d: %s", min_size, toString().c_str()); return nullptr; @@ -311,7 +311,7 @@ std::shared_ptr<NameAndShortName> MgmtEvtCmdComplete::toNameAndShortName() const ERR_PRINT("No Success: %s", toString().c_str()); return nullptr; } - const size_t min_size = MgmtEvtLocalNameChanged::namesDataSize(); + const jau::nsize_t min_size = MgmtEvtLocalNameChanged::namesDataSize(); if( getDataSize() < min_size ) { ERR_PRINT("Data size < %d: %s", min_size, toString().c_str()); return nullptr; diff --git a/src/direct_bt/UUID.cpp b/src/direct_bt/UUID.cpp index 5b3a744c..97b2fe81 100644 --- a/src/direct_bt/UUID.cpp +++ b/src/direct_bt/UUID.cpp @@ -35,7 +35,7 @@ static uint8_t bt_base_uuid_be[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB }; uuid128_t direct_bt::BT_BASE_UUID( bt_base_uuid_be, 0, false ); -uuid_t::TypeSize uuid_t::toTypeSize(const int size) { +uuid_t::TypeSize uuid_t::toTypeSize(const jau::nsize_t size) { switch( static_cast<TypeSize>(size) ) { case TypeSize::UUID16_SZ: return TypeSize::UUID16_SZ; case TypeSize::UUID32_SZ: return TypeSize::UUID32_SZ; @@ -44,7 +44,7 @@ uuid_t::TypeSize uuid_t::toTypeSize(const int size) { throw jau::IllegalArgumentException("Given size "+std::to_string(size)+", not matching uuid16_t, uuid32_t or uuid128_t", E_FILE_LINE); } -std::shared_ptr<const uuid_t> uuid_t::create(TypeSize t, uint8_t const * const buffer, int const byte_offset, bool littleEndian) { +std::shared_ptr<const uuid_t> uuid_t::create(TypeSize t, uint8_t const * const buffer, jau::nsize_t const byte_offset, bool littleEndian) { if( TypeSize::UUID16_SZ == t ) { return std::shared_ptr<const uuid_t>(new uuid16_t(buffer, byte_offset, littleEndian)); } else if( TypeSize::UUID32_SZ == t ) { @@ -52,64 +52,64 @@ std::shared_ptr<const uuid_t> uuid_t::create(TypeSize t, uint8_t const * const b } else if( TypeSize::UUID128_SZ == t ) { return std::shared_ptr<const uuid_t>(new uuid128_t(buffer, byte_offset, littleEndian)); } - throw jau::IllegalArgumentException("Unknown Type "+std::to_string(static_cast<int>(t)), E_FILE_LINE); + throw jau::IllegalArgumentException("Unknown Type "+std::to_string(static_cast<jau::nsize_t>(t)), E_FILE_LINE); } -uuid128_t uuid_t::toUUID128(uuid128_t const & base_uuid, int const uuid32_le_octet_index) const noexcept { +uuid128_t uuid_t::toUUID128(uuid128_t const & base_uuid, jau::nsize_t const uuid32_le_octet_index) const noexcept { switch(type) { case TypeSize::UUID16_SZ: return uuid128_t(*((uuid16_t*)this), base_uuid, uuid32_le_octet_index); case TypeSize::UUID32_SZ: return uuid128_t(*((uuid32_t*)this), base_uuid, uuid32_le_octet_index); case TypeSize::UUID128_SZ: return uuid128_t(*((uuid128_t*)this)); } - ABORT("Unknown Type %d", static_cast<int>(type)); + ABORT("Unknown Type %d", static_cast<jau::nsize_t>(type)); abort(); // never reached } -std::string uuid_t::toUUID128String(uuid128_t const & base_uuid, int const le_octet_index) const noexcept { +std::string uuid_t::toUUID128String(uuid128_t const & base_uuid, jau::nsize_t const le_octet_index) const noexcept { (void)base_uuid; (void)le_octet_index; return ""; } -uuid128_t::uuid128_t(uuid16_t const & uuid16, uuid128_t const & base_uuid, int const uuid16_le_octet_index) noexcept +uuid128_t::uuid128_t(uuid16_t const & uuid16, uuid128_t const & base_uuid, jau::nsize_t const uuid16_le_octet_index) noexcept : uuid_t(TypeSize::UUID128_SZ), value(merge_uint128(uuid16.value, base_uuid.value, uuid16_le_octet_index)) {} -uuid128_t::uuid128_t(uuid32_t const & uuid32, uuid128_t const & base_uuid, int const uuid32_le_octet_index) noexcept +uuid128_t::uuid128_t(uuid32_t const & uuid32, uuid128_t const & base_uuid, jau::nsize_t const uuid32_le_octet_index) noexcept : uuid_t(TypeSize::UUID128_SZ), value(merge_uint128(uuid32.value, base_uuid.value, uuid32_le_octet_index)) {} std::string uuid16_t::toString() const noexcept { - const int length = 4; + const jau::nsize_t length = 4; std::string str; str.reserve(length+1); // including EOS for snprintf str.resize(length); - const int count = snprintf(&str[0], str.capacity(), "%.4x", value); + const jau::nsize_t count = snprintf(&str[0], str.capacity(), "%.4x", value); if( length != count ) { ABORT("UUID16 string not of length %d but %d", length, count); } return str; } -std::string uuid16_t::toUUID128String(uuid128_t const & base_uuid, int const le_octet_index) const noexcept +std::string uuid16_t::toUUID128String(uuid128_t const & base_uuid, jau::nsize_t const le_octet_index) const noexcept { uuid128_t u128(*this, base_uuid, le_octet_index); return u128.toString(); } std::string uuid32_t::toString() const noexcept { - const int length = 8; + const jau::nsize_t length = 8; std::string str; str.reserve(length+1); // including EOS for snprintf str.resize(length); - const int count = snprintf(&str[0], str.capacity(), "%.8x", value); + const jau::nsize_t count = snprintf(&str[0], str.capacity(), "%.8x", value); if( length != count ) { ABORT("UUID32 string not of length %d but %d", length, count); } return str; } -std::string uuid32_t::toUUID128String(uuid128_t const & base_uuid, int const le_octet_index) const noexcept +std::string uuid32_t::toUUID128String(uuid128_t const & base_uuid, jau::nsize_t const le_octet_index) const noexcept { uuid128_t u128(*this, base_uuid, le_octet_index); return u128.toString(); @@ -124,7 +124,7 @@ std::string uuid128_t::toString() const noexcept { // BE: low-mem - 87654321-0000-1000-8000-00805F9B34FB - high-mem // 0 1 2 3 4 5 // - const int length = 36; + const jau::nsize_t length = 36; std::string str; str.reserve(length+1); // including EOS for snprintf str.resize(length); @@ -150,7 +150,7 @@ std::string uuid128_t::toString() const noexcept { #else #error "Unexpected __BYTE_ORDER" #endif - const int count = snprintf(&str[0], str.capacity(), "%.8x-%.4x-%.4x-%.4x-%.8x%.4x", + const jau::nsize_t count = snprintf(&str[0], str.capacity(), "%.8x-%.4x-%.4x-%.4x-%.8x%.4x", part0, part1, part2, part3, part4, part5); if( length != count ) { ABORT("UUID128 string not of length %d but %d", length, count); |