aboutsummaryrefslogtreecommitdiffstats
path: root/java/com/tigervnc/rfb/Configuration.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/com/tigervnc/rfb/Configuration.java')
-rw-r--r--java/com/tigervnc/rfb/Configuration.java241
1 files changed, 212 insertions, 29 deletions
diff --git a/java/com/tigervnc/rfb/Configuration.java b/java/com/tigervnc/rfb/Configuration.java
index f397c85a..de8cfc71 100644
--- a/java/com/tigervnc/rfb/Configuration.java
+++ b/java/com/tigervnc/rfb/Configuration.java
@@ -1,5 +1,6 @@
/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
* Copyright 2004-2005 Cendio AB.
+ * Copyright 2012 Brian P. Hinz
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -25,68 +26,250 @@ package com.tigervnc.rfb;
public class Configuration {
+ static LogWriter vlog = new LogWriter("Config");
+
+ public enum ConfigurationObject { ConfGlobal, ConfServer, ConfViewer };
+
+ // -=- The Global/server/viewer Configuration objects
+ private static Configuration global_ = null;
+ private static Configuration server_ = null;
+ private static Configuration viewer_ = null;
+
+ public static Configuration global() {
+ if (global_ == null)
+ global_ = new Configuration("Global");
+ return global_;
+ }
+
+ public static Configuration server() {
+ if (server_ == null)
+ server_ = new Configuration("Server");
+ return server_;
+ }
+
+ public static Configuration viewer() {
+ if (viewer_ == null)
+ viewer_ = new Configuration("Viewer");
+ return viewer_;
+ }
+
+ // Enable server/viewer specific parameters
+ public static void enableServerParams() { global().appendConfiguration(server()); }
+ public static void enableViewerParams() { global().appendConfiguration(viewer()); }
+
+ // Append configuration object to this instance.
+ // NOTE: conf instance can be only one configuration object
+ public void appendConfiguration(Configuration conf) {
+ conf._next = _next; _next = conf;
+ }
+
+ // -=- Configuration implementation
+ public Configuration(String name_, Configuration attachToGroup) {
+ name = name_; head = null; _next = null;
+ if (attachToGroup != null) {
+ _next = attachToGroup._next;
+ attachToGroup._next = this;
+ }
+ }
+
+ public Configuration(String name_) {
+ this(name_, null);
+ }
+
+ // - Return the buffer containing the Configuration's name
+ final public String getName() { return name; }
+
+ // - Assignment operator. For every Parameter in this Configuration's
+ // group, get()s the corresponding source parameter and copies its
+ // content.
+ public Configuration assign(Configuration src) {
+ VoidParameter current = head;
+ while (current != null) {
+ VoidParameter srcParam = ((Configuration)src).get(current.getName());
+ if (srcParam != null) {
+ current.immutable = false;
+ String value = srcParam.getValueStr();
+ vlog.debug("operator=("+current.getName()+", "+value+")");
+ current.setParam(value);
+ }
+ current = current._next;
+ }
+ if (_next != null)
+ _next = src;
+ return this;
+ }
+
// - Set named parameter to value
- public static boolean setParam(String name, String value) {
- VoidParameter param = getParam(name);
- if (param == null) return false;
- return param.setParam(value);
+ public boolean set(String n, String v, boolean immutable) {
+ return set(n, n.length(), v, immutable);
+ }
+
+ public boolean set(String n, String v) {
+ return set(n, n.length(), v, false);
}
// - Set parameter to value (separated by "=")
- public static boolean setParam(String config) {
+ public boolean set(String name, int len,
+ String val, boolean immutable)
+ {
+ VoidParameter current = head;
+ while (current != null) {
+ if (current.getName().length() == len &&
+ current.getName().equalsIgnoreCase(name.substring(0, len)))
+ {
+ boolean b = current.setParam(val);
+ current.setHasBeenSet();
+ if (b && immutable)
+ current.setImmutable();
+ return b;
+ }
+ current = current._next;
+ }
+ return (_next != null) ? _next.set(name, len, val, immutable) : false;
+ }
+
+ // - Set named parameter to value, with name truncated at len
+ boolean set(String config, boolean immutable) {
boolean hyphen = false;
if (config.charAt(0) == '-') {
hyphen = true;
- if (config.charAt(1) == '-')
- config = config.substring(2); // allow gnu-style --<option>
- else
- config = config.substring(1);
+ config = config.substring(1);
+ if (config.charAt(0) == '-') config = config.substring(1); // allow gnu-style --<option>
}
int equal = config.indexOf('=');
- if (equal != -1) {
- return setParam(config.substring(0, equal), config.substring(equal+1));
+ if (equal > -1) {
+ return set(config, equal, config.substring(equal+1), immutable);
} else if (hyphen) {
- VoidParameter param = getParam(config);
- if (param == null) return false;
- return param.setParam();
- }
- return false;
+ VoidParameter current = head;
+ while (current != null) {
+ if (current.getName().equalsIgnoreCase(config)) {
+ boolean b = current.setParam();
+ current.setHasBeenSet();
+ if (b && immutable)
+ current.setImmutable();
+ return b;
+ }
+ current = current._next;
+ }
+ }
+ return (_next != null) ? _next.set(config, immutable) : false;
+ }
+
+ boolean set(String config) {
+ return set(config, false);
+ }
+
+ // - Container for process-wide Global parameters
+ public static boolean setParam(String param, String value, boolean immutable) {
+ return global().set(param, value, immutable);
+ }
+
+ public static boolean setParam(String param, String value) {
+ return setParam(param, value, false);
+ }
+
+ public static boolean setParam(String config, boolean immutable) {
+ return global().set(config, immutable);
}
+ public static boolean setParam(String config) {
+ return setParam(config, false);
+ }
+
+ public static boolean setParam(String name, int len,
+ String val, boolean immutable) {
+ return global().set(name, len, val, immutable);
+ }
+
+
// - Get named parameter
- public static VoidParameter getParam(String name) {
+ public VoidParameter get(String param)
+ {
VoidParameter current = head;
while (current != null) {
- if (name.equalsIgnoreCase(current.getName()))
+ if (current.getName().equalsIgnoreCase(param))
return current;
- current = current.next;
+ current = current._next;
}
- return null;
+ return (_next != null) ? _next.get(param) : null;
}
+
+ public static VoidParameter getParam(String param) { return global().get(param); }
- public static String listParams() {
- StringBuffer s = new StringBuffer();
+ public static void listParams(int width, int nameWidth) {
+ global().list(width, nameWidth);
+ }
+ public static void listParams() {
+ listParams(79, 10);
+ }
+ public void list(int width, int nameWidth) {
VoidParameter current = head;
+
+ System.err.format("%s Parameters:%n", name);
while (current != null) {
String def_str = current.getDefaultStr();
- String desc = current.getDescription();
- s.append(" "+current.getName()+" - "+desc+" (default="+def_str+")\n");
- current = current.next;
+ String desc = current.getDescription().trim();
+ String format = " %-"+nameWidth+"s -";
+ System.err.format(format, current.getName());
+ int column = current.getName().length();
+ if (column < nameWidth) column = nameWidth;
+ column += 4;
+ while (true) {
+ int s = desc.indexOf(' ');
+ int wordLen;
+ if (s > -1) wordLen = s;
+ else wordLen = desc.length();
+
+ if (column + wordLen + 1 > width) {
+ format = "%n%"+(nameWidth+4)+"s";
+ System.err.format(format, "");
+ column = nameWidth+4;
+ }
+ format = " %"+wordLen+"s";
+ System.err.format(format, desc.substring(0, wordLen));
+ column += wordLen + 1;
+
+ if (s == -1) break;
+ desc = desc.substring(wordLen+1);
+ }
+
+ if (def_str != null) {
+ if (column + def_str.length() + 11 > width)
+ System.err.format("%n%"+(nameWidth+4)+"s","");
+ System.err.format(" (default=%s)%n",def_str);
+ def_str = null;
+ } else {
+ System.err.format("%n");
+ }
+ current = current._next;
}
+
+ if (_next != null)
+ _next.list(width, nameWidth);
+ }
- return s.toString();
+ public void list() {
+ list(79, 10);
}
- public static void readAppletParams(java.applet.Applet applet) {
+ public void readAppletParams(java.applet.Applet applet) {
VoidParameter current = head;
while (current != null) {
String str = applet.getParameter(current.getName());
if (str != null)
current.setParam(str);
- current = current.next;
+ current = current._next;
}
}
- public static VoidParameter head;
+ // Name for this Configuration
+ private String name;
+
+ // - Pointer to first Parameter in this group
+ public VoidParameter head;
+
+ // Pointer to next Configuration in this group
+ public Configuration _next;
+
}