Add open to device initializer
This commit is contained in:
parent
ed2a2a29af
commit
7b56436983
@ -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
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user