diff --git a/README.md b/README.md index 8e9fb54..0177832 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Among other things, you can: ### `dataforge-control-core` module packages - `api` - defines API for device management. The main class here is -[`Device`](dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/api/Device.kt). +[`Device`](controls-core/src/commonMain/kotlin/hep/dataforge/control/api/Device.kt). Generally, a Device has Properties that can be read and written. Also, some Actions can optionally be applied on a device (may or may not affect properties). diff --git a/build.gradle.kts b/build.gradle.kts index f28deb6..519ac45 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,28 +4,26 @@ plugins { kotlin("js") apply false } -val dataforgeVersion: String by extra("0.2.1-dev-2") -val ktorVersion: String by extra("1.5.0") +val dataforgeVersion: String by extra("0.3.0") +val ktorVersion: String by extra(ru.mipt.npm.gradle.KScienceVersions.ktorVersion) val rsocketVersion by extra("0.12.0") allprojects { repositories { mavenLocal() - //maven("https://dl.bintray.com/pdvrieze/maven") //maven("http://maven.jzy3d.org/releases") maven("https://kotlin.bintray.com/js-externals") - maven("https://maven.pkg.github.com/altavir/kotlin-logging/") - //maven("https://dl.bintray.com/rsocket-admin/RSocket") + maven("https://dl.bintray.com/rsocket-admin/RSocket") //maven("https://maven.pkg.github.com/altavir/ktor-client-sse") } - group = "hep.dataforge" + group = "ru.mipt.npm" version = "0.1.0" } ksciencePublish { githubProject = "controls.kt" - bintrayRepo = "dataforge" + bintrayRepo = "kscience" } apiValidation { diff --git a/dataforge-device-core/build.gradle.kts b/controls-core/build.gradle.kts similarity index 89% rename from dataforge-device-core/build.gradle.kts rename to controls-core/build.gradle.kts index 1da9011..85a8c6c 100644 --- a/dataforge-device-core/build.gradle.kts +++ b/controls-core/build.gradle.kts @@ -4,7 +4,6 @@ plugins { } val dataforgeVersion: String by rootProject.extra -val ktorVersion: String by rootProject.extra kscience { useCoroutines("1.4.1") diff --git a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/api/Device.kt b/controls-core/src/commonMain/kotlin/hep/dataforge/control/api/Device.kt similarity index 91% rename from dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/api/Device.kt rename to controls-core/src/commonMain/kotlin/hep/dataforge/control/api/Device.kt index 01762a2..93a21af 100644 --- a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/api/Device.kt +++ b/controls-core/src/commonMain/kotlin/hep/dataforge/control/api/Device.kt @@ -4,7 +4,7 @@ import hep.dataforge.context.ContextAware import hep.dataforge.control.api.Device.Companion.DEVICE_TARGET import hep.dataforge.meta.Meta import hep.dataforge.meta.MetaItem -import hep.dataforge.provider.Type +import hep.dataforge.misc.Type import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.cancel import kotlinx.coroutines.flow.SharedFlow @@ -35,7 +35,7 @@ public interface Device : Closeable, ContextAware { * Get the value of the property or throw error if property in not defined. * Suspend if property value is not available */ - public suspend fun getProperty(propertyName: String): MetaItem<*>? + public suspend fun getProperty(propertyName: String): MetaItem? /** * Invalidate property and force recalculate @@ -46,18 +46,18 @@ public interface Device : Closeable, ContextAware { * Set property [value] for a property with name [propertyName]. * In rare cases could suspend if the [Device] supports command queue and it is full at the moment. */ - public suspend fun setProperty(propertyName: String, value: MetaItem<*>) + public suspend fun setProperty(propertyName: String, value: MetaItem) /** * The [SharedFlow] of property changes */ - public val propertyFlow: SharedFlow>> + public val propertyFlow: SharedFlow> /** * Send an action request and suspend caller while request is being processed. * Could return null if request does not return a meaningful answer. */ - public suspend fun execute(action: String, argument: MetaItem<*>? = null): MetaItem<*>? + public suspend fun execute(action: String, argument: MetaItem? = null): MetaItem? override fun close() { scope.cancel("The device is closed") @@ -74,4 +74,4 @@ public suspend fun Device.getState(): Meta = Meta{ } } -//public suspend fun Device.execute(name: String, meta: Meta?): MetaItem<*>? = execute(name, meta?.let { MetaItem.NodeItem(it) }) \ No newline at end of file +//public suspend fun Device.execute(name: String, meta: Meta?): MetaItem? = execute(name, meta?.let { MetaItemNode(it) }) \ No newline at end of file diff --git a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/api/DeviceHub.kt b/controls-core/src/commonMain/kotlin/hep/dataforge/control/api/DeviceHub.kt similarity index 94% rename from dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/api/DeviceHub.kt rename to controls-core/src/commonMain/kotlin/hep/dataforge/control/api/DeviceHub.kt index 7133f9b..6809046 100644 --- a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/api/DeviceHub.kt +++ b/controls-core/src/commonMain/kotlin/hep/dataforge/control/api/DeviceHub.kt @@ -54,14 +54,14 @@ public operator fun DeviceHub.get(name: Name): Device? = when { public operator fun DeviceHub.get(deviceName: String): Device? = get(deviceName.toName()) -public suspend fun DeviceHub.getProperty(deviceName: Name, propertyName: String): MetaItem<*>? = +public suspend fun DeviceHub.getProperty(deviceName: Name, propertyName: String): MetaItem? = this[deviceName]?.getProperty(propertyName) -public suspend fun DeviceHub.setProperty(deviceName: Name, propertyName: String, value: MetaItem<*>) { +public suspend fun DeviceHub.setProperty(deviceName: Name, propertyName: String, value: MetaItem) { this[deviceName]?.setProperty(propertyName, value) } -public suspend fun DeviceHub.execute(deviceName: Name, command: String, argument: MetaItem<*>?): MetaItem<*>? = +public suspend fun DeviceHub.execute(deviceName: Name, command: String, argument: MetaItem?): MetaItem? = this[deviceName]?.execute(command, argument) diff --git a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/api/Socket.kt b/controls-core/src/commonMain/kotlin/hep/dataforge/control/api/Socket.kt similarity index 100% rename from dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/api/Socket.kt rename to controls-core/src/commonMain/kotlin/hep/dataforge/control/api/Socket.kt diff --git a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/api/descriptors.kt b/controls-core/src/commonMain/kotlin/hep/dataforge/control/api/descriptors.kt similarity index 100% rename from dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/api/descriptors.kt rename to controls-core/src/commonMain/kotlin/hep/dataforge/control/api/descriptors.kt diff --git a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/base/DeviceAction.kt b/controls-core/src/commonMain/kotlin/hep/dataforge/control/base/DeviceAction.kt similarity index 75% rename from dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/base/DeviceAction.kt rename to controls-core/src/commonMain/kotlin/hep/dataforge/control/base/DeviceAction.kt index 9012760..01b6ee6 100644 --- a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/base/DeviceAction.kt +++ b/controls-core/src/commonMain/kotlin/hep/dataforge/control/base/DeviceAction.kt @@ -8,7 +8,7 @@ import hep.dataforge.meta.asMetaItem public interface DeviceAction { public val name: String public val descriptor: ActionDescriptor - public suspend operator fun invoke(arg: MetaItem<*>? = null): MetaItem<*>? + public suspend operator fun invoke(arg: MetaItem? = null): MetaItem? } -public suspend operator fun DeviceAction.invoke(meta: Meta): MetaItem<*>? = invoke(meta.asMetaItem()) \ No newline at end of file +public suspend operator fun DeviceAction.invoke(meta: Meta): MetaItem? = invoke(meta.asMetaItem()) \ No newline at end of file diff --git a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/base/DeviceBase.kt b/controls-core/src/commonMain/kotlin/hep/dataforge/control/base/DeviceBase.kt similarity index 83% rename from dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/base/DeviceBase.kt rename to controls-core/src/commonMain/kotlin/hep/dataforge/control/base/DeviceBase.kt index 9ac7e2b..ecf501b 100644 --- a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/base/DeviceBase.kt +++ b/controls-core/src/commonMain/kotlin/hep/dataforge/control/base/DeviceBase.kt @@ -4,8 +4,8 @@ import hep.dataforge.context.Context import hep.dataforge.control.api.ActionDescriptor import hep.dataforge.control.api.Device import hep.dataforge.control.api.PropertyDescriptor -import hep.dataforge.meta.DFExperimental import hep.dataforge.meta.MetaItem +import hep.dataforge.misc.DFExperimental import kotlinx.coroutines.* import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow @@ -29,9 +29,9 @@ public abstract class DeviceBase(override val context: Context) : Device { private val _actions = HashMap() public val actions: Map get() = _actions - private val sharedPropertyFlow = MutableSharedFlow>>() + private val sharedPropertyFlow = MutableSharedFlow>() - override val propertyFlow: SharedFlow>> get() = sharedPropertyFlow + override val propertyFlow: SharedFlow> get() = sharedPropertyFlow private val sharedLogFlow = MutableSharedFlow() @@ -62,47 +62,47 @@ public abstract class DeviceBase(override val context: Context) : Device { _actions[name] = action } - override suspend fun getProperty(propertyName: String): MetaItem<*> = + override suspend fun getProperty(propertyName: String): MetaItem = (_properties[propertyName] ?: error("Property with name $propertyName not defined")).read() override suspend fun invalidateProperty(propertyName: String) { (_properties[propertyName] ?: error("Property with name $propertyName not defined")).invalidate() } - override suspend fun setProperty(propertyName: String, value: MetaItem<*>) { + override suspend fun setProperty(propertyName: String, value: MetaItem) { (_properties[propertyName] as? DeviceProperty ?: error("Property with name $propertyName not defined")).write( value ) } - override suspend fun execute(action: String, argument: MetaItem<*>?): MetaItem<*>? = + override suspend fun execute(action: String, argument: MetaItem?): MetaItem? = (_actions[action] ?: error("Request with name $action not defined")).invoke(argument) @OptIn(ExperimentalCoroutinesApi::class) private open inner class BasicReadOnlyDeviceProperty( override val name: String, - default: MetaItem<*>?, + default: MetaItem?, override val descriptor: PropertyDescriptor, - private val getter: suspend (before: MetaItem<*>?) -> MetaItem<*>, + private val getter: suspend (before: MetaItem?) -> MetaItem, ) : ReadOnlyDeviceProperty { override val scope: CoroutineScope get() = this@DeviceBase.scope - private val state: MutableStateFlow?> = MutableStateFlow(default) - override val value: MetaItem<*>? get() = state.value + private val state: MutableStateFlow = MutableStateFlow(default) + override val value: MetaItem? get() = state.value override suspend fun invalidate() { state.value = null } - override fun updateLogical(item: MetaItem<*>) { + override fun updateLogical(item: MetaItem) { state.value = item scope.launch { sharedPropertyFlow.emit(Pair(name, item)) } } - override suspend fun read(force: Boolean): MetaItem<*> { + override suspend fun read(force: Boolean): MetaItem { //backup current value val currentValue = value return if (force || currentValue == null) { @@ -118,7 +118,7 @@ public abstract class DeviceBase(override val context: Context) : Device { } } - override fun flow(): StateFlow?> = state + override fun flow(): StateFlow = state } /** @@ -126,9 +126,9 @@ public abstract class DeviceBase(override val context: Context) : Device { */ public fun createReadOnlyProperty( name: String, - default: MetaItem<*>?, + default: MetaItem?, descriptorBuilder: PropertyDescriptor.() -> Unit = {}, - getter: suspend (MetaItem<*>?) -> MetaItem<*>, + getter: suspend (MetaItem?) -> MetaItem, ): ReadOnlyDeviceProperty { val property = BasicReadOnlyDeviceProperty( name, @@ -143,13 +143,13 @@ public abstract class DeviceBase(override val context: Context) : Device { @OptIn(ExperimentalCoroutinesApi::class) private inner class BasicDeviceProperty( name: String, - default: MetaItem<*>?, + default: MetaItem?, descriptor: PropertyDescriptor, - getter: suspend (MetaItem<*>?) -> MetaItem<*>, - private val setter: suspend (oldValue: MetaItem<*>?, newValue: MetaItem<*>) -> MetaItem<*>?, + getter: suspend (MetaItem?) -> MetaItem, + private val setter: suspend (oldValue: MetaItem?, newValue: MetaItem) -> MetaItem?, ) : BasicReadOnlyDeviceProperty(name, default, descriptor, getter), DeviceProperty { - override var value: MetaItem<*>? + override var value: MetaItem? get() = super.value set(value) { scope.launch { @@ -163,7 +163,7 @@ public abstract class DeviceBase(override val context: Context) : Device { private val writeLock = Mutex() - override suspend fun write(item: MetaItem<*>) { + override suspend fun write(item: MetaItem) { writeLock.withLock { //fast return if value is not changed if (item == value) return@withLock @@ -183,10 +183,10 @@ public abstract class DeviceBase(override val context: Context) : Device { */ internal fun createMutableProperty( name: String, - default: MetaItem<*>?, + default: MetaItem?, descriptorBuilder: PropertyDescriptor.() -> Unit = {}, - getter: suspend (MetaItem<*>?) -> MetaItem<*>, - setter: suspend (oldValue: MetaItem<*>?, newValue: MetaItem<*>) -> MetaItem<*>?, + getter: suspend (MetaItem?) -> MetaItem, + setter: suspend (oldValue: MetaItem?, newValue: MetaItem) -> MetaItem?, ): DeviceProperty { val property = BasicDeviceProperty( name, @@ -205,9 +205,9 @@ public abstract class DeviceBase(override val context: Context) : Device { private inner class BasicDeviceAction( override val name: String, override val descriptor: ActionDescriptor, - private val block: suspend (MetaItem<*>?) -> MetaItem<*>?, + private val block: suspend (MetaItem?) -> MetaItem?, ) : DeviceAction { - override suspend fun invoke(arg: MetaItem<*>?): MetaItem<*>? = + override suspend fun invoke(arg: MetaItem?): MetaItem? = withContext(scope.coroutineContext + SupervisorJob(scope.coroutineContext[Job])) { block(arg) } @@ -219,7 +219,7 @@ public abstract class DeviceBase(override val context: Context) : Device { internal fun createAction( name: String, descriptorBuilder: ActionDescriptor.() -> Unit = {}, - block: suspend (MetaItem<*>?) -> MetaItem<*>?, + block: suspend (MetaItem?) -> MetaItem?, ): DeviceAction { val action = BasicDeviceAction(name, ActionDescriptor(name).apply(descriptorBuilder), block) registerAction(name, action) diff --git a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/base/DeviceProperty.kt b/controls-core/src/commonMain/kotlin/hep/dataforge/control/base/DeviceProperty.kt similarity index 85% rename from dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/base/DeviceProperty.kt rename to controls-core/src/commonMain/kotlin/hep/dataforge/control/base/DeviceProperty.kt index 426dee6..f97fcb2 100644 --- a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/base/DeviceProperty.kt +++ b/controls-core/src/commonMain/kotlin/hep/dataforge/control/base/DeviceProperty.kt @@ -30,24 +30,24 @@ public interface ReadOnlyDeviceProperty { /** * Directly update property logical value and notify listener without writing it to device */ - public fun updateLogical(item: MetaItem<*>) + public fun updateLogical(item: MetaItem) /** * Get cached value and return null if value is invalid or not initialized */ - public val value: MetaItem<*>? + public val value: MetaItem? /** * Read value either from cache if cache is valid or directly from physical device. * If [force], reread from physical state even if the logical state is set. */ - public suspend fun read(force: Boolean = false): MetaItem<*> + public suspend fun read(force: Boolean = false): MetaItem /** * The [Flow] representing future logical states of the property. * Produces null when the state is invalidated */ - public fun flow(): Flow?> + public fun flow(): Flow } @@ -65,10 +65,10 @@ public fun ReadOnlyDeviceProperty.readEvery(duration: Duration): Job = scope.lau * A writeable device property with non-suspended write */ public interface DeviceProperty : ReadOnlyDeviceProperty { - override var value: MetaItem<*>? + override var value: MetaItem? /** * Write value to physical device. Invalidates logical value, but does not update it automatically */ - public suspend fun write(item: MetaItem<*>) + public suspend fun write(item: MetaItem) } \ No newline at end of file diff --git a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/base/TypedDeviceProperty.kt b/controls-core/src/commonMain/kotlin/hep/dataforge/control/base/TypedDeviceProperty.kt similarity index 94% rename from dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/base/TypedDeviceProperty.kt rename to controls-core/src/commonMain/kotlin/hep/dataforge/control/base/TypedDeviceProperty.kt index b098899..90ef43a 100644 --- a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/base/TypedDeviceProperty.kt +++ b/controls-core/src/commonMain/kotlin/hep/dataforge/control/base/TypedDeviceProperty.kt @@ -32,7 +32,7 @@ public class TypedDeviceProperty( converter: MetaConverter, ) : TypedReadOnlyDeviceProperty(property, converter), DeviceProperty { - override var value: MetaItem<*>? + override var value: MetaItem? get() = property.value set(arg) { property.value = arg @@ -44,7 +44,7 @@ public class TypedDeviceProperty( property.value = arg?.let { converter.objectToMetaItem(arg) } } - override suspend fun write(item: MetaItem<*>) { + override suspend fun write(item: MetaItem) { property.write(item) } diff --git a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/base/actionDelegates.kt b/controls-core/src/commonMain/kotlin/hep/dataforge/control/base/actionDelegates.kt similarity index 83% rename from dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/base/actionDelegates.kt rename to controls-core/src/commonMain/kotlin/hep/dataforge/control/base/actionDelegates.kt index 1de2cf7..08d3e81 100644 --- a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/base/actionDelegates.kt +++ b/controls-core/src/commonMain/kotlin/hep/dataforge/control/base/actionDelegates.kt @@ -3,6 +3,8 @@ package hep.dataforge.control.base import hep.dataforge.control.api.ActionDescriptor import hep.dataforge.meta.MetaBuilder import hep.dataforge.meta.MetaItem +import hep.dataforge.meta.MetaItemNode +import hep.dataforge.meta.MetaItemValue import hep.dataforge.values.Value import kotlin.properties.PropertyDelegateProvider import kotlin.properties.ReadOnlyProperty @@ -20,7 +22,7 @@ public typealias ActionDelegate = ReadOnlyProperty private class ActionProvider( val owner: D, val descriptorBuilder: ActionDescriptor.() -> Unit = {}, - val block: suspend (MetaItem<*>?) -> MetaItem<*>?, + val block: suspend (MetaItem?) -> MetaItem?, ) : PropertyDelegateProvider { override operator fun provideDelegate(thisRef: D, property: KProperty<*>): ActionDelegate { val name = property.name @@ -31,28 +33,28 @@ private class ActionProvider( public fun DeviceBase.requesting( descriptorBuilder: ActionDescriptor.() -> Unit = {}, - action: suspend (MetaItem<*>?) -> MetaItem<*>?, + action: suspend (MetaItem?) -> MetaItem?, ): PropertyDelegateProvider = ActionProvider(this, descriptorBuilder, action) public fun D.requestingValue( descriptorBuilder: ActionDescriptor.() -> Unit = {}, - action: suspend (MetaItem<*>?) -> Any?, + action: suspend (MetaItem?) -> Any?, ): PropertyDelegateProvider = ActionProvider(this, descriptorBuilder) { val res = action(it) - MetaItem.ValueItem(Value.of(res)) + MetaItemValue(Value.of(res)) } public fun D.requestingMeta( descriptorBuilder: ActionDescriptor.() -> Unit = {}, - action: suspend MetaBuilder.(MetaItem<*>?) -> Unit, + action: suspend MetaBuilder.(MetaItem?) -> Unit, ): PropertyDelegateProvider = ActionProvider(this, descriptorBuilder) { val res = MetaBuilder().apply { action(it) } - MetaItem.NodeItem(res) + MetaItemNode(res) } public fun DeviceBase.acting( descriptorBuilder: ActionDescriptor.() -> Unit = {}, - action: suspend (MetaItem<*>?) -> Unit, + action: suspend (MetaItem?) -> Unit, ): PropertyDelegateProvider = ActionProvider(this, descriptorBuilder) { action(it) null diff --git a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/base/devicePropertyDelegates.kt b/controls-core/src/commonMain/kotlin/hep/dataforge/control/base/devicePropertyDelegates.kt similarity index 79% rename from dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/base/devicePropertyDelegates.kt rename to controls-core/src/commonMain/kotlin/hep/dataforge/control/base/devicePropertyDelegates.kt index 008e2ff..07443cf 100644 --- a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/base/devicePropertyDelegates.kt +++ b/controls-core/src/commonMain/kotlin/hep/dataforge/control/base/devicePropertyDelegates.kt @@ -29,9 +29,9 @@ public typealias TypedReadOnlyPropertyDelegate = ReadOnlyProperty( val owner: D, - val default: MetaItem<*>?, + val default: MetaItem?, val descriptorBuilder: PropertyDescriptor.() -> Unit = {}, - private val getter: suspend (MetaItem<*>?) -> MetaItem<*>, + private val getter: suspend (MetaItem?) -> MetaItem, ) : PropertyDelegateProvider { override operator fun provideDelegate(thisRef: D, property: KProperty<*>): ReadOnlyPropertyDelegate { @@ -43,10 +43,10 @@ private class ReadOnlyDevicePropertyProvider( private class TypedReadOnlyDevicePropertyProvider( val owner: D, - val default: MetaItem<*>?, + val default: MetaItem?, val converter: MetaConverter, val descriptorBuilder: PropertyDescriptor.() -> Unit = {}, - private val getter: suspend (MetaItem<*>?) -> MetaItem<*>, + private val getter: suspend (MetaItem?) -> MetaItem, ) : PropertyDelegateProvider> { override operator fun provideDelegate(thisRef: D, property: KProperty<*>): TypedReadOnlyPropertyDelegate { @@ -57,9 +57,9 @@ private class TypedReadOnlyDevicePropertyProvider( } public fun DeviceBase.reading( - default: MetaItem<*>? = null, + default: MetaItem? = null, descriptorBuilder: PropertyDescriptor.() -> Unit = {}, - getter: suspend (MetaItem<*>?) -> MetaItem<*>, + getter: suspend (MetaItem?) -> MetaItem, ): PropertyDelegateProvider = ReadOnlyDevicePropertyProvider( this, default, @@ -73,9 +73,9 @@ public fun DeviceBase.readingValue( getter: suspend () -> Any?, ): PropertyDelegateProvider = ReadOnlyDevicePropertyProvider( this, - default?.let { MetaItem.ValueItem(it) }, + default?.let { MetaItemValue(it) }, descriptorBuilder, - getter = { MetaItem.ValueItem(Value.of(getter())) } + getter = { MetaItemValue(Value.of(getter())) } ) public fun DeviceBase.readingNumber( @@ -84,12 +84,12 @@ public fun DeviceBase.readingNumber( getter: suspend () -> Number, ): PropertyDelegateProvider> = TypedReadOnlyDevicePropertyProvider( this, - default?.let { MetaItem.ValueItem(it.asValue()) }, + default?.let { MetaItemValue(it.asValue()) }, MetaConverter.number, descriptorBuilder, getter = { val number = getter() - MetaItem.ValueItem(number.asValue()) + MetaItemValue(number.asValue()) } ) @@ -99,12 +99,12 @@ public fun DeviceBase.readingDouble( getter: suspend () -> Double, ): PropertyDelegateProvider> = TypedReadOnlyDevicePropertyProvider( this, - default?.let { MetaItem.ValueItem(it.asValue()) }, + default?.let { MetaItemValue(it.asValue()) }, MetaConverter.double, descriptorBuilder, getter = { val number = getter() - MetaItem.ValueItem(number.asValue()) + MetaItemValue(number.asValue()) } ) @@ -114,12 +114,12 @@ public fun DeviceBase.readingString( getter: suspend () -> String, ): PropertyDelegateProvider> = TypedReadOnlyDevicePropertyProvider( this, - default?.let { MetaItem.ValueItem(it.asValue()) }, + default?.let { MetaItemValue(it.asValue()) }, MetaConverter.string, descriptorBuilder, getter = { val number = getter() - MetaItem.ValueItem(number.asValue()) + MetaItemValue(number.asValue()) } ) @@ -129,12 +129,12 @@ public fun DeviceBase.readingBoolean( getter: suspend () -> Boolean, ): PropertyDelegateProvider> = TypedReadOnlyDevicePropertyProvider( this, - default?.let { MetaItem.ValueItem(it.asValue()) }, + default?.let { MetaItemValue(it.asValue()) }, MetaConverter.boolean, descriptorBuilder, getter = { val boolean = getter() - MetaItem.ValueItem(boolean.asValue()) + MetaItemValue(boolean.asValue()) } ) @@ -144,11 +144,11 @@ public fun DeviceBase.readingMeta( getter: suspend MetaBuilder.() -> Unit, ): PropertyDelegateProvider> = TypedReadOnlyDevicePropertyProvider( this, - default?.let { MetaItem.NodeItem(it) }, + default?.let { MetaItemNode(it) }, MetaConverter.meta, descriptorBuilder, getter = { - MetaItem.NodeItem(MetaBuilder().apply { getter() }) + MetaItemNode(MetaBuilder().apply { getter() }) } ) @@ -170,10 +170,10 @@ public typealias TypedPropertyDelegate = ReadOnlyProperty( val owner: D, - val default: MetaItem<*>?, + val default: MetaItem?, val descriptorBuilder: PropertyDescriptor.() -> Unit = {}, - private val getter: suspend (MetaItem<*>?) -> MetaItem<*>, - private val setter: suspend (oldValue: MetaItem<*>?, newValue: MetaItem<*>) -> MetaItem<*>?, + private val getter: suspend (MetaItem?) -> MetaItem, + private val setter: suspend (oldValue: MetaItem?, newValue: MetaItem) -> MetaItem?, ) : PropertyDelegateProvider { override operator fun provideDelegate(thisRef: D, property: KProperty<*>): PropertyDelegate { @@ -185,11 +185,11 @@ private class DevicePropertyProvider( private class TypedDevicePropertyProvider( val owner: D, - val default: MetaItem<*>?, + val default: MetaItem?, val converter: MetaConverter, val descriptorBuilder: PropertyDescriptor.() -> Unit = {}, - private val getter: suspend (MetaItem<*>?) -> MetaItem<*>, - private val setter: suspend (oldValue: MetaItem<*>?, newValue: MetaItem<*>) -> MetaItem<*>?, + private val getter: suspend (MetaItem?) -> MetaItem, + private val setter: suspend (oldValue: MetaItem?, newValue: MetaItem) -> MetaItem?, ) : PropertyDelegateProvider> { override operator fun provideDelegate(thisRef: D, property: KProperty<*>): TypedPropertyDelegate { @@ -200,10 +200,10 @@ private class TypedDevicePropertyProvider( } public fun DeviceBase.writing( - default: MetaItem<*>? = null, + default: MetaItem? = null, descriptorBuilder: PropertyDescriptor.() -> Unit = {}, - getter: suspend (MetaItem<*>?) -> MetaItem<*>, - setter: suspend (oldValue: MetaItem<*>?, newValue: MetaItem<*>) -> MetaItem<*>?, + getter: suspend (MetaItem?) -> MetaItem, + setter: suspend (oldValue: MetaItem?, newValue: MetaItem) -> MetaItem?, ): PropertyDelegateProvider = DevicePropertyProvider( this, default, @@ -213,7 +213,7 @@ public fun DeviceBase.writing( ) public fun DeviceBase.writingVirtual( - default: MetaItem<*>, + default: MetaItem, descriptorBuilder: PropertyDescriptor.() -> Unit = {}, ): PropertyDelegateProvider = writing( default, @@ -226,9 +226,9 @@ public fun DeviceBase.writingVirtual( default: Value, descriptorBuilder: PropertyDescriptor.() -> Unit = {}, ): PropertyDelegateProvider = writing( - MetaItem.ValueItem(default), + MetaItemValue(default), descriptorBuilder, - getter = { it ?: MetaItem.ValueItem(default) }, + getter = { it ?: MetaItemValue(default) }, setter = { _, newItem -> newItem } ) @@ -236,9 +236,9 @@ public fun DeviceBase.writingVirtual( default: Meta, descriptorBuilder: PropertyDescriptor.() -> Unit = {}, ): PropertyDelegateProvider = writing( - MetaItem.NodeItem(default), + MetaItemNode(default), descriptorBuilder, - getter = { it ?: MetaItem.NodeItem(default) }, + getter = { it ?: MetaItemNode(default) }, setter = { _, newItem -> newItem } ) @@ -247,17 +247,17 @@ public fun D.writingDouble( getter: suspend (Double) -> Double, setter: suspend (oldValue: Double?, newValue: Double) -> Double?, ): PropertyDelegateProvider> { - val innerGetter: suspend (MetaItem<*>?) -> MetaItem<*> = { - MetaItem.ValueItem(getter(it.double ?: Double.NaN).asValue()) + val innerGetter: suspend (MetaItem?) -> MetaItem = { + MetaItemValue(getter(it.double ?: Double.NaN).asValue()) } - val innerSetter: suspend (oldValue: MetaItem<*>?, newValue: MetaItem<*>) -> MetaItem<*>? = { oldValue, newValue -> + val innerSetter: suspend (oldValue: MetaItem?, newValue: MetaItem) -> MetaItem? = { oldValue, newValue -> setter(oldValue.double, newValue.double ?: Double.NaN)?.asMetaItem() } return TypedDevicePropertyProvider( this, - MetaItem.ValueItem(Double.NaN.asValue()), + MetaItemValue(Double.NaN.asValue()), MetaConverter.double, descriptorBuilder, innerGetter, @@ -270,18 +270,18 @@ public fun D.writingBoolean( getter: suspend (Boolean?) -> Boolean, setter: suspend (oldValue: Boolean?, newValue: Boolean) -> Boolean?, ): PropertyDelegateProvider> { - val innerGetter: suspend (MetaItem<*>?) -> MetaItem<*> = { - MetaItem.ValueItem(getter(it.boolean).asValue()) + val innerGetter: suspend (MetaItem?) -> MetaItem = { + MetaItemValue(getter(it.boolean).asValue()) } - val innerSetter: suspend (oldValue: MetaItem<*>?, newValue: MetaItem<*>) -> MetaItem<*>? = { oldValue, newValue -> + val innerSetter: suspend (oldValue: MetaItem?, newValue: MetaItem) -> MetaItem? = { oldValue, newValue -> setter(oldValue.boolean, newValue.boolean ?: error("Can't convert $newValue to boolean"))?.asValue() ?.asMetaItem() } return TypedDevicePropertyProvider( this, - MetaItem.ValueItem(Null), + MetaItemValue(Null), MetaConverter.boolean, descriptorBuilder, innerGetter, diff --git a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/base/misc.kt b/controls-core/src/commonMain/kotlin/hep/dataforge/control/base/misc.kt similarity index 62% rename from dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/base/misc.kt rename to controls-core/src/commonMain/kotlin/hep/dataforge/control/base/misc.kt index 781794c..cc8146f 100644 --- a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/base/misc.kt +++ b/controls-core/src/commonMain/kotlin/hep/dataforge/control/base/misc.kt @@ -8,20 +8,20 @@ import kotlin.time.Duration import kotlin.time.DurationUnit import kotlin.time.toDuration -public fun Double.asMetaItem(): MetaItem.ValueItem = MetaItem.ValueItem(asValue()) +public fun Double.asMetaItem(): MetaItemValue = MetaItemValue(asValue()) //TODO to be moved to DF public object DurationConverter : MetaConverter { - override fun itemToObject(item: MetaItem<*>): Duration = when (item) { - is MetaItem.NodeItem -> { + override fun itemToObject(item: MetaItem): Duration = when (item) { + is MetaItemNode -> { val unit: DurationUnit = item.node["unit"].enum() ?: DurationUnit.SECONDS val value = item.node[Meta.VALUE_KEY].double ?: error("No value present for Duration") value.toDuration(unit) } - is MetaItem.ValueItem -> item.value.double.toDuration(DurationUnit.SECONDS) + is MetaItemValue -> item.value.double.toDuration(DurationUnit.SECONDS) } - override fun objectToMetaItem(obj: Duration): MetaItem<*> = obj.toDouble(DurationUnit.SECONDS).asMetaItem() + override fun objectToMetaItem(obj: Duration): MetaItem = obj.toDouble(DurationUnit.SECONDS).asMetaItem() } public val MetaConverter.Companion.duration: MetaConverter get() = DurationConverter \ No newline at end of file diff --git a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/controllers/DeviceController.kt b/controls-core/src/commonMain/kotlin/hep/dataforge/control/controllers/DeviceController.kt similarity index 96% rename from dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/controllers/DeviceController.kt rename to controls-core/src/commonMain/kotlin/hep/dataforge/control/controllers/DeviceController.kt index 6bd5b4b..4994efd 100644 --- a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/controllers/DeviceController.kt +++ b/controls-core/src/commonMain/kotlin/hep/dataforge/control/controllers/DeviceController.kt @@ -4,9 +4,9 @@ import hep.dataforge.control.api.Device import hep.dataforge.control.api.DeviceHub import hep.dataforge.control.api.get import hep.dataforge.control.messages.* -import hep.dataforge.meta.DFExperimental import hep.dataforge.meta.Meta import hep.dataforge.meta.MetaItem +import hep.dataforge.misc.DFExperimental import hep.dataforge.names.Name import hep.dataforge.names.toName import kotlinx.coroutines.flow.Flow @@ -21,7 +21,7 @@ public class DeviceController( public val deviceName: String, ) { - private val propertyChanges = device.propertyFlow.map { (propertyName: String, value: MetaItem<*>) -> + private val propertyChanges = device.propertyFlow.map { (propertyName: String, value: MetaItem) -> PropertyChangedMessage( sourceDevice = deviceName, property = propertyName, @@ -103,12 +103,12 @@ public class DeviceController( val descriptionMeta = Meta { "properties" put { device.propertyDescriptors.map { descriptor -> - descriptor.name put descriptor.config + descriptor.name put descriptor.toMeta() } } "actions" put { device.actionDescriptors.map { descriptor -> - descriptor.name put descriptor.config + descriptor.name put descriptor.toMeta() } } } diff --git a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/controllers/DeviceManager.kt b/controls-core/src/commonMain/kotlin/hep/dataforge/control/controllers/DeviceManager.kt similarity index 100% rename from dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/controllers/DeviceManager.kt rename to controls-core/src/commonMain/kotlin/hep/dataforge/control/controllers/DeviceManager.kt diff --git a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/controllers/HubController.kt b/controls-core/src/commonMain/kotlin/hep/dataforge/control/controllers/HubController.kt similarity index 97% rename from dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/controllers/HubController.kt rename to controls-core/src/commonMain/kotlin/hep/dataforge/control/controllers/HubController.kt index 5bc630d..acbb9a4 100644 --- a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/controllers/HubController.kt +++ b/controls-core/src/commonMain/kotlin/hep/dataforge/control/controllers/HubController.kt @@ -3,7 +3,7 @@ package hep.dataforge.control.controllers import hep.dataforge.control.api.DeviceHub import hep.dataforge.control.api.get import hep.dataforge.control.messages.DeviceMessage -import hep.dataforge.meta.DFExperimental +import hep.dataforge.misc.DFExperimental import hep.dataforge.names.Name import hep.dataforge.names.toName import kotlinx.coroutines.channels.Channel @@ -33,7 +33,7 @@ public class HubController( // private val listeners: Map = hub.devices.mapValues { (deviceNameToken, device) -> // object : DeviceListener { -// override fun propertyChanged(propertyName: String, value: MetaItem<*>?) { +// override fun propertyChanged(propertyName: String, value: MetaItem?) { // if (value == null) return // scope.launch { // val change = PropertyChangedMessage( diff --git a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/messages/DeviceMessage.kt b/controls-core/src/commonMain/kotlin/hep/dataforge/control/messages/DeviceMessage.kt similarity index 96% rename from dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/messages/DeviceMessage.kt rename to controls-core/src/commonMain/kotlin/hep/dataforge/control/messages/DeviceMessage.kt index e163410..28a4f89 100644 --- a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/messages/DeviceMessage.kt +++ b/controls-core/src/commonMain/kotlin/hep/dataforge/control/messages/DeviceMessage.kt @@ -42,7 +42,7 @@ public sealed class DeviceMessage { @SerialName("property.changed") public data class PropertyChangedMessage( public val property: String, - public val value: MetaItem<*>?, + public val value: MetaItem?, override val sourceDevice: String, override val targetDevice: String? = null, override val comment: String? = null, @@ -55,7 +55,7 @@ public data class PropertyChangedMessage( @SerialName("property.set") public data class PropertySetMessage( public val property: String, - public val value: MetaItem<*>?, + public val value: MetaItem?, override val sourceDevice: String? = null, override val targetDevice: String, override val comment: String? = null, @@ -104,7 +104,7 @@ public data class DescriptionMessage( @SerialName("action.execute") public data class ActionExecuteMessage( public val action: String, - public val argument: MetaItem<*>?, + public val argument: MetaItem?, override val sourceDevice: String? = null, override val targetDevice: String, override val comment: String? = null, @@ -117,7 +117,7 @@ public data class ActionExecuteMessage( @SerialName("action.result") public data class ActionResultMessage( public val action: String, - public val result: MetaItem<*>?, + public val result: MetaItem?, override val sourceDevice: String, override val targetDevice: String? = null, override val comment: String? = null, @@ -154,7 +154,7 @@ public data class EmptyDeviceMessage( @SerialName("log") public data class DeviceLogMessage( val message: String, - val data: MetaItem<*>? = null, + val data: MetaItem? = null, override val sourceDevice: String? = null, override val targetDevice: String? = null, override val comment: String? = null, diff --git a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/ports/Port.kt b/controls-core/src/commonMain/kotlin/hep/dataforge/control/ports/Port.kt similarity index 97% rename from dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/ports/Port.kt rename to controls-core/src/commonMain/kotlin/hep/dataforge/control/ports/Port.kt index e0d7544..9503277 100644 --- a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/ports/Port.kt +++ b/controls-core/src/commonMain/kotlin/hep/dataforge/control/ports/Port.kt @@ -3,6 +3,7 @@ package hep.dataforge.control.ports import hep.dataforge.context.Context import hep.dataforge.context.ContextAware import hep.dataforge.context.Factory +import hep.dataforge.context.logger import hep.dataforge.control.api.Socket import kotlinx.coroutines.* import kotlinx.coroutines.channels.Channel diff --git a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/ports/PortProxy.kt b/controls-core/src/commonMain/kotlin/hep/dataforge/control/ports/PortProxy.kt similarity index 98% rename from dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/ports/PortProxy.kt rename to controls-core/src/commonMain/kotlin/hep/dataforge/control/ports/PortProxy.kt index df7dc17..973a6dd 100644 --- a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/ports/PortProxy.kt +++ b/controls-core/src/commonMain/kotlin/hep/dataforge/control/ports/PortProxy.kt @@ -3,6 +3,7 @@ package hep.dataforge.control.ports import hep.dataforge.context.Context import hep.dataforge.context.ContextAware import hep.dataforge.context.Global +import hep.dataforge.context.logger import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.collect diff --git a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/ports/SynchronousPortHandler.kt b/controls-core/src/commonMain/kotlin/hep/dataforge/control/ports/SynchronousPortHandler.kt similarity index 100% rename from dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/ports/SynchronousPortHandler.kt rename to controls-core/src/commonMain/kotlin/hep/dataforge/control/ports/SynchronousPortHandler.kt diff --git a/dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/ports/phrases.kt b/controls-core/src/commonMain/kotlin/hep/dataforge/control/ports/phrases.kt similarity index 100% rename from dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/ports/phrases.kt rename to controls-core/src/commonMain/kotlin/hep/dataforge/control/ports/phrases.kt diff --git a/dataforge-device-core/src/jvmMain/kotlin/hep/dataforge/control/controllers/delegates.kt b/controls-core/src/jvmMain/kotlin/hep/dataforge/control/controllers/delegates.kt similarity index 95% rename from dataforge-device-core/src/jvmMain/kotlin/hep/dataforge/control/controllers/delegates.kt rename to controls-core/src/jvmMain/kotlin/hep/dataforge/control/controllers/delegates.kt index 4489972..c1b6472 100644 --- a/dataforge-device-core/src/jvmMain/kotlin/hep/dataforge/control/controllers/delegates.kt +++ b/controls-core/src/jvmMain/kotlin/hep/dataforge/control/controllers/delegates.kt @@ -1,7 +1,7 @@ package hep.dataforge.control.controllers import hep.dataforge.control.base.* -import hep.dataforge.meta.* +import hep.dataforge.meta.MetaItem import hep.dataforge.meta.transformations.MetaConverter import kotlinx.coroutines.runBlocking import kotlin.properties.ReadOnlyProperty @@ -12,7 +12,7 @@ import kotlin.time.Duration /** * Blocking read of the value */ -public operator fun ReadOnlyDeviceProperty.getValue(thisRef: Any?, property: KProperty<*>): MetaItem<*> = +public operator fun ReadOnlyDeviceProperty.getValue(thisRef: Any?, property: KProperty<*>): MetaItem = runBlocking(scope.coroutineContext) { read() } @@ -22,7 +22,7 @@ public operator fun TypedReadOnlyDeviceProperty.getValue(thisRef: An readTyped() } -public operator fun DeviceProperty.setValue(thisRef: Any?, property: KProperty<*>, value: MetaItem<*>) { +public operator fun DeviceProperty.setValue(thisRef: Any?, property: KProperty<*>, value: MetaItem) { this.value = value } diff --git a/dataforge-device-core/src/jvmMain/kotlin/hep/dataforge/control/ports/TcpPort.kt b/controls-core/src/jvmMain/kotlin/hep/dataforge/control/ports/TcpPort.kt similarity index 98% rename from dataforge-device-core/src/jvmMain/kotlin/hep/dataforge/control/ports/TcpPort.kt rename to controls-core/src/jvmMain/kotlin/hep/dataforge/control/ports/TcpPort.kt index 9a9ddea..3b6b154 100644 --- a/dataforge-device-core/src/jvmMain/kotlin/hep/dataforge/control/ports/TcpPort.kt +++ b/controls-core/src/jvmMain/kotlin/hep/dataforge/control/ports/TcpPort.kt @@ -1,6 +1,7 @@ package hep.dataforge.control.ports import hep.dataforge.context.Context +import hep.dataforge.context.logger import hep.dataforge.meta.Meta import hep.dataforge.meta.get import hep.dataforge.meta.int diff --git a/dataforge-device-core/src/jvmTest/kotlin/hep/dataforge/control/ports/PortIOTest.kt b/controls-core/src/jvmTest/kotlin/hep/dataforge/control/ports/PortIOTest.kt similarity index 100% rename from dataforge-device-core/src/jvmTest/kotlin/hep/dataforge/control/ports/PortIOTest.kt rename to controls-core/src/jvmTest/kotlin/hep/dataforge/control/ports/PortIOTest.kt diff --git a/dataforge-magix-client/build.gradle.kts b/controls-magix-client/build.gradle.kts similarity index 72% rename from dataforge-magix-client/build.gradle.kts rename to controls-magix-client/build.gradle.kts index 4059a2f..4a29d72 100644 --- a/dataforge-magix-client/build.gradle.kts +++ b/controls-magix-client/build.gradle.kts @@ -3,8 +3,6 @@ plugins { id("ru.mipt.npm.publish") } -val ktorVersion: String by rootProject.extra - kscience{ useSerialization { json() @@ -16,7 +14,7 @@ kotlin { commonMain { dependencies { implementation(project(":magix:magix-service")) - implementation(project(":dataforge-device-core")) + implementation(project(":controls-core")) } } } diff --git a/dataforge-magix-client/src/commonMain/kotlin/hep/dataforge/control/client/TangoPayload.kt b/controls-magix-client/src/commonMain/kotlin/hep/dataforge/control/client/TangoPayload.kt similarity index 100% rename from dataforge-magix-client/src/commonMain/kotlin/hep/dataforge/control/client/TangoPayload.kt rename to controls-magix-client/src/commonMain/kotlin/hep/dataforge/control/client/TangoPayload.kt diff --git a/dataforge-magix-client/src/commonMain/kotlin/hep/dataforge/control/client/magixClient.kt b/controls-magix-client/src/commonMain/kotlin/hep/dataforge/control/client/magixClient.kt similarity index 98% rename from dataforge-magix-client/src/commonMain/kotlin/hep/dataforge/control/client/magixClient.kt rename to controls-magix-client/src/commonMain/kotlin/hep/dataforge/control/client/magixClient.kt index 6e7a908..b0bca9e 100644 --- a/dataforge-magix-client/src/commonMain/kotlin/hep/dataforge/control/client/magixClient.kt +++ b/controls-magix-client/src/commonMain/kotlin/hep/dataforge/control/client/magixClient.kt @@ -1,5 +1,6 @@ package hep.dataforge.control.client +import hep.dataforge.context.logger import hep.dataforge.control.controllers.DeviceManager import hep.dataforge.control.controllers.respondMessage import hep.dataforge.control.messages.DeviceMessage diff --git a/dataforge-device-serial/build.gradle.kts b/controls-serial/build.gradle.kts similarity index 74% rename from dataforge-device-serial/build.gradle.kts rename to controls-serial/build.gradle.kts index a5036d4..1b75a2e 100644 --- a/dataforge-device-serial/build.gradle.kts +++ b/controls-serial/build.gradle.kts @@ -4,6 +4,6 @@ plugins { } dependencies{ - api(project(":dataforge-device-core")) + api(project(":controls-core")) implementation("org.scream3r:jssc:2.8.0") } \ No newline at end of file diff --git a/dataforge-device-serial/src/main/kotlin/hep/dataforge/control/serial/SerialPort.kt b/controls-serial/src/main/kotlin/hep/dataforge/control/serial/SerialPort.kt similarity index 100% rename from dataforge-device-serial/src/main/kotlin/hep/dataforge/control/serial/SerialPort.kt rename to controls-serial/src/main/kotlin/hep/dataforge/control/serial/SerialPort.kt diff --git a/dataforge-device-server/build.gradle.kts b/controls-server/build.gradle.kts similarity index 79% rename from dataforge-device-server/build.gradle.kts rename to controls-server/build.gradle.kts index c7a1a0a..799ce17 100644 --- a/dataforge-device-server/build.gradle.kts +++ b/controls-server/build.gradle.kts @@ -7,8 +7,8 @@ val dataforgeVersion: String by rootProject.extra val ktorVersion: String by rootProject.extra dependencies{ - implementation(project(":dataforge-device-core")) - implementation(project(":dataforge-device-tcp")) + implementation(project(":controls-core")) + implementation(project(":controls-tcp")) implementation("io.ktor:ktor-server-cio:$ktorVersion") implementation("io.ktor:ktor-websockets:$ktorVersion") implementation("io.ktor:ktor-serialization:$ktorVersion") diff --git a/dataforge-device-server/src/main/kotlin/hep/dataforge/control/server/conversions.kt b/controls-server/src/main/kotlin/hep/dataforge/control/server/conversions.kt similarity index 100% rename from dataforge-device-server/src/main/kotlin/hep/dataforge/control/server/conversions.kt rename to controls-server/src/main/kotlin/hep/dataforge/control/server/conversions.kt diff --git a/dataforge-device-server/src/main/kotlin/hep/dataforge/control/server/deviceWebServer.kt b/controls-server/src/main/kotlin/hep/dataforge/control/server/deviceWebServer.kt similarity index 95% rename from dataforge-device-server/src/main/kotlin/hep/dataforge/control/server/deviceWebServer.kt rename to controls-server/src/main/kotlin/hep/dataforge/control/server/deviceWebServer.kt index 55cfba5..d05d058 100644 --- a/dataforge-device-server/src/main/kotlin/hep/dataforge/control/server/deviceWebServer.kt +++ b/controls-server/src/main/kotlin/hep/dataforge/control/server/deviceWebServer.kt @@ -20,18 +20,19 @@ import io.ktor.http.HttpStatusCode import io.ktor.request.receiveText import io.ktor.response.respond import io.ktor.response.respondRedirect -import io.ktor.routing.* +import io.ktor.routing.get +import io.ktor.routing.post +import io.ktor.routing.route +import io.ktor.routing.routing import io.ktor.server.cio.CIO import io.ktor.server.engine.ApplicationEngine import io.ktor.server.engine.embeddedServer import io.ktor.util.KtorExperimentalAPI import io.ktor.util.getValue import io.ktor.websocket.WebSockets -import io.ktor.websocket.webSocket import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.FlowPreview -import kotlinx.coroutines.flow.collect import kotlinx.html.* import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonObject @@ -124,7 +125,7 @@ public fun Application.deviceModule( li { a(href = "../$deviceName/${property.name}/get") { +"${property.name}: " } code { - +property.config.toJson().toString() + +property.toMeta().toJson().toString() } } } @@ -135,7 +136,7 @@ public fun Application.deviceModule( li { +("${action.name}: ") code { - +action.config.toJson().toString() + +action.toMeta().toJson().toString() } } } @@ -152,12 +153,12 @@ public fun Application.deviceModule( put("target", name.toString()) put("properties", buildJsonArray { device.propertyDescriptors.forEach { descriptor -> - add(descriptor.config.toJson()) + add(descriptor.toMeta().toJson()) } }) put("actions", buildJsonArray { device.actionDescriptors.forEach { actionDescriptor -> - add(actionDescriptor.config.toJson()) + add(actionDescriptor.toMeta().toJson()) } }) } diff --git a/dataforge-device-tcp/build.gradle.kts b/controls-tcp/build.gradle.kts similarity index 81% rename from dataforge-device-tcp/build.gradle.kts rename to controls-tcp/build.gradle.kts index 0a77dde..06475b6 100644 --- a/dataforge-device-tcp/build.gradle.kts +++ b/controls-tcp/build.gradle.kts @@ -8,7 +8,7 @@ kotlin { sourceSets { commonMain { dependencies { - api(project(":dataforge-device-core")) + api(project(":controls-core")) api("io.ktor:ktor-network:$ktorVersion") } } diff --git a/dataforge-device-tcp/src/jvmMain/kotlin/hep/dataforge/control/ports/KtorTcpPort.kt b/controls-tcp/src/jvmMain/kotlin/hep/dataforge/control/ports/KtorTcpPort.kt similarity index 100% rename from dataforge-device-tcp/src/jvmMain/kotlin/hep/dataforge/control/ports/KtorTcpPort.kt rename to controls-tcp/src/jvmMain/kotlin/hep/dataforge/control/ports/KtorTcpPort.kt diff --git a/demo/build.gradle.kts b/demo/build.gradle.kts index a25e12a..f7f22b7 100644 --- a/demo/build.gradle.kts +++ b/demo/build.gradle.kts @@ -17,9 +17,9 @@ repositories{ } dependencies{ - implementation(project(":dataforge-device-core")) - implementation(project(":dataforge-device-server")) - implementation(project(":dataforge-magix-client")) + implementation(project(":controls-core")) + implementation(project(":controls-server")) + implementation(project(":controls-magix-client")) implementation("no.tornado:tornadofx:1.7.20") implementation(kotlin("stdlib-jdk8")) implementation("kscience.plotlykt:plotlykt-server:0.3.0") diff --git a/demo/src/main/kotlin/hep/dataforge/control/demo/DemoControllerView.kt b/demo/src/main/kotlin/hep/dataforge/control/demo/DemoControllerView.kt index 03b1d73..0d74f1e 100644 --- a/demo/src/main/kotlin/hep/dataforge/control/demo/DemoControllerView.kt +++ b/demo/src/main/kotlin/hep/dataforge/control/demo/DemoControllerView.kt @@ -2,6 +2,7 @@ package hep.dataforge.control.demo import hep.dataforge.context.ContextAware import hep.dataforge.context.Global +import hep.dataforge.context.logger import io.ktor.server.engine.ApplicationEngine import javafx.scene.Parent import javafx.scene.control.Slider diff --git a/magix/magix-java-client/build.gradle.kts b/magix/magix-java-client/build.gradle.kts new file mode 100644 index 0000000..534f163 --- /dev/null +++ b/magix/magix-java-client/build.gradle.kts @@ -0,0 +1,10 @@ +plugins { + java + id("ru.mipt.npm.jvm") + id("ru.mipt.npm.publish") +} + +dependencies { + implementation(project(":magix:magix-service")) + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk9:${ru.mipt.npm.gradle.KScienceVersions.coroutinesVersion}") +} diff --git a/magix/magix-java-client/src/main/java/ru/mipt/npm/magix/client/MagixClient.java b/magix/magix-java-client/src/main/java/ru/mipt/npm/magix/client/MagixClient.java new file mode 100644 index 0000000..09eb8a7 --- /dev/null +++ b/magix/magix-java-client/src/main/java/ru/mipt/npm/magix/client/MagixClient.java @@ -0,0 +1,26 @@ +package ru.mipt.npm.magix.client; + +import hep.dataforge.magix.api.MagixMessage; +import kotlinx.serialization.json.JsonElement; + +import java.io.IOException; +import java.util.concurrent.Flow; + +/** + * See https://github.com/waltz-controls/rfc/tree/master/2 + * + * @param + */ +public interface MagixClient { + void broadcast(MagixMessage msg) throws IOException; + + Flow.Publisher> subscribe(); + + static MagixClient rSocketTcp(String host, int port) { + return ControlsMagixClient.Companion.rSocketTcp(host, port); + } + + static MagixClient rSocketWs(String host, int port, String path) { + return ControlsMagixClient.Companion.rSocketWs(host, port, path); + } +} diff --git a/magix/magix-java-client/src/main/kotlin/ru/mipt/npm/magix/client/ControlsMagixClient.kt b/magix/magix-java-client/src/main/kotlin/ru/mipt/npm/magix/client/ControlsMagixClient.kt new file mode 100644 index 0000000..88e16f8 --- /dev/null +++ b/magix/magix-java-client/src/main/kotlin/ru/mipt/npm/magix/client/ControlsMagixClient.kt @@ -0,0 +1,42 @@ +package ru.mipt.npm.magix.client + +import hep.dataforge.magix.api.MagixEndpoint +import hep.dataforge.magix.api.MagixMessage +import hep.dataforge.magix.api.MagixMessageFilter +import hep.dataforge.magix.service.RSocketMagixEndpoint +import hep.dataforge.magix.service.withTcp +import kotlinx.coroutines.jdk9.asPublisher +import kotlinx.coroutines.runBlocking +import kotlinx.serialization.KSerializer +import kotlinx.serialization.json.JsonElement +import java.util.concurrent.Flow + +public class ControlsMagixClient( + private val endpoint: MagixEndpoint, + private val filter: MagixMessageFilter, + private val serializer: KSerializer, +) : MagixClient { + + override fun broadcast(msg: MagixMessage): Unit = runBlocking { + endpoint.broadcast(serializer, msg) + } + + override fun subscribe(): Flow.Publisher> = endpoint.subscribe(serializer, filter).asPublisher() + + public companion object { + + public fun rSocketTcp(host: String, port: Int): ControlsMagixClient { + val endpoint = runBlocking { + RSocketMagixEndpoint.withTcp(host, port) + } + return ControlsMagixClient(endpoint, MagixMessageFilter(), JsonElement.serializer()) + } + + public fun rSocketWs(host: String, port: Int, path: String = "/rsocket"): ControlsMagixClient { + val endpoint = runBlocking { + RSocketMagixEndpoint.withWebSockets(host, port, path) + } + return ControlsMagixClient(endpoint, MagixMessageFilter(), JsonElement.serializer()) + } + } +} \ No newline at end of file diff --git a/magix/magix-server/build.gradle.kts b/magix/magix-server/build.gradle.kts index 674fde4..d0be60c 100644 --- a/magix/magix-server/build.gradle.kts +++ b/magix/magix-server/build.gradle.kts @@ -11,8 +11,8 @@ kscience { } val dataforgeVersion: String by rootProject.extra -val ktorVersion: String by rootProject.extra val rsocketVersion: String by rootProject.extra +val ktorVersion: String = ru.mipt.npm.gradle.KScienceVersions.ktorVersion dependencies{ api(project(":magix:magix-api")) diff --git a/magix/magix-server/src/main/kotlin/hep/dataforge/magix/server/MagixServer.kt b/magix/magix-server/src/main/kotlin/hep/dataforge/magix/server/MagixServer.kt index 96a6e5d..1fa6480 100644 --- a/magix/magix-server/src/main/kotlin/hep/dataforge/magix/server/MagixServer.kt +++ b/magix/magix-server/src/main/kotlin/hep/dataforge/magix/server/MagixServer.kt @@ -25,6 +25,7 @@ public fun CoroutineScope.startMagixServer( buffer, extraBufferCapacity = buffer ) + val tcpTransport = aSocket(ActorSelectorManager(Dispatchers.IO)).tcp().serverTransport(port = rawSocketPort) RSocketServer().bind(tcpTransport, magixAcceptor(magixFlow)) diff --git a/magix/magix-server/src/main/kotlin/hep/dataforge/magix/server/magixModule.kt b/magix/magix-server/src/main/kotlin/hep/dataforge/magix/server/magixModule.kt index 18744b1..4514d4a 100644 --- a/magix/magix-server/src/main/kotlin/hep/dataforge/magix/server/magixModule.kt +++ b/magix/magix-server/src/main/kotlin/hep/dataforge/magix/server/magixModule.kt @@ -52,12 +52,14 @@ internal fun CoroutineScope.magixAcceptor(magixFlow: MutableSharedFlow -> + requestChannel { request: Payload, input: Flow -> input.onEach { magixFlow.emit(magixJson.decodeFromString(genericMessageSerializer, it.data.readText())) }.launchIn(this@magixAcceptor) - magixFlow.map { message -> + val filter = magixJson.decodeFromString(MagixMessageFilter.serializer(), request.data.readText()) + + magixFlow.filter(filter).map { message -> val string = magixJson.encodeToString(genericMessageSerializer, message) buildPayload { data(string) } } diff --git a/motors/build.gradle.kts b/motors/build.gradle.kts index c43e16d..52fd36a 100644 --- a/motors/build.gradle.kts +++ b/motors/build.gradle.kts @@ -21,7 +21,7 @@ kscience{ val ktorVersion: String by rootProject.extra dependencies { - implementation(project(":dataforge-device-tcp")) - implementation(project(":dataforge-magix-client")) + implementation(project(":controls-tcp")) + implementation(project(":controls-magix-client")) implementation("no.tornado:tornadofx:1.7.20") } diff --git a/motors/src/main/kotlin/ru/mipt/npm/devices/pimotionmaster/PiMotionMasterDevice.kt b/motors/src/main/kotlin/ru/mipt/npm/devices/pimotionmaster/PiMotionMasterDevice.kt index a98e1ed..20c0338 100644 --- a/motors/src/main/kotlin/ru/mipt/npm/devices/pimotionmaster/PiMotionMasterDevice.kt +++ b/motors/src/main/kotlin/ru/mipt/npm/devices/pimotionmaster/PiMotionMasterDevice.kt @@ -3,6 +3,7 @@ package ru.mipt.npm.devices.pimotionmaster import hep.dataforge.context.Context +import hep.dataforge.context.logger import hep.dataforge.control.api.DeviceHub import hep.dataforge.control.api.PropertyDescriptor import hep.dataforge.control.base.* diff --git a/motors/src/main/kotlin/ru/mipt/npm/devices/pimotionmaster/PiMotionMasterVirtualDevice.kt b/motors/src/main/kotlin/ru/mipt/npm/devices/pimotionmaster/PiMotionMasterVirtualDevice.kt index 3cd4f00..0d97a02 100644 --- a/motors/src/main/kotlin/ru/mipt/npm/devices/pimotionmaster/PiMotionMasterVirtualDevice.kt +++ b/motors/src/main/kotlin/ru/mipt/npm/devices/pimotionmaster/PiMotionMasterVirtualDevice.kt @@ -2,6 +2,7 @@ package ru.mipt.npm.devices.pimotionmaster import hep.dataforge.context.Context import hep.dataforge.context.ContextAware +import hep.dataforge.context.logger import hep.dataforge.control.api.Socket import hep.dataforge.control.ports.AbstractPort import hep.dataforge.control.ports.withDelimiter diff --git a/motors/src/main/kotlin/ru/mipt/npm/devices/pimotionmaster/fxDeviceProperties.kt b/motors/src/main/kotlin/ru/mipt/npm/devices/pimotionmaster/fxDeviceProperties.kt index 7af82e4..73c179e 100644 --- a/motors/src/main/kotlin/ru/mipt/npm/devices/pimotionmaster/fxDeviceProperties.kt +++ b/motors/src/main/kotlin/ru/mipt/npm/devices/pimotionmaster/fxDeviceProperties.kt @@ -1,9 +1,12 @@ package ru.mipt.npm.devices.pimotionmaster +import hep.dataforge.context.logger import hep.dataforge.control.api.Device import hep.dataforge.control.base.TypedDeviceProperty import hep.dataforge.control.base.TypedReadOnlyDeviceProperty -import javafx.beans.property.* +import javafx.beans.property.ObjectPropertyBase +import javafx.beans.property.Property +import javafx.beans.property.ReadOnlyProperty import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach diff --git a/settings.gradle.kts b/settings.gradle.kts index d08689d..4db6541 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,6 +1,6 @@ pluginManagement { - val kotlinVersion = "1.4.21" - val toolsVersion = "0.7.1" + val kotlinVersion = "1.4.30" + val toolsVersion = "0.7.6" repositories { mavenLocal() @@ -27,18 +27,20 @@ pluginManagement { rootProject.name = "controls.kt" include( - ":dataforge-device-core", - ":dataforge-device-tcp", - ":dataforge-device-serial", - ":dataforge-device-server", + ":controls-core", + ":controls-tcp", + ":controls-serial", + ":controls-server", ":demo", ":magix", ":magix:magix-api", ":magix:magix-server", ":magix:magix-service", - ":dataforge-magix-client", + ":magix:magix-java-client", + ":controls-magix-client", ":motors" ) //includeBuild("../dataforge-core") -//includeBuild("../plotly.kt") \ No newline at end of file +//includeBuild("../plotly.kt") +include("magix-java-client")