diff options
author | Pacien TRAN-GIRARD | 2017-07-01 16:24:22 +0200 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2017-07-01 16:24:22 +0200 |
commit | 3e3135b0c7fba811735a30e7fd155ca1e188c787 (patch) | |
tree | 71635795e40dd95c5cf2fd99f4435d8332125a5d /app/src/main/java/org/pacien/tincapp/commands | |
parent | 85a3892d4ecad4aae98f062e824f54e477bf8912 (diff) | |
download | tincapp-3e3135b0c7fba811735a30e7fd155ca1e188c787.tar.gz |
Use global app context
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/commands')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/commands/Tinc.kt | 33 | ||||
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/commands/Tincd.kt | 13 |
2 files changed, 21 insertions, 25 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 index eb5689a..91a2678 100644 --- a/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt +++ b/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt | |||
@@ -1,6 +1,5 @@ | |||
1 | package org.pacien.tincapp.commands | 1 | package org.pacien.tincapp.commands |
2 | 2 | ||
3 | import android.content.Context | ||
4 | import org.pacien.tincapp.context.AppPaths | 3 | import org.pacien.tincapp.context.AppPaths |
5 | import java.io.IOException | 4 | import java.io.IOException |
6 | 5 | ||
@@ -9,22 +8,22 @@ import java.io.IOException | |||
9 | */ | 8 | */ |
10 | object Tinc { | 9 | object Tinc { |
11 | 10 | ||
12 | private fun newCommand(ctx: Context, netName: String): Command = | 11 | private fun newCommand(netName: String): Command = |
13 | Command(AppPaths.tinc(ctx).absolutePath) | 12 | Command(AppPaths.tinc().absolutePath) |
14 | .withOption("config", AppPaths.confDir(ctx, netName).absolutePath) | 13 | .withOption("config", AppPaths.confDir(netName).absolutePath) |
15 | .withOption("pidfile", AppPaths.pidFile(ctx, netName).absolutePath) | 14 | .withOption("pidfile", AppPaths.pidFile(netName).absolutePath) |
16 | 15 | ||
17 | // independently runnable commands | 16 | // independently runnable commands |
18 | 17 | ||
19 | @Throws(IOException::class) | 18 | @Throws(IOException::class) |
20 | fun network(ctx: Context): List<String> = | 19 | fun network(): List<String> = |
21 | Executor.call(Command(AppPaths.tinc(ctx).absolutePath) | 20 | Executor.call(Command(AppPaths.tinc().absolutePath) |
22 | .withOption("config", AppPaths.confDir(ctx).absolutePath) | 21 | .withOption("config", AppPaths.confDir().absolutePath) |
23 | .withArguments("network")) | 22 | .withArguments("network")) |
24 | 23 | ||
25 | @Throws(IOException::class) | 24 | @Throws(IOException::class) |
26 | fun fsck(ctx: Context, netName: String, fix: Boolean): List<String> { | 25 | fun fsck(netName: String, fix: Boolean): List<String> { |
27 | var cmd = newCommand(ctx, netName).withArguments("fsck") | 26 | var cmd = newCommand(netName).withArguments("fsck") |
28 | if (fix) cmd = cmd.withOption("force") | 27 | if (fix) cmd = cmd.withOption("force") |
29 | return Executor.call(cmd) | 28 | return Executor.call(cmd) |
30 | } | 29 | } |
@@ -32,18 +31,18 @@ object Tinc { | |||
32 | // commands requiring a running tinc daemon | 31 | // commands requiring a running tinc daemon |
33 | 32 | ||
34 | @Throws(IOException::class) | 33 | @Throws(IOException::class) |
35 | fun stop(ctx: Context, netName: String) { | 34 | fun stop(netName: String) { |
36 | Executor.call(newCommand(ctx, netName).withArguments("stop")) | 35 | Executor.call(newCommand(netName).withArguments("stop")) |
37 | } | 36 | } |
38 | 37 | ||
39 | @Throws(IOException::class) | 38 | @Throws(IOException::class) |
40 | fun dumpNodes(ctx: Context, netName: String, reachable: Boolean): List<String> = | 39 | fun dumpNodes(netName: String, reachable: Boolean): List<String> = |
41 | Executor.call( | 40 | Executor.call( |
42 | if (reachable) newCommand(ctx, netName).withArguments("dump", "reachable", "nodes") | 41 | if (reachable) newCommand(netName).withArguments("dump", "reachable", "nodes") |
43 | else newCommand(ctx, netName).withArguments("dump", "nodes")) | 42 | else newCommand(netName).withArguments("dump", "nodes")) |
44 | 43 | ||
45 | @Throws(IOException::class) | 44 | @Throws(IOException::class) |
46 | fun info(ctx: Context, netName: String, node: String): String = | 45 | fun info(netName: String, node: String): String = |
47 | Executor.call(newCommand(ctx, netName).withArguments("info", node)).joinToString("\n") | 46 | Executor.call(newCommand(netName).withArguments("info", node)).joinToString("\n") |
48 | 47 | ||
49 | } | 48 | } |
diff --git a/app/src/main/java/org/pacien/tincapp/commands/Tincd.kt b/app/src/main/java/org/pacien/tincapp/commands/Tincd.kt index 9f2491e..19ebfbd 100644 --- a/app/src/main/java/org/pacien/tincapp/commands/Tincd.kt +++ b/app/src/main/java/org/pacien/tincapp/commands/Tincd.kt | |||
@@ -1,9 +1,6 @@ | |||
1 | package org.pacien.tincapp.commands | 1 | package org.pacien.tincapp.commands |
2 | 2 | ||
3 | import android.content.Context | ||
4 | |||
5 | import org.pacien.tincapp.context.AppPaths | 3 | import org.pacien.tincapp.context.AppPaths |
6 | |||
7 | import java.io.IOException | 4 | import java.io.IOException |
8 | 5 | ||
9 | /** | 6 | /** |
@@ -12,12 +9,12 @@ import java.io.IOException | |||
12 | object Tincd { | 9 | object Tincd { |
13 | 10 | ||
14 | @Throws(IOException::class) | 11 | @Throws(IOException::class) |
15 | fun start(ctx: Context, netName: String, fd: Int) { | 12 | fun start(netName: String, fd: Int) { |
16 | Executor.forkExec(Command(AppPaths.tincd(ctx).absolutePath) | 13 | Executor.forkExec(Command(AppPaths.tincd().absolutePath) |
17 | .withOption("no-detach") | 14 | .withOption("no-detach") |
18 | .withOption("config", AppPaths.confDir(ctx, netName).absolutePath) | 15 | .withOption("config", AppPaths.confDir(netName).absolutePath) |
19 | .withOption("pidfile", AppPaths.pidFile(ctx, netName).absolutePath) | 16 | .withOption("pidfile", AppPaths.pidFile(netName).absolutePath) |
20 | .withOption("logfile", AppPaths.logFile(ctx, netName).absolutePath) | 17 | .withOption("logfile", AppPaths.logFile(netName).absolutePath) |
21 | .withOption("option", "DeviceType=fd") | 18 | .withOption("option", "DeviceType=fd") |
22 | .withOption("option", "Device=" + fd)) | 19 | .withOption("option", "Device=" + fd)) |
23 | } | 20 | } |