From 4835376c0de47caa95cd6d0f362c140f1f6af7e8 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 6 Mar 2024 18:55:11 +0300 Subject: [PATCH] Add proper deviceName to in-memory property history --- .../space/kscience/controls/misc/PropertyHistory.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/controls-core/src/commonMain/kotlin/space/kscience/controls/misc/PropertyHistory.kt b/controls-core/src/commonMain/kotlin/space/kscience/controls/misc/PropertyHistory.kt index 96bd8d5..092d9bb 100644 --- a/controls-core/src/commonMain/kotlin/space/kscience/controls/misc/PropertyHistory.kt +++ b/controls-core/src/commonMain/kotlin/space/kscience/controls/misc/PropertyHistory.kt @@ -10,6 +10,7 @@ import space.kscience.controls.api.PropertyChangedMessage import space.kscience.controls.spec.DevicePropertySpec import space.kscience.controls.spec.name import space.kscience.dataforge.meta.MetaConverter +import space.kscience.dataforge.names.Name /** * An interface for device property history. @@ -34,6 +35,7 @@ public interface PropertyHistory { public class CollectedPropertyHistory( public val scope: CoroutineScope, eventFlow: Flow, + public val deviceName: Name, public val propertyName: String, public val converter: MetaConverter, maxSize: Int = 1000, @@ -41,7 +43,7 @@ public class CollectedPropertyHistory( private val store: SharedFlow> = eventFlow .filterIsInstance() - .filter { it.property == propertyName } + .filter { it.sourceDevice == deviceName && it.property == propertyName } .map { ValueWithTime(converter.read(it.value), it.time) } .shareIn(scope, started = SharingStarted.Eagerly, replay = maxSize) @@ -54,13 +56,15 @@ public class CollectedPropertyHistory( */ public fun Device.collectPropertyHistory( scope: CoroutineScope = this, + deviceName: Name, propertyName: String, converter: MetaConverter, maxSize: Int = 1000, -): PropertyHistory = CollectedPropertyHistory(scope, messageFlow, propertyName, converter, maxSize) +): PropertyHistory = CollectedPropertyHistory(scope, messageFlow, deviceName, propertyName, converter, maxSize) public fun D.collectPropertyHistory( scope: CoroutineScope = this, + deviceName: Name, spec: DevicePropertySpec, maxSize: Int = 1000, -): PropertyHistory = collectPropertyHistory(scope, spec.name, spec.converter, maxSize) \ No newline at end of file +): PropertyHistory = collectPropertyHistory(scope, deviceName, spec.name, spec.converter, maxSize) \ No newline at end of file