diff options
author | Robert Jaros <rjaros@finn.pl> | 2018-04-26 15:41:32 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2018-04-26 15:41:32 +0200 |
commit | 95c1cdec5b0e65a0f617d5fa88d1d49a7abcfe95 (patch) | |
tree | b3dc67083cad67d44a385605e4c915a0a05f47bb /src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt | |
parent | 5b9535e9964816eb228d3797f4c8a3e7676d1f53 (diff) | |
download | kvision-95c1cdec5b0e65a0f617d5fa88d1d49a7abcfe95.tar.gz kvision-95c1cdec5b0e65a0f617d5fa88d1d49a7abcfe95.tar.bz2 kvision-95c1cdec5b0e65a0f617d5fa88d1d49a7abcfe95.zip |
Automatic JSON-RPC conectivity.
CallAgent component for remote JSON-RPC and AJAX.
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt')
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt | 45 |
1 files changed, 29 insertions, 16 deletions
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<out T> actual constructor(service: T?) { - protected val calls: MutableMap<String, String> = mutableMapOf() + protected val calls: MutableMap<String, Pair<String, RpcHttpMethod>> = 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 <reified RET> bind( route: String, - noinline function: T.(Request?) -> Deferred<RET> + noinline function: T.(Request?) -> Deferred<RET>, 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 <reified PAR, reified RET> bind( route: String, - noinline function: T.(PAR, Request?) -> Deferred<RET> + noinline function: T.(PAR, Request?) -> Deferred<RET>, 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 <reified PAR1, reified PAR2, reified RET> bind( route: String, - noinline function: T.(PAR1, PAR2, Request?) -> Deferred<RET> + noinline function: T.(PAR1, PAR2, Request?) -> Deferred<RET>, 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 <reified PAR1, reified PAR2, reified PAR3, reified RET> bind( route: String, - noinline function: T.(PAR1, PAR2, PAR3, Request?) -> Deferred<RET> + noinline function: T.(PAR1, PAR2, PAR3, Request?) -> Deferred<RET>, 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 <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified RET> bind( route: String, - noinline function: T.(PAR1, PAR2, PAR3, PAR4, Request?) -> Deferred<RET> + noinline function: T.(PAR1, PAR2, PAR3, PAR4, Request?) -> Deferred<RET>, 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 <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified PAR5, reified RET> bind( route: String, - noinline function: T.(PAR1, PAR2, PAR3, PAR4, PAR5, Request?) -> Deferred<RET> + noinline function: T.(PAR1, PAR2, PAR3, PAR4, PAR5, Request?) -> Deferred<RET>, + 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<out T> 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<String, String> = calls + actual fun getCalls(): Map<String, Pair<String, RpcHttpMethod>> = calls } |