Loading android/pandora/server/src/Gatt.kt +5 −10 Original line number Diff line number Diff line Loading @@ -31,9 +31,7 @@ import java.io.Closeable import java.util.UUID import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import kotlinx.coroutines.cancel import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.delay import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharingStarted Loading Loading @@ -276,18 +274,15 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { service.addCharacteristic(characteristic) } val fullService = coroutineScope { val firstService = mScope.async { serverManager.newServiceFlow.first() } serverManager.server.addService(service) firstService.await() } val addedService = serverManager.serviceFlow.first() RegisterServiceResponse.newBuilder() .setService( GattService.newBuilder() .setHandle(fullService.instanceId) .setType(fullService.type) .setUuid(fullService.uuid.toString().uppercase()) .setHandle(addedService.instanceId) .setType(addedService.type) .setUuid(addedService.uuid.toString().uppercase()) .addAllIncludedServices(generateServicesList(service.includedServices, 1)) .addAllCharacteristics(generateCharacteristicsList(service.characteristics)) .build() Loading android/pandora/server/src/GattServerManager.kt +4 −3 Original line number Diff line number Diff line Loading @@ -28,16 +28,17 @@ import android.util.Log import java.util.UUID import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.launch class GattServerManager( bluetoothManager: BluetoothManager, context: Context, globalScope: CoroutineScope scope: CoroutineScope ) { val TAG = "PandoraGattServerManager" val services = mutableMapOf<UUID, BluetoothGattService>() val newServiceFlow = MutableSharedFlow<BluetoothGattService>(extraBufferCapacity = 8) val serviceFlow = MutableSharedFlow<BluetoothGattService>() var negociatedMtu = -1 val callback = Loading @@ -45,7 +46,7 @@ class GattServerManager( override fun onServiceAdded(status: Int, service: BluetoothGattService) { Log.i(TAG, "onServiceAdded status=$status") check(status == BluetoothGatt.GATT_SUCCESS) check(newServiceFlow.tryEmit(service)) scope.launch { serviceFlow.emit(service) } } override fun onMtuChanged(device: BluetoothDevice, mtu: Int) { Log.i(TAG, "onMtuChanged mtu=$mtu") Loading Loading
android/pandora/server/src/Gatt.kt +5 −10 Original line number Diff line number Diff line Loading @@ -31,9 +31,7 @@ import java.io.Closeable import java.util.UUID import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import kotlinx.coroutines.cancel import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.delay import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharingStarted Loading Loading @@ -276,18 +274,15 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { service.addCharacteristic(characteristic) } val fullService = coroutineScope { val firstService = mScope.async { serverManager.newServiceFlow.first() } serverManager.server.addService(service) firstService.await() } val addedService = serverManager.serviceFlow.first() RegisterServiceResponse.newBuilder() .setService( GattService.newBuilder() .setHandle(fullService.instanceId) .setType(fullService.type) .setUuid(fullService.uuid.toString().uppercase()) .setHandle(addedService.instanceId) .setType(addedService.type) .setUuid(addedService.uuid.toString().uppercase()) .addAllIncludedServices(generateServicesList(service.includedServices, 1)) .addAllCharacteristics(generateCharacteristicsList(service.characteristics)) .build() Loading
android/pandora/server/src/GattServerManager.kt +4 −3 Original line number Diff line number Diff line Loading @@ -28,16 +28,17 @@ import android.util.Log import java.util.UUID import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.launch class GattServerManager( bluetoothManager: BluetoothManager, context: Context, globalScope: CoroutineScope scope: CoroutineScope ) { val TAG = "PandoraGattServerManager" val services = mutableMapOf<UUID, BluetoothGattService>() val newServiceFlow = MutableSharedFlow<BluetoothGattService>(extraBufferCapacity = 8) val serviceFlow = MutableSharedFlow<BluetoothGattService>() var negociatedMtu = -1 val callback = Loading @@ -45,7 +46,7 @@ class GattServerManager( override fun onServiceAdded(status: Int, service: BluetoothGattService) { Log.i(TAG, "onServiceAdded status=$status") check(status == BluetoothGatt.GATT_SUCCESS) check(newServiceFlow.tryEmit(service)) scope.launch { serviceFlow.emit(service) } } override fun onMtuChanged(device: BluetoothDevice, mtu: Int) { Log.i(TAG, "onMtuChanged mtu=$mtu") Loading