2424#include " ble/gatt/GattAttribute.h"
2525#include " ble/gatt/GattCallbackParamTypes.h"
2626
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+
2737/* *
2838 * @addtogroup ble
2939 * @{
@@ -1429,6 +1439,11 @@ class GattCharacteristic {
14291439 GattCharacteristic (const GattCharacteristic &) = delete;
14301440 GattCharacteristic& operator =(const GattCharacteristic &) = delete ;
14311441
1442+ ~GattCharacteristic () {
1443+ delete _implicit_cccd;
1444+ _implicit_cccd = nullptr ;
1445+ }
1446+
14321447public:
14331448
14341449 /* *
@@ -1714,7 +1729,7 @@ class GattCharacteristic {
17141729 */
17151730 uint8_t getDescriptorCount () const
17161731 {
1717- return _descriptorCount;
1732+ return (_implicit_cccd == nullptr ? _descriptorCount : _descriptorCount+ 1 ) ;
17181733 }
17191734
17201735 /* *
@@ -1750,16 +1765,45 @@ class GattCharacteristic {
17501765 *
17511766 * @return A pointer the requested descriptor if @p index is within the
17521767 * 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)
17531772 */
17541773 GattAttribute *getDescriptor (uint8_t index)
17551774 {
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) {
17571781 return nullptr ;
17581782 }
17591783
17601784 return _descriptors[index];
17611785 }
17621786
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+
17631807private:
17641808
17651809 /* *
@@ -1783,6 +1827,16 @@ class GattCharacteristic {
17831827 */
17841828 uint8_t _descriptorCount;
17851829
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+
17861840 /* *
17871841 * The registered callback handler for read authorization reply.
17881842 */
0 commit comments