// Path: modules/cli/src/main/java/de/tobifleig/lxc/plaf/cli/cmds/ListCommand.java
// public class ListCommand extends BackendCommand {
// 
//     public ListCommand() {
//         super(BackendCommandType.LIST);
//     }
// }
// 
// Path: modules/cli/src/main/java/de/tobifleig/lxc/plaf/cli/cmds/StartCommand.java
// public class StartCommand extends BackendCommand {
// 
//     /**
//      * Whether the backend was started for this command.
//      * (If not, the backend prints a "already running" message.
//      */
//     private final boolean backendLaunched;
// 
//     public StartCommand(boolean backendLaunched) {
//         super(BackendCommandType.START);
//         this.backendLaunched = backendLaunched;
//     }
// 
//     public boolean isBackendLaunched() {
//         return backendLaunched;
//     }
// }
// 
// Path: modules/cli/src/main/java/de/tobifleig/lxc/plaf/cli/cmds/StatusCommand.java
// public class StatusCommand extends BackendCommand {
// 
//     public StatusCommand() {
//         super(BackendCommandType.NOP);
//     }
// 
//     @Override
//     public boolean startBackendOnSendError() {
//         return false;
//     }
// 
//     @Override
//     public void onFrontendResult(boolean deliveredToBackend) {
//         if (deliveredToBackend) {
//             CLITools.out.println("LanXchange is running in the background.");
//         } else {
//             CLITools.out.println("LanXchange backend is NOT running.");
//         }
//     }
// }
// 
// Path: modules/cli/src/main/java/de/tobifleig/lxc/plaf/cli/cmds/StopCommand.java
// public class StopCommand extends BackendCommand {
// 
//     private final boolean force;
// 
//     public StopCommand(boolean force) {
//         super(BackendCommandType.STOP);
//         this.force = force;
//     }
// 
//     public boolean isForce() {
//         return force;
//     }
// 
//     @Override
//     public boolean startBackendOnSendError() {
//         return false;
//     }
// 
//     @Override
//     public void onFrontendResult(boolean deliveredToBackend) {
//         if (!deliveredToBackend) {
//             CLITools.out.println("Not running.");
//         }
//     }
// }
// 
// Path: modules/cli/src/main/java/de/tobifleig/lxc/plaf/cli/ui/CLITools.java
// public final class CLITools {
// 
//     /**
//      * This is the original System.out out.
//      * LanXchange may change System.out for logging purposes, but the cli gui must still be able to print to stdout.
//      */
//     public static final PrintStream out = new PrintStream(new FileOutputStream(FileDescriptor.out));
// }


import de.tobifleig.lxc.plaf.cli.cmds.ListCommand;
import de.tobifleig.lxc.plaf.cli.cmds.StartCommand;
import de.tobifleig.lxc.plaf.cli.cmds.StatusCommand;
import de.tobifleig.lxc.plaf.cli.cmds.StopCommand;
import de.tobifleig.lxc.plaf.cli.ui.CLITools;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.ConnectException;
import java.net.InetAddress;
import java.net.Socket;
/*
 * Copyright 2017 Tobias Fleig (tobifleig gmail com)
 * All rights reserved.
 *
 * Usage of this source code is governed by the GNU GENERAL PUBLIC LICENSE version 3 or (at your option) any later version.
 * For the full license text see the file COPYING or https://github.com/tfg13/LanXchange/blob/master/COPYING
 */
package de.tobifleig.lxc.plaf.cli;



/**
 * The frontend, mostly submits commands to the backend.
 */
public class CLIFrontend {

    private static int EXITCODE_REQUEST_BACKEND_START = 7;

    private static int RECONNECT_DELAY_MS_INITIAL = 100;
    private static int RECONNECT_DELAY_MS_MAX = 6400;

