qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kp...@apache.org
Subject svn commit: r474866 - in /incubator/qpid/trunk/qpid/gentools: org/apache/qpid/gentools/ templ.cpp/
Date Tue, 14 Nov 2006 16:56:13 GMT
Author: kpvdr
Date: Tue Nov 14 08:56:12 2006
New Revision: 474866

URL: http://svn.apache.org/viewvc?view=rev&rev=474866
Log:
Fixes to the generated C++ code and templates

Modified:
    incubator/qpid/trunk/qpid/gentools/org/apache/qpid/gentools/CppGenerator.java
    incubator/qpid/trunk/qpid/gentools/org/apache/qpid/gentools/Generator.java
    incubator/qpid/trunk/qpid/gentools/org/apache/qpid/gentools/JavaGenerator.java
    incubator/qpid/trunk/qpid/gentools/org/apache/qpid/gentools/Main.java
    incubator/qpid/trunk/qpid/gentools/templ.cpp/AMQP_Constants.h.tmpl
    incubator/qpid/trunk/qpid/gentools/templ.cpp/AMQP_ServerOperations.h.tmpl
    incubator/qpid/trunk/qpid/gentools/templ.cpp/MethodBodyClass.h.tmpl

Modified: incubator/qpid/trunk/qpid/gentools/org/apache/qpid/gentools/CppGenerator.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/gentools/org/apache/qpid/gentools/CppGenerator.java?view=diff&rev=474866&r1=474865&r2=474866
==============================================================================
--- incubator/qpid/trunk/qpid/gentools/org/apache/qpid/gentools/CppGenerator.java (original)
+++ incubator/qpid/trunk/qpid/gentools/org/apache/qpid/gentools/CppGenerator.java Tue Nov
14 08:56:12 2006
@@ -29,7 +29,6 @@
 
 public class CppGenerator extends Generator
 {
-	protected static final String cr = Utils.lineSeparator;
 	protected static final String versionNamespaceStartToken = "${version_namespace_start}";
 	protected static final String versionNamespaceEndToken = "${version_namespace_end}";
 	protected static final int FIELD_NAME = 0;
@@ -40,7 +39,7 @@
 		"enum", "explicit", "extern", "false", "float", "for", "friend", "goto", "if", "inline",
 		"int", "long", "mutable", "namespace", "new", "not", "not_eq", "operator", "or", "or_eq",
 		"private", "protected", "public", "register", "reinterpret_cast", "return", "short",
-		"signed", "sizeof", "static", "static_cast", "struct", "switch", "template", "this",
+		"signed", "sizeof", "static", "static_cast", "string", "struct", "switch", "template",
"this",
 		"throw", "true", "try", "typedef", "typeid", "typename", "union", "unsigned", "using",
 		"virtual", "void", "volatile", "wchar_t", "while", "xor", "xor_eq"};
 	
@@ -78,12 +77,12 @@
 				"u_int32_t",			// type
 				"4", 					// size
                 "buffer.putLong(#)",	// encodeExpression
