Migrate to DF 0.7

This commit is contained in:
Alexander Nozik 2023-12-12 09:59:52 +03:00
parent 81d6b672cf
commit cf129b6242
13 changed files with 57 additions and 40 deletions

View File

@ -5,15 +5,15 @@ plugins {
id("space.kscience.gradle.project")
}
val dataforgeVersion: String by extra("0.6.2")
val visionforgeVersion by extra("0.3.0-dev-14")
val dataforgeVersion: String by extra("0.7.1")
val visionforgeVersion by extra("0.3.0-RC")
val ktorVersion: String by extra(space.kscience.gradle.KScienceVersions.ktorVersion)
val rsocketVersion by extra("0.15.4")
val xodusVersion by extra("2.0.1")
allprojects {
group = "space.kscience"
version = "0.3.0-dev-2"
version = "0.3.0-dev-3"
repositories{
maven("https://maven.pkg.jetbrains.space/spc/p/sci/dev")
}

View File

@ -11,8 +11,8 @@ import space.kscience.dataforge.context.info
import space.kscience.dataforge.context.logger
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.misc.DFExperimental
import space.kscience.dataforge.misc.Type
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.misc.DfType
import space.kscience.dataforge.names.parseAsName
/**
* A lifecycle state of a device
@ -46,7 +46,7 @@ public enum class DeviceLifecycleState {
* [Device] is a supervisor scope encompassing all operations on a device.
* When canceled, cancels all running processes.
*/
@Type(DEVICE_TARGET)
@DfType(DEVICE_TARGET)
public interface Device : ContextAware, CoroutineScope {
/**
@ -144,7 +144,7 @@ public suspend fun Device.requestProperty(propertyName: String): Meta = if (this
*/
public fun CachingDevice.getAllProperties(): Meta = Meta {
for (descriptor in propertyDescriptors) {
setMeta(Name.parse(descriptor.name), getProperty(descriptor.name))
set(descriptor.name.parseAsName(), getProperty(descriptor.name))
}
}

View File

@ -1,6 +1,5 @@
package space.kscience.controls.api
import io.ktor.utils.io.core.Closeable
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.Flow
@ -9,7 +8,7 @@ import kotlinx.coroutines.launch
/**
* A generic bidirectional sender/receiver object
*/
public interface Socket<T> : Closeable {
public interface Socket<T> : AutoCloseable {
/**
* Send an object to the socket
*/

View File

@ -1,8 +1,8 @@
package space.kscience.controls.misc
import io.ktor.utils.io.core.Input
import io.ktor.utils.io.core.Output
import kotlinx.datetime.Instant
import kotlinx.io.Sink
import kotlinx.io.Source
import space.kscience.dataforge.io.IOFormat
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.meta.get
@ -38,15 +38,16 @@ public data class ValueWithTime<T>(val value: T, val time: Instant) {
private class ValueWithTimeIOFormat<T>(val valueFormat: IOFormat<T>) : IOFormat<ValueWithTime<T>> {
override val type: KType get() = typeOf<ValueWithTime<T>>()
override fun readObject(input: Input): ValueWithTime<T> {
val timestamp = InstantIOFormat.readObject(input)
val value = valueFormat.readObject(input)
override fun readFrom(source: Source): ValueWithTime<T> {
val timestamp = InstantIOFormat.readFrom(source)
val value = valueFormat.readFrom(source)
return ValueWithTime(value, timestamp)
}
override fun writeObject(output: Output, obj: ValueWithTime<T>) {
InstantIOFormat.writeObject(output, obj.time)
valueFormat.writeObject(output, obj.value)
override fun writeTo(sink: Sink, obj: ValueWithTime<T>) {
InstantIOFormat.writeTo(sink, obj.time)
valueFormat.writeTo(sink, obj.value)
}
}
@ -54,7 +55,10 @@ private class ValueWithTimeIOFormat<T>(val valueFormat: IOFormat<T>) : IOFormat<
private class ValueWithTimeMetaConverter<T>(
val valueConverter: MetaConverter<T>,
) : MetaConverter<ValueWithTime<T>> {
override fun metaToObject(
override val type: KType = typeOf<ValueWithTime<T>>()
override fun metaToObjectOrNull(
meta: Meta,
): ValueWithTime<T>? = valueConverter.metaToObject(meta[ValueWithTime.META_VALUE_KEY] ?: Meta.EMPTY)?.let {
ValueWithTime(it, meta[ValueWithTime.META_TIME_KEY]?.instant ?: Instant.DISTANT_PAST)

View File

@ -1,7 +1,9 @@
package space.kscience.controls.misc
import io.ktor.utils.io.core.*
import kotlinx.datetime.Instant
import kotlinx.io.Sink
import kotlinx.io.Source
import space.kscience.dataforge.context.Context
import space.kscience.dataforge.io.IOFormat
import space.kscience.dataforge.io.IOFormatFactory
@ -23,14 +25,14 @@ public object InstantIOFormat : IOFormat<Instant>, IOFormatFactory<Instant> {
override val type: KType get() = typeOf<Instant>()
override fun writeObject(output: Output, obj: Instant) {
output.writeLong(obj.epochSeconds)
output.writeInt(obj.nanosecondsOfSecond)
override fun writeTo(sink: Sink, obj: Instant) {
sink.writeLong(obj.epochSeconds)
sink.writeInt(obj.nanosecondsOfSecond)
}
override fun readObject(input: Input): Instant {
val seconds = input.readLong()
val nanoseconds = input.readInt()
override fun readFrom(source: Source): Instant {
val seconds = source.readLong()
val nanoseconds = source.readInt()
return Instant.fromEpochSeconds(seconds, nanoseconds)
}
}

View File

@ -6,7 +6,8 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.receiveAsFlow
import space.kscience.controls.api.Socket
import space.kscience.dataforge.context.*
import space.kscience.dataforge.misc.Type
import space.kscience.dataforge.misc.DfType
import kotlin.coroutines.CoroutineContext
/**
@ -17,7 +18,7 @@ public interface Port : ContextAware, Socket<ByteArray>
/**
* A specialized factory for [Port]
*/
@Type(PortFactory.TYPE)
@DfType(PortFactory.TYPE)
public interface PortFactory : Factory<Port> {
public val type: String

View File

@ -1,12 +1,10 @@
package space.kscience.controls.ports
import io.ktor.utils.io.core.BytePacketBuilder
import io.ktor.utils.io.core.readBytes
import io.ktor.utils.io.core.reset
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.flow.transform
import kotlinx.io.Buffer
/**
* Transform byte fragments into complete phrases using given delimiter. Not thread safe.
@ -14,7 +12,7 @@ import kotlinx.coroutines.flow.transform
public fun Flow<ByteArray>.withDelimiter(delimiter: ByteArray): Flow<ByteArray> {
require(delimiter.isNotEmpty()) { "Delimiter must not be empty" }
val output = BytePacketBuilder()
val output = Buffer()
var matcherPosition = 0
onCompletion {

View File

@ -9,9 +9,14 @@ import space.kscience.dataforge.meta.transformations.MetaConverter
import kotlin.properties.PropertyDelegateProvider
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
import kotlin.reflect.KType
import kotlin.reflect.typeOf
public object UnitMetaConverter : MetaConverter<Unit> {
override fun metaToObject(meta: Meta): Unit = Unit
override val type: KType = typeOf<Unit>()
override fun metaToObjectOrNull(meta: Meta): Unit = Unit
override fun objectToMeta(obj: Unit): Meta = Meta.EMPTY
}

View File

@ -2,6 +2,8 @@ package space.kscience.controls.spec
import space.kscience.dataforge.meta.*
import space.kscience.dataforge.meta.transformations.MetaConverter
import kotlin.reflect.KType
import kotlin.reflect.typeOf
import kotlin.time.Duration
import kotlin.time.DurationUnit
import kotlin.time.toDuration
@ -10,7 +12,9 @@ public fun Double.asMeta(): Meta = Meta(asValue())
//TODO to be moved to DF
public object DurationConverter : MetaConverter<Duration> {
override fun metaToObject(meta: Meta): Duration = meta.value?.double?.toDuration(DurationUnit.SECONDS)
override val type: KType = typeOf<Duration>()
override fun metaToObjectOrNull(meta: Meta): Duration = meta.value?.double?.toDuration(DurationUnit.SECONDS)
?: run {
val unit: DurationUnit = meta["unit"].enum<DurationUnit>() ?: DurationUnit.SECONDS
val value = meta[Meta.VALUE_KEY].double ?: error("No value present for Duration")

View File

@ -68,7 +68,7 @@ public fun <D : Device> DeviceSpec<D>.booleanProperty(
MetaConverter.boolean,
{
metaDescriptor {
type(ValueType.BOOLEAN)
valueType(ValueType.BOOLEAN)
}
descriptorBuilder()
},
@ -80,7 +80,7 @@ private inline fun numberDescriptor(
crossinline descriptorBuilder: PropertyDescriptor.() -> Unit = {}
): PropertyDescriptor.() -> Unit = {
metaDescriptor {
type(ValueType.NUMBER)
valueType(ValueType.NUMBER)
}
descriptorBuilder()
}
@ -115,7 +115,7 @@ public fun <D : Device> DeviceSpec<D>.stringProperty(
MetaConverter.string,
{
metaDescriptor {
type(ValueType.STRING)
valueType(ValueType.STRING)
}
descriptorBuilder()
},
@ -131,7 +131,7 @@ public fun <D : Device> DeviceSpec<D>.metaProperty(
MetaConverter.meta,
{
metaDescriptor {
type(ValueType.STRING)
valueType(ValueType.STRING)
}
descriptorBuilder()
},
@ -151,7 +151,7 @@ public fun <D : Device> DeviceSpec<D>.booleanProperty(
MetaConverter.boolean,
{
metaDescriptor {
type(ValueType.BOOLEAN)
valueType(ValueType.BOOLEAN)
}
descriptorBuilder()
},

View File

@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode
plugins {
id("space.kscience.gradle.mpp")
id("org.jetbrains.compose") version "1.5.10"
id("org.jetbrains.compose") version "1.5.11"
}
kscience {

View File

@ -7,4 +7,4 @@ org.gradle.parallel=true
org.gradle.configureondemand=true
org.gradle.jvmargs=-Xmx4096m
toolsVersion=0.15.0-kotlin-1.9.20
toolsVersion=0.15.2-kotlin-1.9.21

4
magix/README.md Normal file
View File

@ -0,0 +1,4 @@
# Module magix