    public static void main(String[] args) {
        // this should only be called by lxcc (the cli launch script)
        if (args.length == 0 || !args[0].equals("-cli")) {
// Path: modules/cli/src/main/java/de/tobifleig/lxc/plaf/cli/cmds/ListCommand.java
// public class ListCommand extends BackendCommand {
// 
//     public ListCommand() {
//         super(BackendCommandType.LIST);
//     }
// }
// 
// Path: modules/cli/src/main/java/de/tobifleig/lxc/plaf/cli/cmds/StartCommand.java
// public class StartCommand extends BackendCommand {
// 
//     /**
//      * Whether the backend was started for this command.
//      * (If not, the backend prints a "already running" message.
//      */
//     private final boolean backendLaunched;
// 
//     public StartCommand(boolean backendLaunched) {
//         super(BackendCommandType.START);
//         this.backendLaunched = backendLaunched;
//     }
// 
//     public boolean isBackendLaunched() {
//         return backendLaunched;
//     }
// }
// 
// Path: modules/cli/src/main/java/de/tobifleig/lxc/plaf/cli/cmds/StatusCommand.java
// public class StatusCommand extends BackendCommand {
// 
//     public StatusCommand() {
//         super(BackendCommandType.NOP);
//     }
// 
//     @Override
//     public boolean startBackendOnSendError() {
//         return false;
//     }
// 
//     @Override
//     public void onFrontendResult(boolean deliveredToBackend) {
//         if (deliveredToBackend) {
//             CLITools.out.println("LanXchange is running in the background.");
//         } else {
//             CLITools.out.println("LanXchange backend is NOT running.");
//         }
//     }
// }
// 
// Path: modules/cli/src/main/java/de/tobifleig/lxc/plaf/cli/cmds/StopCommand.java
// public class StopCommand extends BackendCommand {
// 
//     private final boolean force;
// 
//     public StopCommand(boolean force) {
//         super(BackendCommandType.STOP);
//         this.force = force;
//     }
// 
//     public boolean isForce() {
//         return force;
//     }
// 
//     @Override
//     public boolean startBackendOnSendError() {
//         return false;
//     }
// 
//     @Override
//     public void onFrontendResult(boolean deliveredToBackend) {
//         if (!deliveredToBackend) {
//             CLITools.out.println("Not running.");
//         }
//     }
// }
// 
// Path: modules/cli/src/main/java/de/tobifleig/lxc/plaf/cli/ui/CLITools.java
// public final class CLITools {
// 
//     /**
//      * This is the original System.out out.
//      * LanXchange may change System.out for logging purposes, but the cli gui must still be able to print to stdout.
//      */
//     public static final PrintStream out = new PrintStream(new FileOutputStream(FileDescriptor.out));
// }


// Path: modules/cli/src/main/java/de/tobifleig/lxc/plaf/cli/CLIFrontend.java
import de.tobifleig.lxc.plaf.cli.cmds.ListCommand;
import de.tobifleig.lxc.plaf.cli.cmds.StartCommand;
import de.tobifleig.lxc.plaf.cli.cmds.StatusCommand;
import de.tobifleig.lxc.plaf.cli.cmds.StopCommand;
import de.tobifleig.lxc.plaf.cli.ui.CLITools;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.ConnectException;
import java.net.InetAddress;
import java.net.Socket;

/*
 * Copyright 2017 Tobias Fleig (tobifleig gmail com)
 * All rights reserved.
 *
 * Usage of this source code is governed by the GNU GENERAL PUBLIC LICENSE version 3 or (at your option) any later version.
 * For the full license text see the file COPYING or https://github.com/tfg13/LanXchange/blob/master/COPYING
 */
package de.tobifleig.lxc.plaf.cli;



/**
 * The frontend, mostly submits commands to the backend.
 */
public class CLIFrontend {

    private static int EXITCODE_REQUEST_BACKEND_START = 7;

    private static int RECONNECT_DELAY_MS_INITIAL = 100;
    private static int RECONNECT_DELAY_MS_MAX = 6400;

    public static void main(String[] args) {
        // this should only be called by lxcc (the cli launch script)
        if (args.length == 0 || !args[0].equals("-cli")) {
            CLITools.out.println("Please use the script \"lxcc\" to interact with the CLI version of LanXchange. " +