-				"buffer.getLong(#)"));	// decodeExpression
+				"# = buffer.getLong()"));	// decodeExpression
 		typeMap.put("longlong", new DomainInfo(
 				"u_int64_t",			// type
 				"8", 					// size
                 "buffer.putLongLong(#)", // encodeExpression
-				"buffer.getLongLong(#)")); // decodeExpression
+				"# = buffer.getLongLong()")); // decodeExpression
 		typeMap.put("longstr", new DomainInfo(
 				"string",				// type
 				"4 + #.length()", 		// size
@@ -93,12 +92,12 @@
 				"u_int8_t",				// type
 				"1", 					// size
                 "buffer.putOctet(#)",	// encodeExpression
-				"buffer.getOctet(#)"));	// decodeExpression
+				"# = buffer.getOctet()"));	// decodeExpression
 		typeMap.put("short", new DomainInfo(
 				"u_int16_t",			// type
 				"2",					// size
                 "buffer.putShort(#)",	// encodeExpression
-				"buffer.getShort(#)"));	// decodeExpression
+				"# = buffer.getShort()"));	// decodeExpression
 		typeMap.put("shortstr", new DomainInfo(
 				"string",				// type
 				"1 + #.length()",		// size
@@ -473,11 +472,7 @@
         String token = tline.substring(tokxStart).trim();
         sb.delete(listMarkerStartIndex, lend);
         
-        if (token.compareTo("${ch_static_const_decl}") == 0)
-        {
-            codeSnippet = generateConstantDeclarations(constantSet, 4, 4);
-        }
-        else if (token.compareTo("${ch_get_value_method}") == 0)
+        if (token.compareTo("${ch_get_value_method}") == 0)
         {
             codeSnippet = generateConstantGetMethods(constantSet, 4, 4);
         }
@@ -493,30 +488,11 @@
     
     // Methods for generation of code snippets for AMQP_Constants.h file
     
-    protected String generateConstantDeclarations(AmqpConstantSet constantSet,
-        int indentSize, int tabSize)
-    {
-        String indent = Utils.createSpaces(indentSize);
-        String tab = Utils.createSpaces(tabSize);
-        StringBuffer sb = new StringBuffer();
-        Iterator<AmqpConstant> cItr = constantSet.iterator();
-        while (cItr.hasNext())
-        {
-            AmqpConstant constant = cItr.next();
-            // Do nothing if version is consistent across all versions
-            if (!constant.isVersionConsistent(globalVersionSet))
-            {
-                
-            }
-        }
-        return sb.toString();       
-    }
-    
     protected String generateConstantGetMethods(AmqpConstantSet constantSet,
         int indentSize, int tabSize)
+        throws AmqpTypeMappingException
     {
         String indent = Utils.createSpaces(indentSize);
-        String tab = Utils.createSpaces(tabSize);
         StringBuffer sb = new StringBuffer();
         Iterator<AmqpConstant> cItr = constantSet.iterator();
         while (cItr.hasNext())
@@ -526,29 +502,98 @@
             {
                 // return a constant
                 String value = constant.firstKey();
-                sb.append(indent + "public const char* " + constant.name + "() const { return
\"" +
+                sb.append(indent + "static const char* " + constant.name + "() { return \""
+
                     constant.firstKey() + "\"; }" + cr);
-                sb.append(indent + "public const string& " + constant.name + "AsString()
const { return new string(\"" +
-                    constant.firstKey() + "\"); }" + cr);
+//                sb.append(indent + "std::string " + constant.name + "Str(\"" +
+//                    constant.firstKey() + "\");" + cr);
+//                sb.append(indent + "static const std::string& " + constant.name + "AsString()
{ return " +
+//                    constant.name + "Str; }" + cr);
                 if (Utils.containsOnlyDigits(value))
                 {
-                    sb.append(indent + "public int " + constant.name + "AsInt() const { return
" +
+                    sb.append(indent + "static int " + constant.name + "AsInt() { return
" +
                         constant.firstKey() + "; }" + cr);
                 }
                 if (Utils.containsOnlyDigitsAndDecimal(value))
                 {
-                    sb.append(indent + "public double " + constant.name + "AsDouble() const
{ return (double)" +
+                    sb.append(indent + "static double " + constant.name + "AsDouble() { return
(double)" +
                         constant.firstKey() + "; }" + cr);
                 }
                 sb.append(cr);
            }
             else
             {
-                // return value from version map
+                // Return version-specific constant
+                sb.append(generateVersionDependentGet(constant, "const char*", "", "\"",
"\"", indentSize, tabSize));
+//                sb.append(generateVersionDependentGet(constant, "const string&", "AsString",
"string(\"", "\")", indentSize, tabSize));
+                sb.append(generateVersionDependentGet(constant, "int", "AsInt", "", "", indentSize,
tabSize));
+                sb.append(generateVersionDependentGet(constant, "double", "AsDouble", "(double)",
"", indentSize, tabSize));
+                sb.append(cr);
             }
         }        
         return sb.toString();       
     }
+    
+    protected String generateVersionDependentGet(AmqpConstant constant, String methodReturnType,
+        String methodNameSuffix, String returnPrefix, String returnPostfix, int indentSize,
int tabSize)
+        throws AmqpTypeMappingException
+    {
+        String indent = Utils.createSpaces(indentSize);
+        String tab = Utils.createSpaces(tabSize);
+        StringBuffer sb = new StringBuffer();
+        sb.append(indent + methodReturnType + " " + constant.name + methodNameSuffix +
+            "() const" + cr);
+        sb.append(indent + "{" + cr);
+        boolean first = true;
+        Iterator<String> sItr = constant.keySet().iterator();
+        while (sItr.hasNext())
+        {
+            String value = sItr.next();
+            AmqpVersionSet versionSet = constant.get(value);
+            sb.append(indent + tab + (first ? "" : "else ") + "if (" + generateVersionCheck(versionSet)
+
+                ")" + cr);
+            sb.append(indent + tab + "{" + cr);
+            if (methodReturnType.compareTo("int") == 0 && !Utils.containsOnlyDigits(value))
+            {
+                sb.append(generateConstantDeclarationException(constant.name, methodReturnType,
+                    indentSize + (2*tabSize), tabSize));
+            }
+            else if (methodReturnType.compareTo("double") == 0 && !Utils.containsOnlyDigitsAndDecimal(value))
+            {
+                sb.append(generateConstantDeclarationException(constant.name, methodReturnType,
+                    indentSize + (2*tabSize), tabSize));                            
+            }
+            else
+            {
+                sb.append(indent + tab + tab + "return " + returnPrefix + value + returnPostfix
+ ";" + cr);
+            }
+            sb.append(indent + tab + "}" + cr);
+            first = false;
+        }
+        sb.append(indent + tab + "else" + cr);
+        sb.append(indent + tab + "{" + cr);
+        sb.append(indent + tab + tab + "std::stringstream ss;" + cr);
+        sb.append(indent + tab + tab + "ss << \"Constant \\\"" + constant.name +
+            "\\\" is undefined for AMQP version \" <<" + cr);
+        sb.append(indent + tab + tab + tab + "version.toString() << \".\";" + cr);
+        sb.append(indent + tab + tab + "throw ProtocolVersionException(ss.str());" + cr);
+        sb.append(indent + tab + "}" + cr);
+        sb.append(indent + "}" + cr); 
+        return sb.toString();       
+    }
+        
+    protected String generateConstantDeclarationException(String name, String methodReturnType,
+        int indentSize, int tabSize)
+    {
+        String indent = Utils.createSpaces(indentSize);
+        String tab = Utils.createSpaces(tabSize);
+        StringBuffer sb = new StringBuffer();
+        sb.append(indent + "std::stringstream ss;" + cr);
+        sb.append(indent + "ss << \"Constant \\\"" + name + "\\\" cannot be converted
to type " +
+            methodReturnType + " for AMQP version \" <<" + cr);        
+        sb.append(indent + tab + "version.toString() << \".\";" + cr);        
+        sb.append(indent + "throw ProtocolVersionException(ss.str());" + cr);        
+       return sb.toString();       
+    }
 	
 	// Methods used for generation of code snippets for Server/ClientOperations class generation
 	
@@ -628,6 +673,7 @@
 	{
 		String indent = Utils.createSpaces(indentSize);
 		StringBuffer sb = new StringBuffer();
+        String outerClassName = "AMQP_" + (serverFlag ? "Server" : "Client") + (abstractMethodFlag
? "Operations" : "Proxy");
 		boolean first = true;
 		Iterator<String> mItr = thisClass.methodMap.keySet().iterator();
 		while (mItr.hasNext())
@@ -637,7 +683,7 @@
 			boolean serverChassisFlag = method.serverMethodFlagMap.isSet();
 			if ((serverFlag && serverChassisFlag) || (!serverFlag && clientChassisFlag))
 			{
-				String methodName = parseForReservedWords(method.name, thisClass.name);				
+				String methodName = parseForReservedWords(method.name, outerClassName + "." + thisClass.name);
			
 				AmqpOverloadedParameterMap overloadededParameterMap =
 					method.getOverloadedParameterLists(thisClass.versionSet, this);
 				Iterator<AmqpOrdinalFieldMap> ofmItr = overloadededParameterMap.keySet().iterator();
@@ -670,11 +716,12 @@
 	{
 		String indent = Utils.createSpaces(indentSize);
 		StringBuffer sb = new StringBuffer();
+        String outerClassName = "AMQP_" + (serverFlag ? "Server" : "Client") + "Proxy";
 		Iterator<String> cItr = model.classMap.keySet().iterator();
 		while (cItr.hasNext())
 		{
 			AmqpClass thisClass = model.classMap.get(cItr.next());
-			String instanceName = parseForReservedWords(Utils.firstLower(thisClass.name), null);
+			String instanceName = parseForReservedWords(Utils.firstLower(thisClass.name), outerClassName);
 			String className = parseForReservedWords(thisClass.name, null);
 			sb.append(indent + instanceName + " " + className + ";");
 			if (thisClass.versionSet.size() != globalVersionSet.size())
@@ -690,11 +737,12 @@
 	{
 		String indent = Utils.createSpaces(indentSize);
 		StringBuffer sb = new StringBuffer();
+        String outerClassName = "AMQP_" + (serverFlag ? "Server" : "Client") + "Proxy";
 		Iterator<String> cItr = model.classMap.keySet().iterator();
 		while (cItr.hasNext())
 		{
 			AmqpClass thisClass = model.classMap.get(cItr.next());
-			String className = parseForReservedWords(thisClass.name, null);
+			String className = parseForReservedWords(thisClass.name, outerClassName);
 			sb.append(indent + className + "& get" + className + "();");
 			if (thisClass.versionSet.size() != globalVersionSet.size())
 				sb.append(" // AMQP Version(s) " + thisClass.versionSet + cr);
@@ -756,13 +804,14 @@
 	{
 		String indent = Utils.createSpaces(indentSize);
 		StringBuffer sb = new StringBuffer(indent + "out(out)," + cr);
+        String outerClassName = "AMQP_" + (serverFlag ? "Server" : "Client") + "Proxy";
 		sb.append(indent + "major(major)," + cr);
 		sb.append(indent + "minor(minor)");
 		Iterator<String> cItr = model.classMap.keySet().iterator();
 		while (cItr.hasNext())
 		{
 			AmqpClass thisClass = model.classMap.get(cItr.next());
-			String instanceName = parseForReservedWords(Utils.firstLower(thisClass.name), null);
+			String instanceName = parseForReservedWords(Utils.firstLower(thisClass.name), outerClassName);
 			sb.append("," + cr);
 			sb.append(indent + instanceName + "(out)");
 			if (!cItr.hasNext())
@@ -784,7 +833,7 @@
 		{
 			AmqpClass thisClass = model.classMap.get(cItr.next());
 			String className = thisClass.name;
-			String instanceName = parseForReservedWords(Utils.firstLower(thisClass.name), null);
+			String instanceName = parseForReservedWords(Utils.firstLower(thisClass.name), outerClassName);
 			sb.append(indent + outerClassName + "::" + className + "& " +
 				outerClassName + "::get" + className + "()" + cr);
 			sb.append(indent + "{" + cr);
@@ -840,7 +889,7 @@
 			boolean serverChassisFlag = method.serverMethodFlagMap.isSet();
 			if ((serverFlag && serverChassisFlag) || (!serverFlag && clientChassisFlag))
 			{
-				String methodName = parseForReservedWords(method.name, thisClass.name);
+				String methodName = parseForReservedWords(method.name, outerclassName + "." + thisClass.name);
 				AmqpOverloadedParameterMap overloadededParameterMap =
 					method.getOverloadedParameterLists(thisClass.versionSet, this);
 				Iterator<AmqpOrdinalFieldMap> ofmItr = overloadededParameterMap.keySet().iterator();
@@ -944,31 +993,42 @@
 	{
 		String indent = Utils.createSpaces(indentSize);
 		StringBuffer sb = new StringBuffer();
-		Iterator<String> fItr = fieldMap.keySet().iterator();
-		while(fItr.hasNext())
-		{
-			AmqpField fieldDetails = fieldMap.get(fItr.next());
-			if (version == null) // Version consistent - there *should* be only one domain
-			{
-				String domainName =  fieldDetails.domainMap.firstKey();
-				String codeType = getGeneratedType(domainName, globalVersionSet.first());
-				sb.append(indent + codeType + " " + fieldDetails.name + ";" + cr);
-			}
-			else
-			{
-				Iterator<String> dItr = fieldDetails.domainMap.keySet().iterator();
-				while (dItr.hasNext())
-				{
-					String domainName = dItr.next();
-					AmqpVersionSet versionSet = fieldDetails.domainMap.get(domainName);
-					if (versionSet.contains(version))
-					{
-						String codeType = getGeneratedType(domainName, version);
-						sb.append(indent + codeType + " " + fieldDetails.name + ";" + cr);
-					}
-				}
-			}
-		}
+        
+        if (version == null)
+            version = globalVersionSet.first();
+        AmqpOrdinalFieldMap ordinalFieldMap = fieldMap.getMapForVersion(version, true, this);
+        Iterator<Integer> oItr = ordinalFieldMap.keySet().iterator();
+        while (oItr.hasNext())
+        {
+            String[] fieldDomainPair = ordinalFieldMap.get(oItr.next());
+            sb.append(indent + fieldDomainPair[FIELD_DOMAIN] + " " + fieldDomainPair[FIELD_NAME]
+ ";" + cr);
+        }
+        
+//		Iterator<String> fItr = fieldMap.keySet().iterator();
+//		while(fItr.hasNext())
+//		{
+//			AmqpField fieldDetails = fieldMap.get(fItr.next());
+//			if (version == null) // Version consistent - there *should* be only one domain
+//			{
+//				String domainName =  fieldDetails.domainMap.firstKey();
+//				String codeType = getGeneratedType(domainName, globalVersionSet.first());
+//				sb.append(indent + codeType + " " + fieldDetails.name + ";" + cr);
+//			}
+//			else
+//			{
+//				Iterator<String> dItr = fieldDetails.domainMap.keySet().iterator();
+//				while (dItr.hasNext())
+//				{
+//					String domainName = dItr.next();
+//					AmqpVersionSet versionSet = fieldDetails.domainMap.get(domainName);
+//					if (versionSet.contains(version))
+//					{
+//						String codeType = getGeneratedType(domainName, version);
+//						sb.append(indent + codeType + " " + fieldDetails.name + ";" + cr);
+//					}
+//				}
+//			}
+//		}
 		return sb.toString();
 	}
 	
@@ -1139,8 +1199,8 @@
 		int numBytes = ((bitFieldList.size() - 1) / 8) + 1;
 		String indent = Utils.createSpaces(indentSize);
 		String bitArrayName = "flags_" + ordinal;
-		StringBuffer sb = new StringBuffer(indent + "u_int8_t[" + numBytes + "] " +
-			bitArrayName + " = {0};" +
+		StringBuffer sb = new StringBuffer(indent + "u_int8_t " + bitArrayName +
+            "[" + numBytes + "] = {0};" + 
 			(numBytes != 1 ? " /* All array elements will be initialized to 0 */" : "") +
 			cr);
 		for (int i=0; i<bitFieldList.size(); i++)
@@ -1207,11 +1267,11 @@
 		int numBytes = ((bitFieldList.size() - 1) / 8) + 1;
 		String indent = Utils.createSpaces(indentSize);
 		String bitArrayName = "flags_" + ordinal;
-		StringBuffer sb = new StringBuffer(indent + "u_int8_t[" + numBytes + "] " +
-			bitArrayName + ";" + cr);	
+		StringBuffer sb = new StringBuffer(indent + "u_int8_t " + bitArrayName +
+            "[" + numBytes + "];" + cr);	
 		for (int i=0; i<numBytes; i++)
 		{
-			sb.append(indent + "buffer.getOctet(" + bitArrayName + "[" + i + "]);" + cr);
+			sb.append(indent + bitArrayName + "[" + i + "] = buffer.getOctet();" + cr);
 		}
 		for (int i=0; i<bitFieldList.size(); i++)
 		{
@@ -1233,10 +1293,9 @@
 		StringBuffer sb = new StringBuffer();
 		AmqpOrdinalFieldMap ordinalFieldMap = fieldMap.getMapForVersion(version, true, this);
 		Iterator<Integer> oItr = ordinalFieldMap.keySet().iterator();
-		int ordinal = 0;
 		while (oItr.hasNext())
 		{
-			ordinal = oItr.next();
+			int ordinal = oItr.next();
 			String[] fieldDomainPair = ordinalFieldMap.get(ordinal);
 			sb.append(indent + (defineFlag ? fieldDomainPair[FIELD_DOMAIN] + " " : "") +
 				fieldDomainPair[FIELD_NAME] + (initializerFlag ? "(" + fieldDomainPair[FIELD_NAME] +
")" : "") +
@@ -1296,24 +1355,14 @@
 		return sb.toString();
 	}
 	
-	private String parseForReservedWords(String name, String className)
+	private String parseForReservedWords(String name, String context)
 	{
 		for (int i=0; i<cppReservedWords.length; i++)
 			if (name.compareTo(cppReservedWords[i]) == 0)
 			{
-				if (className == null)
-				{
-					System.out.println("WARNING: Found name \"" + name +
-						"\", which is a C/C++ reserved word. " +
-						"Changing generated name to \"" + name + "_\".");
-				}
-				else
-				{
-					System.out.println("WARNING: Found method \"" + name +
-						"\" in class \"" + className +
-						"\", which is a C/C++ reserved word. " +
-						"Changing generated method name to \"" + name + "_\".");
-				}
+				System.out.println("WARNING: " + (context == null ? "" : context + ": ") +
+                    "Found XML method \"" + name + "\", which is a C++ reserved word. " +
+                    "Changing generated name to \"" + name + "_\".");
 				return name + "_";
 			}
 		return name;

Modified: incubator/qpid/trunk/qpid/gentools/org/apache/qpid/gentools/Generator.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/gentools/org/apache/qpid/gentools/Generator.java?view=diff&rev=474866&r1=474865&r2=474866
==============================================================================
--- incubator/qpid/trunk/qpid/gentools/org/apache/qpid/gentools/Generator.java (original)
+++ incubator/qpid/trunk/qpid/gentools/org/apache/qpid/gentools/Generator.java Tue Nov 14
08:56:12 2006
@@ -32,6 +32,9 @@
 
 public abstract class Generator implements LanguageConverter
 {
+    protected static String cr = Utils.lineSeparator;
+    protected static enum EnumConstOutputTypes { OUTPUT_STRING, OUTPUT_INTEGER, OUTPUT_DOUBLE;
};
+    
 	// This string is reproduced in every generated file as a comment
 	// TODO: Tie the version info into the build system.
 	protected static final String generatorInfo = "Qpid Gentools v.0.1";

Modified: incubator/qpid/trunk/qpid/gentools/org/apache/qpid/gentools/JavaGenerator.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/gentools/org/apache/qpid/gentools/JavaGenerator.java?view=diff&rev=474866&r1=474865&r2=474866
==============================================================================
--- incubator/qpid/trunk/qpid/gentools/org/apache/qpid/gentools/JavaGenerator.java (original)
+++ incubator/qpid/trunk/qpid/gentools/org/apache/qpid/gentools/JavaGenerator.java Tue Nov
14 08:56:12 2006
@@ -30,9 +30,6 @@
 
 public class JavaGenerator extends Generator
 {
-	private static String cr = Utils.lineSeparator;
-    private enum OutputTypes { OUTPUT_STRING, OUTPUT_INTEGER, OUTPUT_DOUBLE; };
-	
 	private class DomainInfo
 	{
 		public String type;
@@ -818,36 +815,26 @@
             }
             else
             {
-                // return value from version map
-                sb.append(generateVersionDependentGet(constant, OutputTypes.OUTPUT_STRING,
indentSize, tabSize));
-                sb.append(generateVersionDependentGet(constant, OutputTypes.OUTPUT_INTEGER,
indentSize, tabSize));
-                sb.append(generateVersionDependentGet(constant, OutputTypes.OUTPUT_DOUBLE,
indentSize, tabSize));
+                // Return version-specific constant
+                sb.append(generateVersionDependentGet(constant, "String", "", "\"", "\"",
indentSize, tabSize));
+                sb.append(generateVersionDependentGet(constant, "int", "AsInt", "", "", indentSize,
tabSize));
+                sb.append(generateVersionDependentGet(constant, "double", "AsDouble", "(double)",
"", indentSize, tabSize));
                 sb.append(cr);
            }
         }        
         return sb.toString();       
     }
     
-    protected String generateVersionDependentGet(AmqpConstant constant, OutputTypes outType,
int indentSize, int tabSize)
+    protected String generateVersionDependentGet(AmqpConstant constant,
+        String methodReturnType, String methodNameSuffix, String returnPrefix, String returnPostfix,
+        int indentSize, int tabSize)
         throws AmqpTypeMappingException
     {
         String indent = Utils.createSpaces(indentSize);
         String tab = Utils.createSpaces(tabSize);
         StringBuffer sb = new StringBuffer();
-        String methodNameSuffix = "";
-        String methodReturnType = "String";
-        if (outType == OutputTypes.OUTPUT_INTEGER)
-        {
-            methodNameSuffix = "AsInt";
-            methodReturnType = "int";
-        }
-        else if (outType == OutputTypes.OUTPUT_DOUBLE)
-        {
-            methodNameSuffix = "AsDouble";
-            methodReturnType = "double";
-        }
         sb.append(indent + "public static " + methodReturnType + " " + constant.name +
-             methodNameSuffix + "(byte major, byte minor) throws AMQProtocolVersionException"
+ cr);
+            methodNameSuffix + "(byte major, byte minor) throws AMQProtocolVersionException"
+ cr);
         sb.append(indent + "{" + cr);
         boolean first = true;
         Iterator<String> sItr = constant.keySet().iterator();
@@ -855,36 +842,22 @@
         {
             String value = sItr.next();
             AmqpVersionSet versionSet = constant.get(value);
-            sb.append(indent + tab + (first ? "" : "else ") + "if (" +
-                generateVersionCheck(versionSet) + ")" + cr);
+            sb.append(indent + tab + (first ? "" : "else ") + "if (" + generateVersionCheck(versionSet)
+
+                ")" + cr);
             sb.append(indent + tab + "{" + cr);
-            if (outType == OutputTypes.OUTPUT_STRING)
+            if (methodReturnType.compareTo("int") == 0 && !Utils.containsOnlyDigits(value))
             {
-                sb.append(indent + tab + tab + "return \"" + value + "\";" + cr);
+                sb.append(generateConstantDeclarationException(constant.name, methodReturnType,
+                    indentSize + (2*tabSize), tabSize));
             }
-            else if (outType == OutputTypes.OUTPUT_INTEGER)
+            else if (methodReturnType.compareTo("double") == 0 && !Utils.containsOnlyDigitsAndDecimal(value))
             {
-                if (Utils.containsOnlyDigits(value))
-                {
-                    sb.append(indent + tab + tab + "return " + value + ";" + cr);
-                }
-                else
-                {
-                    sb.append(generateConstantDeclarationException(constant.name, outType,
-                        indentSize + (2*tabSize), tabSize));
-                }
+                sb.append(generateConstantDeclarationException(constant.name, methodReturnType,
+                    indentSize + (2*tabSize), tabSize));                            
             }
-            else if (outType == OutputTypes.OUTPUT_DOUBLE)
+            else
             {
-                if (Utils.containsOnlyDigitsAndDecimal(value))
-                {
-                    sb.append(indent + tab + tab + "return (double)" + value + ";" + cr);
-                }
-                else
-                {
-                    sb.append(generateConstantDeclarationException(constant.name, outType,
-                        indentSize + (2*tabSize), tabSize));
-                }
+                sb.append(indent + tab + tab + "return " + returnPrefix + value + returnPostfix
+ ";" + cr);
             }
             sb.append(indent + tab + "}" + cr);
             first = false;
@@ -894,37 +867,22 @@
         sb.append(indent + tab + tab + "throw new AMQProtocolVersionException(\"Constant
\\\"" +
             constant.name + "\\\" \" +" + cr);
         sb.append(indent + tab + tab + tab +
-            "\"undefined for AMQP version \" + major + \"-\" + minor + \".\");" + cr);
+            "\"is undefined for AMQP version \" + major + \"-\" + minor + \".\");" + cr);
         sb.append(indent + tab + "}" + cr);
-        sb.append(indent + "}" + cr);        
+        sb.append(indent + "}" + cr); 
         return sb.toString();       
     }
-    
-    protected String generateConstantDeclarationException(String name, OutputTypes outType,
+        
+    protected String generateConstantDeclarationException(String name, String methodReturnType,
         int indentSize, int tabSize)
     {
         String indent = Utils.createSpaces(indentSize);
         String tab = Utils.createSpaces(tabSize);
         StringBuffer sb = new StringBuffer();
-        String typeStr;
-        switch (outType)
-        {
-            case OUTPUT_STRING:
-                typeStr = "a String";
-                break;
-            case OUTPUT_INTEGER:
-                typeStr = "an integer";
-               break;
-            case OUTPUT_DOUBLE:
-                typeStr = "a double";
-                break;
-            default:
-                typeStr = "*ERROR*";
-        }
         sb.append(indent + "throw new AMQProtocolVersionException(\"Constant \\\"" +
-                        name + "\\\" \" +" + cr);
-        sb.append(indent + tab + "\"is not " + typeStr +
-            " type for AMQP version \" + major + \"-\" + minor + \".\");" + cr);        
+            name + "\\\" \" +" + cr);
+        sb.append(indent + tab + "\"cannot be converted to type " + methodReturnType +
+            " for AMQP version \" + major + \"-\" + minor + \".\");" + cr);        
         return sb.toString();       
     }
     

Modified: incubator/qpid/trunk/qpid/gentools/org/apache/qpid/gentools/Main.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/gentools/org/apache/qpid/gentools/Main.java?view=diff&rev=474866&r1=474865&r2=474866
==============================================================================
--- incubator/qpid/trunk/qpid/gentools/org/apache/qpid/gentools/Main.java (original)
+++ incubator/qpid/trunk/qpid/gentools/org/apache/qpid/gentools/Main.java Tue Nov 14 08:56:12
2006
@@ -162,7 +162,7 @@
 //		System.out.println();
 //		System.out.println("*** Debug output ***");
 //		System.out.println();
-		constants.print(System.out, 0, 2);
+//		constants.print(System.out, 0, 2);
 //      System.out.println();
 //      versionSet.print(System.out, 0, 2);
 //		System.out.println();

Modified: incubator/qpid/trunk/qpid/gentools/templ.cpp/AMQP_Constants.h.tmpl
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/gentools/templ.cpp/AMQP_Constants.h.tmpl?view=diff&rev=474866&r1=474865&r2=474866
==============================================================================
--- incubator/qpid/trunk/qpid/gentools/templ.cpp/AMQP_Constants.h.tmpl (original)
+++ incubator/qpid/trunk/qpid/gentools/templ.cpp/AMQP_Constants.h.tmpl Tue Nov 14 08:56:12
2006
@@ -27,10 +27,6 @@
  */
 	// NOTE: This file is intended to be included within the class structure of both
 	// the client and server operations classes.
-
-	// Constant declarations for constants that change by version
-	
-%{TLIST} ${ch_static_const_decl}
  
  	// Constant getValue methods
  	

Modified: incubator/qpid/trunk/qpid/gentools/templ.cpp/AMQP_ServerOperations.h.tmpl
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/gentools/templ.cpp/AMQP_ServerOperations.h.tmpl?view=diff&rev=474866&r1=474865&r2=474866
==============================================================================
--- incubator/qpid/trunk/qpid/gentools/templ.cpp/AMQP_ServerOperations.h.tmpl (original)
+++ incubator/qpid/trunk/qpid/gentools/templ.cpp/AMQP_ServerOperations.h.tmpl Tue Nov 14 08:56:12
2006
@@ -30,6 +30,9 @@
 #define _AMQP_ServerOperations_
 
 #include "qpid/framing/FieldTable.h"
+#include "qpid/framing/ProtocolVersion.h"
+#include "qpid/framing/ProtocolVersionException.h"
+#include <sstream>
 
 namespace qpid {
 namespace framing {
@@ -47,11 +50,11 @@
     inline u_int8_t getMajor() const { return version.getMajor(); }
     inline u_int8_t getMinor() const { return version.getMinor(); }
     inline const ProtocolVersion& getVersion() const { return version; }
-    inline isVersion(u_int8_t _major, u_int8_t _minor) const
+    inline bool isVersion(u_int8_t _major, u_int8_t _minor) const
     {
         return version.equals(_major, _minor);
     }
-    inline isVersion(ProtocolVersion& _version) const
+    inline bool isVersion(ProtocolVersion& _version) const
     {
         return version.equals(_version);
     }
@@ -59,13 +62,13 @@
 	// Include framing constant declarations
 	#include "AMQP_Constants.h"
 
-    // Method handler get methods
-
-%{CLIST} ${soh_method_handler_get_method}
-
     // Inner classes
 
 %{CLIST} ${soh_inner_class}
+
+    // Method handler get methods
+
+%{CLIST} ${soh_method_handler_get_method}
 
 }; /* class AMQP_ServerOperations */
 

Modified: incubator/qpid/trunk/qpid/gentools/templ.cpp/MethodBodyClass.h.tmpl
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/gentools/templ.cpp/MethodBodyClass.h.tmpl?view=diff&rev=474866&r1=474865&r2=474866
==============================================================================
--- incubator/qpid/trunk/qpid/gentools/templ.cpp/MethodBodyClass.h.tmpl (original)
+++ incubator/qpid/trunk/qpid/gentools/templ.cpp/MethodBodyClass.h.tmpl Tue Nov 14 08:56:12
2006
@@ -47,16 +47,13 @@
  
 class ${CLASS}${METHOD}Body : virtual public AMQMethodBody
 {
-	const int classId = ${CLASS_ID_INIT};
-	const int methodId = ${METHOD_ID_INIT};
-	
 	// Method field declarations
 
 %{FLIST} ${mb_field_declaration}
      
 
 public:
-    typedef std::tr1::shared_ptr<${CLASS}${METHOD}Body> shared_ptr;
+    typedef boost::shared_ptr<${CLASS}${METHOD}Body> shared_ptr;
 
 	// Constructors and destructors
 	
@@ -68,8 +65,6 @@
 
     inline ${CLASS}${METHOD}Body() {}
 
-	${CLASS}${METHOD}Body() {}
-	
     virtual ~${CLASS}${METHOD}Body() {}
     
     // Attribute get methods
@@ -86,12 +81,12 @@
 
     inline u_int16_t amqpClassId() const
     {
-    	return classId;
+    	return ${CLASS_ID_INIT};
     }
     
     inline u_int16_t amqpMethodId() const
     {
-    	return methodId;
+    	return ${METHOD_ID_INIT};
     }
 
     inline u_int32_t bodySize() const
@@ -113,7 +108,7 @@
 
     inline void invoke(AMQP_ServerOperations& target, u_int16_t channel)
     {
-		target.getBasicHandler()->consume(
+		target.getBasicHandler()->publish(channel,
 %{FLIST} ${mb_field_list}
 		);
     }



Mime
View raw message