diff options
author | Robert Jaros <rjaros@finn.pl> | 2020-04-15 20:16:39 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2020-04-15 20:16:39 +0200 |
commit | 6eca49df30836633cb584e2a62301825fab6f883 (patch) | |
tree | 579a09dd43c9a33f2fa7237f993a093748c25828 /kvision-modules/kvision-common-remote/src/jsMain/kotlin | |
parent | 07f2a729431ac4e36f6c0573630870b64e4c1705 (diff) | |
download | kvision-6eca49df30836633cb584e2a62301825fab6f883.tar.gz kvision-6eca49df30836633cb584e2a62301825fab6f883.tar.bz2 kvision-6eca49df30836633cb584e2a62301825fab6f883.zip |
Increase the number of parameters for server side interface methods
Diffstat (limited to 'kvision-modules/kvision-common-remote/src/jsMain/kotlin')
-rw-r--r-- | kvision-modules/kvision-common-remote/src/jsMain/kotlin/pl/treksoft/kvision/remote/KVRemoteAgent.kt | 75 |
1 files changed, 75 insertions, 0 deletions
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 @@ -374,6 +374,81 @@ open class KVRemoteAgent<T : Any>(val serviceManager: KVServiceMgr<T>) : } /** + * Executes defined call to a remote web service. + */ + @Suppress("LongParameterList") + suspend inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified PAR5, reified PAR6, + reified RET : Any, T> 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<RET>(it, RET::class.js.name) + } catch (t: NotStandardTypeException) { + try { + @Suppress("UNCHECKED_CAST") + tryDeserializeEnum(RET::class as KClass<Any>, 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 <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified PAR5, reified PAR6, + reified RET : Any, T> call( + noinline function: suspend T.(PAR1, PAR2, PAR3, PAR4, PAR5, PAR6) -> List<RET>, + p1: PAR1, + p2: PAR2, + p3: PAR3, + p4: PAR4, + p5: PAR5, + p6: PAR6 + ): List<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 { + deserializeList<RET>(it, RET::class.js.name) + } catch (t: NotStandardTypeException) { + try { + @Suppress("UNCHECKED_CAST") + tryDeserializeEnumList(RET::class as KClass<Any>, it) as List<RET> + } catch (t: NotEnumTypeException) { + JSON.nonstrict.parse(RET::class.serializer().list, it) + } + } + }.asDeferred().await() + } + + /** * Executes defined web socket connection */ @Suppress("ComplexMethod", "TooGenericExceptionCaught") |