From 3e3135b0c7fba811735a30e7fd155ca1e188c787 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sat, 1 Jul 2017 16:24:22 +0200 Subject: Use global app context --- .../main/java/org/pacien/tincapp/commands/Tinc.kt | 33 +++++++++++----------- .../main/java/org/pacien/tincapp/commands/Tincd.kt | 13 ++++----- 2 files changed, 21 insertions(+), 25 deletions(-) (limited to 'app/src/main/java/org/pacien/tincapp/commands') 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 @@ package org.pacien.tincapp.commands -import android.content.Context import org.pacien.tincapp.context.AppPaths import java.io.IOException @@ -9,22 +8,22 @@ import java.io.IOException */ object Tinc { - private fun newCommand(ctx: Context, netName: String): Command = - Command(AppPaths.tinc(ctx).absolutePath) - .withOption("config", AppPaths.confDir(ctx, netName).absolutePath) - .withOption("pidfile", AppPaths.pidFile(ctx, netName).absolutePath) + private fun newCommand(netName: String): Command = + Command(AppPaths.tinc().absolutePath) + .withOption("config", AppPaths.confDir(netName).absolutePath) + .withOption("pidfile", AppPaths.pidFile(netName).absolutePath) // independently runnable commands @Throws(IOException::class) - fun network(ctx: Context): List = - Executor.call(Command(AppPaths.tinc(ctx).absolutePath) - .withOption("config", AppPaths.confDir(ctx).absolutePath) + fun network(): List = + Executor.call(Command(AppPaths.tinc().absolutePath) + .withOption("config", AppPaths.confDir().absolutePath) .withArguments("network")) @Throws(IOException::class) - fun fsck(ctx: Context, netName: String, fix: Boolean): List { - var cmd = newCommand(ctx, netName).withArguments("fsck") + fun fsck(netName: String, fix: Boolean): List { + var cmd = newCommand(netName).withArguments("fsck") if (fix) cmd = cmd.withOption("force") return Executor.call(cmd) } @@ -32,18 +31,18 @@ object Tinc { // commands requiring a running tinc daemon @Throws(IOException::class) - fun stop(ctx: Context, netName: String) { - Executor.call(newCommand(ctx, netName).withArguments("stop")) + fun stop(netName: String) { + Executor.call(newCommand(netName).withArguments("stop")) } @Throws(IOException::class) - fun dumpNodes(ctx: Context, netName: String, reachable: Boolean): List = + fun dumpNodes(netName: String, reachable: Boolean): List = Executor.call( - if (reachable) newCommand(ctx, netName).withArguments("dump", "reachable", "nodes") - else newCommand(ctx, netName).withArguments("dump", "nodes")) + if (reachable) newCommand(netName).withArguments("dump", "reachable", "nodes") + else newCommand(netName).withArguments("dump", "nodes")) @Throws(IOException::class) - fun info(ctx: Context, netName: String, node: String): String = - Executor.call(newCommand(ctx, netName).withArguments("info", node)).joinToString("\n") + fun info(netName: String, node: String): String = + Executor.call(newCommand(netName).withArguments("info", node)).joinToString("\n") } 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 @@ package org.pacien.tincapp.commands -import android.content.Context - import org.pacien.tincapp.context.AppPaths - import java.io.IOException /** @@ -12,12 +9,12 @@ import java.io.IOException object Tincd { @Throws(IOException::class) - fun start(ctx: Context, netName: String, fd: Int) { - Executor.forkExec(Command(AppPaths.tincd(ctx).absolutePath) + fun start(netName: String, fd: Int) { + Executor.forkExec(Command(AppPaths.tincd().absolutePath) .withOption("no-detach") - .withOption("config", AppPaths.confDir(ctx, netName).absolutePath) - .withOption("pidfile", AppPaths.pidFile(ctx, netName).absolutePath) - .withOption("logfile", AppPaths.logFile(ctx, netName).absolutePath) + .withOption("config", AppPaths.confDir(netName).absolutePath) + .withOption("pidfile", AppPaths.pidFile(netName).absolutePath) + .withOption("logfile", AppPaths.logFile(netName).absolutePath) .withOption("option", "DeviceType=fd") .withOption("option", "Device=" + fd)) } -- cgit v1.2.3