Add open to device initializer

This commit is contained in:
Alexander Nozik 2021-10-23 20:00:00 +03:00
parent ed2a2a29af
commit 7b56436983
2 changed files with 7 additions and 1 deletions

View File

@ -1,5 +1,6 @@
package ru.mipt.npm.controls.controllers
import kotlinx.coroutines.launch
import ru.mipt.npm.controls.api.Device
import ru.mipt.npm.controls.api.DeviceHub
import space.kscience.dataforge.context.*
@ -38,6 +39,9 @@ public class DeviceManager : AbstractPlugin(), DeviceHub {
public fun <D : Device> DeviceManager.install(name: String, factory: Factory<D>, meta: Meta = Meta.EMPTY): D {
val device = factory(meta, context)
registerDevice(NameToken(name), device)
device.launch {
device.open()
}
return device
}

View File

@ -34,6 +34,9 @@ class DemoDevice(context: Context, meta: Meta) : DeviceBySpec<DemoDevice>(DemoDe
companion object : DeviceSpec<DemoDevice>(), Factory<DemoDevice> {
override fun invoke(meta: Meta, context: Context): DemoDevice = DemoDevice(context, meta)
// register virtual properties based on actual object state
val timeScale by property(MetaConverter.double, DemoDevice::timeScaleState) {
metaDescriptor {
@ -77,6 +80,5 @@ class DemoDevice(context: Context, meta: Meta) : DeviceBySpec<DemoDevice>(DemoDe
null
}
override fun invoke(meta: Meta, context: Context): DemoDevice = DemoDevice(context, meta)
}
}