Command.java

  1. /*
  2.  * #%L
  3.  * This file is part of jFold.
  4.  * %%
  5.  * Copyright (C) 2012 - 2024 Mike Thomas <mikepthomas@outlook.com>
  6.  * %%
  7.  * jFold is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation, either version 3 of the License, or
  10.  * (at your option) any later version.
  11.  * %
  12.  * jFold is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  * %
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with jFold.  If not, see <http://www.gnu.org/licenses/>.
  19.  * #L%
  20.  */
  21. package info.mikethomas.jfold.util;

  22. import lombok.AllArgsConstructor;
  23. import lombok.Getter;

  24. /**
  25.  * <p>Command class.</p>
  26.  *
  27.  * @author Michael Thomas (mikepthomas@outlook.com)
  28.  * @version 7.6.21
  29.  */
  30. @AllArgsConstructor
  31. @Getter
  32. public enum Command {

  33. // <editor-fold defaultstate="collapsed" desc="Commands">

  34.     /** Authenticate. */
  35.     AUTH("auth", ResponseType.VOID),

  36.     /** Error message. */
  37.     ERROR("error", ResponseType.PYON),

  38.     /** Exit the command processor. */
  39.     EXIT("exit", ResponseType.VOID),

  40.     /** Prints an increasing heartbeat count. */
  41.     HEARTBEAT("heartbeat", ResponseType.PYON),

  42.     /** Enable/disable log updates. */
  43.     LOG_UPDATES("log-updates", ResponseType.PYON), // start | restart | stop

  44.     /** Exit the command processor. */
  45.     QUIT("quit", ResponseType.VOID),

  46.     /**
  47.      * Unpause all slots which are paused waiting for a screensaver and pause
  48.      * them again on disconnect.
  49.      */
  50.     SCREENSAVER("screensaver", ResponseType.VOID),

  51.     /** Enable/disable updates. */
  52.     UPDATES("updates", ResponseType.VOID), // add <id> <rate> <expression> | del <id> | list | clear | reset

  53.     // Folding@home Client:
  54.     /** Bond a packet file to a outgoing debug socket connection. */
  55.     BOND("bond", ResponseType.VOID), // <ip>:<port> <input> [output] [ip:port]

  56.     /**
  57.      * Return a PyON message indicating if the client has set a user, team or
  58.      * passkey.
  59.      */
  60.     CONFIGURED("configured", ResponseType.PYON),

  61.     /** Run one client cycle. */
  62.     DO_CYCLE("do-cycle", ResponseType.VOID),

  63.     /**
  64.      * Download a core.
  65.      *
  66.      * @deprecated Command no longer supported.
  67.      */
  68.     @Deprecated
  69.     DOWNLOAD_CORE("download-core", ResponseType.VOID), // <type> <url>

  70.     /** Finish all or one slot(s). */
  71.     FINISH("finish", ResponseType.VOID), // [slot]

  72.     /** Print application information. */
  73.     GET_INFO("get-info", ResponseType.STRING), // <category> <key>

  74.     /** Print application information in PyON format. */
  75.     INFO("info", ResponseType.PYON),

  76.     /**
  77.      * Inject a packet file to a listening debug socket. Will wait until packet
  78.      * is processed.
  79.      */
  80.     INJECT("inject", ResponseType.VOID), // <ip>:<port> <input> [output] [ip:port]

  81.     /** Disable specified unit states. */
  82.     MASK_UNIT_STATE("mask-unit-state", ResponseType.VOID),

  83.     /** Get number of slots in PyON format. */
  84.     NUM_SLOTS("num-slots", ResponseType.PYON),

  85.     /** Get or set a configuration option. */
  86.     OPTION("option", ResponseType.STRING), // <name> [value]

  87.     /**
  88.      * List or set options with their values.
  89.      *
  90.      * If no name arguments are given then all options with non-default values
  91.      * will be listed. If the '-d' argument is given then even defaulted options
  92.      * will be listed. If the '-a' option is given then unset options will also
  93.      * be listed. Otherwise, if option names are provided only those options
  94.      * will be listed.
  95.      * The special name '*' lists all options which have not yet been listed and
  96.      * is affected by the '-d' and '-a' options.
  97.      * If a name argument is followed directly by an equal sign then the rest of
  98.      * the argument will be used to set the option's value. If instead a name
  99.      * argument is followed immediately by a '!' then the option will be reset
  100.      * to its default value.
  101.      * Options which are set or reset will also be listed.
  102.      * Options are listed as a PyON format dictionary.
  103.      */
  104.     OPTIONS("options", ResponseType.PYON),

  105.     /** Pause all or one slot(s). */
  106.     PAUSE("pause", ResponseType.VOID), // [slot]

  107.     /** Get current total estimated Points Per Day. */
  108.     PPD("ppd", ResponseType.PYON),

  109.     /** Get work unit queue information in PyON format. */
  110.     QUEUE_INFO("queue-info", ResponseType.PYON),

  111.     /** Request an ID from the assignment server. */
  112.     REQUEST_ID("request-id", ResponseType.VOID),

  113.     /** Request work server assignment from the assignment server. */
  114.     REQUEST_WS("request-ws", ResponseType.VOID),

  115.     /**
  116.      * Save the configuration either to the specified file or to the file the
  117.      * configuration was last loaded from.
  118.      */
  119.     SAVE("save", ResponseType.VOID), // [file]

  120.     /** Shutdown the application. */
  121.     SHUTDOWN("shutdown", ResponseType.VOID),

  122.     /** Get current simulation information. */
  123.     SIMULATION_INFO("simulation-info", ResponseType.PYON), // <slot id>

  124.     /**
  125.      * Add a new slot. Configuration options for the new slot can be provided.
  126.      */
  127.     SLOT_ADD("slot-add", ResponseType.VOID), // <type> [<name>=<value>]...

  128.     /** Delete a slot. If it is running a unit it will be stopped. */
  129.     SLOT_DELETE("slot-delete", ResponseType.VOID), // <slot>

  130.     /** Get slot information in PyON format. */
  131.     SLOT_INFO("slot-info", ResponseType.PYON),

  132.     /**
  133.      * Modify an existing slot.
  134.      *
  135.      * Configuration options can be either set or reset using the same syntax
  136.      * used by the 'options' command.
  137.      */
  138.     SLOT_MODIFY("slot-modify", ResponseType.VOID), // <id> <type> [<name><! | =<value>>]...

  139.     /**
  140.      * The first argument is the slot ID.
  141.      *
  142.      * See 'options' help for a description of the remaining arguments.
  143.      */
  144.     SLOT_OPTIONS("slot-options", ResponseType.PYON), // <slot> [-d | -a] | [name]...

  145.     /** Get current protein trajectory. */
  146.     TRAJECTORY("trajectory", ResponseType.VOID), // <slot id>

  147.     /** Trigger config save after a delay. */
  148.     TRIGGER_SAVE("trigger-save", ResponseType.VOID),

  149.     /** Unpause all or one slot(s). */
  150.     UNPAUSE("unpause", ResponseType.VOID), // [slot]

  151.     /** Print application uptime. */
  152.     UPTIME("uptime", ResponseType.STRING),

  153.     /** Wait for all running units to finish. */
  154.     WAIT_FOR_UNITS("wait-for-units", ResponseType.VOID),

  155.     // Standard Commands:
  156.     /** Add two values. */
  157.     ADD("add", ResponseType.VOID), // <number> <number>

  158.     /** Clear the screen. */
  159.     CLEAR("clear", ResponseType.VOID),

  160.     /**
  161.      * Print the date and time.
  162.      *
  163.      * Optionally, with 'format'. See: man strftime
  164.      */
  165.     DATE("date", ResponseType.VOID), // [format]

  166.     /** Divide two values. */
  167.     DIV("div", ResponseType.VOID), // <number> <number>

  168.     /** Evaluate all arguments. */
  169.     EVAL("eval", ResponseType.VOID), // [expr]...

  170.     /**
  171.      * If 'cond' evaluates to a non-empty string then evalute 'expr1' otherwise,
  172.      * if provided, evaluate 'expr2'.
  173.      */
  174.     IF("if", ResponseType.VOID), // <cond> <expr1> [expr2]

  175.     /** Multiply two values. */
  176.     MUL("mul", ResponseType.VOID), // <number> <number>

  177.     /** Invert the truth value of the argument. */
  178.     NOT("not", ResponseType.VOID), // <expr>

  179.     /** Sleep for a number of seconds. */
  180.     SLEEP("sleep", ResponseType.VOID), // <seconds>

  181.     /** Subtract two values. */
  182.     SUB("sub", ResponseType.VOID); // <number> <number>

  183. // </editor-fold>

  184.     /**
  185.      * Command.
  186.      *
  187.      * @return String Folding@Home command.
  188.      */
  189.     private final String command;

  190.     /**
  191.      * Response type of this command.
  192.      *
  193.      * @return ResponseType type of response.
  194.      */
  195.     private final ResponseType responseType;

  196.     /** {@inheritDoc} */
  197.     @Override
  198.     public String toString() {
  199.         return command;
  200.     }
  201. }