24
24
#include " ble/gatt/GattAttribute.h"
25
25
#include " ble/gatt/GattCallbackParamTypes.h"
26
26
27
+ // Forward declare ble::impl::GattServer
28
+ namespace ble {
29
+
30
+ #if !defined(DOXYGEN_ONLY)
31
+ namespace impl {
32
+ class GattServer ;
33
+ }
34
+ #endif // !defined(DOXYGEN_ONLY)
35
+ }
36
+
27
37
/* *
28
38
* @addtogroup ble
29
39
* @{
@@ -1429,6 +1439,11 @@ class GattCharacteristic {
1429
1439
GattCharacteristic (const GattCharacteristic &) = delete;
1430
1440
GattCharacteristic& operator =(const GattCharacteristic &) = delete ;
1431
1441
1442
+ ~GattCharacteristic () {
1443
+ delete _implicit_cccd;
1444
+ _implicit_cccd = nullptr ;
1445
+ }
1446
+
1432
1447
public:
1433
1448
1434
1449
/* *
@@ -1714,7 +1729,7 @@ class GattCharacteristic {
1714
1729
*/
1715
1730
uint8_t getDescriptorCount () const
1716
1731
{
1717
- return _descriptorCount;
1732
+ return (_implicit_cccd == nullptr ? _descriptorCount : _descriptorCount+ 1 ) ;
1718
1733
}
1719
1734
1720
1735
/* *
@@ -1750,16 +1765,45 @@ class GattCharacteristic {
1750
1765
*
1751
1766
* @return A pointer the requested descriptor if @p index is within the
1752
1767
* range of the descriptor array or nullptr otherwise.
1768
+ *
1769
+ * @note if this characteristic has an implicitly-created CCCD this
1770
+ * descriptor will be available at the highest index
1771
+ * (ie: return of getDescriptorCount() - 1)
1753
1772
*/
1754
1773
GattAttribute *getDescriptor (uint8_t index)
1755
1774
{
1756
- if (index >= _descriptorCount) {
1775
+
1776
+ if (index == _descriptorCount) {
1777
+ // If _implicit_cccd is nullptr, we want to return that anyway
1778
+ return _implicit_cccd;
1779
+ }
1780
+ else if (index > _descriptorCount) {
1757
1781
return nullptr ;
1758
1782
}
1759
1783
1760
1784
return _descriptors[index];
1761
1785
}
1762
1786
1787
+
1788
+ private:
1789
+
1790
+ friend ble::impl::GattServer;
1791
+
1792
+ #if !defined(DOXYGEN_ONLY)
1793
+ /* *
1794
+ * Sets this GattCharacteristic's implicitly-created CCCD, if
1795
+ * applicable.
1796
+ *
1797
+ * @note once this is called, the pointed-to GattAttribute
1798
+ * is owned by this GattCharacteristic and will be deleted
1799
+ * during this object's destructor
1800
+ */
1801
+ void setImplicitCCCD (GattAttribute *implicit_cccd) {
1802
+ _implicit_cccd = implicit_cccd;
1803
+ }
1804
+ #endif // !defined(DOXYGEN_ONLY)
1805
+
1806
+
1763
1807
private:
1764
1808
1765
1809
/* *
@@ -1783,6 +1827,16 @@ class GattCharacteristic {
1783
1827
*/
1784
1828
uint8_t _descriptorCount;
1785
1829
1830
+ /* *
1831
+ * Pointer to characteristic's implicit CCCD, if applicable
1832
+ *
1833
+ * @note this is only populated if the stack creates an implicit CCCD
1834
+ * for this GattCharacteristic. If the descriptors array passed into
1835
+ * the constructor includes a CCCD this field is left as nullptr to
1836
+ * indicate the CCCD was explicitly created.
1837
+ */
1838
+ GattAttribute* _implicit_cccd = nullptr ;
1839
+
1786
1840
/* *
1787
1841
* The registered callback handler for read authorization reply.
1788
1842
*/
0 commit comments