aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2018-04-25 08:12:25 +0200
committerRobert Jaros <rjaros@finn.pl>2018-04-25 08:12:25 +0200
commit5b9535e9964816eb228d3797f4c8a3e7676d1f53 (patch)
tree00889e3c489288d6386367e8ac26973868e11f8f /src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt
parent76c436567b87672609879a11762202599ed27af4 (diff)
downloadkvision-5b9535e9964816eb228d3797f4c8a3e7676d1f53.tar.gz
kvision-5b9535e9964816eb228d3797f4c8a3e7676d1f53.tar.bz2
kvision-5b9535e9964816eb228d3797f4c8a3e7676d1f53.zip
Multiplatform kvision-common and kvision-server modules.
Support for automatic remote bindings (work in progress).
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt117
1 files changed, 117 insertions, 0 deletions
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<out T> actual constructor(service: T?) {
+ protected val calls: MutableMap<String, String> = 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 <reified RET> bind(
+ route: String,
+ noinline function: T.(Request?) -> Deferred<RET>
+ ) {
+ 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 <reified PAR, reified RET> bind(
+ route: String,
+ noinline function: T.(PAR, Request?) -> Deferred<RET>
+ ) {
+ 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 <reified PAR1, reified PAR2, reified RET> bind(
+ route: String,
+ noinline function: T.(PAR1, PAR2, Request?) -> Deferred<RET>
+ ) {
+ 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 <reified PAR1, reified PAR2, reified PAR3, reified RET> bind(
+ route: String,
+ noinline function: T.(PAR1, PAR2, PAR3, Request?) -> Deferred<RET>
+ ) {
+ 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 <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified RET> bind(
+ route: String,
+ noinline function: T.(PAR1, PAR2, PAR3, PAR4, Request?) -> Deferred<RET>
+ ) {
+ 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 <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>
+ ) {
+ 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<String, String> = calls
+}