1#ifndef ELEC_C7222_BLE_GATT_SERVICE_HPP_
2#define ELEC_C7222_BLE_GATT_SERVICE_HPP_
148 uint16_t declaration_handle = 0);
163 std::vector<Attribute>&& included_service_declarations,
164 std::list<Characteristic>&& characteristics);
237 return characteristics_;
245 return characteristics_;
462 uint16_t declaration_handle,
463 uint16_t value_handle);
517 auto begin() {
return characteristics_.begin(); }
523 auto end() {
return characteristics_.end(); }
529 [[nodiscard]]
auto begin()
const {
return characteristics_.begin(); }
535 [[nodiscard]]
auto end()
const {
return characteristics_.end(); }
541 [[nodiscard]]
auto cbegin()
const {
return characteristics_.cbegin(); }
547 [[nodiscard]]
auto cend()
const {
return characteristics_.cend(); }
600 uint16_t connection_handle_ = 0;
608 std::list<Characteristic> characteristics_;
616 std::list<Service> included_services_;
626 std::vector<Attribute> included_service_declarations_;
ATT attribute wrapper with BTstack-compatible fields.
Definition attribute.hpp:119
uint16_t GetHandle() const
Get the ATT handle.
Definition attribute.hpp:403
Represents a GATT Characteristic with its declaration, value, and descriptors.
Definition characteristic.hpp:229
Properties
GATT Characteristic Properties as defined in Bluetooth Core Spec.
Definition characteristic.hpp:242
@ kNotify
Characteristic supports notifications.
@ kRead
Characteristic value can be read.
@ kWrite
Characteristic value can be written with response.
@ kIndicate
Characteristic supports indications.
Convenience base that allows move but forbids copy.
Definition non_copyable.hpp:91
Represents a GATT Service with its characteristics and included services.
Definition service.hpp:119
const Characteristic * FindCharacteristicByUuid(const Uuid &uuid) const
Get a characteristic by UUID (const version).
std::list< Characteristic * > FindCharacteristicsWritable() const
Find characteristics that are writable.
Definition service.hpp:319
void ClearIncludedServices()
Remove all included services.
Characteristic * FindCharacteristicByHandle(uint16_t handle)
Get a characteristic that containes the specfied attribute handle.
void SetConnectionHandle(uint16_t connection_handle)
Set the connection handle for all characteristics in this service.
bool IsValid() const
Check if this service is valid.
const Uuid & GetUuid() const
Get the UUID of this service.
Definition service.hpp:212
void ClearCharacteristics()
Remove all characteristics from this service.
const Attribute * FindServiceAttributeByHandle(uint16_t handle) const
Find a service declaration or included service declaration by handle (const version).
auto end() const
Get const iterator to end of characteristics.
Definition service.hpp:535
~Service() override=default
Destructor. Cleans up all managed characteristics and included services.
Service()=delete
Deleted default constructor. A service must have a UUID and type specified.
Service & operator=(Service &&other) noexcept=default
Move assignment operator. Transfers ownership of all internal characteristics and attributes.
bool RemoveCharacteristic(size_t index)
Remove a characteristic by index.
size_t GetCharacteristicCount() const
Get the number of characteristics in this service.
Definition service.hpp:230
uint16_t GetConnectionHandle() const
Get the current connection handle for this service.
Definition service.hpp:430
bool HasCharacteristicsRequiringAuthentication() const
Check whether any characteristic requires authentication.
ServiceType GetServiceType() const
Get the service type (Primary or Secondary).
Definition service.hpp:218
std::list< Characteristic > & GetCharacteristics()
Get the Characteristics object.
Definition service.hpp:244
Characteristic & GetCharacteristic(size_t index)
Get a characteristic by index.
Characteristic & CreateCharacteristic(const Uuid &uuid, uint8_t properties, uint16_t declaration_handle, uint16_t value_handle)
Create and add a new characteristic to this service.
ServiceType
Service type indicators.
Definition service.hpp:129
@ kSecondary
Secondary Service - included in other services, not directly discoverable.
@ kPrimary
Primary Service - top-level service discoverable by clients.
const Characteristic & GetCharacteristic(size_t index) const
Get a characteristic by index (const version).
size_t GetIncludedServiceCount() const
Get the number of included services.
Definition service.hpp:385
auto begin() const
Get const iterator to first characteristic.
Definition service.hpp:529
std::list< Characteristic * > FindCharacteristicsReadable() const
Find characteristics that are readable.
Definition service.hpp:329
Service(Attribute &&declaration_attr, std::vector< Attribute > &&included_service_declarations, std::list< Characteristic > &&characteristics)
Construct a Service by moving parsed attributes.
const Characteristic * FindCharacteristicByHandle(uint16_t handle) const
Get a characteristic that containes the specfied attribute handle (const version).
std::list< Characteristic * > FindCharacteristicsByProperties(Characteristic::Properties properties) const
Find characteristics that include all specified properties.
friend std::ostream & operator<<(std::ostream &os, const Service &service)
Stream insertion operator for service information.
const std::list< Characteristic > & GetCharacteristics() const
Get the list of characteristics in this service.
Definition service.hpp:236
bool HasCharacteristicsRequiringAuthorization() const
Check whether any characteristic requires authorization.
uint16_t GetDeclarationHandle() const
Get the handle of the Declaration attribute.
Definition service.hpp:224
bool Uses128BitUuid() const
Check if this service uses 128-bit UUID.
Definition service.hpp:417
auto cend() const
Get const iterator to end of characteristics.
Definition service.hpp:547
bool RemoveIncludedService(size_t index)
Remove an included service by index.
Attribute * FindServiceAttributeByHandle(uint16_t handle)
Find a service declaration or included service declaration by handle.
auto begin()
Get iterator to first characteristic.
Definition service.hpp:517
Service & GetIncludedService(size_t index)
Get an included service by index.
bool HasCharacteristicsRequiringEncryption() const
Check whether any characteristic requires encrypted link security.
auto end()
Get iterator to end of characteristics.
Definition service.hpp:523
size_t GetIncludedServiceDeclarationCount() const
Get the number of included service declaration attributes.
Definition service.hpp:405
std::list< Characteristic * > FindCharacteristicsNotifiableOrIndicatable() const
Find characteristics that can notify or indicate.
Definition service.hpp:339
Characteristic & AddCharacteristic(Characteristic &&characteristic)
Add a characteristic to this service.
Characteristic * FindCharacteristicByUuid(const Uuid &uuid)
Get a characteristic by UUID.
const Service & GetIncludedService(size_t index) const
Get an included service by index (const version).
void AddIncludedService(const Service &included_service, uint16_t declaration_handle=0)
Add an included service reference.
Service(const Uuid &uuid, ServiceType service_type=ServiceType::kPrimary, uint16_t declaration_handle=0)
Construct a new Service. Creates the service with the given UUID and type.
std::list< Characteristic * > FindCharacteristicsDynamic() const
Find characteristics that use dynamically assigned value handles.
Service(Service &&other) noexcept=default
Move constructor. Transfers ownership of all internal characteristics and attributes.
static std::list< Service > ParseFromAttributes(std::list< Attribute > &attributes)
Parse Services from an ordered attribute list.
auto cbegin() const
Get const iterator to first characteristic.
Definition service.hpp:541
UUID storage for 16-bit and 128-bit UUIDs.
Definition uuid.hpp:53
bool Is128Bit() const
Returns true if this UUID is 128-bit.
C7222 course abstractions namespace.
Definition ble.hpp:20