This repository has been archived by the owner on Aug 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
KeepAliveGatt EventHandler #74
Merged
Merged
Changes from 23 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
716dea5
KeepAliveGatt now takes in a onEventAction, allowing the consumer of …
sdonn3 72baad9
merge changes from travis' PR
sdonn3 aaa739d
Some changes to the README to reflect changes in KeepAliveGatt
sdonn3 785c709
Changes from PR
sdonn3 934c824
Add API changes
sdonn3 fe650b1
test format
sdonn3 7598997
Merge branch 'develop' into steve/esc-965_onDisconnect
sdonn3 21f6320
fix test
sdonn3 0adefb9
Merge remote-tracking branch 'origin/steve/esc-965_onDisconnect' into…
sdonn3 1e1aa35
changes
sdonn3 acd9291
PR feedback requests
sdonn3 76b07d1
connectionAttempt fix
sdonn3 29109b5
Code clean up
twyatt 2368bd6
Drop Disconnected.Info and put properties directly on Disconnected event
twyatt 2ae24d4
API dump
twyatt c04b2cd
Kotlinter
twyatt c2e9421
Add test that assumes connection rejection should yield Disconnected …
twyatt 4ef5191
Code clean up and add Rejected event
twyatt 8c8b54c
Add documentation re: states and events
twyatt 803cdad
Simplify example in documentation
twyatt b1f4654
API dump
twyatt d26fafd
Kotlinter
twyatt 0b80726
Reduce size of state and event flow diagram
twyatt 521af43
Merge branch 'develop' into steve/esc-965_onDisconnect
twyatt 6421846
Fix reconnect test
twyatt 05ba36e
Settle on disconnected state on exception in onConnected
twyatt bec6b43
Fix which scope is cancelled due to onConnected exception
twyatt fe24455
Remove test that is no longer valid
twyatt 560802d
Remove nested scopes and launch in `establishConnection`
twyatt 70357d7
Minor documentation updates
twyatt f3e0e91
couple new tests
sdonn3 cb9b61d
Unwrap special exception for Disconnected event
twyatt c0e38ee
Test clean up
twyatt 045f845
Update state and event flow diagram
twyatt a89e741
Properly propagate failure through Disconnected state
twyatt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,47 @@ | ||
/* | ||
* Copyright 2020 JUUL Labs, Inc. | ||
*/ | ||
|
||
package com.juul.able.keepalive | ||
|
||
import com.juul.able.gatt.GattIo | ||
|
||
sealed class Event { | ||
|
||
/** Triggered upon a connection being successfully established. */ | ||
data class Connected(val gatt: GattIo) : Event() | ||
|
||
/** | ||
* Triggered either immediately after an established connection has dropped or after a failed | ||
* connection attempt. | ||
* | ||
* The [connectionAttempt] property represents which connection attempt iteration over the | ||
* lifespan of the [KeepAliveGatt]. The value begins at 1 and increase by 1 for each iteration. | ||
* | ||
* @param wasConnected is `true` if event follows an established connection, or `false` if previous connection attempt failed. | ||
* @param connectionAttempt is the number of connection attempts since creation of [KeepAliveGatt]. | ||
*/ | ||
data class Disconnected( | ||
val wasConnected: Boolean, | ||
val connectionAttempt: Int | ||
) : Event() | ||
|
||
/** | ||
* Triggered when the connection request was rejected by the operating system (e.g. bluetooth | ||
* hardware unavailable). [KeepAliveGatt] will not attempt to reconnect until | ||
* [connect][KeepAliveGatt.connect] is called again. | ||
*/ | ||
data class Rejected(val cause: Throwable) : Event() | ||
} | ||
|
||
suspend fun Event.onConnected(action: suspend GattIo.() -> Unit) { | ||
if (this is Event.Connected) action.invoke(gatt) | ||
} | ||
|
||
suspend fun Event.onDisconnected(action: suspend (Event.Disconnected) -> Unit) { | ||
if (this is Event.Disconnected) action.invoke(this) | ||
} | ||
|
||
suspend fun Event.onRejected(action: suspend (Event.Rejected) -> Unit) { | ||
if (this is Event.Rejected) action.invoke(this) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2020 JUUL Labs, Inc. | ||
*/ | ||
|
||
package com.juul.able.keepalive | ||
|
||
sealed class State { | ||
|
||
object Connecting : State() | ||
|
||
object Connected : State() | ||
|
||
object Disconnecting : State() | ||
|
||
data class Disconnected(val cause: Throwable? = null) : State() { | ||
override fun toString() = super.toString() | ||
} | ||
|
||
data class Cancelled(val cause: Throwable?) : State() { | ||
override fun toString() = super.toString() | ||
} | ||
|
||
override fun toString(): String = javaClass.simpleName | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this new naming way better