Migrate to DF 0.7
This commit is contained in:
parent
81d6b672cf
commit
cf129b6242
@ -5,15 +5,15 @@ plugins {
|
|||||||
id("space.kscience.gradle.project")
|
id("space.kscience.gradle.project")
|
||||||
}
|
}
|
||||||
|
|
||||||
val dataforgeVersion: String by extra("0.6.2")
|
val dataforgeVersion: String by extra("0.7.1")
|
||||||
val visionforgeVersion by extra("0.3.0-dev-14")
|
val visionforgeVersion by extra("0.3.0-RC")
|
||||||
val ktorVersion: String by extra(space.kscience.gradle.KScienceVersions.ktorVersion)
|
val ktorVersion: String by extra(space.kscience.gradle.KScienceVersions.ktorVersion)
|
||||||
val rsocketVersion by extra("0.15.4")
|
val rsocketVersion by extra("0.15.4")
|
||||||
val xodusVersion by extra("2.0.1")
|
val xodusVersion by extra("2.0.1")
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
group = "space.kscience"
|
group = "space.kscience"
|
||||||
version = "0.3.0-dev-2"
|
version = "0.3.0-dev-3"
|
||||||
repositories{
|
repositories{
|
||||||
maven("https://maven.pkg.jetbrains.space/spc/p/sci/dev")
|
maven("https://maven.pkg.jetbrains.space/spc/p/sci/dev")
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,8 @@ import space.kscience.dataforge.context.info
|
|||||||
import space.kscience.dataforge.context.logger
|
import space.kscience.dataforge.context.logger
|
||||||
import space.kscience.dataforge.meta.Meta
|
import space.kscience.dataforge.meta.Meta
|
||||||
import space.kscience.dataforge.misc.DFExperimental
|
import space.kscience.dataforge.misc.DFExperimental
|
||||||
import space.kscience.dataforge.misc.Type
|
import space.kscience.dataforge.misc.DfType
|
||||||
import space.kscience.dataforge.names.Name
|
import space.kscience.dataforge.names.parseAsName
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A lifecycle state of a device
|
* 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.
|
* [Device] is a supervisor scope encompassing all operations on a device.
|
||||||
* When canceled, cancels all running processes.
|
* When canceled, cancels all running processes.
|
||||||
*/
|
*/
|
||||||
@Type(DEVICE_TARGET)
|
@DfType(DEVICE_TARGET)
|
||||||
public interface Device : ContextAware, CoroutineScope {
|
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 {
|
public fun CachingDevice.getAllProperties(): Meta = Meta {
|
||||||
for (descriptor in propertyDescriptors) {
|
for (descriptor in propertyDescriptors) {
|
||||||
setMeta(Name.parse(descriptor.name), getProperty(descriptor.name))
|
set(descriptor.name.parseAsName(), getProperty(descriptor.name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package space.kscience.controls.api
|
package space.kscience.controls.api
|
||||||
|
|
||||||
import io.ktor.utils.io.core.Closeable
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
@ -9,7 +8,7 @@ import kotlinx.coroutines.launch
|
|||||||
/**
|
/**
|
||||||
* A generic bidirectional sender/receiver object
|
* A generic bidirectional sender/receiver object
|
||||||
*/
|
*/
|
||||||
public interface Socket<T> : Closeable {
|
public interface Socket<T> : AutoCloseable {
|
||||||
/**
|
/**
|
||||||
* Send an object to the socket
|
* Send an object to the socket
|
||||||
*/
|
*/
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package space.kscience.controls.misc
|
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.datetime.Instant
|
||||||
|
import kotlinx.io.Sink
|
||||||
|
import kotlinx.io.Source
|
||||||
import space.kscience.dataforge.io.IOFormat
|
import space.kscience.dataforge.io.IOFormat
|
||||||
import space.kscience.dataforge.meta.Meta
|
import space.kscience.dataforge.meta.Meta
|
||||||
import space.kscience.dataforge.meta.get
|
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>> {
|
private class ValueWithTimeIOFormat<T>(val valueFormat: IOFormat<T>) : IOFormat<ValueWithTime<T>> {
|
||||||
override val type: KType get() = typeOf<ValueWithTime<T>>()
|
override val type: KType get() = typeOf<ValueWithTime<T>>()
|
||||||
|
|
||||||
override fun readObject(input: Input): ValueWithTime<T> {
|
|
||||||
val timestamp = InstantIOFormat.readObject(input)
|
override fun readFrom(source: Source): ValueWithTime<T> {
|
||||||
val value = valueFormat.readObject(input)
|
val timestamp = InstantIOFormat.readFrom(source)
|
||||||
|
val value = valueFormat.readFrom(source)
|
||||||
return ValueWithTime(value, timestamp)
|
return ValueWithTime(value, timestamp)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun writeObject(output: Output, obj: ValueWithTime<T>) {
|
override fun writeTo(sink: Sink, obj: ValueWithTime<T>) {
|
||||||
InstantIOFormat.writeObject(output, obj.time)
|
InstantIOFormat.writeTo(sink, obj.time)
|
||||||
valueFormat.writeObject(output, obj.value)
|
valueFormat.writeTo(sink, obj.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -54,7 +55,10 @@ private class ValueWithTimeIOFormat<T>(val valueFormat: IOFormat<T>) : IOFormat<
|
|||||||
private class ValueWithTimeMetaConverter<T>(
|
private class ValueWithTimeMetaConverter<T>(
|
||||||
val valueConverter: MetaConverter<T>,
|
val valueConverter: MetaConverter<T>,
|
||||||
) : MetaConverter<ValueWithTime<T>> {
|
) : MetaConverter<ValueWithTime<T>> {
|
||||||
override fun metaToObject(
|
|
||||||
|
override val type: KType = typeOf<ValueWithTime<T>>()
|
||||||
|
|
||||||
|
override fun metaToObjectOrNull(
|
||||||
meta: Meta,
|
meta: Meta,
|
||||||
): ValueWithTime<T>? = valueConverter.metaToObject(meta[ValueWithTime.META_VALUE_KEY] ?: Meta.EMPTY)?.let {
|
): ValueWithTime<T>? = valueConverter.metaToObject(meta[ValueWithTime.META_VALUE_KEY] ?: Meta.EMPTY)?.let {
|
||||||
ValueWithTime(it, meta[ValueWithTime.META_TIME_KEY]?.instant ?: Instant.DISTANT_PAST)
|
ValueWithTime(it, meta[ValueWithTime.META_TIME_KEY]?.instant ?: Instant.DISTANT_PAST)
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package space.kscience.controls.misc
|
package space.kscience.controls.misc
|
||||||
|
|
||||||
import io.ktor.utils.io.core.*
|
|
||||||
import kotlinx.datetime.Instant
|
import kotlinx.datetime.Instant
|
||||||
|
import kotlinx.io.Sink
|
||||||
|
import kotlinx.io.Source
|
||||||
import space.kscience.dataforge.context.Context
|
import space.kscience.dataforge.context.Context
|
||||||
import space.kscience.dataforge.io.IOFormat
|
import space.kscience.dataforge.io.IOFormat
|
||||||
import space.kscience.dataforge.io.IOFormatFactory
|
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 val type: KType get() = typeOf<Instant>()
|
||||||
|
|
||||||
override fun writeObject(output: Output, obj: Instant) {
|
override fun writeTo(sink: Sink, obj: Instant) {
|
||||||
output.writeLong(obj.epochSeconds)
|
sink.writeLong(obj.epochSeconds)
|
||||||
output.writeInt(obj.nanosecondsOfSecond)
|
sink.writeInt(obj.nanosecondsOfSecond)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun readObject(input: Input): Instant {
|
override fun readFrom(source: Source): Instant {
|
||||||
val seconds = input.readLong()
|
val seconds = source.readLong()
|
||||||
val nanoseconds = input.readInt()
|
val nanoseconds = source.readInt()
|
||||||
return Instant.fromEpochSeconds(seconds, nanoseconds)
|
return Instant.fromEpochSeconds(seconds, nanoseconds)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,8 @@ import kotlinx.coroutines.flow.Flow
|
|||||||
import kotlinx.coroutines.flow.receiveAsFlow
|
import kotlinx.coroutines.flow.receiveAsFlow
|
||||||
import space.kscience.controls.api.Socket
|
import space.kscience.controls.api.Socket
|
||||||
import space.kscience.dataforge.context.*
|
import space.kscience.dataforge.context.*
|
||||||
import space.kscience.dataforge.misc.Type
|
import space.kscience.dataforge.misc.DfType
|
||||||
|
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,7 +18,7 @@ public interface Port : ContextAware, Socket<ByteArray>
|
|||||||
/**
|
/**
|
||||||
* A specialized factory for [Port]
|
* A specialized factory for [Port]
|
||||||
*/
|
*/
|
||||||
@Type(PortFactory.TYPE)
|
@DfType(PortFactory.TYPE)
|
||||||
public interface PortFactory : Factory<Port> {
|
public interface PortFactory : Factory<Port> {
|
||||||
public val type: String
|
public val type: String
|
||||||
|
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
package space.kscience.controls.ports
|
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.Flow
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.onCompletion
|
import kotlinx.coroutines.flow.onCompletion
|
||||||
import kotlinx.coroutines.flow.transform
|
import kotlinx.coroutines.flow.transform
|
||||||
|
import kotlinx.io.Buffer
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transform byte fragments into complete phrases using given delimiter. Not thread safe.
|
* 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> {
|
public fun Flow<ByteArray>.withDelimiter(delimiter: ByteArray): Flow<ByteArray> {
|
||||||
require(delimiter.isNotEmpty()) { "Delimiter must not be empty" }
|
require(delimiter.isNotEmpty()) { "Delimiter must not be empty" }
|
||||||
|
|
||||||
val output = BytePacketBuilder()
|
val output = Buffer()
|
||||||
var matcherPosition = 0
|
var matcherPosition = 0
|
||||||
|
|
||||||
onCompletion {
|
onCompletion {
|
||||||
|
@ -9,9 +9,14 @@ import space.kscience.dataforge.meta.transformations.MetaConverter
|
|||||||
import kotlin.properties.PropertyDelegateProvider
|
import kotlin.properties.PropertyDelegateProvider
|
||||||
import kotlin.properties.ReadOnlyProperty
|
import kotlin.properties.ReadOnlyProperty
|
||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
import kotlin.reflect.KType
|
||||||
|
import kotlin.reflect.typeOf
|
||||||
|
|
||||||
public object UnitMetaConverter : MetaConverter<Unit> {
|
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
|
override fun objectToMeta(obj: Unit): Meta = Meta.EMPTY
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ package space.kscience.controls.spec
|
|||||||
|
|
||||||
import space.kscience.dataforge.meta.*
|
import space.kscience.dataforge.meta.*
|
||||||
import space.kscience.dataforge.meta.transformations.MetaConverter
|
import space.kscience.dataforge.meta.transformations.MetaConverter
|
||||||
|
import kotlin.reflect.KType
|
||||||
|
import kotlin.reflect.typeOf
|
||||||
import kotlin.time.Duration
|
import kotlin.time.Duration
|
||||||
import kotlin.time.DurationUnit
|
import kotlin.time.DurationUnit
|
||||||
import kotlin.time.toDuration
|
import kotlin.time.toDuration
|
||||||
@ -10,7 +12,9 @@ public fun Double.asMeta(): Meta = Meta(asValue())
|
|||||||
|
|
||||||
//TODO to be moved to DF
|
//TODO to be moved to DF
|
||||||
public object DurationConverter : MetaConverter<Duration> {
|
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 {
|
?: run {
|
||||||
val unit: DurationUnit = meta["unit"].enum<DurationUnit>() ?: DurationUnit.SECONDS
|
val unit: DurationUnit = meta["unit"].enum<DurationUnit>() ?: DurationUnit.SECONDS
|
||||||
val value = meta[Meta.VALUE_KEY].double ?: error("No value present for Duration")
|
val value = meta[Meta.VALUE_KEY].double ?: error("No value present for Duration")
|
||||||
|
@ -68,7 +68,7 @@ public fun <D : Device> DeviceSpec<D>.booleanProperty(
|
|||||||
MetaConverter.boolean,
|
MetaConverter.boolean,
|
||||||
{
|
{
|
||||||
metaDescriptor {
|
metaDescriptor {
|
||||||
type(ValueType.BOOLEAN)
|
valueType(ValueType.BOOLEAN)
|
||||||
}
|
}
|
||||||
descriptorBuilder()
|
descriptorBuilder()
|
||||||
},
|
},
|
||||||
@ -80,7 +80,7 @@ private inline fun numberDescriptor(
|
|||||||
crossinline descriptorBuilder: PropertyDescriptor.() -> Unit = {}
|
crossinline descriptorBuilder: PropertyDescriptor.() -> Unit = {}
|
||||||
): PropertyDescriptor.() -> Unit = {
|
): PropertyDescriptor.() -> Unit = {
|
||||||
metaDescriptor {
|
metaDescriptor {
|
||||||
type(ValueType.NUMBER)
|
valueType(ValueType.NUMBER)
|
||||||
}
|
}
|
||||||
descriptorBuilder()
|
descriptorBuilder()
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ public fun <D : Device> DeviceSpec<D>.stringProperty(
|
|||||||
MetaConverter.string,
|
MetaConverter.string,
|
||||||
{
|
{
|
||||||
metaDescriptor {
|
metaDescriptor {
|
||||||
type(ValueType.STRING)
|
valueType(ValueType.STRING)
|
||||||
}
|
}
|
||||||
descriptorBuilder()
|
descriptorBuilder()
|
||||||
},
|
},
|
||||||
@ -131,7 +131,7 @@ public fun <D : Device> DeviceSpec<D>.metaProperty(
|
|||||||
MetaConverter.meta,
|
MetaConverter.meta,
|
||||||
{
|
{
|
||||||
metaDescriptor {
|
metaDescriptor {
|
||||||
type(ValueType.STRING)
|
valueType(ValueType.STRING)
|
||||||
}
|
}
|
||||||
descriptorBuilder()
|
descriptorBuilder()
|
||||||
},
|
},
|
||||||
@ -151,7 +151,7 @@ public fun <D : Device> DeviceSpec<D>.booleanProperty(
|
|||||||
MetaConverter.boolean,
|
MetaConverter.boolean,
|
||||||
{
|
{
|
||||||
metaDescriptor {
|
metaDescriptor {
|
||||||
type(ValueType.BOOLEAN)
|
valueType(ValueType.BOOLEAN)
|
||||||
}
|
}
|
||||||
descriptorBuilder()
|
descriptorBuilder()
|
||||||
},
|
},
|
||||||
|
@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode
|
|||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("space.kscience.gradle.mpp")
|
id("space.kscience.gradle.mpp")
|
||||||
id("org.jetbrains.compose") version "1.5.10"
|
id("org.jetbrains.compose") version "1.5.11"
|
||||||
}
|
}
|
||||||
|
|
||||||
kscience {
|
kscience {
|
||||||
|
@ -7,4 +7,4 @@ org.gradle.parallel=true
|
|||||||
org.gradle.configureondemand=true
|
org.gradle.configureondemand=true
|
||||||
org.gradle.jvmargs=-Xmx4096m
|
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
4
magix/README.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Module magix
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user