Skip to content

Commit

Permalink
updated for latest Swift 3.0 syntax and ignored CommandDisallowed err…
Browse files Browse the repository at this point in the history
…or for Enabling Bluetooth
  • Loading branch information
colemancda committed Jun 12, 2016
1 parent 49ec887 commit 24913a3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
24 changes: 12 additions & 12 deletions Sources/BluetoothLinux/ATTConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public final class ATTConnection {
}

/// Registers a callback for an opcode and returns the ID associated with that callback.
public func register<T: ATTProtocolDataUnit>(_ callback: T -> ()) -> UInt {
public func register<T: ATTProtocolDataUnit>(_ callback: (T) -> ()) -> UInt {

let identifier = nextRegisterID

Expand Down Expand Up @@ -204,7 +204,7 @@ public final class ATTConnection {
}

/// Sends an error.
public func send(error: ATT.Error, opcode: ATTOpcode, handle: UInt16 = 0, response: (ATTErrorResponse -> ())? = nil) -> UInt? {
public func send(error: ATT.Error, opcode: ATTOpcode, handle: UInt16 = 0, response: ((ATTErrorResponse) -> ())? = nil) -> UInt? {

let error = ATTErrorResponse(requestOpcode: opcode, attributeHandle: handle, error: error)

Expand All @@ -214,7 +214,7 @@ public final class ATTConnection {
/// Adds a PDU to the queue to send.
///
/// - Returns: Identifier of queued send operation or `nil` if the PDU cannot be sent.
public func send<T: ATTProtocolDataUnit>(PDU: T, response: T -> ()) -> UInt? {
public func send<T: ATTProtocolDataUnit>(PDU: T, response: (T) -> ()) -> UInt? {

let attributeOpcode = T.attributeOpcode

Expand Down Expand Up @@ -373,7 +373,7 @@ public final class ATTConnection {

let errorResponse = ATTErrorResponse(requestOpcode: opcode, attributeHandle: 0x00, error: .RequestNotSupported)

send(PDU: errorResponse) { _ in }
let _ = send(PDU: errorResponse) { _ in }
}

}
Expand Down Expand Up @@ -429,7 +429,7 @@ private protocol ATTSendOpcodeType {

var data: [UInt8] { get }

var callback: ATTProtocolDataUnit -> () { get }
var callback: (ATTProtocolDataUnit) -> () { get }
}

private struct ATTSendOpcode<PDU: ATTProtocolDataUnit>: ATTSendOpcodeType {
Expand All @@ -440,11 +440,11 @@ private struct ATTSendOpcode<PDU: ATTProtocolDataUnit>: ATTSendOpcodeType {

let data: [UInt8]

let response: PDU -> ()
let response: (PDU) -> ()

var callback: ATTProtocolDataUnit -> () { return { self.response($0 as! PDU) } }
var callback: (ATTProtocolDataUnit) -> () { return { self.response($0 as! PDU) } }

init(identifier: UInt, opcode: ATT.Opcode, data: [UInt8], response: PDU -> ()) {
init(identifier: UInt, opcode: ATT.Opcode, data: [UInt8], response: (PDU) -> ()) {

self.identifier = identifier
self.data = data
Expand All @@ -458,7 +458,7 @@ private protocol ATTNotifyType {

var identifier: UInt { get }

var callback: ATTProtocolDataUnit -> () { get }
var callback: (ATTProtocolDataUnit) -> () { get }
}

private struct ATTNotify<PDU: ATTProtocolDataUnit>: ATTNotifyType {
Expand All @@ -467,11 +467,11 @@ private struct ATTNotify<PDU: ATTProtocolDataUnit>: ATTNotifyType {

let identifier: UInt

let notify: PDU -> ()
let notify: (PDU) -> ()

var callback: ATTProtocolDataUnit -> () { return { self.notify($0 as! PDU) } }
var callback: (ATTProtocolDataUnit) -> () { return { self.notify($0 as! PDU) } }

init(identifier: UInt, notify: PDU -> ()) {
init(identifier: UInt, notify: (PDU) -> ()) {

self.identifier = identifier
self.notify = notify
Expand Down
30 changes: 15 additions & 15 deletions Sources/BluetoothLinux/GATTServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public final class GATTServer {

// MARK: - Properties

public var log: (String -> ())?
public var log: ((String) -> ())?

public var database = GATTDatabase()

Expand Down Expand Up @@ -63,40 +63,40 @@ public final class GATTServer {
private func registerATTHandlers() {

// Exchange MTU
connection.register(exchangeMTU)
let _ = connection.register(exchangeMTU)

// Read By Group Type
connection.register(readByGroupType)
let _ = connection.register(readByGroupType)

// Read By Type
connection.register(readByType)
let _ = connection.register(readByType)

// Find Information
connection.register(findInformation)
let _ = connection.register(findInformation)

// Find By Type Value
connection.register(findByTypeValue)
let _ = connection.register(findByTypeValue)

// Write Request
connection.register(writeRequest)
let _ = connection.register(writeRequest)

// Write Command
connection.register(writeCommand)
let _ = connection.register(writeCommand)

// Read Request
connection.register(readRequest)
let _ = connection.register(readRequest)

// Read Blob Request
connection.register(readBlobRequest)
let _ = connection.register(readBlobRequest)

// Read Multiple Request
connection.register(readMultipleRequest)
let _ = connection.register(readMultipleRequest)

// Prepare Write Request
connection.register(prepareWriteRequest)
let _ = connection.register(prepareWriteRequest)

// Execute Write Request
connection.register(executeWriteRequest)
let _ = connection.register(executeWriteRequest)
}

@inline(__always)
Expand All @@ -113,7 +113,7 @@ public final class GATTServer {

errorResponse(opcode, ATT.Error.UnlikelyError, handle)

do { try connection.write() }
do { let _ = try connection.write() }

catch { print("Could not send UnlikelyError to client. (\(error))") }

Expand Down Expand Up @@ -272,7 +272,7 @@ public final class GATTServer {
let finalMTU = max(min(pdu.clientMTU, serverMTU), UInt16(ATT.MTU.LowEnergy.Default))

// Respond with the server MTU
connection.send(PDU: ATTMaximumTranssmissionUnitResponse(serverMTU: serverMTU)) { _ in }
let _ = connection.send(PDU: ATTMaximumTranssmissionUnitResponse(serverMTU: serverMTU)) { _ in }

// Set MTU to minimum
connection.maximumTransmissionUnit = Int(finalMTU)
Expand Down
3 changes: 2 additions & 1 deletion Sources/BluetoothLinux/iBeacon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public extension Adapter {
//print("Enabling Advertising")

// start advertising
try enableAdvertising(timeout: commandTimeout)
do { try enableAdvertising(timeout: commandTimeout) }
catch HCIError.CommandDisallowed { /* ignore, means already turned on */ }

//print("Setting iBeacon Data")

Expand Down
2 changes: 1 addition & 1 deletion Sources/GATTServerTest/GATTServerTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private func generateDB() -> GATTDatabase {

for service in TestProfile.services {

database.add(service: service)
let _ = database.add(service: service)
}

return database
Expand Down

0 comments on commit 24913a3

Please sign in to comment.