Updata to DataForge 0.6
This commit is contained in:
parent
bd29789545
commit
c22902cc91
@ -2,7 +2,7 @@ plugins {
|
||||
id("ru.mipt.npm.gradle.project")
|
||||
}
|
||||
|
||||
val dataforgeVersion: String by extra("0.5.2")
|
||||
val dataforgeVersion: String by extra("0.6.0-dev-12")
|
||||
val ktorVersion: String by extra(ru.mipt.npm.gradle.KScienceVersions.ktorVersion)
|
||||
val rsocketVersion by extra("0.15.4")
|
||||
|
||||
|
@ -31,7 +31,7 @@ public class DeviceManager : AbstractPlugin(), DeviceHub {
|
||||
override val tag: PluginTag = PluginTag("devices", group = PluginTag.DATAFORGE_GROUP)
|
||||
override val type: KClass<out DeviceManager> = DeviceManager::class
|
||||
|
||||
override fun invoke(meta: Meta, context: Context): DeviceManager = DeviceManager()
|
||||
override fun build(context: Context, meta: Meta): DeviceManager = DeviceManager()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,10 +10,10 @@ import kotlinx.coroutines.flow.transform
|
||||
/**
|
||||
* Transform byte fragments into complete phrases using given delimiter. Not thread safe.
|
||||
*/
|
||||
public fun Flow<ByteArray>.withDelimiter(delimiter: ByteArray, expectedMessageSize: Int = 32): Flow<ByteArray> {
|
||||
public fun Flow<ByteArray>.withDelimiter(delimiter: ByteArray): Flow<ByteArray> {
|
||||
require(delimiter.isNotEmpty()) { "Delimiter must not be empty" }
|
||||
|
||||
val output = BytePacketBuilder(expectedMessageSize)
|
||||
val output = BytePacketBuilder()
|
||||
var matcherPosition = 0
|
||||
|
||||
return transform { chunk ->
|
||||
@ -40,12 +40,12 @@ public fun Flow<ByteArray>.withDelimiter(delimiter: ByteArray, expectedMessageSi
|
||||
/**
|
||||
* Transform byte fragments into utf-8 phrases using utf-8 delimiter
|
||||
*/
|
||||
public fun Flow<ByteArray>.withDelimiter(delimiter: String, expectedMessageSize: Int = 32): Flow<String> {
|
||||
return withDelimiter(delimiter.encodeToByteArray(), expectedMessageSize).map { it.decodeToString() }
|
||||
public fun Flow<ByteArray>.withDelimiter(delimiter: String): Flow<String> {
|
||||
return withDelimiter(delimiter.encodeToByteArray()).map { it.decodeToString() }
|
||||
}
|
||||
|
||||
/**
|
||||
* A flow of delimited phrases
|
||||
*/
|
||||
public suspend fun Port.delimitedIncoming(delimiter: ByteArray, expectedMessageSize: Int = 32): Flow<ByteArray> =
|
||||
receiving().withDelimiter(delimiter, expectedMessageSize)
|
||||
public suspend fun Port.delimitedIncoming(delimiter: ByteArray): Flow<ByteArray> =
|
||||
receiving().withDelimiter(delimiter)
|
||||
|
@ -83,7 +83,7 @@ public class TcpPort private constructor(
|
||||
return TcpPort(context, host, port, coroutineContext)
|
||||
}
|
||||
|
||||
override fun invoke(meta: Meta, context: Context): Port {
|
||||
override fun build(context: Context, meta: Meta): Port {
|
||||
val host = meta["host"].string ?: "localhost"
|
||||
val port = meta["port"].int ?: error("Port value for TCP port is not defined in $meta")
|
||||
return open(context, host, port)
|
||||
|
@ -77,7 +77,7 @@ public class SerialPort private constructor(
|
||||
return SerialPort(context, jssc, coroutineContext)
|
||||
}
|
||||
|
||||
override fun invoke(meta: Meta, context: Context): Port {
|
||||
override fun build(context: Context, meta: Meta): Port {
|
||||
val name by meta.string { error("Serial port name not defined") }
|
||||
val baudRate by meta.int(BAUDRATE_9600)
|
||||
val dataBits by meta.int(DATABITS_8)
|
||||
|
@ -111,8 +111,7 @@ public class XodusDeviceMessageStorage(
|
||||
internal const val DEVICE_MESSAGE_ENTITY_TYPE = "controls-kt.message"
|
||||
public val XODUS_STORE_PROPERTY: Name = Name.of("xodus", "storagePath")
|
||||
|
||||
|
||||
override fun invoke(meta: Meta, context: Context): XodusDeviceMessageStorage {
|
||||
override fun build(context: Context, meta: Meta): XodusDeviceMessageStorage {
|
||||
val io = context.fetch(IOPlugin)
|
||||
val storePath = io.workDirectory.resolve(
|
||||
meta[XODUS_STORE_PROPERTY]?.string
|
||||
|
@ -15,7 +15,7 @@ import space.kscience.dataforge.context.logger
|
||||
//TODO replace by plugin?
|
||||
public fun DeviceManager.storage(
|
||||
factory: Factory<DeviceMessageStorage>,
|
||||
): DeviceMessageStorage = factory(meta, context)
|
||||
): DeviceMessageStorage = factory.build(context, meta)
|
||||
|
||||
/**
|
||||
* Begin to store DeviceMessages from this DeviceManager
|
||||
@ -28,7 +28,7 @@ public fun DeviceManager.storeMessages(
|
||||
factory: Factory<DeviceMessageStorage>,
|
||||
filterCondition: suspend (DeviceMessage) -> Boolean = { true },
|
||||
): Job {
|
||||
val storage = factory(meta, context)
|
||||
val storage = factory.build(context, meta)
|
||||
logger.debug { "Message storage with meta = $meta created" }
|
||||
|
||||
return hubMessageFlow(context).filter(filterCondition).onEach { message ->
|
||||
|
@ -3,8 +3,8 @@ package space.kscience.controls.storage
|
||||
import space.kscience.dataforge.context.ContextBuilder
|
||||
import space.kscience.dataforge.io.IOPlugin
|
||||
import space.kscience.dataforge.meta.get
|
||||
import space.kscience.dataforge.meta.set
|
||||
import space.kscience.dataforge.meta.string
|
||||
import space.kscience.dataforge.values.set
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.Path
|
||||
|
||||
|
@ -65,7 +65,7 @@ public class KtorTcpPort internal constructor(
|
||||
return KtorTcpPort(context, host, port, coroutineContext)
|
||||
}
|
||||
|
||||
override fun invoke(meta: Meta, context: Context): Port {
|
||||
override fun build(context: Context, meta: Meta): Port {
|
||||
val host = meta["host"].string ?: "localhost"
|
||||
val port = meta["port"].int ?: error("Port value for TCP port is not defined in $meta")
|
||||
return open(context, host, port)
|
||||
|
@ -35,7 +35,7 @@ class DemoDevice(context: Context, meta: Meta) : DeviceBySpec<DemoDevice>(DemoDe
|
||||
|
||||
companion object : DeviceSpec<DemoDevice>(), Factory<DemoDevice> {
|
||||
|
||||
override fun invoke(meta: Meta, context: Context): DemoDevice = DemoDevice(context, meta)
|
||||
override fun build(context: Context, meta: Meta): DemoDevice = DemoDevice(context, meta)
|
||||
|
||||
// register virtual properties based on actual object state
|
||||
val timeScale by mutableProperty(MetaConverter.double, DemoDevice::timeScaleState) {
|
||||
|
@ -43,6 +43,6 @@ class MagixVirtualCar(context: Context, meta: Meta) : VirtualCar(context, meta)
|
||||
}
|
||||
|
||||
companion object : Factory<MagixVirtualCar> {
|
||||
override fun invoke(meta: Meta, context: Context): MagixVirtualCar = MagixVirtualCar(context, meta)
|
||||
override fun build(context: Context, meta: Meta): MagixVirtualCar = MagixVirtualCar(context, meta)
|
||||
}
|
||||
}
|
||||
|
@ -110,6 +110,6 @@ open class VirtualCar(context: Context, meta: Meta) : DeviceBySpec<VirtualCar>(I
|
||||
}
|
||||
|
||||
companion object : Factory<VirtualCar> {
|
||||
override fun invoke(meta: Meta, context: Context): VirtualCar = VirtualCar(context, meta)
|
||||
override fun build(context: Context, meta: Meta): VirtualCar = VirtualCar(context, meta)
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ class PiMotionMasterDevice(
|
||||
|
||||
companion object : DeviceSpec<PiMotionMasterDevice>(), Factory<PiMotionMasterDevice> {
|
||||
|
||||
override fun invoke(meta: Meta, context: Context): PiMotionMasterDevice = PiMotionMasterDevice(context)
|
||||
override fun build(context: Context, meta: Meta): PiMotionMasterDevice = PiMotionMasterDevice(context)
|
||||
|
||||
val connected by booleanProperty(descriptorBuilder = {
|
||||
info = "True if the connection address is defined and the device is initialized"
|
||||
|
Loading…
Reference in New Issue
Block a user