Skip to content

Commit

Permalink
Updated for Swift 4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Oct 30, 2018
1 parent 80360e4 commit d123f40
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 27 deletions.
39 changes: 17 additions & 22 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
// swift-tools-version:4.1
import PackageDescription

let package = Package(
name: "BluetoothLinux",
targets: [
Target(
name: "BluetoothLinux",
_ = Package(name: "BluetoothLinux",
products: [
.library(
name: "BluetoothLinux",
targets: ["BluetoothLinux"]
)
],
dependencies: [
.Target(name: "CSwiftBluetoothLinux")
]),
Target(
name: "CSwiftBluetoothLinux"),
Target(
name: "CSwiftBluetoothLinuxTest"),
Target(
name: "BluetoothLinuxTests",
dependencies: [
.Target(name: "BluetoothLinux"),
.Target(name: "CSwiftBluetoothLinuxTest")
])
],
dependencies: [
.Package(url: "https://github.com/PureSwift/Bluetooth.git", majorVersion: 2)
]
)
.package(url: "https://github.com/PureSwift/Bluetooth.git", .branch("master"))
],
targets: [
.target(name: "BluetoothLinux", dependencies: ["Bluetooth", "CSwiftBluetoothLinux"]),
.target(name: "CSwiftBluetoothLinux"),
.target(name: "CSwiftBluetoothLinuxTest"),
.testTarget(name: "BluetoothLinuxTests", dependencies: ["BluetoothLinux", "CSwiftBluetoothLinuxTest"])
],
swiftLanguageVersions: [4])
4 changes: 2 additions & 2 deletions Sources/BluetoothLinux/HostController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public extension HostController {

return try HCIRequestDeviceList { (_, list) in

list.sorted(by: { $0.0.identifier < $0.1.identifier })
list.sorted(by: { $0.identifier < $1.identifier })
.filter { HCITestBit(.up, $0.options) && $0.identifier >= 0 }
.flatMap { try? HostController(identifier: $0.identifier) }
.compactMap { try? HostController(identifier: $0.identifier) }
}
}

Expand Down
8 changes: 6 additions & 2 deletions Sources/BluetoothLinux/IOCTL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ internal struct IOC {
static func IOC(_ direction: CUnsignedInt, _ type: CInt, _ nr: CInt, _ size: CInt) -> CUnsignedLong {

let dir = CInt(direction)

return CUnsignedLong(bitPattern: CLong(((dir) << DIRSHIFT) | ((type) << TYPESHIFT) | ((nr) << NRSHIFT) | ((size) << SIZESHIFT)))
let dirValue = dir << DIRSHIFT
let typeValue = type << TYPESHIFT
let nrValue = nr << NRSHIFT
let sizeValue = size << SIZESHIFT
let value = CLong(dirValue | typeValue | nrValue | sizeValue)
return CUnsignedLong(bitPattern: value)
}

@inline(__always)
Expand Down
34 changes: 34 additions & 0 deletions Sources/BluetoothLinux/POSIXError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// POSIXError.swift
// SwiftFoundation
//
// Created by Alsey Coleman Miller on 7/22/15.
// Copyright © 2015 PureSwift. All rights reserved.
//

import Foundation

internal extension POSIXError {

/// Creates error from C ```errno```.
static var fromErrno: POSIXError? {

guard let code = POSIXError.Code(rawValue: POSIXError.Code.RawValue(errno))
else { return nil }

return self.init(code: code)
}

/// Creates `POSIXError` from error code.
init(code: POSIXError.Code) {

let nsError = NSError(
domain: NSPOSIXErrorDomain,
code: Int(code.rawValue),
userInfo: [
NSLocalizedDescriptionKey: String(cString: strerror(CInt(code.rawValue)), encoding: .ascii)!
])

self.init(_nsError: nsError)
}
}
2 changes: 1 addition & 1 deletion Sources/BluetoothLinux/Scan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ internal func HCIInquiry(_ deviceIdentifier: UInt16,

let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: bufferSize)

defer { buffer.deallocate(capacity: bufferSize) }
defer { buffer.deallocate() }

let deviceClass = deviceClass ?? (0x33, 0x8b, 0x9e)

Expand Down

0 comments on commit d123f40

Please sign in to comment.