2019-10-23 18:28:19 -04:00
|
|
|
package ns
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
#cgo CFLAGS: -x objective-c -fno-objc-arc
|
|
|
|
#cgo LDFLAGS: -framework Foundation -framework CoreBluetooth
|
|
|
|
#pragma clang diagnostic ignored "-Wformat-security"
|
|
|
|
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
#import <CoreBluetooth/CoreBluetooth.h>
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
2021-11-15 14:14:45 -05:00
|
|
|
"fmt"
|
2019-10-23 18:28:19 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
//export CBDelegateCentralManagerDidConnectPeripheral
|
|
|
|
func CBDelegateCentralManagerDidConnectPeripheral(o unsafe.Pointer, central unsafe.Pointer, peripheral unsafe.Pointer) {
|
|
|
|
CBDelegateMux.RLock()
|
|
|
|
cb := CBDelegateLookup[o].CentralManagerDidConnectPeripheral
|
|
|
|
CBDelegateMux.RUnlock()
|
|
|
|
if cb == nil { return }
|
2021-11-15 14:14:45 -05:00
|
|
|
self := CBDelegate{}
|
|
|
|
self.ptr = o
|
2019-10-23 18:28:19 -04:00
|
|
|
a1 := &CBCentralManager{}; a1.ptr = central
|
|
|
|
a2 := &CBPeripheral{}; a2.ptr = peripheral
|
2021-11-15 14:14:45 -05:00
|
|
|
cb(self, a1, a2)
|
2019-10-23 18:28:19 -04:00
|
|
|
}
|
|
|
|
|
2019-12-05 08:49:41 -05:00
|
|
|
//export CBDelegateCentralManagerDidDisconnectPeripheral
|
|
|
|
func CBDelegateCentralManagerDidDisconnectPeripheral(o unsafe.Pointer, central unsafe.Pointer, peripheral unsafe.Pointer, error unsafe.Pointer) {
|
|
|
|
CBDelegateMux.RLock()
|
|
|
|
cb := CBDelegateLookup[o].CentralManagerDidDisconnectPeripheral
|
|
|
|
CBDelegateMux.RUnlock()
|
|
|
|
if cb == nil { return }
|
2021-11-15 14:14:45 -05:00
|
|
|
self := CBDelegate{}
|
|
|
|
self.ptr = o
|
2019-12-05 08:49:41 -05:00
|
|
|
a1 := &CBCentralManager{}; a1.ptr = central
|
|
|
|
a2 := &CBPeripheral{}; a2.ptr = peripheral
|
|
|
|
a3 := &NSError{}; a3.ptr = error
|
2021-11-15 14:14:45 -05:00
|
|
|
cb(self, a1, a2, a3)
|
2019-12-05 08:49:41 -05:00
|
|
|
}
|
|
|
|
|
2019-10-23 18:28:19 -04:00
|
|
|
//export CBDelegateCentralManagerDidDiscoverPeripheral
|
|
|
|
func CBDelegateCentralManagerDidDiscoverPeripheral(o unsafe.Pointer, central unsafe.Pointer, peripheral unsafe.Pointer, advertisementData unsafe.Pointer, RSSI unsafe.Pointer) {
|
|
|
|
CBDelegateMux.RLock()
|
|
|
|
cb := CBDelegateLookup[o].CentralManagerDidDiscoverPeripheral
|
|
|
|
CBDelegateMux.RUnlock()
|
|
|
|
if cb == nil { return }
|
2021-11-15 14:14:45 -05:00
|
|
|
self := CBDelegate{}
|
|
|
|
self.ptr = o
|
2019-10-23 18:28:19 -04:00
|
|
|
a1 := &CBCentralManager{}; a1.ptr = central
|
|
|
|
a2 := &CBPeripheral{}; a2.ptr = peripheral
|
|
|
|
a3 := &NSDictionary{}; a3.ptr = advertisementData
|
|
|
|
a4 := &NSNumber{}; a4.ptr = RSSI
|
2021-11-15 14:14:45 -05:00
|
|
|
cb(self, a1, a2, a3, a4)
|
|
|
|
}
|
|
|
|
|
|
|
|
//export CBDelegateCentralManagerDidUpdateState
|
|
|
|
func CBDelegateCentralManagerDidUpdateState(o unsafe.Pointer, central unsafe.Pointer) {
|
|
|
|
fmt.Print("CentralManagerDidUpdateState")
|
|
|
|
CBDelegateMux.RLock()
|
|
|
|
cb := CBDelegateLookup[o].CentralManagerDidUpdateState
|
|
|
|
CBDelegateMux.RUnlock()
|
|
|
|
if cb == nil { return }
|
|
|
|
self := CBDelegate{}
|
|
|
|
self.ptr = o
|
|
|
|
a1 := &CBCentralManager{}; a1.ptr = central
|
|
|
|
cb(self, a1)
|
2019-10-23 18:28:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
//export CBDelegatePeripheralDidDiscoverServices
|
|
|
|
func CBDelegatePeripheralDidDiscoverServices(o unsafe.Pointer, peripheral unsafe.Pointer, error unsafe.Pointer) {
|
|
|
|
CBDelegateMux.RLock()
|
|
|
|
cb := CBDelegateLookup[o].PeripheralDidDiscoverServices
|
|
|
|
CBDelegateMux.RUnlock()
|
|
|
|
if cb == nil { return }
|
2021-11-15 14:14:45 -05:00
|
|
|
self := CBDelegate{}
|
|
|
|
self.ptr = o
|
2019-10-23 18:28:19 -04:00
|
|
|
a1 := &CBPeripheral{}; a1.ptr = peripheral
|
|
|
|
a2 := &NSError{}; a2.ptr = error
|
2021-11-15 14:14:45 -05:00
|
|
|
cb(self, a1, a2)
|
2019-10-23 18:28:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
//export CBDelegatePeripheralDidDiscoverCharacteristicsForService
|
|
|
|
func CBDelegatePeripheralDidDiscoverCharacteristicsForService(o unsafe.Pointer, peripheral unsafe.Pointer, service unsafe.Pointer, error unsafe.Pointer) {
|
|
|
|
CBDelegateMux.RLock()
|
|
|
|
cb := CBDelegateLookup[o].PeripheralDidDiscoverCharacteristicsForService
|
|
|
|
CBDelegateMux.RUnlock()
|
|
|
|
if cb == nil { return }
|
2021-11-15 14:14:45 -05:00
|
|
|
self := CBDelegate{}
|
|
|
|
self.ptr = o
|
2019-10-23 18:28:19 -04:00
|
|
|
a1 := &CBPeripheral{}; a1.ptr = peripheral
|
|
|
|
a2 := &CBService{}; a2.ptr = service
|
|
|
|
a3 := &NSError{}; a3.ptr = error
|
2021-11-15 14:14:45 -05:00
|
|
|
cb(self, a1, a2, a3)
|
2019-10-23 18:28:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
//export CBDelegatePeripheralDidUpdateValueForCharacteristic
|
|
|
|
func CBDelegatePeripheralDidUpdateValueForCharacteristic(o unsafe.Pointer, peripheral unsafe.Pointer, characteristic unsafe.Pointer, error unsafe.Pointer) {
|
|
|
|
CBDelegateMux.RLock()
|
|
|
|
cb := CBDelegateLookup[o].PeripheralDidUpdateValueForCharacteristic
|
|
|
|
CBDelegateMux.RUnlock()
|
|
|
|
if cb == nil { return }
|
2021-11-15 14:14:45 -05:00
|
|
|
self := CBDelegate{}
|
|
|
|
self.ptr = o
|
2019-10-23 18:28:19 -04:00
|
|
|
a1 := &CBPeripheral{}; a1.ptr = peripheral
|
|
|
|
a2 := &CBCharacteristic{}; a2.ptr = characteristic
|
|
|
|
a3 := &NSError{}; a3.ptr = error
|
2021-11-15 14:14:45 -05:00
|
|
|
cb(self, a1, a2, a3)
|
2019-10-23 18:28:19 -04:00
|
|
|
}
|