From 95c1cdec5b0e65a0f617d5fa88d1d49a7abcfe95 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Thu, 26 Apr 2018 15:41:32 +0200 Subject: Automatic JSON-RPC conectivity. CallAgent component for remote JSON-RPC and AJAX. --- .../pl/treksoft/kvision/remote/ServiceManager.kt | 45 ++++++++++++++-------- 1 file changed, 29 insertions(+), 16 deletions(-) (limited to 'src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt') diff --git a/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt b/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt index cd42f038..df3245c3 100644 --- a/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt +++ b/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt @@ -27,79 +27,93 @@ import kotlinx.coroutines.experimental.Deferred * Multiplatform service manager. */ actual open class ServiceManager actual constructor(service: T?) { - protected val calls: MutableMap = mutableMapOf() + protected val calls: MutableMap> = mutableMapOf() /** * Binds a given route with a function of the receiver. * @param route a route * @param function a function of the receiver + * @param method a HTTP method + * @param prefix an URL address prefix */ protected actual inline fun bind( route: String, - noinline function: T.(Request?) -> Deferred + noinline function: T.(Request?) -> Deferred, method: RpcHttpMethod, prefix: String ) { - calls[function.toString()] = "$SERVICE_PREFIX/$route" + calls[function.toString()] = Pair("$prefix$route", method) } /** * Binds a given route with a function of the receiver. * @param route a route * @param function a function of the receiver + * @param method a HTTP method + * @param prefix an URL address prefix */ protected actual inline fun bind( route: String, - noinline function: T.(PAR, Request?) -> Deferred + noinline function: T.(PAR, Request?) -> Deferred, method: RpcHttpMethod, prefix: String ) { - calls[function.toString()] = "$SERVICE_PREFIX/$route" + calls[function.toString()] = Pair("$prefix$route", method) } /** * Binds a given route with a function of the receiver. * @param route a route * @param function a function of the receiver + * @param method a HTTP method + * @param prefix an URL address prefix */ protected actual inline fun bind( route: String, - noinline function: T.(PAR1, PAR2, Request?) -> Deferred + noinline function: T.(PAR1, PAR2, Request?) -> Deferred, method: RpcHttpMethod, prefix: String ) { - calls[function.toString()] = "$SERVICE_PREFIX/$route" + calls[function.toString()] = Pair("$prefix$route", method) } /** * Binds a given route with a function of the receiver. * @param route a route * @param function a function of the receiver + * @param method a HTTP method + * @param prefix an URL address prefix */ protected actual inline fun bind( route: String, - noinline function: T.(PAR1, PAR2, PAR3, Request?) -> Deferred + noinline function: T.(PAR1, PAR2, PAR3, Request?) -> Deferred, method: RpcHttpMethod, prefix: String ) { - calls[function.toString()] = "$SERVICE_PREFIX/$route" + calls[function.toString()] = Pair("$prefix$route", method) } /** * Binds a given route with a function of the receiver. * @param route a route * @param function a function of the receiver + * @param method a HTTP method + * @param prefix an URL address prefix */ protected actual inline fun bind( route: String, - noinline function: T.(PAR1, PAR2, PAR3, PAR4, Request?) -> Deferred + noinline function: T.(PAR1, PAR2, PAR3, PAR4, Request?) -> Deferred, method: RpcHttpMethod, prefix: String ) { - calls[function.toString()] = "$SERVICE_PREFIX/$route" + calls[function.toString()] = Pair("$prefix$route", method) } /** * Binds a given route with a function of the receiver. * @param route a route * @param function a function of the receiver + * @param method a HTTP method + * @param prefix an URL address prefix */ protected actual inline fun bind( route: String, - noinline function: T.(PAR1, PAR2, PAR3, PAR4, PAR5, Request?) -> Deferred + noinline function: T.(PAR1, PAR2, PAR3, PAR4, PAR5, Request?) -> Deferred, + method: RpcHttpMethod, + prefix: String ) { - calls[function.toString()] = "$SERVICE_PREFIX/$route" + calls[function.toString()] = Pair("$prefix$route", method) } /** @@ -110,8 +124,7 @@ actual open class ServiceManager actual constructor(service: T?) { } /** - * Returns the list of defined bindings. - * Not used on the jvm platform. + * Returns the map of defined paths. */ - actual fun getCalls(): Map = calls + actual fun getCalls(): Map> = calls } -- cgit