summaryrefslogtreecommitdiff
path: root/cpp/rubygen/templates/InvocationVisitor.rb
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2007-10-16 19:07:54 +0000
committerAlan Conway <aconway@apache.org>2007-10-16 19:07:54 +0000
commit428de9b6fe6f81f2bfc3f47d5db013b4b00da6a2 (patch)
treee3fe772cbe0e08ea84f4b2f54b969dc7471bb8e1 /cpp/rubygen/templates/InvocationVisitor.rb
parent3bd61c1fa1a748789707b502ada85200f6180f5b (diff)
downloadqpid-python-428de9b6fe6f81f2bfc3f47d5db013b4b00da6a2.tar.gz
* Summary: generalized Invoker visitor to all *Operations and
*Handler classes, client and broker. Single template free function invoke(Invocable, const AMQBody&); works for all invocable handlers. * rubygen/templates/OperationsInvoker.rb: Generates invoker visitors for all Operations classes, client and server. * src/qpid/framing/Invoker.h: Invoker base class and template invoke() function. * rubygen/templates/structs.rb: add generic invoke method template to invoke an arbitrary object with the correct memeber function. * src/qpid/framing/AMQMethodBody.cpp, .h: Removed invoke(), replaced by qpid::framing::invoke() * src/qpid/broker/SemanticHandler.cpp, ConnectionHandler.cpp: Replace AMQMethodBody::invoke with invoke() free function. * src/qpid/framing/StructHelper.h: Avoid un-necessary alloc and copy in encode/decode. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@585223 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/rubygen/templates/InvocationVisitor.rb')
-rw-r--r--cpp/rubygen/templates/InvocationVisitor.rb101
1 files changed, 0 insertions, 101 deletions
diff --git a/cpp/rubygen/templates/InvocationVisitor.rb b/cpp/rubygen/templates/InvocationVisitor.rb
deleted file mode 100644
index 67a0479bb6..0000000000
--- a/cpp/rubygen/templates/InvocationVisitor.rb
+++ /dev/null
@@ -1,101 +0,0 @@
-#!/usr/bin/env ruby
-$: << ".." # Include .. in load path
-require 'cppgen'
-
-class InvocationVisitor < CppGen
-
- def initialize(outdir, amqp)
- super(outdir, amqp)
- @namespace="qpid::framing"
- @classname="InvocationVisitor"
- @filename="qpid/framing/InvocationVisitor"
- end
-
- def invocation_args(m)
- m.param_names.collect {|p| "body.get" + p.caps + "()" }.join(",\n")
- end
-
- def null_visit(m)
- genl "void InvocationVisitor::visit(const #{m.body_name}&){}"
- end
-
- def define_visit(m)
- if (m.fields.size > 0)
- body = "body"
- else
- body = "/*body*/"
- end
- gen <<EOS
-void InvocationVisitor::visit(const #{m.body_name}& #{body})
-{
- AMQP_ServerOperations::#{m.parent.cppname}Handler* ptr(0);
- if (invocable) {
- ptr = dynamic_cast<AMQP_ServerOperations::#{m.parent.cppname}Handler*>(invocable);
- } else {
- ptr = ops->get#{m.parent.cppname}Handler();
- }
-
- if (ptr) {
-EOS
- if (m.result)
- indent(2) { genl "encode<#{m.result.struct.cpptype.name}>(ptr->#{m.cppname}(#{invocation_args(m)}), result);" }
- else
- indent(2) { genl "ptr->#{m.cppname}(#{invocation_args(m)});" }
- end
-
- gen <<EOS
- succeeded = true;
- } else {
- succeeded = false;
- }
-}
-EOS
- end
-
- def generate()
- h_file("#{@filename}") {
- include "AMQP_ServerOperations.h"
- include "MethodBodyConstVisitor.h"
- include "qpid/framing/StructHelper.h"
- namespace(@namespace) {
- cpp_class("InvocationVisitor", ["public MethodBodyConstVisitor", "private StructHelper"]) {
- indent {
- genl "AMQP_ServerOperations* const ops;"
- genl "Invocable* const invocable;"
- genl "std::string result;"
- genl "bool succeeded;"
- }
- genl "public:"
- indent {
- genl "InvocationVisitor(AMQP_ServerOperations* _ops) : ops(_ops), invocable(0), succeeded(false) {}"
- genl "InvocationVisitor(Invocable* _invocable) : ops(0), invocable(_invocable), succeeded(false) {}"
- genl "const std::string& getResult() const { return result; }"
- genl "const bool hasResult() const { return !result.empty(); }"
- genl "bool wasHandled() const { return succeeded; }"
- genl "void clear();"
- genl "virtual ~InvocationVisitor() {}"
- }
- @amqp.methods_.each { |m| genl "void visit(const #{m.body_name}&);" }
- }
- }
- }
-
- cpp_file("#{@filename}") {
- include "InvocationVisitor.h"
- @amqp.methods_.each { |m| include m.body_name }
- namespace(@namespace) {
- genl "void InvocationVisitor::clear() {"
- indent {
- genl "succeeded = false;"
- genl "result.clear();"
- }
- genl "}"
- genl
- @amqp.methods_.each { |m| m.on_server? && !m.content() ? define_visit(m) : null_visit(m) }
- }
- }
- end
-end
-
-InvocationVisitor.new(Outdir, Amqp).generate();
-