diff options
author | Pacien TRAN-GIRARD | 2017-06-30 10:21:51 +0200 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2017-06-30 10:21:51 +0200 |
commit | c89016e7427defd1f8a095d7aeb30292a42fad92 (patch) | |
tree | aec80e6f501824f966ea727d2f6e102a75e9655f /app/src/main/java/org/pacien/tincapp/commands/Tinc.kt | |
parent | 94d77ce43152a4e144417d8d5cfff363f65c904e (diff) | |
download | tincapp-c89016e7427defd1f8a095d7aeb30292a42fad92.tar.gz |
Conversion to Kotlin
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/commands/Tinc.kt')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/commands/Tinc.kt | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt b/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt new file mode 100644 index 0000000..eb5689a --- /dev/null +++ b/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt | |||
@@ -0,0 +1,49 @@ | |||
1 | package org.pacien.tincapp.commands | ||
2 | |||
3 | import android.content.Context | ||
4 | import org.pacien.tincapp.context.AppPaths | ||
5 | import java.io.IOException | ||
6 | |||
7 | /** | ||
8 | * @author pacien | ||
9 | */ | ||
10 | object Tinc { | ||
11 | |||
12 | private fun newCommand(ctx: Context, netName: String): Command = | ||
13 | Command(AppPaths.tinc(ctx).absolutePath) | ||
14 | .withOption("config", AppPaths.confDir(ctx, netName).absolutePath) | ||
15 | .withOption("pidfile", AppPaths.pidFile(ctx, netName).absolutePath) | ||
16 | |||
17 | // independently runnable commands | ||
18 | |||
19 | @Throws(IOException::class) | ||
20 | fun network(ctx: Context): List<String> = | ||
21 | Executor.call(Command(AppPaths.tinc(ctx).absolutePath) | ||
22 | .withOption("config", AppPaths.confDir(ctx).absolutePath) | ||
23 | .withArguments("network")) | ||
24 | |||
25 | @Throws(IOException::class) | ||
26 | fun fsck(ctx: Context, netName: String, fix: Boolean): List<String> { | ||
27 | var cmd = newCommand(ctx, netName).withArguments("fsck") | ||
28 | if (fix) cmd = cmd.withOption("force") | ||
29 | return Executor.call(cmd) | ||
30 | } | ||
31 | |||
32 | // commands requiring a running tinc daemon | ||
33 | |||
34 | @Throws(IOException::class) | ||
35 | fun stop(ctx: Context, netName: String) { | ||
36 | Executor.call(newCommand(ctx, netName).withArguments("stop")) | ||
37 | } | ||
38 | |||
39 | @Throws(IOException::class) | ||
40 | fun dumpNodes(ctx: Context, netName: String, reachable: Boolean): List<String> = | ||
41 | Executor.call( | ||
42 | if (reachable) newCommand(ctx, netName).withArguments("dump", "reachable", "nodes") | ||
43 | else newCommand(ctx, netName).withArguments("dump", "nodes")) | ||
44 | |||
45 | @Throws(IOException::class) | ||
46 | fun info(ctx: Context, netName: String, node: String): String = | ||
47 | Executor.call(newCommand(ctx, netName).withArguments("info", node)).joinToString("\n") | ||
48 | |||
49 | } | ||