Skip to content

Commit

Permalink
Update sourceMetadata fields and SourceService binder handling
Browse files Browse the repository at this point in the history
  • Loading branch information
this-Aditya committed Oct 19, 2024
1 parent 113a653 commit 3da0c50
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import java.util.regex.Pattern

@Serializable(with = SourceMetadataSerializer::class)
data class SourceMetadata(
val type: SourceType? = null,
val sourceId: String? = null,
val sourceName: String? = null,
val expectedSourceName: String? = null,
val attributes: Map<String, String> = mapOf()
var type: SourceType? = null,
var sourceId: String? = null,
var sourceName: String? = null,
var expectedSourceName: String? = null,
var attributes: Map<String, String> = mapOf()
) {
fun deduplicateType(types: MutableCollection<SourceType>): SourceMetadata {
val currentType = type ?: return this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import androidx.lifecycle.LifecycleService
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import org.apache.avro.specific.SpecificRecord
import org.radarbase.android.RadarApplication.Companion.radarApp
Expand Down Expand Up @@ -103,6 +105,8 @@ abstract class SourceService<T : BaseSourceState> :

private var _registeredSource: SourceMetadata? = null

private var authConnectionBinder: AuthService.AuthServiceBinder? = null

var registeredSource: SourceMetadata?
get() = handler.compute { _registeredSource }
private set(value) {
Expand Down Expand Up @@ -176,6 +180,15 @@ abstract class SourceService<T : BaseSourceState> :
startFuture?.runNow()
}
}
launch {
authConnection.state
.onEach { bindState ->
authConnectionBinder = when (bindState) {
is ManagedServiceConnection.BoundService -> bindState.binder
is ManagedServiceConnection.Unbound -> null
}
}.launchIn(this)
}
radarConnection.bind()
}
handler = SafeHandler.getInstance("SourceService-$name", THREAD_PRIORITY_BACKGROUND)
Expand Down Expand Up @@ -236,7 +249,7 @@ abstract class SourceService<T : BaseSourceState> :
SourceConnectFailed(
this@SourceService.javaClass,
name,
)
))
}

private fun broadcastSourceStatus(status: SourceStatusListener.Status) {
Expand Down Expand Up @@ -427,7 +440,7 @@ abstract class SourceService<T : BaseSourceState> :
}
}

authConnection.binder?.updateSource(
authConnectionBinder?.updateSource(
source,
{ authState, updatedSource ->
key.projectId = authState.projectId
Expand Down

0 comments on commit 3da0c50

Please sign in to comment.