From 6eca49df30836633cb584e2a62301825fab6f883 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Wed, 15 Apr 2020 20:16:39 +0200 Subject: Increase the number of parameters for server side interface methods --- .../pl/treksoft/kvision/remote/KVRemoteAgent.kt | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) (limited to 'kvision-modules/kvision-common-remote/src/jsMain/kotlin/pl/treksoft') diff --git a/kvision-modules/kvision-common-remote/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVRemoteAgent.kt b/kvision-modules/kvision-common-remote/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVRemoteAgent.kt index 232e0607..24cea176 100644 --- a/kvision-modules/kvision-common-remote/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVRemoteAgent.kt +++ b/kvision-modules/kvision-common-remote/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVRemoteAgent.kt @@ -373,6 +373,81 @@ open class KVRemoteAgent(val serviceManager: KVServiceMgr) : }.asDeferred().await() } + /** + * Executes defined call to a remote web service. + */ + @Suppress("LongParameterList") + suspend inline fun call( + noinline function: suspend T.(PAR1, PAR2, PAR3, PAR4, PAR5, PAR6) -> RET, + p1: PAR1, + p2: PAR2, + p3: PAR3, + p4: PAR4, + p5: PAR5, + p6: PAR6 + ): RET { + val data1 = serialize(p1) + val data2 = serialize(p2) + val data3 = serialize(p3) + val data4 = serialize(p4) + val data5 = serialize(p5) + val data6 = serialize(p6) + val (url, method) = + serviceManager.getCalls()[function.toString().replace("\\s".toRegex(), "")] + ?: throw IllegalStateException("Function not specified!") + return callAgent.jsonRpcCall(url, listOf(data1, data2, data3, data4, data5, data6), method).then { + try { + @Suppress("UNCHECKED_CAST") + deserialize(it, RET::class.js.name) + } catch (t: NotStandardTypeException) { + try { + @Suppress("UNCHECKED_CAST") + tryDeserializeEnum(RET::class as KClass, it) as RET + } catch (t: NotEnumTypeException) { + JSON.nonstrict.parse(RET::class.serializer(), it) + } + } + }.asDeferred().await() + } + + /** + * Executes defined call to a remote web service. + */ + @Suppress("LongParameterList") + suspend inline fun call( + noinline function: suspend T.(PAR1, PAR2, PAR3, PAR4, PAR5, PAR6) -> List, + p1: PAR1, + p2: PAR2, + p3: PAR3, + p4: PAR4, + p5: PAR5, + p6: PAR6 + ): List { + val data1 = serialize(p1) + val data2 = serialize(p2) + val data3 = serialize(p3) + val data4 = serialize(p4) + val data5 = serialize(p5) + val data6 = serialize(p6) + val (url, method) = + serviceManager.getCalls()[function.toString().replace("\\s".toRegex(), "")] + ?: throw IllegalStateException("Function not specified!") + return callAgent.jsonRpcCall(url, listOf(data1, data2, data3, data4, data5, data6), method).then { + try { + deserializeList(it, RET::class.js.name) + } catch (t: NotStandardTypeException) { + try { + @Suppress("UNCHECKED_CAST") + tryDeserializeEnumList(RET::class as KClass, it) as List + } catch (t: NotEnumTypeException) { + JSON.nonstrict.parse(RET::class.serializer().list, it) + } + } + }.asDeferred().await() + } + /** * Executes defined web socket connection */ -- cgit