diff --git a/controls-magix-client/build.gradle.kts b/controls-magix-client/build.gradle.kts index 1943d0b..3d50b56 100644 --- a/controls-magix-client/build.gradle.kts +++ b/controls-magix-client/build.gradle.kts @@ -13,7 +13,7 @@ kotlin { sourceSets { commonMain { dependencies { - implementation(project(":magix:magix-service")) + implementation(project(":magix:magix-rsocket")) implementation(project(":controls-core")) } } diff --git a/controls-server/src/main/kotlin/ru/mipt/npm/controls/server/deviceWebServer.kt b/controls-server/src/main/kotlin/ru/mipt/npm/controls/server/deviceWebServer.kt index 41a2a85..e02b82c 100644 --- a/controls-server/src/main/kotlin/ru/mipt/npm/controls/server/deviceWebServer.kt +++ b/controls-server/src/main/kotlin/ru/mipt/npm/controls/server/deviceWebServer.kt @@ -1,4 +1,3 @@ -@file:OptIn(ExperimentalCoroutinesApi::class, KtorExperimentalAPI::class, FlowPreview::class) package ru.mipt.npm.controls.server @@ -18,12 +17,9 @@ 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 kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.FlowPreview import kotlinx.html.* import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonObject @@ -74,7 +70,6 @@ public fun ApplicationEngine.whenStarted(callback: Application.() -> Unit) { public const val WEB_SERVER_TARGET: String = "@webServer" -@OptIn(KtorExperimentalAPI::class) public fun Application.deviceModule( manager: DeviceManager, deviceNames: Collection = manager.devices.keys.map { it.toString() }, @@ -114,7 +109,8 @@ public fun Application.deviceModule( } deviceNames.forEach { deviceName -> val device = - manager.getOrNull(deviceName) ?: error("The device with name $deviceName not found in $manager") + manager.getOrNull(deviceName) + ?: error("The device with name $deviceName not found in $manager") div { id = deviceName h2 { +deviceName } diff --git a/controls-tcp/src/jvmMain/kotlin/ru/mipt/npm/controls/ports/KtorTcpPort.kt b/controls-tcp/src/jvmMain/kotlin/ru/mipt/npm/controls/ports/KtorTcpPort.kt index 5b47265..d3f48d3 100644 --- a/controls-tcp/src/jvmMain/kotlin/ru/mipt/npm/controls/ports/KtorTcpPort.kt +++ b/controls-tcp/src/jvmMain/kotlin/ru/mipt/npm/controls/ports/KtorTcpPort.kt @@ -4,7 +4,6 @@ import io.ktor.network.selector.ActorSelectorManager import io.ktor.network.sockets.aSocket import io.ktor.network.sockets.openReadChannel import io.ktor.network.sockets.openWriteChannel -import io.ktor.util.KtorExperimentalAPI import io.ktor.utils.io.consumeEachBufferRange import io.ktor.utils.io.core.Closeable import io.ktor.utils.io.writeAvailable @@ -29,7 +28,6 @@ public class KtorTcpPort internal constructor( override fun toString(): String = "port[tcp:$host:$port]" - @OptIn(KtorExperimentalAPI::class) private val futureSocket = scope.async { aSocket(ActorSelectorManager(Dispatchers.IO)).tcp().connect(InetSocketAddress(host, port)) } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f371643..69a9715 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/magix/magix-java-client/build.gradle.kts b/magix/magix-java-client/build.gradle.kts index 4a281e3..5e34637 100644 --- a/magix/magix-java-client/build.gradle.kts +++ b/magix/magix-java-client/build.gradle.kts @@ -5,6 +5,6 @@ plugins { } dependencies { - implementation(project(":magix:magix-service")) + implementation(project(":magix:magix-rsocket")) implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk9:${ru.mipt.npm.gradle.KScienceVersions.coroutinesVersion}") } 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 index efa4c41..5bfbdd1 100644 --- 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 @@ -6,8 +6,8 @@ import kotlinx.serialization.KSerializer import ru.mipt.npm.magix.api.MagixEndpoint import ru.mipt.npm.magix.api.MagixMessage import ru.mipt.npm.magix.api.MagixMessageFilter -import ru.mipt.npm.magix.service.RSocketMagixEndpoint -import ru.mipt.npm.magix.service.withTcp +import ru.mipt.npm.magix.rsocket.RSocketMagixEndpoint +import ru.mipt.npm.magix.rsocket.withTcp import java.util.concurrent.Flow public class ControlsMagixClient( diff --git a/magix/magix-service/build.gradle.kts b/magix/magix-rsocket/build.gradle.kts similarity index 69% rename from magix/magix-service/build.gradle.kts rename to magix/magix-rsocket/build.gradle.kts index 75b38a1..1e0647c 100644 --- a/magix/magix-service/build.gradle.kts +++ b/magix/magix-rsocket/build.gradle.kts @@ -3,25 +3,24 @@ plugins { `maven-publish` } +description = """ + Magix endpoint (client) based on RSocket +""".trimIndent() + kscience { - useSerialization{ + useSerialization { json() } } -val dataforgeVersion: String by rootProject.extra val ktorVersion: String by rootProject.extra val rsocketVersion: String by rootProject.extra -repositories{ - maven("https://maven.pkg.github.com/altavir/ktor-client-sse") -} - kotlin { sourceSets { commonMain { dependencies { - api(project(":magix:magix-api")) + api(projects.magix.magixApi) implementation("io.ktor:ktor-client-core:$ktorVersion") implementation("io.rsocket.kotlin:rsocket-transport-ktor-client:$rsocketVersion") } diff --git a/magix/magix-service/src/commonMain/kotlin/ru/mipt/npm/magix/service/RSocketMagixEndpoint.kt b/magix/magix-rsocket/src/commonMain/kotlin/ru/mipt/npm/magix/rsocket/RSocketMagixEndpoint.kt similarity index 94% rename from magix/magix-service/src/commonMain/kotlin/ru/mipt/npm/magix/service/RSocketMagixEndpoint.kt rename to magix/magix-rsocket/src/commonMain/kotlin/ru/mipt/npm/magix/rsocket/RSocketMagixEndpoint.kt index 111ba9b..2753a0e 100644 --- a/magix/magix-service/src/commonMain/kotlin/ru/mipt/npm/magix/service/RSocketMagixEndpoint.kt +++ b/magix/magix-rsocket/src/commonMain/kotlin/ru/mipt/npm/magix/rsocket/RSocketMagixEndpoint.kt @@ -1,4 +1,4 @@ -package ru.mipt.npm.magix.service +package ru.mipt.npm.magix.rsocket import io.ktor.client.HttpClient import io.ktor.client.features.websocket.WebSockets @@ -51,6 +51,9 @@ public class RSocketMagixEndpoint( connectionConfig(rSocketConfig) } + /** + * Build a websocket based endpoint connected to [host], [port] and given routing [path] + */ public suspend fun withWebSockets( host: String, port: Int, diff --git a/magix/magix-service/src/jvmMain/kotlin/ru/mipt/npm/magix/service/withTcp.kt b/magix/magix-rsocket/src/jvmMain/kotlin/ru/mipt/npm/magix/rsocket/withTcp.kt similarity index 89% rename from magix/magix-service/src/jvmMain/kotlin/ru/mipt/npm/magix/service/withTcp.kt rename to magix/magix-rsocket/src/jvmMain/kotlin/ru/mipt/npm/magix/rsocket/withTcp.kt index 133b379..cd8f6b3 100644 --- a/magix/magix-service/src/jvmMain/kotlin/ru/mipt/npm/magix/service/withTcp.kt +++ b/magix/magix-rsocket/src/jvmMain/kotlin/ru/mipt/npm/magix/rsocket/withTcp.kt @@ -1,4 +1,4 @@ -package ru.mipt.npm.magix.service +package ru.mipt.npm.magix.rsocket import io.ktor.network.selector.ActorSelectorManager import io.ktor.network.sockets.SocketOptions @@ -11,7 +11,7 @@ import kotlin.coroutines.coroutineContext /** - * Create a plain TCP based [RSocketMagixEndpoint] + * Create a plain TCP based [RSocketMagixEndpoint] connected to [host] and [port] */ public suspend fun RSocketMagixEndpoint.Companion.withTcp( host: String, diff --git a/magix/magix-server/src/main/kotlin/ru/mipt/npm/magix/server/MagixServer.kt b/magix/magix-server/src/main/kotlin/ru/mipt/npm/magix/server/MagixServer.kt index cbd15f5..dbe2369 100644 --- a/magix/magix-server/src/main/kotlin/ru/mipt/npm/magix/server/MagixServer.kt +++ b/magix/magix-server/src/main/kotlin/ru/mipt/npm/magix/server/MagixServer.kt @@ -5,7 +5,6 @@ import io.ktor.network.sockets.aSocket 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.rsocket.kotlin.core.RSocketServer import io.rsocket.kotlin.transport.ktor.serverTransport import kotlinx.coroutines.CoroutineScope @@ -14,7 +13,6 @@ import kotlinx.coroutines.flow.MutableSharedFlow import ru.mipt.npm.magix.api.MagixEndpoint.Companion.DEFAULT_MAGIX_RAW_PORT import ru.mipt.npm.magix.api.MagixEndpoint.Companion.DEFAULT_MAGIX_WS_PORT -@OptIn(KtorExperimentalAPI::class) public fun CoroutineScope.startMagixServer( port: Int = DEFAULT_MAGIX_WS_PORT, rawSocketPort: Int = DEFAULT_MAGIX_RAW_PORT, diff --git a/magix/magix-server/src/main/kotlin/ru/mipt/npm/magix/server/magixModule.kt b/magix/magix-server/src/main/kotlin/ru/mipt/npm/magix/server/magixModule.kt index e2a1980..74f3d8d 100644 --- a/magix/magix-server/src/main/kotlin/ru/mipt/npm/magix/server/magixModule.kt +++ b/magix/magix-server/src/main/kotlin/ru/mipt/npm/magix/server/magixModule.kt @@ -10,7 +10,6 @@ import io.ktor.routing.post import io.ktor.routing.route import io.ktor.routing.routing import io.ktor.serialization.json -import io.ktor.util.KtorExperimentalAPI import io.ktor.util.getValue import io.ktor.websocket.WebSockets import io.rsocket.kotlin.ConnectionAcceptor @@ -70,7 +69,6 @@ internal fun CoroutineScope.magixAcceptor(magixFlow: MutableSharedFlow): Unit = flush() } -@OptIn(KtorExperimentalAPI::class) public suspend fun ApplicationCall.respondSse(events: Flow) { response.cacheControl(CacheControl.NoCache(null)) respondBytesWriter(contentType = ContentType.Text.EventStream) { diff --git a/magix/magix-zmq/build.gradle.kts b/magix/magix-zmq/build.gradle.kts new file mode 100644 index 0000000..d4e991b --- /dev/null +++ b/magix/magix-zmq/build.gradle.kts @@ -0,0 +1,10 @@ +plugins { + id("ru.mipt.npm.gradle.jvm") + `maven-publish` +} + + +dependencies { + api(projects.magix.magixApi) + implementation("org.zeromq:jeromq:0.5.2") +} diff --git a/magix/magix-zmq/src/main/kotlin/ru/mipt/npm/magix/zmq/ZmqMagixEndpoint.kt b/magix/magix-zmq/src/main/kotlin/ru/mipt/npm/magix/zmq/ZmqMagixEndpoint.kt new file mode 100644 index 0000000..ca02a78 --- /dev/null +++ b/magix/magix-zmq/src/main/kotlin/ru/mipt/npm/magix/zmq/ZmqMagixEndpoint.kt @@ -0,0 +1,22 @@ +package ru.mipt.npm.magix.zmq + +import kotlinx.coroutines.flow.Flow +import kotlinx.serialization.KSerializer +import ru.mipt.npm.magix.api.MagixEndpoint +import ru.mipt.npm.magix.api.MagixMessage +import ru.mipt.npm.magix.api.MagixMessageFilter +import kotlin.coroutines.CoroutineContext + +class ZmqMagixEndpoint( + private val coroutineContext: CoroutineContext, + private val payloadSerializer: KSerializer, +) : MagixEndpoint { + + override fun subscribe(filter: MagixMessageFilter): Flow> { + TODO("Not yet implemented") + } + + override suspend fun broadcast(message: MagixMessage) { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index c297374..4430f74 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,4 +1,6 @@ -rootProject.name = "controls.kt" +rootProject.name = "controls" + +enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") pluginManagement { val toolsVersion = "0.10.0" @@ -26,12 +28,9 @@ include( ":magix", ":magix:magix-api", ":magix:magix-server", - ":magix:magix-service", + ":magix:magix-rsocket", ":magix:magix-java-client", + ":magix:magix-zmq", ":controls-magix-client", ":motors" ) - -//includeBuild("../dataforge-core") -//includeBuild("../plotly.kt") -include("magix-java-client")