ELEC-C7222
Libraries for ELEC C7222 Course Work
Loading...
Searching...
No Matches
c7222::Attribute Class Reference

ATT attribute wrapper with BTstack-compatible fields. More...

#include <attribute.hpp>

Inheritance diagram for c7222::Attribute:
Inheritance graph
Collaboration diagram for c7222::Attribute:
Collaboration graph

Public Types

Types
enum class  Properties : std::uint16_t {
  kNone = 0x0000 , kWritePermissionBit0 = 0x0001 , kRead = 0x0002 , kWriteWithoutResponse = 0x0004 ,
  kWrite = 0x0008 , kWritePermissionBit1 = 0x0010 , kReadPermissionSc = 0x0020 , kAuthenticatedSignedWrite = 0x0040 ,
  kWritePermissionSc = 0x0080 , kDynamic = 0x0100 , kUuid128 = 0x0200 , kReadPermissionBit0 = 0x0400 ,
  kReadPermissionBit1 = 0x0800 , kEncryptionKeySizeMask = 0xF000
}
 Attribute flags with direct BTstack ATT_PROPERTY_* mapping. More...
 
using ReadCallback = std::function< uint16_t(uint16_t offset, uint8_t *buffer, uint16_t buffer_size)>
 Callback type for reading attribute value. Parameters: offset, destination buffer, buffer size Returns: number of bytes read, or ATT error code if > 0xfe00.
 
using WriteCallback = std::function< BleError(uint16_t offset, const uint8_t *data, uint16_t size)>
 Callback type for writing attribute value. Parameters: offset, source data, data size Returns: BleError code (BleError::kSuccess = success)
 

Public Member Functions

Construction and Assignment
 Attribute ()=default
 Default-construct an invalid attribute.
 
 Attribute (Attribute &&) noexcept=default
 Move constructor (transfers storage and callbacks).
 
Attributeoperator= (Attribute &&) noexcept=default
 Move assignment operator (transfers storage and callbacks).
 
 Attribute (const Uuid &uuid, uint16_t properties, uint16_t handle=0)
 Construct an attribute with a UUID and properties.
 
 Attribute (const Uuid &uuid, uint16_t properties, const uint8_t *data, size_t size, uint16_t handle=0)
 Construct an attribute with a UUID, properties, and value data.
 
Identity and Matching
uint16_t GetHandle () const
 Get the ATT handle.
 
void SetHandle (uint16_t handle)
 Set the ATT handle.
 
const UuidGetUuid () const
 Get the attribute UUID.
 
bool IsUuid128 () const
 Check if the attribute UUID is 128-bit.
 
bool IsValid () const
 Check if this attribute has a valid handle and UUID.
 
bool IsThisAttribute (const Uuid &uuid) const
 Check if this attribute matches a UUID.
 
bool IsThisAttribute (uint16_t handle) const
 Check if this attribute matches a handle.
 
bool IsThisAttribute (const Uuid &uuid, uint16_t handle) const
 Check if this attribute matches both UUID and handle.
 
Properties
uint16_t GetProperties () const
 Get the properties bitmask of the attribute.
 
void SetProperties (uint16_t properties)
 Set the properties bitmask of the attribute.
 
Value Accessors and Mutators
const std::vector< uint8_t > & GetDynamicValue () const
 Get value as vector (for compatibility). Note: Returns empty for static attributes because they are DB-backed.
 
const uint8_t * GetValueData () const
 Get pointer to attribute value data.
 
size_t GetValueSize () const
 Get size of attribute value.
 
bool SetValue (const uint8_t *data, size_t size)
 Set attribute value. Only allowed for dynamic attributes; static attributes are immutable because their bytes reside in the ATT DB image.
 
bool SetStaticValue (const uint8_t *data, size_t size)
 Set attribute value for static attributes. Copies the data into owned storage and updates the static value pointer.
 
bool SetValue (std::vector< uint8_t > &&data)
 Set attribute value from rvalue vector (move semantics). Only allowed for dynamic attributes.
 
