Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/NimBLECharacteristic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void NimBLECharacteristic::addDescriptor(NimBLEDescriptor* pDescriptor) {
}

pDescriptor->setCharacteristic(this);
NimBLEDevice::getServer()->serviceChanged();
NimBLEDevice::getServer()->setServiceChanged();
}

/**
Expand All @@ -159,7 +159,7 @@ void NimBLECharacteristic::removeDescriptor(NimBLEDescriptor* pDescriptor, bool
}

pDescriptor->setRemoved(deleteDsc ? NIMBLE_ATT_REMOVE_DELETE : NIMBLE_ATT_REMOVE_HIDE);
NimBLEDevice::getServer()->serviceChanged();
NimBLEDevice::getServer()->setServiceChanged();
} // removeDescriptor

/**
Expand Down
19 changes: 13 additions & 6 deletions src/NimBLEServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ NimBLEService* NimBLEServer::createService(const char* uuid) {
NimBLEService* NimBLEServer::createService(const NimBLEUUID& uuid) {
NimBLEService* pService = new NimBLEService(uuid);
m_svcVec.push_back(pService);
serviceChanged();

setServiceChanged();
return pService;
} // createService

Expand Down Expand Up @@ -187,12 +186,20 @@ NimBLEAdvertising* NimBLEServer::getAdvertising() const {
* @brief Called when the services are added/removed and sets a flag to indicate they should be reloaded.
* @details This has no effect if the GATT server was not already started.
*/
void NimBLEServer::serviceChanged() {
void NimBLEServer::setServiceChanged() {
if (m_gattsStarted) {
m_svcChanged = true;
}
} // serviceChanged

/**
* @brief Send a service changed indication to all clients.
* @details This should be called when services are added, removed or modified after the server has been started.
*/
void NimBLEServer::sendServiceChangedIndication() const {
ble_svc_gatt_changed(0x0001, 0xffff);
}

/**
* @brief Callback for GATT registration events,
* used to obtain the assigned handles for services, characteristics, and descriptors.
Expand Down Expand Up @@ -313,7 +320,7 @@ bool NimBLEServer::start() {
// If the services have changed indicate it now
if (m_svcChanged) {
m_svcChanged = false;
ble_svc_gatt_changed(0x0001, 0xffff);
sendServiceChangedIndication();
}

m_gattsStarted = true;
Expand Down Expand Up @@ -836,7 +843,7 @@ void NimBLEServer::removeService(NimBLEService* service, bool deleteSvc) {
}

service->setRemoved(deleteSvc ? NIMBLE_ATT_REMOVE_DELETE : NIMBLE_ATT_REMOVE_HIDE);
serviceChanged();
setServiceChanged();
# if !MYNEWT_VAL(BLE_EXT_ADV) && MYNEWT_VAL(BLE_ROLE_BROADCASTER)
NimBLEDevice::getAdvertising()->removeServiceUUID(service->getUUID());
# endif
Expand All @@ -863,7 +870,7 @@ void NimBLEServer::addService(NimBLEService* service) {
}

service->setRemoved(0);
serviceChanged();
setServiceChanged();
} // addService

/**
Expand Down
3 changes: 2 additions & 1 deletion src/NimBLEServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class NimBLEServer {
void setDataLen(uint16_t connHandle, uint16_t tx_octets) const;
bool updatePhy(uint16_t connHandle, uint8_t txPhysMask, uint8_t rxPhysMask, uint16_t phyOptions);
bool getPhy(uint16_t connHandle, uint8_t* txPhy, uint8_t* rxPhy);
void serviceChanged();
void sendServiceChangedIndication() const;

# if MYNEWT_VAL(BLE_ROLE_CENTRAL)
NimBLEClient* getClient(uint16_t connHandle);
Expand Down Expand Up @@ -123,6 +123,7 @@ class NimBLEServer {
static int handleGapEvent(struct ble_gap_event* event, void* arg);
static int handleGattEvent(uint16_t connHandle, uint16_t attrHandle, ble_gatt_access_ctxt* ctxt, void* arg);
static void gattRegisterCallback(struct ble_gatt_register_ctxt* ctxt, void* arg);
void setServiceChanged();
bool resetGATT();

bool m_gattsStarted : 1;
Expand Down
4 changes: 2 additions & 2 deletions src/NimBLEService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ void NimBLEService::addCharacteristic(NimBLECharacteristic* pChar) {
}

pChar->setService(this);
getServer()->serviceChanged();
getServer()->setServiceChanged();
} // addCharacteristic

/**
Expand All @@ -272,7 +272,7 @@ void NimBLEService::removeCharacteristic(NimBLECharacteristic* pChar, bool delet
}

pChar->setRemoved(deleteChr ? NIMBLE_ATT_REMOVE_DELETE : NIMBLE_ATT_REMOVE_HIDE);
getServer()->serviceChanged();
getServer()->setServiceChanged();
} // removeCharacteristic

/**
Expand Down