From 5b9535e9964816eb228d3797f4c8a3e7676d1f53 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Wed, 25 Apr 2018 08:12:25 +0200 Subject: Multiplatform kvision-common and kvision-server modules. Support for automatic remote bindings (work in progress). --- .../pl/treksoft/kvision/remote/ServiceManager.kt | 117 +++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt (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 new file mode 100644 index 00000000..cd42f038 --- /dev/null +++ b/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package pl.treksoft.kvision.remote + +import kotlinx.coroutines.experimental.Deferred + +/** + * Multiplatform service manager. + */ +actual open class ServiceManager actual constructor(service: T?) { + 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 + */ + protected actual inline fun bind( + route: String, + noinline function: T.(Request?) -> Deferred + ) { + calls[function.toString()] = "$SERVICE_PREFIX/$route" + } + + /** + * Binds a given route with a function of the receiver. + * @param route a route + * @param function a function of the receiver + */ + protected actual inline fun bind( + route: String, + noinline function: T.(PAR, Request?) -> Deferred + ) { + calls[function.toString()] = "$SERVICE_PREFIX/$route" + } + + /** + * Binds a given route with a function of the receiver. + * @param route a route + * @param function a function of the receiver + */ + protected actual inline fun bind( + route: String, + noinline function: T.(PAR1, PAR2, Request?) -> Deferred + ) { + calls[function.toString()] = "$SERVICE_PREFIX/$route" + } + + /** + * Binds a given route with a function of the receiver. + * @param route a route + * @param function a function of the receiver + */ + protected actual inline fun bind( + route: String, + noinline function: T.(PAR1, PAR2, PAR3, Request?) -> Deferred + ) { + calls[function.toString()] = "$SERVICE_PREFIX/$route" + } + + /** + * Binds a given route with a function of the receiver. + * @param route a route + * @param function a function of the receiver + */ + protected actual inline fun bind( + route: String, + noinline function: T.(PAR1, PAR2, PAR3, PAR4, Request?) -> Deferred + ) { + calls[function.toString()] = "$SERVICE_PREFIX/$route" + } + + /** + * Binds a given route with a function of the receiver. + * @param route a route + * @param function a function of the receiver + */ + protected actual inline fun bind( + route: String, + noinline function: T.(PAR1, PAR2, PAR3, PAR4, PAR5, Request?) -> Deferred + ) { + calls[function.toString()] = "$SERVICE_PREFIX/$route" + } + + /** + * Applies all defined routes to the given server. + * Not used on the js platform. + */ + actual fun applyRoutes(k: JoobyServer) { + } + + /** + * Returns the list of defined bindings. + * Not used on the jvm platform. + */ + actual fun getCalls(): Map = calls +} -- cgit