diff --git a/build.gradle.kts b/build.gradle.kts index 2b3f6b3..fd2f3d8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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") } diff --git a/controls-core/src/commonMain/kotlin/space/kscience/controls/api/Device.kt b/controls-core/src/commonMain/kotlin/space/kscience/controls/api/Device.kt index f967c89..4b78f24 100644 --- a/controls-core/src/commonMain/kotlin/space/kscience/controls/api/Device.kt +++ b/controls-core/src/commonMain/kotlin/space/kscience/controls/api/Device.kt @@ -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)) } } diff --git a/controls-core/src/commonMain/kotlin/space/kscience/controls/api/Socket.kt b/controls-core/src/commonMain/kotlin/space/kscience/controls/api/Socket.kt index 02598ba..700db2c 100644 --- a/controls-core/src/commonMain/kotlin/space/kscience/controls/api/Socket.kt +++ b/controls-core/src/commonMain/kotlin/space/kscience/controls/api/Socket.kt @@ -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 : Closeable { +public interface Socket : AutoCloseable { /** * Send an object to the socket */ diff --git a/controls-core/src/commonMain/kotlin/space/kscience/controls/misc/ValueWithTime.kt b/controls-core/src/commonMain/kotlin/space/kscience/controls/misc/ValueWithTime.kt index ce651e4..0bf07d3 100644 --- a/controls-core/src/commonMain/kotlin/space/kscience/controls/misc/ValueWithTime.kt +++ b/controls-core/src/commonMain/kotlin/space/kscience/controls/misc/ValueWithTime.kt @@ -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(val value: T, val time: Instant) { private class ValueWithTimeIOFormat(val valueFormat: IOFormat) : IOFormat> { override val type: KType get() = typeOf>() - override fun readObject(input: Input): ValueWithTime { - val timestamp = InstantIOFormat.readObject(input) - val value = valueFormat.readObject(input) + + override fun readFrom(source: Source): ValueWithTime { + val timestamp = InstantIOFormat.readFrom(source) + val value = valueFormat.readFrom(source) return ValueWithTime(value, timestamp) } - override fun writeObject(output: Output, obj: ValueWithTime) { - InstantIOFormat.writeObject(output, obj.time) - valueFormat.writeObject(output, obj.value) + override fun writeTo(sink: Sink, obj: ValueWithTime) { + InstantIOFormat.writeTo(sink, obj.time) + valueFormat.writeTo(sink, obj.value) } } @@ -54,7 +55,10 @@ private class ValueWithTimeIOFormat(val valueFormat: IOFormat) : IOFormat< private class ValueWithTimeMetaConverter( val valueConverter: MetaConverter, ) : MetaConverter> { - override fun metaToObject( + + override val type: KType = typeOf>() + + override fun metaToObjectOrNull( meta: Meta, ): ValueWithTime? = valueConverter.metaToObject(meta[ValueWithTime.META_VALUE_KEY] ?: Meta.EMPTY)?.let { ValueWithTime(it, meta[ValueWithTime.META_TIME_KEY]?.instant ?: Instant.DISTANT_PAST) diff --git a/controls-core/src/commonMain/kotlin/space/kscience/controls/misc/timeIO.kt b/controls-core/src/commonMain/kotlin/space/kscience/controls/misc/timeIO.kt index aef7401..8686c67 100644 --- a/controls-core/src/commonMain/kotlin/space/kscience/controls/misc/timeIO.kt +++ b/controls-core/src/commonMain/kotlin/space/kscience/controls/misc/timeIO.kt @@ -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, IOFormatFactory { override val type: KType get() = typeOf() - 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) } } diff --git a/controls-core/src/commonMain/kotlin/space/kscience/controls/ports/Port.kt b/controls-core/src/commonMain/kotlin/space/kscience/controls/ports/Port.kt index 1f07251..83044ec 100644 --- a/controls-core/src/commonMain/kotlin/space/kscience/controls/ports/Port.kt +++ b/controls-core/src/commonMain/kotlin/space/kscience/controls/ports/Port.kt @@ -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 /** * A specialized factory for [Port] */ -@Type(PortFactory.TYPE) +@DfType(PortFactory.TYPE) public interface PortFactory : Factory { public val type: String diff --git a/controls-core/src/commonMain/kotlin/space/kscience/controls/ports/phrases.kt b/controls-core/src/commonMain/kotlin/space/kscience/controls/ports/phrases.kt index 02a0058..0f2b9bd 100644 --- a/controls-core/src/commonMain/kotlin/space/kscience/controls/ports/phrases.kt +++ b/controls-core/src/commonMain/kotlin/space/kscience/controls/ports/phrases.kt @@ -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.withDelimiter(delimiter: ByteArray): Flow { require(delimiter.isNotEmpty()) { "Delimiter must not be empty" } - val output = BytePacketBuilder() + val output = Buffer() var matcherPosition = 0 onCompletion { diff --git a/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/DeviceSpec.kt b/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/DeviceSpec.kt index cd0d7cc..4091921 100644 --- a/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/DeviceSpec.kt +++ b/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/DeviceSpec.kt @@ -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 { - override fun metaToObject(meta: Meta): Unit = Unit + + override val type: KType = typeOf() + + override fun metaToObjectOrNull(meta: Meta): Unit = Unit override fun objectToMeta(obj: Unit): Meta = Meta.EMPTY } diff --git a/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/misc.kt b/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/misc.kt index e264212..ee14237 100644 --- a/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/misc.kt +++ b/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/misc.kt @@ -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 { - override fun metaToObject(meta: Meta): Duration = meta.value?.double?.toDuration(DurationUnit.SECONDS) + override val type: KType = typeOf() + + override fun metaToObjectOrNull(meta: Meta): Duration = meta.value?.double?.toDuration(DurationUnit.SECONDS) ?: run { val unit: DurationUnit = meta["unit"].enum() ?: DurationUnit.SECONDS val value = meta[Meta.VALUE_KEY].double ?: error("No value present for Duration") diff --git a/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/propertySpecDelegates.kt b/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/propertySpecDelegates.kt index 6f599a8..231891c 100644 --- a/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/propertySpecDelegates.kt +++ b/controls-core/src/commonMain/kotlin/space/kscience/controls/spec/propertySpecDelegates.kt @@ -68,7 +68,7 @@ public fun DeviceSpec.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 DeviceSpec.stringProperty( MetaConverter.string, { metaDescriptor { - type(ValueType.STRING) + valueType(ValueType.STRING) } descriptorBuilder() }, @@ -131,7 +131,7 @@ public fun DeviceSpec.metaProperty( MetaConverter.meta, { metaDescriptor { - type(ValueType.STRING) + valueType(ValueType.STRING) } descriptorBuilder() }, @@ -151,7 +151,7 @@ public fun DeviceSpec.booleanProperty( MetaConverter.boolean, { metaDescriptor { - type(ValueType.BOOLEAN) + valueType(ValueType.BOOLEAN) } descriptorBuilder() }, diff --git a/demo/constructor/build.gradle.kts b/demo/constructor/build.gradle.kts index 9026247..470533f 100644 --- a/demo/constructor/build.gradle.kts +++ b/demo/constructor/build.gradle.kts @@ -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 { diff --git a/gradle.properties b/gradle.properties index ea080f4..717cec4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,4 +7,4 @@ org.gradle.parallel=true org.gradle.configureondemand=true org.gradle.jvmargs=-Xmx4096m -toolsVersion=0.15.0-kotlin-1.9.20 \ No newline at end of file +toolsVersion=0.15.2-kotlin-1.9.21 \ No newline at end of file diff --git a/magix/README.md b/magix/README.md new file mode 100644 index 0000000..de1d7a3 --- /dev/null +++ b/magix/README.md @@ -0,0 +1,4 @@ +# Module magix + + +