forked from NPM/numass-framework
implement devices config endpoint
This commit is contained in:
parent
650e789fc5
commit
e367bd62f1
@ -9,7 +9,7 @@ import hep.dataforge.optional
|
|||||||
import javafx.scene.Scene
|
import javafx.scene.Scene
|
||||||
import javafx.stage.Stage
|
import javafx.stage.Stage
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import tornadofx.*
|
import tornadofx.App
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,8 +46,10 @@ abstract class NumassControlApplication<in D : Device> : App() {
|
|||||||
|
|
||||||
abstract fun getDeviceMeta(config: Meta): Meta
|
abstract fun getDeviceMeta(config: Meta): Meta
|
||||||
|
|
||||||
|
fun getDeviceConfig() : Meta = getConfig(this).optional.orElseGet { readResourceMeta("config/devices.xml") }
|
||||||
|
|
||||||
private fun setupDevice(): D {
|
private fun setupDevice(): D {
|
||||||
val config = getConfig(this).optional.orElseGet { readResourceMeta("config/devices.xml") }
|
val config = getDeviceConfig()
|
||||||
|
|
||||||
val ctx = setupContext(config)
|
val ctx = setupContext(config)
|
||||||
val deviceConfig = getDeviceMeta(config)
|
val deviceConfig = getDeviceMeta(config)
|
||||||
|
@ -100,7 +100,6 @@ fun getConfig(app: Application): Meta? {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun findDeviceMeta(config: Meta, criterion: (Meta) -> Boolean): Meta? {
|
fun findDeviceMeta(config: Meta, criterion: (Meta) -> Boolean): Meta? {
|
||||||
return config.getMetaList("device").stream().filter(criterion).findFirst().nullable
|
return config.getMetaList("device").stream().filter(criterion).findFirst().nullable
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ import javafx.stage.Stage
|
|||||||
/**
|
/**
|
||||||
* @author Alexander Nozik
|
* @author Alexander Nozik
|
||||||
*/
|
*/
|
||||||
class ReadVac : NumassControlApplication<VacCollectorDevice>() {
|
open class ReadVac : NumassControlApplication<VacCollectorDevice>() {
|
||||||
|
|
||||||
override val deviceFactory = VacDeviceFactory()
|
override val deviceFactory = VacDeviceFactory()
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
application
|
application
|
||||||
|
id("org.openjfx.javafxplugin") version "0.1.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "inr.numass"
|
group = "inr.numass"
|
||||||
@ -8,11 +9,18 @@ repositories {
|
|||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
javafx {
|
||||||
|
modules("javafx.controls", "javafx.web")
|
||||||
|
version = "16"
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
testImplementation(platform("org.junit:junit-bom:5.9.1"))
|
testImplementation(platform("org.junit:junit-bom:5.9.1"))
|
||||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||||
implementation("io.ktor:ktor-server-core:2.3.7")
|
implementation("io.ktor:ktor-server-core:2.3.7")
|
||||||
implementation("io.ktor:ktor-server-netty:2.3.7")
|
implementation("io.ktor:ktor-server-netty:2.3.7")
|
||||||
|
api(project(":numass-control:vac"))
|
||||||
|
api(project(":dataforge-core:dataforge-json"))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,26 +1,50 @@
|
|||||||
package inr.numass.webcontrol
|
package inr.numass.webcontrol
|
||||||
|
|
||||||
import io.ktor.server.routing.*
|
import hep.dataforge.io.JSONMetaWriter
|
||||||
|
import inr.numass.control.readvac.ReadVac
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
import io.ktor.server.application.*
|
import io.ktor.server.application.*
|
||||||
import io.ktor.server.response.*
|
|
||||||
import io.ktor.server.request.*
|
|
||||||
import io.ktor.server.engine.*
|
import io.ktor.server.engine.*
|
||||||
import io.ktor.server.netty.*
|
|
||||||
import java.nio.file.Paths
|
|
||||||
import io.ktor.server.http.content.*
|
import io.ktor.server.http.content.*
|
||||||
fun main() {
|
import io.ktor.server.netty.*
|
||||||
|
import io.ktor.server.response.*
|
||||||
|
import io.ktor.server.routing.*
|
||||||
|
import javafx.application.Application
|
||||||
|
import javafx.stage.Stage
|
||||||
|
import java.nio.file.Paths
|
||||||
|
class ReadVacSvr : ReadVac() {
|
||||||
|
var server : NettyApplicationEngine? = null
|
||||||
var clickNumber = 0
|
var clickNumber = 0
|
||||||
embeddedServer(Netty, port = 8000) {
|
override fun start(stage: Stage) {
|
||||||
|
super.start(stage)
|
||||||
|
|
||||||
routing {
|
this.server = embeddedServer(Netty, port = 8000) {
|
||||||
staticFiles("/", Paths.get(this.javaClass.classLoader.getResource("index.html").toURI()).toFile().parentFile)
|
routing {
|
||||||
get ("/api") {
|
staticFiles("/", Paths.get(this.javaClass.classLoader.getResource("index.html").toURI()).toFile().parentFile)
|
||||||
call.respondText(call.parameters.toString())
|
get ("/api") {
|
||||||
}
|
call.respondText(call.parameters.toString())
|
||||||
get ("/api/clicker") {
|
}
|
||||||
call.respondText(clickNumber++.toString())
|
get ("/api/devices") {
|
||||||
|
call.respondOutputStream(ContentType.Application.Json, HttpStatusCode.OK, null) {
|
||||||
|
JSONMetaWriter.write(this, this@ReadVacSvr.getDeviceMeta(this@ReadVacSvr.getDeviceConfig()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
get ("/api/clicker") {
|
||||||
|
call.respondText(this@ReadVacSvr.clickNumber++.toString())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.start(wait = true)
|
|
||||||
|
this.server!!.start(wait = false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun stop() {
|
||||||
|
super.stop()
|
||||||
|
this.server?.stop()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
Application.launch(ReadVacSvr::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user