Skip to content

Add NimBLEServer::sendServiceChangedIndication#409

Merged
h2zero merged 1 commit intomasterfrom
send-svc-changed
Mar 24, 2026
Merged

Add NimBLEServer::sendServiceChangedIndication#409
h2zero merged 1 commit intomasterfrom
send-svc-changed

Conversation

@h2zero
Copy link
Owner

@h2zero h2zero commented Mar 22, 2026

This reverts changing NimBLEServer::serviceChanged from private to public and adds a new function that is more user firendly to indicate to clients that the services should be re-discovered.

  • Renames serviceChanged to setServiceChanged to better indicate its function.

Summary by CodeRabbit

  • Refactor
    • Public API for service-change notifications reorganized: emission is now a separate, const-safe operation while marking a change is handled internally.
    • Internal callers updated to use the new internal mark mechanism.
    • Notification emission centralized so notifications are sent from a single, consistent code path.

@coderabbitai
Copy link

coderabbitai bot commented Mar 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6189f328-11fc-4306-a60e-ac42490c5490

📥 Commits

Reviewing files that changed from the base of the PR and between d5148d3 and 98b379d.

📒 Files selected for processing (4)
  • src/NimBLECharacteristic.cpp
  • src/NimBLEServer.cpp
  • src/NimBLEServer.h
  • src/NimBLEService.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/NimBLEServer.cpp

📝 Walkthrough

Walkthrough

Arrr — Public serviceChanged() was replaced: a private setServiceChanged() now marks the change and a new public const sendServiceChangedIndication() emits the BLE service-changed indication; callers updated and start() clears the flag and uses the new emitter (≤50 words).

Changes

Cohort / File(s) Summary
Server API & impl
src/NimBLEServer.h, src/NimBLEServer.cpp
Renamed public serviceChanged() → private setServiceChanged(); added public sendServiceChangedIndication() const; start() now clears m_svcChanged and calls sendServiceChangedIndication() instead of calling ble_svc_gatt_changed(...) inline.
Service behavior callers
src/NimBLEService.cpp
Calls updated to use getServer()->setServiceChanged() when characteristics are added/removed.
Characteristic behavior callers
src/NimBLECharacteristic.cpp
Calls updated to use NimBLEDevice::getServer()->setServiceChanged() when descriptors are added/removed.

Sequence Diagram(s)

sequenceDiagram
    participant Characteristic as Characteristic
    participant Service as Service
    participant Server as NimBLEServer
    participant BLE as BLE_Stack

    Note over Characteristic,Service: On add/remove descriptor/characteristic
    Characteristic->>Server: setServiceChanged()
    Service->>Server: setServiceChanged()
    Server->>Server: set m_svcChanged = true

    Note over Server,BLE: On server start
    Server->>Server: if m_svcChanged then clear flag
    Server->>BLE: sendServiceChangedIndication() \n(ble_svc_gatt_changed(0x0001,0xffff))
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

Yarrr — a flag now set in secret keep,
A new, brave horn to wake the deep,
Old name sunk where shadows sleep,
BLE tides shift, the waters creep 🏴‍☠️

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main addition to the PR: a new public method sendServiceChangedIndication() that encapsulates the service-changed indication logic.
Docstring Coverage ✅ Passed Docstring coverage is 90.91% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch send-svc-changed

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/NimBLEServer.h (1)

126-126: Ahoy: consider renamin’ the private helper for clearer intent.

Now that the public API changed, a name like markServiceChanged() would better signal that this one sets internal state, notifies none.

🏴‍☠️ Optional refactor sketch
-    void        serviceChanged();
+    void        markServiceChanged();
-void NimBLEServer::serviceChanged() {
+void NimBLEServer::markServiceChanged() {
     if (m_gattsStarted) {
         m_svcChanged = true;
     }
-} // serviceChanged
+} // markServiceChanged
-    serviceChanged();
+    markServiceChanged();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/NimBLEServer.h` at line 126, The private helper currently named
serviceChanged() should be renamed to markServiceChanged() to clarify it only
sets internal state and does not notify; update the declaration in the
NimBLEServer class (serviceChanged -> markServiceChanged), rename the
corresponding definition/implementation to markServiceChanged, and update every
call site that invokes serviceChanged() to call markServiceChanged() instead;
ensure visibility (private) and any forward declarations or tests are updated to
use the new name.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/NimBLEServer.h`:
- Line 126: The private helper currently named serviceChanged() should be
renamed to markServiceChanged() to clarify it only sets internal state and does
not notify; update the declaration in the NimBLEServer class (serviceChanged ->
markServiceChanged), rename the corresponding definition/implementation to
markServiceChanged, and update every call site that invokes serviceChanged() to
call markServiceChanged() instead; ensure visibility (private) and any forward
declarations or tests are updated to use the new name.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 99c99f9d-828f-4878-84cc-b2273a56364b

📥 Commits

Reviewing files that changed from the base of the PR and between bc6bb98 and 602daf3.

📒 Files selected for processing (2)
  • src/NimBLEServer.cpp
  • src/NimBLEServer.h

@h2zero h2zero force-pushed the send-svc-changed branch from 602daf3 to d5148d3 Compare March 22, 2026 21:24
@h2zero h2zero changed the title Add NimBLEServer::sendServiceChangeIndication Add NimBLEServer::sendServiceChangedIndication Mar 22, 2026
This reverts changing NimBLEServer::serviceChanged from private to public and adds a new function that is more user firendly to indicate to clients that the services should be re-discovered.

* Renames serviceChanged to setServiceChanged to better indicate its function.
@h2zero h2zero force-pushed the send-svc-changed branch from d5148d3 to 98b379d Compare March 22, 2026 21:48
Copy link
Contributor

@chmorgan chmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sendServiceChangedIndication() looks good, and the flag for sending it at startup seems like the right approach although I'm not sure I have a good use case to test it.

@h2zero h2zero merged commit 74443d9 into master Mar 24, 2026
66 checks passed
@h2zero h2zero deleted the send-svc-changed branch March 24, 2026 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants