-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PPoG neatening, patches found while working on other things
- Loading branch information
Showing
14 changed files
with
305 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...oid/pebble_bt_transport/src/main/java/io/rebble/cobble/bluetooth/ble/GattServerManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.rebble.cobble.bluetooth.ble | ||
|
||
import android.bluetooth.BluetoothManager | ||
import android.content.Context | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.flow.launchIn | ||
import kotlinx.coroutines.flow.onEach | ||
import timber.log.Timber | ||
|
||
object GattServerManager { | ||
private var gattServer: GattServer? = null | ||
private var gattServerJob: Job? = null | ||
private var _ppogService: PPoGService? = null | ||
val ppogService: PPoGService? | ||
get() = _ppogService | ||
|
||
fun getGattServer(): GattServer? { | ||
return gattServer | ||
} | ||
|
||
fun initIfNeeded(context: Context, scope: CoroutineScope): GattServer { | ||
if (gattServer?.isOpened() != true || gattServerJob?.isActive != true) { | ||
gattServer?.close() | ||
_ppogService = PPoGService(scope) | ||
gattServer = GattServerImpl( | ||
context.getSystemService(BluetoothManager::class.java)!!, | ||
context, | ||
listOf(ppogService!!, DummyService()) | ||
) | ||
} | ||
gattServerJob = gattServer!!.getFlow().onEach { | ||
Timber.v("Server state: $it") | ||
}.launchIn(scope) | ||
return gattServer!! | ||
} | ||
|
||
fun close() { | ||
gattServer?.close() | ||
gattServerJob?.cancel() | ||
gattServer = null | ||
gattServerJob = null | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.