mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
Remove operation enum - just use opcode.
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
<groupId>net.sourceforge.guacamole</groupId>
|
<groupId>net.sourceforge.guacamole</groupId>
|
||||||
<artifactId>guacamole-common</artifactId>
|
<artifactId>guacamole-common</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>0.7.1</version>
|
<version>0.8.0</version>
|
||||||
<name>guacamole-common</name>
|
<name>guacamole-common</name>
|
||||||
<url>http://guac-dev.org/</url>
|
<url>http://guac-dev.org/</url>
|
||||||
|
|
||||||
|
@@ -43,7 +43,6 @@ import java.util.LinkedList;
|
|||||||
import net.sourceforge.guacamole.GuacamoleException;
|
import net.sourceforge.guacamole.GuacamoleException;
|
||||||
import net.sourceforge.guacamole.GuacamoleServerException;
|
import net.sourceforge.guacamole.GuacamoleServerException;
|
||||||
import net.sourceforge.guacamole.protocol.GuacamoleInstruction;
|
import net.sourceforge.guacamole.protocol.GuacamoleInstruction;
|
||||||
import net.sourceforge.guacamole.protocol.GuacamoleInstruction.Operation;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A GuacamoleReader which wraps a standard Java Reader, using that Reader as
|
* A GuacamoleReader which wraps a standard Java Reader, using that Reader as
|
||||||
@@ -251,7 +250,7 @@ public class ReaderGuacamoleReader implements GuacamoleReader {
|
|||||||
|
|
||||||
// Create instruction
|
// Create instruction
|
||||||
GuacamoleInstruction instruction = new GuacamoleInstruction(
|
GuacamoleInstruction instruction = new GuacamoleInstruction(
|
||||||
Operation.fromOpcode(opcode),
|
opcode,
|
||||||
elements.toArray(new String[elements.size()])
|
elements.toArray(new String[elements.size()])
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@@ -42,7 +42,6 @@ import net.sourceforge.guacamole.GuacamoleServerException;
|
|||||||
import net.sourceforge.guacamole.io.GuacamoleReader;
|
import net.sourceforge.guacamole.io.GuacamoleReader;
|
||||||
import net.sourceforge.guacamole.io.GuacamoleWriter;
|
import net.sourceforge.guacamole.io.GuacamoleWriter;
|
||||||
import net.sourceforge.guacamole.net.GuacamoleSocket;
|
import net.sourceforge.guacamole.net.GuacamoleSocket;
|
||||||
import net.sourceforge.guacamole.protocol.GuacamoleInstruction.Operation;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A GuacamoleSocket which pre-configures the connection based on a given
|
* A GuacamoleSocket which pre-configures the connection based on a given
|
||||||
@@ -104,7 +103,7 @@ public class ConfiguredGuacamoleSocket implements GuacamoleSocket {
|
|||||||
GuacamoleWriter writer = socket.getWriter();
|
GuacamoleWriter writer = socket.getWriter();
|
||||||
|
|
||||||
// Send protocol
|
// Send protocol
|
||||||
writer.writeInstruction(new GuacamoleInstruction(Operation.CLIENT_SELECT, config.getProtocol()));
|
writer.writeInstruction(new GuacamoleInstruction("select", config.getProtocol()));
|
||||||
|
|
||||||
// Wait for server args
|
// Wait for server args
|
||||||
GuacamoleInstruction instruction;
|
GuacamoleInstruction instruction;
|
||||||
@@ -115,7 +114,7 @@ public class ConfiguredGuacamoleSocket implements GuacamoleSocket {
|
|||||||
if (instruction == null)
|
if (instruction == null)
|
||||||
throw new GuacamoleServerException("End of stream during initial handshake.");
|
throw new GuacamoleServerException("End of stream during initial handshake.");
|
||||||
|
|
||||||
} while (instruction.getOperation() != Operation.SERVER_ARGS);
|
} while (!instruction.getOpcode().equals("args"));
|
||||||
|
|
||||||
// Build args list off provided names and config
|
// Build args list off provided names and config
|
||||||
String[] args = new String[instruction.getArgs().length];
|
String[] args = new String[instruction.getArgs().length];
|
||||||
@@ -134,7 +133,7 @@ public class ConfiguredGuacamoleSocket implements GuacamoleSocket {
|
|||||||
// Send size
|
// Send size
|
||||||
writer.writeInstruction(
|
writer.writeInstruction(
|
||||||
new GuacamoleInstruction(
|
new GuacamoleInstruction(
|
||||||
Operation.CLIENT_SIZE,
|
"size",
|
||||||
Integer.toString(info.getOptimalScreenWidth()),
|
Integer.toString(info.getOptimalScreenWidth()),
|
||||||
Integer.toString(info.getOptimalScreenHeight())
|
Integer.toString(info.getOptimalScreenHeight())
|
||||||
)
|
)
|
||||||
@@ -143,19 +142,19 @@ public class ConfiguredGuacamoleSocket implements GuacamoleSocket {
|
|||||||
// Send supported audio formats
|
// Send supported audio formats
|
||||||
writer.writeInstruction(
|
writer.writeInstruction(
|
||||||
new GuacamoleInstruction(
|
new GuacamoleInstruction(
|
||||||
Operation.CLIENT_AUDIO,
|
"audio",
|
||||||
info.getAudioMimetypes().toArray(new String[0])
|
info.getAudioMimetypes().toArray(new String[0])
|
||||||
));
|
));
|
||||||
|
|
||||||
// Send supported video formats
|
// Send supported video formats
|
||||||
writer.writeInstruction(
|
writer.writeInstruction(
|
||||||
new GuacamoleInstruction(
|
new GuacamoleInstruction(
|
||||||
Operation.CLIENT_VIDEO,
|
"video",
|
||||||
info.getVideoMimetypes().toArray(new String[0])
|
info.getVideoMimetypes().toArray(new String[0])
|
||||||
));
|
));
|
||||||
|
|
||||||
// Send args
|
// Send args
|
||||||
writer.writeInstruction(new GuacamoleInstruction(Operation.CLIENT_CONNECT, args));
|
writer.writeInstruction(new GuacamoleInstruction("connect", args));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -37,8 +37,6 @@ package net.sourceforge.guacamole.protocol;
|
|||||||
*
|
*
|
||||||
* ***** END LICENSE BLOCK ***** */
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An abstract representation of a Guacamole instruction, as defined by the
|
* An abstract representation of a Guacamole instruction, as defined by the
|
||||||
* Guacamole protocol.
|
* Guacamole protocol.
|
||||||
@@ -47,111 +45,28 @@ import java.util.HashMap;
|
|||||||
*/
|
*/
|
||||||
public class GuacamoleInstruction {
|
public class GuacamoleInstruction {
|
||||||
|
|
||||||
/**
|
private String opcode;
|
||||||
* The operation performed by a particular Guacamole instruction. Each
|
|
||||||
* Operation is associated with a unique opcode.
|
|
||||||
*/
|
|
||||||
public enum Operation {
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Message sent from client to server specifying the optimal or
|
|
||||||
* desired screen size.
|
|
||||||
*/
|
|
||||||
CLIENT_SIZE("size"),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Message sent from client to server specifying which audio mimetypes
|
|
||||||
* are supported.
|
|
||||||
*/
|
|
||||||
CLIENT_AUDIO("audio"),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Message sent from client to server specifying which video mimetypes
|
|
||||||
* are supported.
|
|
||||||
*/
|
|
||||||
CLIENT_VIDEO("video"),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Message sent from client to server specifying which protocol is
|
|
||||||
* to be used.
|
|
||||||
*/
|
|
||||||
CLIENT_SELECT("select"),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Message sent from client to server specifying which argument
|
|
||||||
* values correspond to the arguments required by the selected
|
|
||||||
* protocol.
|
|
||||||
*/
|
|
||||||
CLIENT_CONNECT("connect"),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Message sent from server to client specifying which arguments
|
|
||||||
* are required by the selected protocol.
|
|
||||||
*/
|
|
||||||
SERVER_ARGS("args");
|
|
||||||
|
|
||||||
private String opcode;
|
|
||||||
private Operation(String opcode) {
|
|
||||||
this.opcode = opcode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the unique opcode associated with this Operation.
|
|
||||||
* @return The unique opcode associated with this Operation.
|
|
||||||
*/
|
|
||||||
public String getOpcode() {
|
|
||||||
return opcode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Static hash of all opcodes and their corresponding Operations.
|
|
||||||
*/
|
|
||||||
private static final HashMap<String, Operation> opcodeToOperation;
|
|
||||||
static {
|
|
||||||
|
|
||||||
opcodeToOperation = new HashMap<String, Operation>();
|
|
||||||
|
|
||||||
for (Operation operation : Operation.values())
|
|
||||||
opcodeToOperation.put(operation.getOpcode(), operation);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the corresponding Operation having the given opcode, if any.
|
|
||||||
*
|
|
||||||
* @param opcode The unique opcode associated with an Operation.
|
|
||||||
* @return The Operation associated with the given opcode, or null if
|
|
||||||
* no such Operation is defined.
|
|
||||||
*/
|
|
||||||
public static Operation fromOpcode(String opcode) {
|
|
||||||
return opcodeToOperation.get(opcode);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private Operation operation;
|
|
||||||
private String[] args;
|
private String[] args;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new GuacamoleInstruction having the given Operation and
|
* Creates a new GuacamoleInstruction having the given Operation and
|
||||||
* list of arguments values.
|
* list of arguments values.
|
||||||
*
|
*
|
||||||
* @param operation The Operation of the instruction to create.
|
* @param operation The opcode of the instruction to create.
|
||||||
* @param args The list of argument values to provide in the new
|
* @param args The list of argument values to provide in the new
|
||||||
* instruction if any.
|
* instruction if any.
|
||||||
*/
|
*/
|
||||||
public GuacamoleInstruction(Operation operation, String... args) {
|
public GuacamoleInstruction(String opcode, String... args) {
|
||||||
this.operation = operation;
|
this.opcode = opcode;
|
||||||
this.args = args;
|
this.args = args;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Operation associated with this GuacamoleInstruction.
|
* Returns the opcode associated with this GuacamoleInstruction.
|
||||||
* @return The Operation associated with this GuacamoleInstruction.
|
* @return The opcode associated with this GuacamoleInstruction.
|
||||||
*/
|
*/
|
||||||
public Operation getOperation() {
|
public String getOpcode() {
|
||||||
return operation;
|
return opcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -177,9 +92,9 @@ public class GuacamoleInstruction {
|
|||||||
|
|
||||||
StringBuilder buff = new StringBuilder();
|
StringBuilder buff = new StringBuilder();
|
||||||
|
|
||||||
buff.append(operation.getOpcode().length());
|
buff.append(opcode.length());
|
||||||
buff.append('.');
|
buff.append('.');
|
||||||
buff.append(operation.getOpcode());
|
buff.append(opcode);
|
||||||
|
|
||||||
for (int i=0; i<args.length; i++) {
|
for (int i=0; i<args.length; i++) {
|
||||||
buff.append(',');
|
buff.append(',');
|
||||||
|
Reference in New Issue
Block a user