Skip to content

Commit

Permalink
Renamed Address to BluetoothAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Nov 18, 2018
1 parent 07c6f9b commit 6b52198
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Sources/BluetoothLinux/HCI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ internal struct HCIDeviceInformation {
var name: (CChar, CChar, CChar, CChar, CChar, CChar, CChar, CChar) = (0, 0, 0, 0, 0, 0, 0, 0)

/// bdaddr_t bdaddr;
var address: Address = Address()
var address: BluetoothAddress = BluetoothAddress()

/// uint32_t flags;
var flags: UInt32 = 0
Expand Down
16 changes: 7 additions & 9 deletions Sources/BluetoothLinux/HostController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public final class HostController: BluetoothHostControllerInterface {
public let identifier: Identifier

/// The Bluetooth Address of the controller.
public let address: Address
public let address: BluetoothAddress

// MARK: - Internal Properties

Expand All @@ -44,12 +44,12 @@ public final class HostController: BluetoothHostControllerInterface {
public init(identifier: Identifier) throws {

self.identifier = identifier
self.address = try Address(deviceIdentifier: identifier)
self.address = try BluetoothAddress(deviceIdentifier: identifier)
self.internalSocket = try HCIOpenDevice(identifier)
}

/// Initializes the Bluetooth controller with the specified address.
public init(address: Address) throws {
public init(address: BluetoothAddress) throws {

guard let deviceIdentifier = try HCIGetRoute(address)
else { throw Error.adapterNotFound }
Expand Down Expand Up @@ -90,7 +90,7 @@ public extension HostController {

// MARK: - Address Extensions

public extension Address {
public extension BluetoothAddress {

/// Extracts the Bluetooth address from the device ID.
///
Expand Down Expand Up @@ -200,7 +200,7 @@ internal func HCIIdentifierOfDevice(_ flagFilter: HCIDeviceFlag = HCIDeviceFlag(
return result
}

internal func HCIGetRoute(_ address: Address? = nil) throws -> UInt16? {
internal func HCIGetRoute(_ address: BluetoothAddress? = nil) throws -> UInt16? {

return try HCIIdentifierOfDevice { (dd, deviceIdentifier) in

Expand Down Expand Up @@ -238,7 +238,7 @@ internal func HCIDeviceInfo(_ deviceIdentifier: UInt16) throws -> HCIDeviceInfor
return deviceInfo
}

internal func HCIDeviceAddress(_ deviceIdentifier: UInt16) throws -> Address {
internal func HCIDeviceAddress(_ deviceIdentifier: UInt16) throws -> BluetoothAddress {

let deviceInfo = try HCIDeviceInfo(deviceIdentifier)

Expand Down Expand Up @@ -275,7 +275,5 @@ internal func HCITestBit(_ flag: HCI.DeviceFlag, _ options: UInt32) -> Bool {
// MARK: - Darwin Stubs

#if os(OSX) || os(iOS)

var SOCK_CLOEXEC: CInt { stub() }

var SOCK_CLOEXEC: CInt { stub() }
#endif
18 changes: 9 additions & 9 deletions Sources/BluetoothLinux/L2CAP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public final class L2CAPSocket: L2CAPSocketProtocol {
}

/// Create a new L2CAP socket on the HostController with the specified identifier.
public init(controllerAddress: Address,
public init(controllerAddress: BluetoothAddress,
protocolServiceMultiplexer: UInt16 = 0,
channelIdentifier: UInt16 = ATT.CID,
addressType: AddressType? = .lowEnergyPublic,
Expand Down Expand Up @@ -71,7 +71,7 @@ public final class L2CAPSocket: L2CAPSocketProtocol {
}

/// Creates a server socket for an L2CAP connection.
public static func lowEnergyServer(controllerAddress: Address = .any,
public static func lowEnergyServer(controllerAddress: BluetoothAddress = .any,
isRandom: Bool = false,
securityLevel: SecurityLevel = .low) throws -> L2CAPSocket {

Expand All @@ -87,8 +87,8 @@ public final class L2CAPSocket: L2CAPSocketProtocol {
}

/// Creates a client socket for an L2CAP connection.
public static func lowEnergyClient(controllerAddress: Address = .any,
destination: (address: Address, type: AddressType),
public static func lowEnergyClient(controllerAddress: BluetoothAddress = .any,
destination: (address: BluetoothAddress, type: AddressType),
securityLevel: SecurityLevel = .low) throws -> L2CAPSocket {

let socket = try L2CAPSocket(controllerAddress: controllerAddress,
Expand Down Expand Up @@ -128,7 +128,7 @@ public final class L2CAPSocket: L2CAPSocketProtocol {

/// Create the underlying socket for the L2CAP.
@inline(__always)
private static func createSocket(controllerAddress: Address,
private static func createSocket(controllerAddress: BluetoothAddress,
protocolServiceMultiplexer: UInt16,
channelIdentifier: UInt16,
addressType: AddressType?) throws -> (CInt, sockaddr_l2) {
Expand Down Expand Up @@ -164,9 +164,9 @@ public final class L2CAPSocket: L2CAPSocketProtocol {
// MARK: - Accessors

/// Bluetooth address
public var address: Address {
public var address: BluetoothAddress {

return Address(littleEndian: internalAddress.l2_bdaddr)
return BluetoothAddress(littleEndian: internalAddress.l2_bdaddr)
}

public var addressType: AddressType {
Expand Down Expand Up @@ -240,7 +240,7 @@ public final class L2CAPSocket: L2CAPSocketProtocol {
}

/// Connect to another L2CAP server.
public func openConnection(to address: Address,
public func openConnection(to address: BluetoothAddress,
type addressType: AddressType = .lowEnergyPublic) throws {

// Set up destination address
Expand Down Expand Up @@ -415,7 +415,7 @@ let L2CAP_OPTIONS: CInt = 0x01
struct sockaddr_l2 {
var l2_family: sa_family_t = 0
var l2_psm: CUnsignedShort = 0
var l2_bdaddr: Address = .zero
var l2_bdaddr: BluetoothAddress = .zero
var l2_cid: CUnsignedShort = 0
var l2_bdaddr_type: UInt8 = 0
init() { }
Expand Down
2 changes: 1 addition & 1 deletion Sources/BluetoothLinux/Scan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public extension HostController {
public struct InquiryResult {

/// Device Address
public var address = Address()
public var address = BluetoothAddress()

public var pscanRepMode: UInt8 = 0

Expand Down

0 comments on commit 6b52198

Please sign in to comment.