bool SetValue (const std::vector< uint8_t > &data)
 Set attribute value from lvalue vector (copy semantics). Only allowed for dynamic attributes.
 
bool SetStaticValue (const std::vector< uint8_t > &data)
 Set attribute value for static attributes from vector (copy semantics).
 
template<typename T >
bool SetValue (const T &value)
 Set attribute value from a typed value (generic template). Converts any trivial type to bytes and stores as the attribute value. Only allowed for dynamic attributes.
 
Callbacks
void SetReadCallback (ReadCallback callback)
 Set the read callback for this attribute. Called when a remote client reads this attribute.
 
bool HasReadCallback () const
 Check if a read callback is registered.
 
uint16_t InvokeReadCallback (uint16_t offset, uint8_t *buffer, uint16_t buffer_size) const
 Invoke the read callback.
 
void SetWriteCallback (WriteCallback callback)
 Set the write callback for this attribute. Called when a remote client writes this attribute.
 
bool HasWriteCallback () const
 Check if a write callback is registered.
 
BleError InvokeWriteCallback (uint16_t offset, const uint8_t *data, uint16_t size)
 Invoke the write callback.
 
- Public Member Functions inherited from c7222::MovableOnly
virtual ~MovableOnly ()=default
 
 MovableOnly (MovableOnly &&)=default
 
MovableOnlyoperator= (MovableOnly &&)=default
 
 MovableOnly ()=default
 
- Public Member Functions inherited from c7222::NonCopyable
 NonCopyable (const NonCopyable &)=delete
 
NonCopyableoperator= (const NonCopyable &)=delete
 
 NonCopyable (NonCopyable &&)=default
 
NonCopyableoperator= (NonCopyable &&)=default
 

Static Public Member Functions

Attribute Type Checks (Attribute wrappers)

For UUID-only checks, use the corresponding Uuid::Is* helpers.

static bool IsPrimaryServiceDeclaration (const Attribute &attr)
 Check if an attribute is a Primary Service Declaration.
 
static bool IsSecondaryServiceDeclaration (const Attribute &attr)
 Check if an attribute is a Secondary Service Declaration.
 
static bool IsServiceDeclaration (const Attribute &attr)
 Check if an attribute is any Service Declaration (Primary or Secondary).
 
static bool IsIncludedServiceDeclaration (const Attribute &attr)
 Check if an attribute is an Included Service Declaration.
 
static bool IsCharacteristicDeclaration (const Attribute &attr)
 Check if an attribute is a Characteristic Declaration.
 
static bool IsClientCharacteristicConfiguration (const Attribute &attr)
 Check if an attribute is a Client Characteristic Configuration Descriptor.
 
static bool IsServerCharacteristicConfiguration (const Attribute &attr)
 Check if an attribute is a Server Characteristic Configuration Descriptor.
 
static bool IsCharacteristicUserDescription (const Attribute &attr)
 Check if an attribute is a Characteristic User Description.
 
static bool IsCharacteristicExtendedProperties (const Attribute &attr)
 Check if an attribute is a Characteristic Extended Properties descriptor.
 
static bool IsDescriptor (const Attribute &attr)
 Check if an attribute is a descriptor (not declaration or value).
 
Attribute Type Factories
static Attribute PrimaryServiceDeclaration (const Uuid &service_uuid, uint16_t handle=0)
 Create a Primary Service Declaration with a service UUID payload.
 
static Attribute SecondaryServiceDeclaration (const Uuid &service_uuid, uint16_t handle=0)
 Create a Secondary Service Declaration with a service UUID payload.
 
static Attribute IncludedServiceDeclaration (uint16_t start_handle, uint16_t end_handle, const Uuid &service_uuid, uint16_t handle=0)
 Create an Included Service Declaration payload.
 
static Attribute CharacteristicDeclaration (uint8_t properties, uint16_t value_handle, const Uuid &characteristic_uuid, uint16_t handle=0)
 Create a Characteristic Declaration payload.
 
