@@ -1429,6 +1429,12 @@ class GattCharacteristic {
1429
1429
GattCharacteristic (const GattCharacteristic &) = delete;
1430
1430
GattCharacteristic& operator =(const GattCharacteristic &) = delete ;
1431
1431
1432
+ ~GattCharacteristic () {
1433
+ if (_implicit_cccd != nullptr ) {
1434
+ delete _implicit_cccd;
1435
+ }
1436
+ }
1437
+
1432
1438
public:
1433
1439
1434
1440
/* *
@@ -1714,7 +1720,7 @@ class GattCharacteristic {
1714
1720
*/
1715
1721
uint8_t getDescriptorCount () const
1716
1722
{
1717
- return _descriptorCount;
1723
+ return (_implicit_cccd == nullptr ? _descriptorCount : _descriptorCount+ 1 ) ;
1718
1724
}
1719
1725
1720
1726
/* *
@@ -1750,16 +1756,40 @@ class GattCharacteristic {
1750
1756
*
1751
1757
* @return A pointer the requested descriptor if @p index is within the
1752
1758
* range of the descriptor array or nullptr otherwise.
1759
+ *
1760
+ * @note if this characteristic has an implicitly-created CCCD this
1761
+ * descriptor will be available at the highest index
1762
+ * (ie: return of getDescriptorCount() - 1)
1753
1763
*/
1754
1764
GattAttribute *getDescriptor (uint8_t index)
1755
1765
{
1756
- if (index >= _descriptorCount) {
1766
+
1767
+ if (index == _descriptorCount) {
1768
+ // If _implicit_cccd is nullptr, we want to return that anyway
1769
+ return _implicit_cccd;
1770
+ }
1771
+ else if (index > _descriptorCount) {
1757
1772
return nullptr ;
1758
1773
}
1759
1774
1760
1775
return _descriptors[index];
1761
1776
}
1762
1777
1778
+ /* *
1779
+ * Sets this GattCharacteristic's implicitly-created CCCD, if
1780
+ * applicable.
1781
+ *
1782
+ * @note once this is called, the pointed-to GattAttribute
1783
+ * is owned by this GattCharacteristic and will be deleted
1784
+ * during this object's destructor
1785
+ *
1786
+ * @note this is an internal function and should not be called
1787
+ * by the application
1788
+ */
1789
+ void _setImplicitCCCD (GattAttribute *implicit_cccd) {
1790
+ _implicit_cccd = implicit_cccd;
1791
+ }
1792
+
1763
1793
private:
1764
1794
1765
1795
/* *
@@ -1783,6 +1813,16 @@ class GattCharacteristic {
1783
1813
*/
1784
1814
uint8_t _descriptorCount;
1785
1815
1816
+ /* *
1817
+ * Pointer to characteristic's implicit CCCD, if applicable
1818
+ *
1819
+ * @note this is only populated if the stack creates an implicit CCCD
1820
+ * for this GattCharacteristic. If the descriptors array passed into
1821
+ * the constructor includes a CCCD this field is left as nullptr to
1822
+ * indicate the CCCD was explicitly created.
1823
+ */
1824
+ GattAttribute* _implicit_cccd;
1825
+
1786
1826
/* *
1787
1827
* The registered callback handler for read authorization reply.
1788
1828
*/
0 commit comments