View Javadoc
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  
23  import lombok.AllArgsConstructor;
24  import lombok.Getter;
25  
26  /**
27   * <p>Command class.</p>
28   *
29   * @author Michael Thomas (mikepthomas@outlook.com)
30   * @version 7.6.21
31   */
32  @AllArgsConstructor
33  @Getter
34  public enum Command {
35  
36  // <editor-fold defaultstate="collapsed" desc="Commands">
37  
38      /** Authenticate. */
39      AUTH("auth", ResponseType.VOID),
40  
41      /** Error message. */
42      ERROR("error", ResponseType.PYON),
43  
44      /** Exit the command processor. */
45      EXIT("exit", ResponseType.VOID),
46  
47      /** Prints an increasing heartbeat count. */
48      HEARTBEAT("heartbeat", ResponseType.PYON),
49  
50      /** Enable/disable log updates. */
51      LOG_UPDATES("log-updates", ResponseType.PYON), // start | restart | stop
52  
53      /** Exit the command processor. */
54      QUIT("quit", ResponseType.VOID),
55  
56      /**
57       * Unpause all slots which are paused waiting for a screensaver and pause
58       * them again on disconnect.
59       */
60      SCREENSAVER("screensaver", ResponseType.VOID),
61  
62      /** Enable/disable updates. */
63      UPDATES("updates", ResponseType.VOID), // add <id> <rate> <expression> | del <id> | list | clear | reset
64  
65      // Folding@home Client:
66      /** Bond a packet file to a outgoing debug socket connection. */
67      BOND("bond", ResponseType.VOID), // <ip>:<port> <input> [output] [ip:port]
68  
69      /**
70       * Return a PyON message indicating if the client has set a user, team or
71       * passkey.
72       */
73      CONFIGURED("configured", ResponseType.PYON),
74  
75      /** Run one client cycle. */
76      DO_CYCLE("do-cycle", ResponseType.VOID),
77  
78      /**
79       * Download a core.
80       *
81       * @deprecated Command no longer supported.
82       */
83      @Deprecated
84      DOWNLOAD_CORE("download-core", ResponseType.VOID), // <type> <url>
85  
86      /** Finish all or one slot(s). */
87      FINISH("finish", ResponseType.VOID), // [slot]
88  
89      /** Print application information. */
90      GET_INFO("get-info", ResponseType.STRING), // <category> <key>
91  
92      /** Print application information in PyON format. */
93      INFO("info", ResponseType.PYON),
94  
95      /**
96       * Inject a packet file to a listening debug socket. Will wait until packet
97       * is processed.
98       */
99      INJECT("inject", ResponseType.VOID), // <ip>:<port> <input> [output] [ip:port]
100 
101     /** Disable specified unit states. */
102     MASK_UNIT_STATE("mask-unit-state", ResponseType.VOID),
103 
104     /** Get number of slots in PyON format. */
105     NUM_SLOTS("num-slots", ResponseType.PYON),
106 
107     /** Get or set a configuration option. */
108     OPTION("option", ResponseType.STRING), // <name> [value]
109 
110     /**
111      * List or set options with their values.
112      *
113      * If no name arguments are given then all options with non-default values
114      * will be listed. If the '-d' argument is given then even defaulted options
115      * will be listed. If the '-a' option is given then unset options will also
116      * be listed. Otherwise, if option names are provided only those options
117      * will be listed.
118      * The special name '*' lists all options which have not yet been listed and
119      * is affected by the '-d' and '-a' options.
120      * If a name argument is followed directly by an equal sign then the rest of
121      * the argument will be used to set the option's value. If instead a name
122      * argument is followed immediately by a '!' then the option will be reset
123      * to its default value.
124      * Options which are set or reset will also be listed.
125      * Options are listed as a PyON format dictionary.
126      */
127     OPTIONS("options", ResponseType.PYON),
128 
129     /** Pause all or one slot(s). */
130     PAUSE("pause", ResponseType.VOID), // [slot]
131 
132     /** Get current total estimated Points Per Day. */
133     PPD("ppd", ResponseType.PYON),
134 
135     /** Get work unit queue information in PyON format. */
136     QUEUE_INFO("queue-info", ResponseType.PYON),
137 
138     /** Request an ID from the assignment server. */
139     REQUEST_ID("request-id", ResponseType.VOID),
140 
141     /** Request work server assignment from the assignment server. */
142     REQUEST_WS("request-ws", ResponseType.VOID),
143 
144     /**
145      * Save the configuration either to the specified file or to the file the
146      * configuration was last loaded from.
147      */
148     SAVE("save", ResponseType.VOID), // [file]
149 
150     /** Shutdown the application. */
151     SHUTDOWN("shutdown", ResponseType.VOID),
152 
153     /** Get current simulation information. */
154     SIMULATION_INFO("simulation-info", ResponseType.PYON), // <slot id>
155 
156     /**
157      * Add a new slot. Configuration options for the new slot can be provided.
158      */
159     SLOT_ADD("slot-add", ResponseType.VOID), // <type> [<name>=<value>]...
160 
161     /** Delete a slot. If it is running a unit it will be stopped. */
162     SLOT_DELETE("slot-delete", ResponseType.VOID), // <slot>
163 
164     /** Get slot information in PyON format. */
165     SLOT_INFO("slot-info", ResponseType.PYON),
166 
167     /**
168      * Modify an existing slot.
169      *
170      * Configuration options can be either set or reset using the same syntax
171      * used by the 'options' command.
172      */
173     SLOT_MODIFY("slot-modify", ResponseType.VOID), // <id> <type> [<name><! | =<value>>]...
174 
175     /**
176      * The first argument is the slot ID.
177      *
178      * See 'options' help for a description of the remaining arguments.
179      */
180     SLOT_OPTIONS("slot-options", ResponseType.PYON), // <slot> [-d | -a] | [name]...
181 
182     /** Get current protein trajectory. */
183     TRAJECTORY("trajectory", ResponseType.VOID), // <slot id>
184 
185     /** Trigger config save after a delay. */
186     TRIGGER_SAVE("trigger-save", ResponseType.VOID),
187 
188     /** Unpause all or one slot(s). */
189     UNPAUSE("unpause", ResponseType.VOID), // [slot]
190 
191     /** Print application uptime. */
192     UPTIME("uptime", ResponseType.STRING),
193 
194     /** Wait for all running units to finish. */
195     WAIT_FOR_UNITS("wait-for-units", ResponseType.VOID),
196 
197     // Standard Commands:
198     /** Add two values. */
199     ADD("add", ResponseType.VOID), // <number> <number>
200 
201     /** Clear the screen. */
202     CLEAR("clear", ResponseType.VOID),
203 
204     /**
205      * Print the date and time.
206      *
207      * Optionally, with 'format'. See: man strftime
208      */
209     DATE("date", ResponseType.VOID), // [format]
210 
211     /** Divide two values. */
212     DIV("div", ResponseType.VOID), // <number> <number>
213 
214     /** Evaluate all arguments. */
215     EVAL("eval", ResponseType.VOID), // [expr]...
216 
217     /**
218      * If 'cond' evaluates to a non-empty string then evalute 'expr1' otherwise,
219      * if provided, evaluate 'expr2'.
220      */
221     IF("if", ResponseType.VOID), // <cond> <expr1> [expr2]
222 
223     /** Multiply two values. */
224     MUL("mul", ResponseType.VOID), // <number> <number>
225 
226     /** Invert the truth value of the argument. */
227     NOT("not", ResponseType.VOID), // <expr>
228 
229     /** Sleep for a number of seconds. */
230     SLEEP("sleep", ResponseType.VOID), // <seconds>
231 
232     /** Subtract two values. */
233     SUB("sub", ResponseType.VOID); // <number> <number>
234 
235 // </editor-fold>
236 
237     /**
238      * Command.
239      *
240      * @return String Folding@Home command.
241      */
242     private final String command;
243 
244     /**
245      * Response type of this command.
246      *
247      * @return ResponseType type of response.
248      */
249     private final ResponseType responseType;
250 
251     /** {@inheritDoc} */
252     @Override
253     public String toString() {
254         return command;
255     }
256 }