static Attribute ClientCharacteristicConfiguration (uint16_t value, uint16_t handle=0)
 Create a Client Characteristic Configuration with a 16-bit value.
 
static Attribute ServerCharacteristicConfiguration (uint16_t value, uint16_t handle=0)
 Create a Server Characteristic Configuration with a 16-bit value.
 
static Attribute CharacteristicUserDescription (const std::string &description, uint16_t handle=0)
 Create a Characteristic User Description with a UTF-8 string.
 
static Attribute CharacteristicExtendedProperties (uint16_t value, uint16_t handle=0)
 Create a Characteristic Extended Properties with a 16-bit value.
 
static Attribute CharacteristicPresentationFormat (uint8_t format, int8_t exponent, uint16_t unit, uint8_t name_space, uint16_t description, uint16_t handle=0)
 Create a Characteristic Presentation Format payload (0x2904).
 
static Attribute CharacteristicAggregateFormat (const std::vector< uint16_t > &handles, uint16_t handle=0)
 Create a Characteristic Aggregate Format from a list of handles.
 

Friends

Streaming
std::ostream & operator<< (std::ostream &os, const Attribute &attr)
 Stream insertion operator for Attribute. Outputs the attribute handle, UUID, and parsed properties flags.
 

Additional Inherited Members

- Protected Member Functions inherited from c7222::NonCopyable
 NonCopyable ()=default
 
 ~NonCopyable ()=default
 

Detailed Description

ATT attribute wrapper with BTstack-compatible fields.

This class mirrors a single ATT database entry as used by the RP2040 Pico W BLE stack (BTstack). The fields align with BTstack's binary ATT DB layout parsed by the AttributeServer, so the properties_ bitmask and handle_ values can be populated directly from the stack.

Value storage model:

  • Static attributes (no kDynamic flag): keep a pointer/size pair into the ATT DB blob without copying. This matches BTstack, which treats these values as immutable, fixed-at-compile-time data. Avoiding a copy saves RAM and preserves the DB as the single source of truth.
    • Storage: static_value_ptr_ + static_value_size_ point into the ATT DB image parsed by AttributeServer.
    • Mutability: immutable at runtime; SetValue() rejects writes.
    • Access: GetValueData() returns the DB pointer; GetValueSize() returns the DB length.
    • Lifetime: the DB buffer must remain valid for the life of the Attribute; use SetStaticValue() to own a copy.
    • Optional override: SetStaticValue() repoints static_value_ptr_, allowing a controlled, owned static value without toggling kDynamic.
  • Dynamic attributes (kDynamic set): keep a mutable std::vector that can be updated at runtime. Dynamic attributes rely on callbacks and writable storage; copying into a vector provides ownership and resize capability that a DB-backed pointer cannot offer.
    • Storage: dynamic_value_ owns the bytes and can grow/shrink.
    • Mutability: SetValue() and write callbacks may update contents.
    • Access: GetValueData() returns the vector data pointer; size is dynamic_value_.size().
    • Writes: InvokeWriteCallback() stores data even if no write callback is installed; callbacks are optional for dynamic attributes.

Consequence:

  • SetValue() is only valid for dynamic attributes.
  • Remote writes are accepted only through InvokeWriteCallback(). If no write callback is installed for a dynamic attribute, the value is still stored and the write succeeds.

Ownership and moves:

  • The class is move-only (inherits MovableOnly) to avoid accidental copies of pointer-backed/static storage and callback state.

Construction:

  • Provide a Uuid plus a properties bitmask; an optional handle can be supplied (otherwise it defaults to 0 until assigned).
  • Provide a Uuid, properties, and initial value buffer for static data.

Setting flags:

  • Flags are stored as a uint16_t bitmask. Use the Properties enum constants and the provided bitwise operators to combine them.
  • The kUuid128 flag is synchronized automatically based on the Uuid when constructing or calling SetProperties().
  • Permission bits are not enforced by this class; the stack should gate read/write requests before invoking callbacks.

