diff options
author | Alan Conway <aconway@apache.org> | 2008-04-10 12:36:58 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2008-04-10 12:36:58 +0000 |
commit | 599ff4a59af78af75639a05a3e87a29f81a29e2b (patch) | |
tree | fc7bf12213abb6c2cdbfa8dd658cbc2c62f47741 /cpp/rubygen | |
parent | 0e16f6997fe87a5241d0cbbd6ad6b0df1bfffc8f (diff) | |
download | qpid-python-599ff4a59af78af75639a05a3e87a29f81a29e2b.tar.gz |
Invocation handlers, see src/tests/amqp_0_10/handlers.cpp for example.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@646778 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/rubygen')
-rwxr-xr-x | cpp/rubygen/0-10/handlers.rb | 29 | ||||
-rwxr-xr-x | cpp/rubygen/0-10/specification.rb | 25 | ||||
-rwxr-xr-x | cpp/rubygen/cppgen.rb | 1 |
3 files changed, 51 insertions, 4 deletions
diff --git a/cpp/rubygen/0-10/handlers.rb b/cpp/rubygen/0-10/handlers.rb new file mode 100755 index 0000000000..c23eb5faf4 --- /dev/null +++ b/cpp/rubygen/0-10/handlers.rb @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +$: << ".." # Include .. in load path +require 'cppgen' + +class GenHandlers < CppGen + def initialize(outdir, amqp) + super(outdir, amqp) + @ns="qpid::amqp_#{@amqp.version.bars}" + @dir="qpid/amqp_#{@amqp.version.bars}" + end + + def action_handler(type, actions) + genl + bases=actions.map { |a| "public #{a.fqclassname}::Handler" } + struct("#{type}Handler", *bases) { } + end + + def generate() + h_file("#{@dir}/handlers.h") { + include "specification" + namespace("#{@ns}") { + action_handler "Command", @amqp.collect_all(AmqpCommand) + action_handler "Control", @amqp.collect_all(AmqpControl) + } + } + end +end + +GenHandlers.new($outdir, $amqp).generate() diff --git a/cpp/rubygen/0-10/specification.rb b/cpp/rubygen/0-10/specification.rb index abc754d1ef..020cb63c89 100755 --- a/cpp/rubygen/0-10/specification.rb +++ b/cpp/rubygen/0-10/specification.rb @@ -69,7 +69,7 @@ class Specification < CppGen genl "bool operator==(const #{x.classname}&, const #{x.classname}&);" end - def action_struct_cpp(x) + def action_struct_cpp(x, &block) genl genl "const char* #{x.classname}::NAME=\"#{x.fqname}\";" genl "const char* #{x.classname}::CLASS_NAME=#{x.containing_class.nsname}::NAME;" @@ -92,6 +92,7 @@ class Specification < CppGen genl "o << \"]\";" genl "return o;" } + yield if block end # structs @@ -103,13 +104,28 @@ class Specification < CppGen def action_h(a) action_struct_h(a, a.base, ["code"]) { - function_defn("template <class T> void invoke", ["T& target"]) { - genl "target.#{a.funcname}(#{a.values.join(', ')});" + struct("Handler") { + scope("void #{a.funcname}(", ");") { + genl a.parameters.join(",\n") + } + } + function_defn("template <class T> void invoke", ["T& target"], "const") { + genl "target.#{a.funcname}(#{a.values.join(', ')} );" } } end - def action_cpp(a) action_struct_cpp(a); end + def action_cpp(a) + action_struct_cpp(a) { + scope("void #{a.classname}::Handler::#{a.funcname}(", ")") { + genl a.unused_parameters.join(",\n") + } + scope { + genl "assert(0);" + genl "throw NotImplementedException(QPID_MSG(\"#{a.fqname} not implemented.\"));" + } + } + end # Types that must be generated early because they are used by other types. def pregenerate?(x) not @amqp.used_by[x.fqname].empty?; end @@ -172,6 +188,7 @@ class Specification < CppGen cpp_file("#{@dir}/specification") { include "#{@dir}/specification" + include "#{@dir}/exceptions" include "<iostream>" # FIXME aconway 2008-03-04: add Struct visitors. ["Command","Control"].each { |x| include "#{@dir}/Apply#{x}" } diff --git a/cpp/rubygen/cppgen.rb b/cpp/rubygen/cppgen.rb index d0f31a8ba8..0c17b68335 100755 --- a/cpp/rubygen/cppgen.rb +++ b/cpp/rubygen/cppgen.rb @@ -152,6 +152,7 @@ end module AmqpHasFields def parameters() fields.map { |f| "#{f.paramtype} #{f.cppname}_"} end + def unused_parameters() fields.map { |f| "#{f.paramtype} /*#{f.cppname}_*/"} end def arguments() fields.map { |f| "#{f.cppname}_"} end def values() fields.map { |f| "#{f.cppname}"} end def initializers() fields.map { |f| "#{f.cppname}(#{f.cppname}_)"} end |