summaryrefslogtreecommitdiff
path: root/qpid/dotnet/client-010/gentool
diff options
context:
space:
mode:
authorRajith Muditha Attapattu <rajith@apache.org>2011-05-27 15:44:23 +0000
committerRajith Muditha Attapattu <rajith@apache.org>2011-05-27 15:44:23 +0000
commit66765100f4257159622cefe57bed50125a5ad017 (patch)
treea88ee23bb194eb91f0ebb2d9b23ff423e3ea8e37 /qpid/dotnet/client-010/gentool
parent1aeaa7b16e5ce54f10c901d75c4d40f9f88b9db6 (diff)
parent88b98b2f4152ef59a671fad55a0d08338b6b78ca (diff)
downloadqpid-python-rajith_jms_client.tar.gz
Creating a branch for experimenting with some ideas for JMS client.rajith_jms_client
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/rajith_jms_client@1128369 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/dotnet/client-010/gentool')
-rw-r--r--qpid/dotnet/client-010/gentool/Composite.tpl291
-rw-r--r--qpid/dotnet/client-010/gentool/Constant.tpl37
-rw-r--r--qpid/dotnet/client-010/gentool/Enum.tpl59
-rw-r--r--qpid/dotnet/client-010/gentool/IInvoker.tpl57
-rw-r--r--qpid/dotnet/client-010/gentool/Invoker.tpl67
-rw-r--r--qpid/dotnet/client-010/gentool/MethodDelegate.tpl35
-rw-r--r--qpid/dotnet/client-010/gentool/Option.tpl42
-rw-r--r--qpid/dotnet/client-010/gentool/StructFactory.tpl64
-rw-r--r--qpid/dotnet/client-010/gentool/Type.tpl103
-rw-r--r--qpid/dotnet/client-010/gentool/build.xml52
-rw-r--r--qpid/dotnet/client-010/gentool/codegen86
-rw-r--r--qpid/dotnet/client-010/gentool/dotnetgenutil.py271
12 files changed, 1164 insertions, 0 deletions
diff --git a/qpid/dotnet/client-010/gentool/Composite.tpl b/qpid/dotnet/client-010/gentool/Composite.tpl
new file mode 100644
index 0000000000..c5a1099ef3
--- /dev/null
+++ b/qpid/dotnet/client-010/gentool/Composite.tpl
@@ -0,0 +1,291 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+using System;
+using org.apache.qpid.transport.codec;
+using System.Collections.Generic;
+using org.apache.qpid.transport.util;
+using org.apache.qpid.transport.network;
+using System.IO;
+
+namespace org.apache.qpid.transport
+{
+
+${
+from genutil import *
+
+cls = klass(type)["@name"]
+
+segments = type["segments"]
+
+if type.name in ("control", "command"):
+ override = "override"
+ base = "Method"
+ size = 0
+ pack = 2
+ if segments:
+ payload = "true"
+ else:
+ payload = "false"
+ if type.name == "control" and cls == "connection":
+ track = "Frame.L1"
+ elif cls == "session" and type["@name"] in ("attach", "attached", "detach", "detached"):
+ track = "Frame.L2"
+ elif type.name == "command":
+ track = "Frame.L4"
+ else:
+ track = "Frame.L3"
+else:
+ override = ""
+ base = "Struct"
+ size = type["@size"]
+ pack = num(type["@pack"])
+ payload = "false"
+ track = "4"
+
+PACK_TYPES = {
+ 1: "byte",
+ 2: "int",
+ 4: "int"
+}
+
+typecode = code(type)
+}
+
+public sealed class $name : $base {
+
+ public const int TYPE = $typecode;
+
+ public override int GetStructType() {
+ return TYPE;
+ }
+
+ public override int GetSizeWidth() {
+ return $size;
+ }
+
+ public override int GetPackWidth() {
+ return $pack;
+ }
+
+ public $override bool HasPayload() {
+ return $payload;
+ }
+
+ public $override byte EncodedTrack
+ {
+ get{ return $track; }
+ set { throw new NotImplementedException(); }
+ }
+
+${
+from dotnetgenutil import *
+if pack > 0:
+ out(" private $(PACK_TYPES[pack]) packing_flags = 0;\n");
+
+fields = get_fields(type)
+params = get_dotnetparameters(type, fields)
+options = get_options(fields)
+
+for f in fields:
+ if not f.empty:
+ out(" private $(f.type) _$(f.name);\n")
+
+if segments:
+ out(" private Header _header;\n")
+ out(" private MemoryStream _body = new MemoryStream();\n")
+}
+
+${
+if fields:
+ out(" public $name() {}\n")
+}
+
+ public $name($(", ".join(params))) {
+${
+for f in fields:
+ if f.option: continue
+ out(" $(f.set)($(f.name));\n")
+
+if segments:
+ out(" Header = header;\n")
+ out(" Body = body;\n")
+
+if options or base == "Method":
+ out("""
+ for (int i=0; i < options.Length; i++) {
+ switch (options[i]) {
+""")
+
+ for f in options:
+ out(" case Option.$(f.option): packing_flags |= $(f.flag_mask(pack)); break;\n")
+
+ if base == "Method":
+ out(""" case Option.SYNC: Sync = true; break;
+ case Option.BATCH: Batch = true; break;
+""")
+ out(""" case Option.NONE: break;
+ default: throw new Exception("invalid option: " + options[i]);
+ }
+ }
+""")
+}
+ }
+
+ public $override void Dispatch<C>(C context, MethodDelegate<C> mdelegate) {
+ mdelegate.$(name)(context, this);
+ }
+
+${
+for f in fields:
+ if pack > 0:
+ out("""
+ public bool $(f.has)() {
+ return (packing_flags & $(f.flag_mask(pack))) != 0;
+ }
+
+ public $name $(f.clear)() {
+ packing_flags = (byte) (packing_flags & ~$(f.flag_mask(pack)));
+${
+if (not f.empty and not (f.default == "null")):
+ out(" _$(f.name) = $(f.default);")
+}
+ Dirty = true;
+ return this;
+ }
+""")
+
+ out("""
+ public $(f.type) $(f.get)() {
+${
+if f.empty:
+ out(" return $(f.has)();")
+else:
+ out(" return _$(f.name);")
+}
+ }
+
+ public $name $(f.set)($(f.type) value) {
+${
+if not f.empty:
+ out(" _$(f.name) = value;")
+}
+${
+if pack > 0:
+ out(" packing_flags |= $(f.flag_mask(pack));")
+}
+ Dirty = true;
+ return this;
+ }
+
+""")
+}
+
+${
+if segments:
+ out(""" public override Header Header {
+ get { return _header;}
+ set { _header = value;}
+ }
+
+ public $name SetHeader(Header header) {
+ Header = header;
+ return this;
+ }
+
+ public override MemoryStream Body
+ {
+ get{ return _body;}
+ set{ _body = value;}
+ }
+
+ public $name SetBody(MemoryStream body)
+ {
+ Body = body;
+ return this;
+ }
+""")
+}
+
+ public override void Write(IEncoder enc)
+ {
+${
+if pack > 0:
+ out(" enc.WriteUint%s(packing_flags);\n" % (pack*8));
+
+for f in fields:
+ if f.empty:
+ continue
+ if pack > 0:
+ out(" if ((packing_flags & $(f.flag_mask(pack))) != 0)\n ")
+ pre = ""
+ post = ""
+ if f.type_node.name == "struct":
+ pre = "%s.TYPE, " % cname(f.type_node)
+ elif f.type_node.name == "domain":
+ post = ""
+ pre = "(short)"
+ out(" enc.Write$(f.coder)($(pre)_$(f.name)$(post));\n")
+}
+ }
+
+ public override void Read(IDecoder dec)
+ {
+${
+if pack > 0:
+ out(" packing_flags = ($(PACK_TYPES[pack])) dec.ReadUint%s();\n" % (pack*8));
+
+for f in fields:
+ if f.empty:
+ continue
+ if pack > 0:
+ out(" if ((packing_flags & $(f.flag_mask(pack))) != 0)\n ")
+ pre = ""
+ post = ""
+ arg = ""
+ if f.type_node.name == "struct":
+ pre = "(%s)" % cname(f.type_node)
+ arg = "%s.TYPE" % cname(f.type_node)
+ elif f.type_node.name == "domain":
+ pre = "%sGetter.Get(" % cname(f.type_node)
+ post = ")"
+ out(" _$(f.name) = $(pre)dec.Read$(f.coder)($(arg))$(post);\n")
+}
+ }
+
+ public override Dictionary<String,Object> Fields
+ {
+ get
+ {
+ Dictionary<String,Object> result = new Dictionary<String,Object>();
+
+${
+for f in fields:
+ if pack > 0:
+ out(" if ((packing_flags & $(f.flag_mask(pack))) != 0)\n ")
+ out(' result.Add("_$(f.name)", $(f.get)());\n')
+}
+ return result;
+ }
+ }
+
+}
+}
diff --git a/qpid/dotnet/client-010/gentool/Constant.tpl b/qpid/dotnet/client-010/gentool/Constant.tpl
new file mode 100644
index 0000000000..191a1dbd6e
--- /dev/null
+++ b/qpid/dotnet/client-010/gentool/Constant.tpl
@@ -0,0 +1,37 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+namespace org.apache.qpid.transport
+{
+
+${from genutil import *}
+
+public class Constant
+{
+${
+constants = spec.query["amqp/constant"]
+
+for c in constants:
+ name = scream(c["@name"])
+ value = c["@value"]
+ out(" public const int $name = $value;\n")
+}}
+}
diff --git a/qpid/dotnet/client-010/gentool/Enum.tpl b/qpid/dotnet/client-010/gentool/Enum.tpl
new file mode 100644
index 0000000000..5d958c7bf6
--- /dev/null
+++ b/qpid/dotnet/client-010/gentool/Enum.tpl
@@ -0,0 +1,59 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+using System;
+namespace org.apache.qpid.transport
+{
+${
+from genutil import *
+
+vtype = jtype(resolve_type(type))
+
+out(" public enum $name : $vtype")
+
+choices = [(scream(ch["@name"]), "= %s" % (ch["@value"]))
+ for ch in type.query["enum/choice"]]
+}
+ {
+ $(",\n ".join(["%s%s" % ch for ch in choices]))
+ }
+
+${
+
+out(" public struct $name")
+out("Getter")
+}
+ {
+ public static $name Get($vtype value)
+ {
+ switch (value)
+ {
+${
+choices = [(scream(ch["@name"]), "%s" % (ch["@value"]))
+ for ch in type.query["enum/choice"]]
+
+for ch, value in choices:
+ out(' case $value: return $name.$ch;\n')
+} default: throw new Exception("no such value: " + value);
+ }
+ }
+ }
+}
diff --git a/qpid/dotnet/client-010/gentool/IInvoker.tpl b/qpid/dotnet/client-010/gentool/IInvoker.tpl
new file mode 100644
index 0000000000..713d10c610
--- /dev/null
+++ b/qpid/dotnet/client-010/gentool/IInvoker.tpl
@@ -0,0 +1,57 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+namespace org.apache.qpid.transport
+{
+
+public interface IInvoker {
+
+ IFuture Invoke(Method method, IFuture resultClass);
+
+${
+from dotnetgenutil import *
+
+for c in composites:
+ name = cname(c)
+ fields = get_fields(c)
+ params = get_dotnetparameters(c, fields)
+ args = get_arguments(c, fields)
+ result = c["result"]
+ if result:
+ if not result["@type"]:
+ rname = cname(result["struct"])
+ else:
+ rname = cname(result, "@type")
+ jresult = "IFuture"
+ else:
+ jresult = "void"
+
+ out("""
+ $jresult $(name)($(", ".join(params)));
+""")
+}
+
+}
+}
diff --git a/qpid/dotnet/client-010/gentool/Invoker.tpl b/qpid/dotnet/client-010/gentool/Invoker.tpl
new file mode 100644
index 0000000000..2f69aee66d
--- /dev/null
+++ b/qpid/dotnet/client-010/gentool/Invoker.tpl
@@ -0,0 +1,67 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using common.org.apache.qpid.transport.util;
+
+namespace org.apache.qpid.transport
+{
+
+public abstract class Invoker : IInvoker {
+
+ protected abstract void Invoke(Method method);
+ public abstract IFuture Invoke(Method method, IFuture resultClass);
+
+${
+from dotnetgenutil import *
+
+for c in composites:
+ name = cname(c)
+ fields = get_fields(c)
+ params = get_dotnetparameters(c, fields)
+ args = get_arguments(c, fields)
+ result = c["result"]
+ if result:
+ if not result["@type"]:
+ rname = cname(result["struct"])
+ else:
+ rname = cname(result, "@type")
+ jresult = "IFuture"
+ jreturn = "return "
+ jclass = ", new ResultFuture()"
+ jinvoke = "Invoke"
+ else:
+ jinvoke = "Invoke"
+ jresult = "void"
+ jreturn = ""
+ jclass = ""
+
+ out("""
+ public $jresult $(name)($(", ".join(params))) {
+ $(jreturn)$jinvoke(new $name($(", ".join(args)))$jclass);
+ }
+""")
+}
+
+}
+}
diff --git a/qpid/dotnet/client-010/gentool/MethodDelegate.tpl b/qpid/dotnet/client-010/gentool/MethodDelegate.tpl
new file mode 100644
index 0000000000..788d2e29e6
--- /dev/null
+++ b/qpid/dotnet/client-010/gentool/MethodDelegate.tpl
@@ -0,0 +1,35 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+namespace org.apache.qpid.transport
+{
+
+public abstract class MethodDelegate<C> {
+
+${
+from genutil import *
+
+for c in composites:
+ name = cname(c)
+ out(" public virtual void $(name)(C context, $name mystruct) {}\n")
+}
+}
+}
diff --git a/qpid/dotnet/client-010/gentool/Option.tpl b/qpid/dotnet/client-010/gentool/Option.tpl
new file mode 100644
index 0000000000..d6e1a44870
--- /dev/null
+++ b/qpid/dotnet/client-010/gentool/Option.tpl
@@ -0,0 +1,42 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+namespace org.apache.qpid.transport
+{
+public enum Option {
+
+${
+from genutil import *
+
+options = {}
+
+for c in composites:
+ for f in c.query["field"]:
+ t = resolve_type(f)
+ if t["@name"] == "bit":
+ option = scream(f["@name"])
+ if not options.has_key(option):
+ options[option] = None
+ out(" $option,\n")}
+ BATCH,
+ NONE
+}
+}
diff --git a/qpid/dotnet/client-010/gentool/StructFactory.tpl b/qpid/dotnet/client-010/gentool/StructFactory.tpl
new file mode 100644
index 0000000000..2a11e2530c
--- /dev/null
+++ b/qpid/dotnet/client-010/gentool/StructFactory.tpl
@@ -0,0 +1,64 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+using System;
+
+namespace org.apache.qpid.transport
+{
+
+class StructFactory {
+
+ public static Struct create(int type)
+ {
+ switch (type)
+ {
+${
+from genutil import *
+
+fragment = """ case $name.TYPE:
+ return new $name();
+"""
+
+for c in composites:
+ name = cname(c)
+ if c.name == "struct":
+ out(fragment)
+} default:
+ throw new Exception("type: " + type);
+ }
+ }
+
+ public static Struct createInstruction(int type)
+ {
+ switch (type)
+ {
+${
+for c in composites:
+ name = cname(c)
+ if c.name in ("command", "control"):
+ out(fragment)
+} default:
+ throw new Exception("type: " + type);
+ }
+ }
+
+}
+}
diff --git a/qpid/dotnet/client-010/gentool/Type.tpl b/qpid/dotnet/client-010/gentool/Type.tpl
new file mode 100644
index 0000000000..c8ec7ac153
--- /dev/null
+++ b/qpid/dotnet/client-010/gentool/Type.tpl
@@ -0,0 +1,103 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+using System;
+
+namespace org.apache.qpid.transport
+{
+
+${from genutil import *}
+
+public struct QpidType
+{
+ public Code code;
+ public int width;
+ public bool isfixed;
+
+ public Code Code
+ {
+ get { return code; }
+ set { code = value; }
+ }
+
+ public int Width
+ {
+ get { return width; }
+ set { width = value; }
+ }
+
+ public bool Fixed
+ {
+ get { return isfixed; }
+ set { isfixed = value; }
+ }
+
+ QpidType(Code code, int width, bool isfixed)
+ {
+ this.code = code;
+ this.width = width;
+ this.isfixed = isfixed;
+ }
+
+ public static QpidType get(byte code)
+ {
+ switch (code)
+ {
+${
+types = spec.query["amqp/type"] + spec.query["amqp/class/type"]
+codes = {}
+first = True
+for t in types:
+ code = t["@code"]
+ fix_width = t["@fixed-width"]
+ var_width = t["@variable-width"]
+
+ if code is None:
+ continue
+
+ if fix_width is None:
+ width = var_width
+ fixed = "false"
+ else:
+ width = fix_width
+ fixed = "true"
+
+ name = scream(t["@name"])
+ codes[code] = name
+
+ out(" case $code : return new QpidType(Code.$name, $width, $fixed);\n")
+}
+ default: throw new Exception("unknown code: " + code);
+ }
+ }
+}
+
+public enum Code : byte
+ {
+${
+keys = list(codes.keys())
+keys.sort()
+
+for code in keys:
+ out(" $(codes[code]) = $code,\n")
+}
+ }
+}
diff --git a/qpid/dotnet/client-010/gentool/build.xml b/qpid/dotnet/client-010/gentool/build.xml
new file mode 100644
index 0000000000..76ddb1571d
--- /dev/null
+++ b/qpid/dotnet/client-010/gentool/build.xml
@@ -0,0 +1,52 @@
+<!--
+ -
+ - Licensed to the Apache Software Foundation (ASF) under one
+ - or more contributor license agreements. See the NOTICE file
+ - distributed with this work for additional information
+ - regarding copyright ownership. The ASF licenses this file
+ - to you under the Apache License, Version 2.0 (the
+ - "License"); you may not use this file except in compliance
+ - with the License. You may obtain a copy of the License at
+ -
+ - http://www.apache.org/licenses/LICENSE-2.0
+ -
+ - Unless required by applicable law or agreed to in writing,
+ - software distributed under the License is distributed on an
+ - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ - KIND, either express or implied. See the License for the
+ - specific language governing permissions and limitations
+ - under the License.
+ -
+ -->
+<project name="GenTool" default="build">
+
+ <property name="generated.dir" location="../client/" />
+ <property name="gentools.timestamp" location="${generated.dir}/gentools.timestamp" />
+ <property name="jython.timestamp" location="${generated.dir}/jython.timestamp" />
+ <property name="java.basedir" location="../../../java/common" />
+ <property name="mllib.dir" location="../../../python" />
+ <property name="xml.spec.dir" location="../../../specs" />
+
+
+ <target name="check_jython_deps">
+ <uptodate property="jython.notRequired" targetfile="${jython.timestamp}">
+ <srcfiles dir="${xml.spec.dir}" includes="amqp.0-10-qpid-errata.xml" />
+ </uptodate>
+ </target>
+
+ <target name="build" depends="check_jython_deps" unless="jython.notRequired">
+ <java classname="org.python.util.jython" fork="true" failonerror="true">
+ <arg value="-Dpython.cachedir.skip=true"/>
+ <arg value="-Dpython.path=${java.basedir}/../lib/jython-lib.jar/Lib${path.separator}${mllib.dir}${path.separator}${java.basedir}${path.separator}${basedir}"/>
+ <arg value="${basedir}/codegen"/>
+ <arg value="${generated.dir}"/>
+ <arg value="${xml.spec.dir}/amqp.0-10-qpid-errata.xml"/>
+ <arg value="${basedir}"/>
+ <classpath>
+ <pathelement location="../../../java/lib/jython-2.5.0.jar"/>
+ </classpath>
+ </java>
+ <touch file="${jython.timestamp}" />
+ </target>
+
+</project>
diff --git a/qpid/dotnet/client-010/gentool/codegen b/qpid/dotnet/client-010/gentool/codegen
new file mode 100644
index 0000000000..baebf378fd
--- /dev/null
+++ b/qpid/dotnet/client-010/gentool/codegen
@@ -0,0 +1,86 @@
+#!/usr/bin/env python
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+
+
+import os, sys, mllib
+from templating import Parser
+from dotnetgenutil import *
+
+out_dir = sys.argv[1]
+spec_file = sys.argv[2]
+tpl_dir = sys.argv[3]
+pkg_dir = os.path.join(out_dir, "generated")
+
+if not os.path.exists(pkg_dir):
+ os.makedirs(pkg_dir)
+
+spec = mllib.xml_parse(spec_file)
+
+def excludes(nd):
+ if (nd.parent is not None and
+ nd.parent.name == "class" and
+ nd.parent["@name"] in ("file", "stream")):
+ return False
+ else:
+ return True
+
+def execute(output, template, **kwargs):
+ f = open(os.path.join(tpl_dir, template))
+ input = f.read()
+ f.close()
+ p = Parser(**kwargs)
+ p.parse(input)
+ fname = os.path.join(pkg_dir, output)
+ f = open(fname, "w")
+ f.write(p.output)
+ f.close()
+
+execute("Type.cs", "Type.tpl", spec = spec)
+execute("Constant.cs", "Constant.tpl", spec = spec)
+
+structs = spec.query["amqp/struct"] + \
+ spec.query["amqp/class/struct", excludes] + \
+ spec.query["amqp/class/command/result/struct", excludes]
+controls = spec.query["amqp/class/control", excludes]
+commands = spec.query["amqp/class/command", excludes]
+
+composites = structs + controls + commands
+
+for c in composites:
+ name = cname(c)
+ execute("%s.cs" % name, "Composite.tpl", type = c, name = name)
+
+execute("MethodDelegate.cs", "MethodDelegate.tpl", composites = composites)
+execute("Option.cs", "Option.tpl", composites = composites)
+execute("Invoker.cs", "Invoker.tpl", composites = controls + commands)
+execute("IInvoker.cs", "IInvoker.tpl", composites = controls + commands)
+execute("StructFactory.cs", "StructFactory.tpl", composites = composites)
+
+def is_enum(nd):
+ return nd["enum"] is not None
+
+enums = spec.query["amqp/domain", is_enum] + \
+ spec.query["amqp/class/domain", is_enum]
+
+for e in enums:
+ name = cname(e)
+ execute("%s.cs" % name, "Enum.tpl", name = name, type = e)
diff --git a/qpid/dotnet/client-010/gentool/dotnetgenutil.py b/qpid/dotnet/client-010/gentool/dotnetgenutil.py
new file mode 100644
index 0000000000..4d9c8a69d7
--- /dev/null
+++ b/qpid/dotnet/client-010/gentool/dotnetgenutil.py
@@ -0,0 +1,271 @@
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+
+
+def pascal(offset, *args):
+ parts = []
+ for a in args:
+ parts.extend(a.split("-"))
+ return "".join([p[0].upper() + p[1:] for p in parts[:offset]] + [p[0].upper() + p[1:] for p in parts[offset:]])
+
+
+def scream(*args):
+ return "_".join([a.replace("-", "_").upper() for a in args])
+
+def num(x, default=None):
+ if x is not None and x != "":
+ return int(x, 0)
+ else:
+ return default
+
+def klass(nd):
+ parent = nd.parent
+ while parent is not None:
+ if hasattr(parent, "name") and parent.name == "class":
+ return parent
+ parent = parent.parent
+
+untyped = -1
+
+def code(nd):
+ global untyped
+ cd = num(nd["@code"])
+ if cd is None:
+ cd = untyped
+ untyped -= 1
+ return cd
+
+ cls = klass(nd)
+ if cls:
+ cd |= (num(cls["@code"]) << 8)
+ return cd
+
+def root(nd):
+ if nd.parent is None:
+ return nd
+ else:
+ return root(nd.parent)
+
+def qname(nd):
+ name = nd["@name"]
+ cls = klass(nd)
+ if cls != None:
+ return "%s.%s" % (cls["@name"], name)
+ else:
+ return name
+
+RESOLVED = {}
+
+def resolve(node, name):
+ key = (node, name)
+ if RESOLVED.has_key(key):
+ return RESOLVED[key]
+ else:
+ spec = root(node)
+ cls = klass(node)
+ if cls:
+ for nd in cls.query["#tag"]:
+ if nd["@name"] == name:
+ RESOLVED[key] = nd
+ return nd
+ for nd in spec.query["amqp/#tag"] + spec.query["amqp/class/#tag"]:
+ if name == qname(nd):
+ RESOLVED[key] = nd
+ return nd
+ raise Exception("unresolved name: %s" % name)
+
+def resolve_type(nd):
+ if hasattr(nd, "_resolved_type"):
+ return nd._resolved_type
+ else:
+ name = nd["@type"]
+ type = resolve(nd, name)
+ if type.name == "domain" and not type["enum"]:
+ type = resolve_type(type)
+ nd._resolved_type = type
+ return type
+
+TYPES = {
+ "bit": "bool",
+ "uint8": "short",
+ "uint16": "int",
+ "uint32": "long",
+ "uint64": "long",
+ "datetime": "long",
+ "uuid": "UUID",
+ "sequence-no": "int",
+ "sequence-set": "RangeSet", # XXX
+ "byte-ranges": "RangeSet", # XXX
+ "str8": "String",
+ "str16": "String",
+ "vbin8": "byte[]",
+ "vbin16": "byte[]",
+ "vbin32": "byte[]",
+ "struct32": "Struct",
+ "map": "Dictionary<String,Object>",
+ "array": "List<Object>"
+ }
+
+def cname(nd, field="@name"):
+ cls = klass(nd)
+ if cls:
+ if (nd.name in ("struct", "result") and
+ cls["@name"] != "session" and
+ nd[field] != "header"):
+ return pascal(0, nd[field])
+ else:
+ return pascal(0, cls["@name"], nd[field])
+ else:
+ return pascal(0, nd[field])
+
+def jtype(nd):
+ if nd.name == "struct" or nd["enum"]:
+ return cname(nd)
+ else:
+ return TYPES[nd["@name"]]
+
+REFS = {
+ "bool": "Boolean",
+ "byte": "Byte",
+ "short": "Short",
+ "int": "Integer",
+ "long": "Long",
+ "float": "Float",
+ "double": "Double",
+ "char": "Character"
+}
+
+def jref(jt):
+ return REFS.get(jt, jt)
+
+def jclass(jt):
+ idx = jt.find('<')
+ if idx > 0:
+ return jt[:idx]
+ else:
+ return jt
+
+DEFAULTS = {
+ "long": 0,
+ "int": 0,
+ "short": 0,
+ "byte": 0,
+ "char": 0,
+ "bool": "false"
+ }
+
+class Field:
+
+ def __init__(self, index, nd):
+ self.index = index
+ self.name = pascal(1, nd["@name"])
+ self.type_node = resolve_type(nd)
+ if self.type_node.name == "domain":
+ self.prim_type = resolve_type(self.type_node)
+ else:
+ self.prim_type = self.type_node
+ self.variable_width = num(self.prim_type["@variable-width"], 0)
+ self.fixed_width = num(self.prim_type["@fixed-width"], 0)
+ self.empty = self.variable_width == 0 and self.fixed_width == 0 and self.prim_type.name != "struct"
+ tname = cname(self.type_node)
+ if self.type_node.name == "struct":
+ self.read = "(%s) dec.ReadStruct(%s.TYPE)" % (tname, tname)
+ self.write = "enc.WriteStruct(%s.TYPE, check(struct).%s)" % (tname, self.name)
+ self.coder = "Struct"
+ elif self.type_node.name == "domain":
+ self.coder = pascal(0, self.prim_type["@name"])
+ self.read = "%s.Get(dec.Read%s())" % (tname, self.coder)
+ self.write = "enc.Write%s(check(struct).%s.GetValue())" % (self.coder, self.name)
+ else:
+ self.coder = pascal(0, self.type_node["@name"])
+ self.read = "dec.Read%s()" % self.coder
+ self.write = "enc.Write%s(check(struct).%s)" % (self.coder, self.name)
+ self.type = jtype(self.type_node)
+ self.default = DEFAULTS.get(self.type, "null")
+ self.has = pascal(1, "Has", self.name)
+ self.get = pascal(1, "Get", self.name)
+ self.set = pascal(1, "Set", self.name)
+ self.clear = pascal(1, "clear", self.name)
+ if self.type == "bool":
+ self.option = scream(nd["@name"])
+ else:
+ self.option = None
+
+ def flag_mask(self, pack):
+ flag = pack * 8 - 8 - (self.index/8)*8 + (self.index % 8)
+ return 1 << flag
+
+
+def get_fields(nd):
+ fields = []
+ index = 0
+ for f in nd.query["field"]:
+ fields.append(Field(index, f))
+ index += 1
+ return fields
+
+def get_parameters(type, fields):
+ params = []
+ options = False
+ for f in fields:
+ if f.option:
+ options = True
+ else:
+ params.append("%s %s" % (f.type, f.name))
+ if type["segments"]:
+ params.append("Header header")
+ params.append("MemoryStream body")
+ if options or type.name in ("control", "command"):
+ params.append("Option ... options")
+ return params
+
+def get_arguments(type, fields):
+ args = []
+ options = False
+ for f in fields:
+ if f.option:
+ options = True
+ else:
+ args.append(f.name)
+ if type["segments"]:
+ args.append("header")
+ args.append("body")
+ if options or type.name in ("control", "command"):
+ args.append("options")
+ return args
+
+def get_options(fields):
+ return [f for f in fields if f.option]
+
+def get_dotnetparameters(type, fields):
+ params = []
+ options = False
+ for f in fields:
+ if f.option:
+ options = True
+ else:
+ params.append("%s %s" % (f.type, f.name))
+ if type["segments"]:
+ params.append("Header header")
+ params.append("MemoryStream body")
+ if options or type.name in ("control", "command"):
+ params.append("params Option[] options")
+ return params