Callback architecture:

  • Read callbacks return uint16_t: byte count on success, or ATT error code (cast from BleError) on failure. This allows reads to dynamically determine how much data to return.
  • Write callbacks return BleError: type-safe error codes ensure correct error handling without manual conversions. Returns BleError::kSuccess on successful write operations.
  • Platform-specific implementations in platform/rpi_pico/ handle BTstack integration; core logic remains platform-independent.

Attribute type helpers:

  • Use Uuid::AttributeType for the standard 16-bit type UUIDs.
  • Use Uuid::Is* helpers when you only have a UUID. This class provides wrappers that accept an Attribute object.

Example:

// Create readable/writable attribute
Attribute attr(Uuid(0x2A37), props);
// Set write callback with BleError return type
attr.SetWriteCallback([](uint16_t offset, const uint8_t* data, uint16_t size) {
// Process write...
return BleError::kSuccess; // Type-safe error handling
});
// Set read callback with uint16_t return (byte count or error)
attr.SetReadCallback([](uint16_t offset, uint8_t* buffer, uint16_t buffer_size) {
// Fill buffer...
return bytes_read; // Return number of bytes read
});
ATT attribute wrapper with BTstack-compatible fields.
Definition attribute.hpp:119
@ kRead
Attribute can be read via ATT Read Request.
@ kWrite
Attribute can be written via Write Request (with response).
UUID storage for 16-bit and 128-bit UUIDs.
Definition uuid.hpp:53
@ kSuccess
Generic HCI status and controller errors.

Dynamic attributes:

  • If kDynamic is set, the attribute uses owned storage and optional callbacks rather than a fixed in-DB value.
  • When a write callback is installed, InvokeWriteCallback() calls the callback first. If it succeeds, dynamic_value_ is updated (when data is provided).

Thread safety:

  • Not thread-safe. External synchronization required for concurrent access.

Member Typedef Documentation

◆ ReadCallback

using c7222::Attribute::ReadCallback = std::function<uint16_t(uint16_t offset, uint8_t* buffer, uint16_t buffer_size)>

Callback type for reading attribute value. Parameters: offset, destination buffer, buffer size Returns: number of bytes read, or ATT error code if > 0xfe00.

◆ WriteCallback

using c7222::Attribute::WriteCallback = std::function<BleError(uint16_t offset, const uint8_t* data, uint16_t size)>

Callback type for writing attribute value. Parameters: offset, source data, data size Returns: BleError code (BleError::kSuccess = success)

Member Enumeration Documentation

◆ Properties

enum class c7222::Attribute::Properties : std::uint16_t
strong

Attribute flags with direct BTstack ATT_PROPERTY_* mapping.

These bits are stored in the ATT DB entry flags field. The layout matches the BTstack att_db.c format used by the Pico W stack.

Enumerator
kNone 

No properties set.

kWritePermissionBit0 

Write permission bit 0 (LSB of a 2-bit write security level). Combined with kWritePermissionBit1 by the stack.

kRead 

Attribute can be read via ATT Read Request.

kWriteWithoutResponse 

Attribute can be written via Write Command (no response).

kWrite 

Attribute can be written via Write Request (with response).

kWritePermissionBit1 

Write permission bit 1 (MSB of a 2-bit write security level). Combined with kWritePermissionBit0 by the stack.

kReadPermissionSc 

Read requires Secure Connections (SC) per BTstack flags.

kAuthenticatedSignedWrite 

Attribute supports Authenticated Signed Write.

kWritePermissionSc 

Write requires Secure Connections (SC) per BTstack flags.

kDynamic 

Value is dynamic (handled by callbacks, not fixed DB storage).

The local dynamic_value_ may be used as a cache, but when no write callback is installed, InvokeWriteCallback() rejects writes for dynamic attrs.

kUuid128 

Entry uses a 128-bit UUID in the ATT DB.

