Skip to content

Commit

Permalink
Initial Swift support
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviermartin committed May 18, 2024
1 parent 0d2d629 commit e459f76
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
.vscode/

# Generated files
.build
build
__pycache__
MANIFEST.in
dist
gattlib-py/gattlib_py.egg-info/

# Python
/venv*
23 changes: 23 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// swift-tools-version: 5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "Gattlib",
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "Gattlib",
targets: ["Gattlib"]),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(name: "Gattlib", path: "swift/Gattlib"),
.executableTarget(
name: "GattlibExample",
dependencies: [ "Gattlib" ],
path: "swift/GattlibExample"),
]
)
125 changes: 125 additions & 0 deletions swift/Gattlib/Gattlib.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import Foundation

public typealias dispatch_queue_t = Any

public let CBCentralManagerScanOptionAllowDuplicatesKey = "CBCentralManagerScanOptionAllowDuplicatesKey"
public let CBAdvertisementDataLocalNameKey = "CBAdvertisementDataLocalNameKey"

public enum CBCharacteristicWriteType {
case withResponse
case withoutResponse
}

public class CBUUID : Equatable {
let uuid: UUID?

public init(string: String) {
self.uuid = UUID(uuidString: string)
}

public static func == (left: CBUUID, right: CBUUID) -> Bool {
return left.uuid == right.uuid
}
}

public class CBManager {
public enum CBManagerState {
case poweredOn
case poweredOff
case unsupported
case resetting
case unauthorized
case unknown
}
public var state: CBManagerState

init(state: CBManagerState) {
self.state = state
}
}

public class CBPeer : Equatable {
public var identifier: UUID

init(identifier: UUID) {
self.identifier = identifier
}

public static func == (left: CBPeer, right: CBPeer) -> Bool {
return left.identifier == right.identifier
}
}

public class CBAttribute {
public var uuid: CBUUID

init(uuid: CBUUID) {
self.uuid = uuid
}
}

public class CBMutableService {

}

public class CBCentralManager : CBManager {
init(delegate: (any CBCentralManagerDelegate)?, queue: dispatch_queue_t?, options: [String : Any]?) {
super.init(state: .unknown)
}

func scanForPeripherals(withServices serviceUUIDs: [CBUUID]?, options: [String : Any]? = nil) {

}

func stopScan() {

}

func connect(_ peripheral: CBPeripheral, options: [String : Any]? = nil) {

}
}

public protocol CBCentralManagerDelegate {

}

public class CBService : CBAttribute {
var characteristics: [CBCharacteristic]?
}

public protocol CBPeripheralDelegate {

}

public class CBCharacteristic : CBAttribute {
var service: CBService?
var value: Data?
}

public class CBPeripheral : CBPeer {
var name: String?
var delegate: (any CBPeripheralDelegate)?
var services: [CBService]?

func discoverServices(_ serviceUUIDs: [CBUUID]?) {

}

func discoverCharacteristics(_ characteristicUUIDs: [CBUUID]?, for service: CBService) {

}

func setNotifyValue(_ enabled: Bool, for characteristic: CBCharacteristic) {

}

func writeValue(_ data: Data, for: CBCharacteristic, type: CBCharacteristicWriteType) {

}

func maximumWriteValueLength(for type: CBCharacteristicWriteType) -> Int {
assert(false)
return -1
}
}
1 change: 1 addition & 0 deletions swift/GattlibExample/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Hello World!")

0 comments on commit e459f76

Please sign in to comment.