Updata to DataForge 0.6

This commit is contained in:
Alexander Nozik 2022-08-02 09:37:36 +03:00
parent bd29789545
commit c22902cc91
No known key found for this signature in database
GPG Key ID: F7FCF2DD25C71357
13 changed files with 19 additions and 20 deletions

View File

@ -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")

View File

@ -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()
}
}

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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 ->

View File

@ -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

View File

@ -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)

View File

@ -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) {

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -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"