[freenet-cvs] r17877 - in trunk/freenet/src/freenet: config node/fcp

jflesch at freenetproject.org jflesch at freenetproject.org
Wed Feb 13 21:31:44 UTC 2008


Author: jflesch
Date: 2008-02-13 21:31:43 +0000 (Wed, 13 Feb 2008)
New Revision: 17877

Modified:
   trunk/freenet/src/freenet/config/BooleanOption.java
   trunk/freenet/src/freenet/config/Config.java
   trunk/freenet/src/freenet/config/IntOption.java
   trunk/freenet/src/freenet/config/LongOption.java
   trunk/freenet/src/freenet/config/Option.java
   trunk/freenet/src/freenet/config/ShortOption.java
   trunk/freenet/src/freenet/config/StringArrOption.java
   trunk/freenet/src/freenet/config/StringOption.java
   trunk/freenet/src/freenet/config/SubConfig.java
   trunk/freenet/src/freenet/node/fcp/ConfigData.java
   trunk/freenet/src/freenet/node/fcp/GetConfig.java
   trunk/freenet/src/freenet/node/fcp/ModifyConfig.java
Log:
Config / FCP : ConfigData message can now also specify the type of data expected for each field (number, string, boolean, etc)

Modified: trunk/freenet/src/freenet/config/BooleanOption.java
===================================================================
--- trunk/freenet/src/freenet/config/BooleanOption.java	2008-02-13 19:53:35 UTC (rev 17876)
+++ trunk/freenet/src/freenet/config/BooleanOption.java	2008-02-13 21:31:43 UTC (rev 17877)
@@ -14,7 +14,7 @@
 	
 	public BooleanOption(SubConfig conf, String optionName, boolean defaultValue, int sortOrder, 
 			boolean expert, boolean forceWrite, String shortDesc, String longDesc, BooleanCallback cb) {
-		super(conf, optionName, cb, sortOrder, expert, forceWrite, shortDesc, longDesc);
+		super(conf, optionName, cb, sortOrder, expert, forceWrite, shortDesc, longDesc, Option.DATA_TYPE_BOOLEAN);
 		this.defaultValue = defaultValue;
 		this.cb = cb;
 		this.currentValue = defaultValue;

Modified: trunk/freenet/src/freenet/config/Config.java
===================================================================
--- trunk/freenet/src/freenet/config/Config.java	2008-02-13 19:53:35 UTC (rev 17876)
+++ trunk/freenet/src/freenet/config/Config.java	2008-02-13 21:31:43 UTC (rev 17877)
@@ -17,6 +17,7 @@
     public static final int CONFIG_REQUEST_TYPE_FORCE_WRITE_FLAG = 5;
     public static final int CONFIG_REQUEST_TYPE_SHORT_DESCRIPTION = 6;
     public static final int CONFIG_REQUEST_TYPE_LONG_DESCRIPTION = 7;
+    public static final int CONFIG_REQUEST_TYPE_DATA_TYPE = 8;
 
 	protected final LinkedHashMap configsByPrefix;
 	

Modified: trunk/freenet/src/freenet/config/IntOption.java
===================================================================
--- trunk/freenet/src/freenet/config/IntOption.java	2008-02-13 19:53:35 UTC (rev 17876)
+++ trunk/freenet/src/freenet/config/IntOption.java	2008-02-13 21:31:43 UTC (rev 17877)
@@ -18,7 +18,7 @@
 	
 	public IntOption(SubConfig conf, String optionName, int defaultValue, String defaultValueString,
 			int sortOrder, boolean expert, boolean forceWrite, String shortDesc, String longDesc, IntCallback cb) {
-		super(conf, optionName, cb, sortOrder, expert, forceWrite, shortDesc, longDesc);
+		super(conf, optionName, cb, sortOrder, expert, forceWrite, shortDesc, longDesc, Option.DATA_TYPE_NUMBER);
 		this.defaultValue = defaultValue;
 		this.cb = cb;
 		this.currentValue = defaultValue;
@@ -27,7 +27,7 @@
 
 	public IntOption(SubConfig conf, String optionName, String defaultValueString,
 			int sortOrder, boolean expert, boolean forceWrite, String shortDesc, String longDesc, IntCallback cb) {
-		super(conf, optionName, cb, sortOrder, expert, forceWrite, shortDesc, longDesc);
+		super(conf, optionName, cb, sortOrder, expert, forceWrite, shortDesc, longDesc, Option.DATA_TYPE_NUMBER);
 		this.defaultValue = Fields.parseInt(defaultValueString);
 		this.cb = cb;
 		this.currentValue = defaultValue;

Modified: trunk/freenet/src/freenet/config/LongOption.java
===================================================================
--- trunk/freenet/src/freenet/config/LongOption.java	2008-02-13 19:53:35 UTC (rev 17876)
+++ trunk/freenet/src/freenet/config/LongOption.java	2008-02-13 21:31:43 UTC (rev 17877)
@@ -18,7 +18,7 @@
 
 	public LongOption(SubConfig conf, String optionName, long defaultValue, String defaultValueString, 
 			int sortOrder, boolean expert, boolean forceWrite, String shortDesc, String longDesc, LongCallback cb) {
-		super(conf, optionName, cb, sortOrder, expert, forceWrite, shortDesc, longDesc);
+		super(conf, optionName, cb, sortOrder, expert, forceWrite, shortDesc, longDesc, Option.DATA_TYPE_NUMBER);
 		this.defaultValue = defaultValue;
 		this.cb = cb;
 		this.currentValue = defaultValue;
@@ -27,7 +27,7 @@
 	
 	public LongOption(SubConfig conf, String optionName, String defaultValueString, 
 			int sortOrder, boolean expert, boolean forceWrite, String shortDesc, String longDesc, LongCallback cb) {
-		super(conf, optionName, cb, sortOrder, expert, forceWrite, shortDesc, longDesc);
+		super(conf, optionName, cb, sortOrder, expert, forceWrite, shortDesc, longDesc, Option.DATA_TYPE_NUMBER);
 		this.defaultValue = Fields.parseLong(defaultValueString);
 		this.cb = cb;
 		this.currentValue = defaultValue;

Modified: trunk/freenet/src/freenet/config/Option.java
===================================================================
--- trunk/freenet/src/freenet/config/Option.java	2008-02-13 19:53:35 UTC (rev 17876)
+++ trunk/freenet/src/freenet/config/Option.java	2008-02-13 21:31:43 UTC (rev 17877)
@@ -25,7 +25,15 @@
 	/** The configCallback associated to the Option */
 	final ConfigCallback cb;
 	
-	Option(SubConfig config, String name, ConfigCallback cb, int sortOrder, boolean expert, boolean forceWrite, String shortDesc, String longDesc) {
+	public final static int DATA_TYPE_STRING = 0;
+	public final static int DATA_TYPE_NUMBER = 1;
+	public final static int DATA_TYPE_BOOLEAN = 2;
+	public final static int DATA_TYPE_STRING_ARRAY = 3;
+	
+	/** Data type : used to make it possible to make user inputs more friendly in FCP apps */
+	final int dataType;
+	
+	Option(SubConfig config, String name, ConfigCallback cb, int sortOrder, boolean expert, boolean forceWrite, String shortDesc, String longDesc, int dataType) {
 		this.config = config;
 		this.name = name;
 		this.cb = cb;
@@ -34,6 +42,7 @@
 		this.shortDesc = shortDesc;
 		this.longDesc = longDesc;
 		this.forceWrite = forceWrite;
+		this.dataType = dataType;
 	}
 
 	/**
@@ -84,6 +93,20 @@
 	public int getSortOrder(){
 		return sortOrder;
 	}
+	
+	public int getDataType() {
+		return dataType;
+	}
+	
+	public String getDataTypeStr() {
+		switch(dataType) {
+		case(DATA_TYPE_STRING): return "string";
+		case(DATA_TYPE_NUMBER): return "number";
+		case(DATA_TYPE_BOOLEAN): return "boolean";
+		case(DATA_TYPE_STRING_ARRAY): return "stringArray";
+		default: return null;
+		}
+	}
 
 	/**
 	 * Is this option set to the default?

Modified: trunk/freenet/src/freenet/config/ShortOption.java
===================================================================
--- trunk/freenet/src/freenet/config/ShortOption.java	2008-02-13 19:53:35 UTC (rev 17876)
+++ trunk/freenet/src/freenet/config/ShortOption.java	2008-02-13 21:31:43 UTC (rev 17877)
@@ -12,7 +12,7 @@
 	
 	public ShortOption(SubConfig conf, String optionName, short defaultValue, int sortOrder, 
 			boolean expert, boolean forceWrite, String shortDesc, String longDesc, ShortCallback cb) {
-		super(conf, optionName, cb, sortOrder, expert, forceWrite, shortDesc, longDesc);
+		super(conf, optionName, cb, sortOrder, expert, forceWrite, shortDesc, longDesc, Option.DATA_TYPE_NUMBER);
 		this.defaultValue = defaultValue;
 		this.cb = cb;
 		this.currentValue = defaultValue;

Modified: trunk/freenet/src/freenet/config/StringArrOption.java
===================================================================
--- trunk/freenet/src/freenet/config/StringArrOption.java	2008-02-13 19:53:35 UTC (rev 17876)
+++ trunk/freenet/src/freenet/config/StringArrOption.java	2008-02-13 21:31:43 UTC (rev 17877)
@@ -18,7 +18,7 @@
 	
 	public StringArrOption(SubConfig conf, String optionName, String[] defaultValue, int sortOrder, 
 			boolean expert, boolean forceWrite, String shortDesc, String longDesc, StringArrCallback cb) {
-		super(conf, optionName, cb, sortOrder, expert, forceWrite, shortDesc, longDesc);
+		super(conf, optionName, cb, sortOrder, expert, forceWrite, shortDesc, longDesc, Option.DATA_TYPE_STRING_ARRAY);
 		this.defaultValue = (defaultValue==null)?new String[0]:defaultValue;
 		this.cb = cb;
 		this.currentValue = (defaultValue==null)?new String[0]:defaultValue;

Modified: trunk/freenet/src/freenet/config/StringOption.java
===================================================================
--- trunk/freenet/src/freenet/config/StringOption.java	2008-02-13 19:53:35 UTC (rev 17876)
+++ trunk/freenet/src/freenet/config/StringOption.java	2008-02-13 21:31:43 UTC (rev 17877)
@@ -13,7 +13,7 @@
 	
 	public StringOption(SubConfig conf, String optionName, String defaultValue, int sortOrder, 
 			boolean expert, boolean forceWrite, String shortDesc, String longDesc, StringCallback cb) {
-		super(conf, optionName, cb, sortOrder, expert, forceWrite, shortDesc, longDesc);
+		super(conf, optionName, cb, sortOrder, expert, forceWrite, shortDesc, longDesc, Option.DATA_TYPE_STRING);
 		this.defaultValue = defaultValue;
 		this.cb = cb;
 		this.currentValue = defaultValue;

Modified: trunk/freenet/src/freenet/config/SubConfig.java
===================================================================
--- trunk/freenet/src/freenet/config/SubConfig.java	2008-02-13 19:53:35 UTC (rev 17876)
+++ trunk/freenet/src/freenet/config/SubConfig.java	2008-02-13 21:31:43 UTC (rev 17877)
@@ -241,6 +241,9 @@
 				case Config.CONFIG_REQUEST_TYPE_LONG_DESCRIPTION:
 					fs.putSingle(key, L10n.getString(o.getLongDesc()));
 					break;
+				case Config.CONFIG_REQUEST_TYPE_DATA_TYPE:
+					fs.putSingle(key, o.getDataTypeStr());
+					break;
 				default:
 					Logger.error(this, "Unknown config request type value: "+configRequestType);
 					break;

Modified: trunk/freenet/src/freenet/node/fcp/ConfigData.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ConfigData.java	2008-02-13 19:53:35 UTC (rev 17876)
+++ trunk/freenet/src/freenet/node/fcp/ConfigData.java	2008-02-13 21:31:43 UTC (rev 17877)
@@ -18,8 +18,9 @@
 	final boolean withForceWriteFlag;
 	final boolean withShortDescription;
 	final boolean withLongDescription;
+	final boolean withDataTypes;
 	
-	public ConfigData(Node node, boolean withCurrent, boolean withDefaults, boolean withSortOrder, boolean withExpertFlag, boolean withForceWriteFlag, boolean withShortDescription, boolean withLongDescription) {
+	public ConfigData(Node node, boolean withCurrent, boolean withDefaults, boolean withSortOrder, boolean withExpertFlag, boolean withForceWriteFlag, boolean withShortDescription, boolean withLongDescription, boolean withDataTypes) {
 		this.node = node;
 		this.withCurrent = withCurrent;
 		this.withDefaults = withDefaults;
@@ -28,6 +29,7 @@
 		this.withForceWriteFlag = withForceWriteFlag;
 		this.withShortDescription = withShortDescription;
 		this.withLongDescription = withLongDescription;
+		this.withDataTypes = withDataTypes;
 	}
 
 	
@@ -75,6 +77,12 @@
 				fs.put("longDescription", longDescription);
 			}
 		}
+		if(withDataTypes) {
+			SimpleFieldSet type = node.config.exportFieldSet(Config.CONFIG_REQUEST_TYPE_DATA_TYPE, false);
+			if(!type.isEmpty()) {
+				fs.put("dataType", type);
+			}
+		}
 		return fs;
 	}
 

Modified: trunk/freenet/src/freenet/node/fcp/GetConfig.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/GetConfig.java	2008-02-13 19:53:35 UTC (rev 17876)
+++ trunk/freenet/src/freenet/node/fcp/GetConfig.java	2008-02-13 21:31:43 UTC (rev 17877)
@@ -16,6 +16,7 @@
 	final boolean withForceWriteFlag;
 	final boolean withShortDescription;
 	final boolean withLongDescription;
+	final boolean withDataTypes;
 	static final String NAME = "GetConfig";
 	
 	public GetConfig(SimpleFieldSet fs) {
@@ -26,6 +27,7 @@
 		withForceWriteFlag = Fields.stringToBool(fs.get("WithForceWriteFlag"), false);
 		withShortDescription = Fields.stringToBool(fs.get("WithShortDescription"), false);
 		withLongDescription = Fields.stringToBool(fs.get("WithLongDescription"), false);
+		withDataTypes = Fields.stringToBool(fs.get("withDataTypes"), false);
 	}
 	
 	public SimpleFieldSet getFieldSet() {
@@ -41,7 +43,7 @@
 		if(!handler.hasFullAccess()) {
 			throw new MessageInvalidException(ProtocolErrorMessage.ACCESS_DENIED, "GetConfig requires full access", null, false);
 		}
-		handler.outputHandler.queue(new ConfigData(node, withCurrent, withDefaults, withSortOrder, withExpertFlag, withForceWriteFlag, withShortDescription, withLongDescription));
+		handler.outputHandler.queue(new ConfigData(node, withCurrent, withDefaults, withSortOrder, withExpertFlag, withForceWriteFlag, withShortDescription, withLongDescription, withDataTypes));
 	}
 	
 }

Modified: trunk/freenet/src/freenet/node/fcp/ModifyConfig.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ModifyConfig.java	2008-02-13 19:53:35 UTC (rev 17876)
+++ trunk/freenet/src/freenet/node/fcp/ModifyConfig.java	2008-02-13 21:31:43 UTC (rev 17877)
@@ -61,6 +61,6 @@
 			}
 		}
 		node.clientCore.storeConfig();
-		handler.outputHandler.queue(new ConfigData(node, true, false, false, false, false, false, false));
+		handler.outputHandler.queue(new ConfigData(node, true, false, false, false, false, false, false, false));
 	}
 }




More information about the cvs mailing list