@@ -53,6 +53,7 @@ NimBLEService::NimBLEService(const NimBLEUUID &uuid, uint16_t numHandles, NimBLE
53
53
m_pSvcDef = nullptr ;
54
54
m_removed = 0 ;
55
55
m_secondary = false ;
56
+ m_pSecSvcDef = nullptr ;
56
57
57
58
} // NimBLEService
58
59
@@ -71,6 +72,13 @@ NimBLEService::~NimBLEService() {
71
72
delete (m_pSvcDef);
72
73
}
73
74
75
+ if (m_pSecSvcDef != nullptr ) {
76
+ for (auto &it : m_secSvcVec) {
77
+ delete it;
78
+ }
79
+ delete m_pSecSvcDef;
80
+ }
81
+
74
82
for (auto &it : m_chrVec) {
75
83
delete it;
76
84
}
@@ -223,6 +231,19 @@ bool NimBLEService::start() {
223
231
// end of services must indicate to api with type = 0
224
232
svc[1 ].type = 0 ;
225
233
m_pSvcDef = svc;
234
+
235
+ if (m_secSvcVec.size () > 0 ){
236
+ size_t numSecSvcs = m_secSvcVec.size ();
237
+ ble_gatt_svc_def** m_pSecSvcDef = new ble_gatt_svc_def*[numSecSvcs + 1 ];
238
+ int i = 0 ;
239
+ for (auto & it : m_secSvcVec) {
240
+ it->start ();
241
+ m_pSecSvcDef[i] = it->m_pSvcDef ;
242
+ ++i;
243
+ }
244
+ m_pSecSvcDef[numSecSvcs] = nullptr ;
245
+ m_pSvcDef->includes = (const ble_gatt_svc_def**)m_pSecSvcDef;
246
+ }
226
247
}
227
248
228
249
int rc = ble_gatts_count_cfg ((const ble_gatt_svc_def*)m_pSvcDef);
@@ -235,13 +256,6 @@ bool NimBLEService::start() {
235
256
if (rc != 0 ) {
236
257
NIMBLE_LOGE (LOG_TAG, " ble_gatts_add_svcs, rc= %d, %s" , rc, NimBLEUtils::returnCodeToString (rc));
237
258
return false ;
238
-
239
- }
240
-
241
- if (m_secSvcVec.size () > 0 ){
242
- for (auto & it : m_secSvcVec) {
243
- it->start ();
244
- }
245
259
}
246
260
247
261
NIMBLE_LOGD (LOG_TAG, " << start()" );
0 commit comments