Attribute keeps this bit in sync with the Uuid type.

kReadPermissionBit0 

Read permission bit 0 (LSB of a 2-bit read security level). Combined with kReadPermissionBit1 by the stack.

kReadPermissionBit1 

Read permission bit 1 (MSB of a 2-bit read security level). Combined with kReadPermissionBit0 by the stack.

kEncryptionKeySizeMask 

Mask for encryption key size requirement (bits 12-15).

The stack encodes the required key size in the upper nibble.

Constructor & Destructor Documentation

◆ Attribute() [1/4]

c7222::Attribute::Attribute ( )
default

Default-construct an invalid attribute.

Use the UUID/properties constructors or the factory helpers to create usable attributes.

◆ Attribute() [2/4]

c7222::Attribute::Attribute ( Attribute &&  )
defaultnoexcept

Move constructor (transfers storage and callbacks).

◆ Attribute() [3/4]

c7222::Attribute::Attribute ( const Uuid uuid,
uint16_t  properties,
uint16_t  handle = 0 
)

Construct an attribute with a UUID and properties.

◆ Attribute() [4/4]

c7222::Attribute::Attribute ( const Uuid uuid,
uint16_t  properties,
const uint8_t *  data,
size_t  size,
uint16_t  handle = 0 
)

Construct an attribute with a UUID, properties, and value data.

Static attributes store a pointer/size into the ATT DB buffer; dynamic attributes copy the data into owned storage so it can be mutated.

Member Function Documentation

◆ CharacteristicAggregateFormat()

static Attribute c7222::Attribute::CharacteristicAggregateFormat ( const std::vector< uint16_t > &  handles,
uint16_t  handle = 0 
)
static

Create a Characteristic Aggregate Format from a list of handles.

Note
This factory synthesizes the payload in memory and therefore returns an Attribute with dynamic-backed owned storage.

◆ CharacteristicDeclaration()

static Attribute c7222::Attribute::CharacteristicDeclaration ( uint8_t  properties,
uint16_t  value_handle,
const Uuid characteristic_uuid,
uint16_t  handle = 0 
)
static

Create a Characteristic Declaration payload.

Parameters
propertiesCharacteristic properties byte (GATT characteristic properties)
value_handleHandle of the characteristic value attribute
characteristic_uuidCharacteristic UUID (16-bit or 128-bit)
handleOptional attribute handle (0 = auto-assign)
Note
This factory synthesizes the payload in memory and therefore returns an Attribute with dynamic-backed owned storage.

◆ CharacteristicExtendedProperties()

static Attribute c7222::Attribute::CharacteristicExtendedProperties ( uint16_t  value,
uint16_t  handle = 0 
)
static

Create a Characteristic Extended Properties with a 16-bit value.

Note
This factory synthesizes the payload in memory and therefore returns an Attribute with dynamic-backed owned storage.

◆ CharacteristicPresentationFormat()

static Attribute c7222::Attribute::CharacteristicPresentationFormat ( uint8_t  format,
int8_t  exponent,
uint16_t  unit,
uint8_t  name_space,
uint16_t  description,
uint16_t  handle = 0 
)
static

Create a Characteristic Presentation Format payload (0x2904).

Note
This factory synthesizes the payload in memory and therefore returns an Attribute with dynamic-backed owned storage.

◆ CharacteristicUserDescription()

static Attribute c7222::Attribute::CharacteristicUserDescription ( const std::string &  description,
uint16_t  handle = 0 
)
static

Create a Characteristic User Description with a UTF-8 string.

Note
This factory synthesizes the payload in memory and therefore returns an Attribute with dynamic-backed owned storage.

◆ ClientCharacteristicConfiguration()

static Attribute c7222::Attribute::ClientCharacteristicConfiguration ( uint16_t  value,
uint16_t  handle = 0 
)
static

Create a Client Characteristic Configuration with a 16-bit value.

◆ GetDynamicValue()

