diff options
| author | Alan Conway <aconway@apache.org> | 2007-08-16 20:12:33 +0000 |
|---|---|---|
| committer | Alan Conway <aconway@apache.org> | 2007-08-16 20:12:33 +0000 |
| commit | 49c7a491c98c26fe7d4f017a7ba655dfc029278c (patch) | |
| tree | 304d51ba039a5391b4ebde08caab3da978b465fb /cpp/rubygen/templates | |
| parent | dc13ca80ff893f74ab57fee6543de6543aa366bc (diff) | |
| download | qpid-python-49c7a491c98c26fe7d4f017a7ba655dfc029278c.tar.gz | |
AMQBodies are no longer allocated on the heap and passed with shared_ptr.
AMQFrame contains a boost::variant of AMQHeaderBody,AMQContentBody,
AMQHeatbeatBody, and MethodHolder. A variant is basically a type-safe
union, it can allocate any of the types in-place.
MethodHolder contains a Blob, a less sophisticated kind of variant,
which can contain any of the concrete method body types.
Using variants for all the method types causes outrageous compile
times and bloated library symbol names. Blob lacks some of the finer
features of variant and needs help from generated code. For now both
are hidden to the rest of the code base behind AMQFrame and MethodBody
classes so if/when we decide to settle on just one "variant" type
solution we can do so.
This commit touches nearly 100 files, mostly converting method
signatures with shared_ptr<FooBody> to FooBody* or FooBody&, and
converting stored shared_ptr<AMQBody> to AMQFrame and
share_ptr<AMQMethodBody> to MethodHolder.
There is one outstanding client memory leak, which I will fix in my next commit.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@566822 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/rubygen/templates')
| -rwxr-xr-x | cpp/rubygen/templates/MethodBodyConstVisitor.rb | 27 | ||||
| -rwxr-xr-x | cpp/rubygen/templates/MethodHolder.rb | 37 | ||||
| -rwxr-xr-x | cpp/rubygen/templates/Proxy.rb | 2 | ||||
| -rw-r--r-- | cpp/rubygen/templates/Session.rb | 4 | ||||
| -rwxr-xr-x | cpp/rubygen/templates/all_method_bodies.rb | 21 |
5 files changed, 79 insertions, 12 deletions
diff --git a/cpp/rubygen/templates/MethodBodyConstVisitor.rb b/cpp/rubygen/templates/MethodBodyConstVisitor.rb new file mode 100755 index 0000000000..6fd7fe8ead --- /dev/null +++ b/cpp/rubygen/templates/MethodBodyConstVisitor.rb @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +$: << ".." # Include .. in load path +require 'cppgen' + +class MethodBodyConstVisitorGen < CppGen + + def initialize(outdir, amqp) + super(outdir, amqp) + @namespace="qpid::framing" + @classname="MethodBodyConstVisitor" + @filename="qpid/framing/MethodBodyConstVisitor" + end + + def generate() + h_file("#{@filename}") { + namespace(@namespace) { + @amqp.amqp_methods.each { |m| genl "class #{m.body_name};" } + cpp_class("MethodBodyConstVisitor") { + genl "public:" + genl "virtual ~MethodBodyConstVisitor() {}" + @amqp.amqp_methods.each { |m| genl "virtual void visit(const #{m.body_name}&) = 0;" } + }}} + end +end + +MethodBodyConstVisitorGen.new(Outdir, Amqp).generate(); + diff --git a/cpp/rubygen/templates/MethodHolder.rb b/cpp/rubygen/templates/MethodHolder.rb index 65fa824fd4..39a570c982 100755 --- a/cpp/rubygen/templates/MethodHolder.rb +++ b/cpp/rubygen/templates/MethodHolder.rb @@ -40,23 +40,42 @@ EOS def gen_construct cpp_file(@filename+"_construct") { include @filename + include "qpid/framing/MethodBodyConstVisitor.h" @amqp.amqp_methods.each { |m| include "qpid/framing/#{m.body_name}" } genl - namespace(@namespace) { - scope("void #{@classname}::construct(const Id& newId) {") { - scope("switch (newId.first) {") { + include "qpid/Exception.h" + genl + namespace(@namespace) { + # construct function + scope("void #{@classname}::construct(ClassId c, MethodId m) {") { + scope("switch (c) {") { @amqp.amqp_classes.each { |c| - scope("case #{c.index}: switch(newId.second) {") { + scope("case #{c.index}: switch(m) {") { c.amqp_methods.each { |m| genl "case #{m.index}: blob.construct(in_place<#{m.body_name}>()); break;" - }} + } + genl "default: throw Exception(QPID_MSG(\"Invalid method id \" << m << \" for class #{c.name} \"));" + } genl "break;" - }} - genl "id=newId;"; - }}} + } + genl "default: throw Exception(QPID_MSG(\"Invalid class id \" << c));" + } + } + # CopyVisitor + struct("#{@classname}::CopyVisitor", "public MethodBodyConstVisitor") { genl "MethodHolder& holder;" + genl "CopyVisitor(MethodHolder& h) : holder(h) {}" + @amqp.amqp_methods.each { |m| + genl "void visit(const #{m.body_name}& x) { holder.blob=x; }" + } + } + genl + # operator= + scope("#{@classname}& MethodHolder::operator=(const AMQMethodBody& m) {") { + genl "CopyVisitor cv(*this); m.accept(cv); return *this;" + } + }} end - def generate gen_max_size gen_construct diff --git a/cpp/rubygen/templates/Proxy.rb b/cpp/rubygen/templates/Proxy.rb index f36d6bcd99..a6c0763a8a 100755 --- a/cpp/rubygen/templates/Proxy.rb +++ b/cpp/rubygen/templates/Proxy.rb @@ -38,7 +38,7 @@ EOS genl "void #{@classname}::#{cname}::#{m.cppname}(#{m.signature.join(", ")})" scope { params=(["channel.getVersion()"]+m.param_names).join(", ") - genl "channel.send(make_shared_ptr(new #{m.body_name}(#{params})));" + genl "channel.send(#{m.body_name}(#{params}));" }} end diff --git a/cpp/rubygen/templates/Session.rb b/cpp/rubygen/templates/Session.rb index eaa4347974..4265731d32 100644 --- a/cpp/rubygen/templates/Session.rb +++ b/cpp/rubygen/templates/Session.rb @@ -37,7 +37,7 @@ class SessionGen < CppGen indent { gen params.join(",\n") } gen "){\n\n" indent (2) { - gen "return impl->send(AMQMethodBody::shared_ptr(new #{m.body_name}(" + gen "return impl->send(#{m.body_name}(" params = ["version"] + m.param_names gen params.join(", ") other_params=[] @@ -49,7 +49,7 @@ class SessionGen < CppGen else other_params << "true" end - gen ")), #{other_params.join(", ")});\n" + gen "), #{other_params.join(", ")});\n" } gen "}\n\n" end diff --git a/cpp/rubygen/templates/all_method_bodies.rb b/cpp/rubygen/templates/all_method_bodies.rb new file mode 100755 index 0000000000..38fbc31593 --- /dev/null +++ b/cpp/rubygen/templates/all_method_bodies.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env ruby +$: << ".." # Include .. in load path +require 'cppgen' + +class AllMethodBodiesGen < CppGen + + def initialize(outdir, amqp) + super(outdir, amqp) + @namespace="qpid::framing" + @filename="qpid/framing/all_method_bodies" + end + + def generate() + h_file(@filename) { + @amqp.amqp_methods.each { |m| include "qpid/framing/"+m.body_name } + } + end +end + +AllMethodBodiesGen.new(Outdir, Amqp).generate(); + |
