Skip to content

Commit

Permalink
Retain characteristic handles
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Nov 24, 2024
1 parent 302df2b commit 6d39890
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Sources/NimBLE/GATTServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public struct GATTServer {

var buffers = [[UInt8]]()

var characteristicValueHandles = [[UInt16]]()

/// Callback to handle GATT read requests.
var willRead: ((GATTReadRequest<Central, [UInt8]>) -> ATTError?)?

Expand Down Expand Up @@ -128,6 +130,7 @@ public struct GATTServer {
self.context.pointee.gattServer.characteristicsBuffers = characteristicsBuffers
self.context.pointee.gattServer.buffers = buffers
self.context.pointee.gattServer.services = services
self.context.pointee.gattServer.characteristicValueHandles = valueHandles
// get handles
return valueHandles
}
Expand All @@ -140,10 +143,11 @@ public struct GATTServer {
/// Clears the local GATT database.
public func removeAllServices() {
ble_gatts_reset()
self.context.pointee.gattServer.services.removeAll()
self.context.pointee.gattServer.services.removeAll(keepingCapacity: false)
self.context.pointee.gattServer.buffers.removeAll(keepingCapacity: false)
self.context.pointee.gattServer.services.removeAll(keepingCapacity: false)
self.context.pointee.gattServer.characteristicsBuffers.removeAll(keepingCapacity: false)
self.context.pointee.gattServer.characteristicValueHandles.removeAll(keepingCapacity: false)
}

public func dump() {
Expand Down Expand Up @@ -205,5 +209,5 @@ internal func _ble_gatt_access(
default:
break
}
return BLE_ATT_ERR_UNLIKELY
return 0
}
1 change: 1 addition & 0 deletions Tests/NimBLETests/GATTServerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ struct GATTServerTests {
}
server.dump()
#expect(handles[0][0] == 0x03)
#expect(server.context.pointee.gattServer.characteristic(for: 0x03)?.uuid == .manufacturerNameString)
}
}

0 comments on commit 6d39890

Please sign in to comment.