const std::vector< uint8_t > & c7222::Attribute::GetDynamicValue ( ) const
inline

Get value as vector (for compatibility). Note: Returns empty for static attributes because they are DB-backed.

◆ GetHandle()

uint16_t c7222::Attribute::GetHandle ( ) const
inline

Get the ATT handle.

Returns
Attribute handle (0 if unassigned)
Here is the caller graph for this function:

◆ GetProperties()

uint16_t c7222::Attribute::GetProperties ( ) const
inline

Get the properties bitmask of the attribute.

Returns
Properties bitmask
Here is the caller graph for this function:

◆ GetUuid()

const Uuid & c7222::Attribute::GetUuid ( ) const
inline

Get the attribute UUID.

Returns
Reference to the UUID identifying this attribute type

◆ GetValueData()

const uint8_t * c7222::Attribute::GetValueData ( ) const
inline

Get pointer to attribute value data.

Returns
Pointer to value data, or nullptr if no value
Note
Static attributes return the ATT DB pointer; dynamic attributes return the owned vector data pointer.

◆ GetValueSize()

size_t c7222::Attribute::GetValueSize ( ) const
inline

Get size of attribute value.

Returns
Size of value in bytes
Note
Mirrors the storage choice: DB size for static, vector size for dynamic.

◆ HasReadCallback()

bool c7222::Attribute::HasReadCallback ( ) const
inline

Check if a read callback is registered.

Returns
true if read callback is set

◆ HasWriteCallback()

bool c7222::Attribute::HasWriteCallback ( ) const
inline

Check if a write callback is registered.

Returns
true if write callback is set

◆ IncludedServiceDeclaration()

static Attribute c7222::Attribute::IncludedServiceDeclaration ( uint16_t  start_handle,
uint16_t  end_handle,
const Uuid service_uuid,
uint16_t  handle = 0 
)
static

Create an Included Service Declaration payload.

Parameters
start_handleFirst attribute handle of the included service
end_handleLast attribute handle of the included service
service_uuidIncluded service UUID (16-bit or 128-bit)
handleOptional attribute handle (0 = auto-assign)
Note
This factory synthesizes the payload in memory and therefore returns an Attribute with dynamic-backed owned storage.

◆ InvokeReadCallback()

uint16_t c7222::Attribute::InvokeReadCallback ( uint16_t  offset,
uint8_t *  buffer,
uint16_t  buffer_size 
) const

Invoke the read callback.

Parameters
offsetOffset into the attribute value
bufferDestination buffer for data
buffer_sizeSize of destination buffer
Returns
Number of bytes read, or error code
Note
Implemented in src/attribute.cpp; falls back to stored value if no callback.

◆ InvokeWriteCallback()

BleError c7222::Attribute::InvokeWriteCallback ( uint16_t  offset,
const uint8_t *  data,
uint16_t  size 
)

Invoke the write callback.

Parameters
offsetOffset into the attribute value
dataSource data to write
sizeNumber of bytes to write
Returns
BleError code (BleError::kSuccess = success)
Note
Platform-independent implementation in src/attribute.cpp
For dynamic attributes, the callback (if installed) runs first. On success, the data is stored. If no callback is set, the write stores the data and succeeds. If the callback returns an error, the value is restored.

◆ IsCharacteristicDeclaration()

static bool c7222::Attribute::IsCharacteristicDeclaration ( const Attribute attr)
static

Check if an attribute is a Characteristic Declaration.

Parameters
attrAttribute to check
Returns
true if the attribute UUID matches the Characteristic Declaration type

◆ IsCharacteristicExtendedProperties()

static bool c7222::Attribute::IsCharacteristicExtendedProperties ( const Attribute attr)
static

Check if an attribute is a Characteristic Extended Properties descriptor.

Parameters
attrAttribute to check
Returns
true if the attribute UUID matches Extended Properties type

◆ IsCharacteristicUserDescription()

static bool c7222::Attribute::IsCharacteristicUserDescription ( const Attribute attr)
static

Check if an attribute is a Characteristic User Description.

Parameters
attrAttribute to check
Returns
true if the attribute UUID matches User Description type

◆ IsClientCharacteristicConfiguration()

static bool c7222::Attribute::IsClientCharacteristicConfiguration ( const Attribute attr)
static

Check if an attribute is a Client Characteristic Configuration Descriptor.

Parameters
attrAttribute to check
Returns
true if the attribute UUID matches CCCD type

◆ IsDescriptor()

static bool c7222::Attribute::IsDescriptor ( const Attribute attr)
static

Check if an attribute is a descriptor (not declaration or value).

Parameters
attrAttribute to check
Returns
true if the attribute is a known descriptor type

◆ IsIncludedServiceDeclaration()

static bool c7222::Attribute::IsIncludedServiceDeclaration ( const Attribute attr)
static

Check if an attribute is an Included Service Declaration.

Parameters
attrAttribute to check
Returns
true if the attribute UUID matches the Included Service Declaration type

◆ IsPrimaryServiceDeclaration()

static bool c7222::Attribute::IsPrimaryServiceDeclaration ( const Attribute attr)
static

Check if an attribute is a Primary Service Declaration.

Parameters
attrAttribute to check
Returns
true if the attribute UUID matches the Primary Service Declaration type

◆ IsSecondaryServiceDeclaration()

static bool c7222::Attribute::IsSecondaryServiceDeclaration ( const Attribute attr)
static

Check if an attribute is a Secondary Service Declaration.

Parameters
attrAttribute to check
Returns
true if the attribute UUID matches the Secondary Service Declaration type

◆ IsServerCharacteristicConfiguration()

static bool c7222::Attribute::IsServerCharacteristicConfiguration ( const Attribute attr)
static

Check if an attribute is a Server Characteristic Configuration Descriptor.

Parameters
attrAttribute to check
Returns
true if the attribute UUID matches SCCD type

◆ IsServiceDeclaration()

static bool c7222::Attribute::IsServiceDeclaration ( const Attribute attr)
static

Check if an attribute is any Service Declaration (Primary or Secondary).

Parameters
attrAttribute to check
Returns
true if the attribute UUID matches either service declaration type

◆ IsThisAttribute() [1/3]

bool c7222::Attribute::IsThisAttribute ( const Uuid uuid) const
inline

Check if this attribute matches a UUID.

Parameters
uuidUUID to compare
Returns
true if UUIDs match

◆ IsThisAttribute() [2/3]

bool c7222::Attribute::IsThisAttribute ( const Uuid uuid,
uint16_t  handle 
) const
inline

Check if this attribute matches both UUID and handle.

Parameters
uuidUUID to compare
handleAttribute handle to compare
Returns
true if both UUID and handle match

◆ IsThisAttribute() [3/3]

bool c7222::Attribute::IsThisAttribute ( uint16_t  handle) const
inline

Check if this attribute matches a handle.

Parameters
handleAttribute handle to compare
Returns
true if handles match and handle != 0

◆ IsUuid128()

bool c7222::Attribute::IsUuid128 ( ) const
inline

Check if the attribute UUID is 128-bit.

Returns
true for 128-bit UUIDs, false for 16-bit
Here is the call graph for this function:

◆ IsValid()

bool c7222::Attribute::IsValid ( ) const
inline

Check if this attribute has a valid handle and UUID.

Here is the call graph for this function:

◆ operator=()

Attribute & c7222::Attribute::operator= ( Attribute &&  )
defaultnoexcept

Move assignment operator (transfers storage and callbacks).

◆ PrimaryServiceDeclaration()

static Attribute c7222::Attribute::PrimaryServiceDeclaration ( const Uuid service_uuid,
uint16_t  handle = 0 
)
static

Create a Primary Service Declaration with a service UUID payload.

Note
This factory synthesizes the payload in memory and therefore returns an Attribute with dynamic-backed owned storage.

◆ SecondaryServiceDeclaration()

static Attribute c7222::Attribute::SecondaryServiceDeclaration ( const Uuid service_uuid,
uint16_t  handle = 0 
)
static

Create a Secondary Service Declaration with a service UUID payload.

Note
This factory synthesizes the payload in memory and therefore returns an Attribute with dynamic-backed owned storage.

◆ ServerCharacteristicConfiguration()

static Attribute c7222::Attribute::ServerCharacteristicConfiguration ( uint16_t  value,
uint16_t  handle = 0 
)
static

Create a Server Characteristic Configuration with a 16-bit value.

◆ SetHandle()

void c7222::Attribute::SetHandle ( uint16_t  handle)
inline

Set the ATT handle.

Parameters
handleNew handle assigned by the stack or builder

◆ SetProperties()

void c7222::Attribute::SetProperties ( uint16_t  properties)
inline

Set the properties bitmask of the attribute.

Parameters
propertiesNew properties bitmask

◆ SetReadCallback()

void c7222::Attribute::SetReadCallback ( ReadCallback  callback)
inline

Set the read callback for this attribute. Called when a remote client reads this attribute.

Parameters
callbackFunction to handle reads

◆ SetStaticValue() [1/2]

bool c7222::Attribute::SetStaticValue ( const std::vector< uint8_t > &  data)

Set attribute value for static attributes from vector (copy semantics).

Parameters
dataConst reference to vector (copied into static storage)
Returns
true if value was set, false if rejected (dynamic attribute)

◆ SetStaticValue() [2/2]

bool c7222::Attribute::SetStaticValue ( const uint8_t *  data,
size_t  size 
)

Set attribute value for static attributes. Copies the data into owned storage and updates the static value pointer.

Parameters
dataPointer to value data
sizeSize of value in bytes
Returns
true if value was set, false if rejected (dynamic attribute)

◆ SetValue() [1/4]

bool c7222::Attribute::SetValue ( const std::vector< uint8_t > &  data)

Set attribute value from lvalue vector (copy semantics). Only allowed for dynamic attributes.

Parameters
dataConst reference to vector (copied into internal storage)
Returns
true if value was set, false if rejected (static attribute)

◆ SetValue() [2/4]

template<typename T >
bool c7222::Attribute::SetValue ( const T &  value)
inline

Set attribute value from a typed value (generic template). Converts any trivial type to bytes and stores as the attribute value. Only allowed for dynamic attributes.

Template Parameters
TMust be a trivial type (primitive types, arrays, small structs)
Parameters
valueThe value to store
Returns
true if value was set, false if rejected (static attribute)
Note
Uses binary representation; for endian-sensitive types, ensure consistency
Example
SetValue(0x1234) stores as bytes {0x34, 0x12} (little-endian).
Here is the call graph for this function:

◆ SetValue() [3/4]

bool c7222::Attribute::SetValue ( const uint8_t *  data,
size_t  size 
)

Set attribute value. Only allowed for dynamic attributes; static attributes are immutable because their bytes reside in the ATT DB image.

Parameters
dataPointer to value data
sizeSize of value in bytes
Returns
true if value was set, false if rejected (static attribute)
Here is the caller graph for this function:

◆ SetValue() [4/4]

bool c7222::Attribute::SetValue ( std::vector< uint8_t > &&  data)

Set attribute value from rvalue vector (move semantics). Only allowed for dynamic attributes.

Parameters
dataRvalue reference to vector (ownership transferred via move)
Returns
true if value was set, false if rejected (static attribute)

◆ SetWriteCallback()

void c7222::Attribute::SetWriteCallback ( WriteCallback  callback)
inline

Set the write callback for this attribute. Called when a remote client writes this attribute.

Parameters
callbackFunction to handle writes

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const Attribute attr 
)
friend

Stream insertion operator for Attribute. Outputs the attribute handle, UUID, and parsed properties flags.


The documentation for this class was generated from the following file: