summaryrefslogtreecommitdiff
path: root/qpid/cpp/rubygen
diff options
context:
space:
mode:
Diffstat (limited to 'qpid/cpp/rubygen')
-rwxr-xr-xqpid/cpp/rubygen/amqpgen.rb8
-rwxr-xr-xqpid/cpp/rubygen/cppgen.rb2
-rwxr-xr-xqpid/cpp/rubygen/samples/Operations.rb4
-rwxr-xr-xqpid/cpp/rubygen/samples/Proxy.rb4
-rw-r--r--qpid/cpp/rubygen/templates/Session.rb136
5 files changed, 147 insertions, 7 deletions
diff --git a/qpid/cpp/rubygen/amqpgen.rb b/qpid/cpp/rubygen/amqpgen.rb
index 5cad9d6336..0da1bfe824 100755
--- a/qpid/cpp/rubygen/amqpgen.rb
+++ b/qpid/cpp/rubygen/amqpgen.rb
@@ -76,6 +76,10 @@ end
class AmqpMethod < AmqpElement
def initialize(xml, amqp) super; end
+ def content()
+ attributes["content"]
+ end
+
def index() attributes["index"]; end
def fields()
@@ -84,7 +88,7 @@ class AmqpMethod < AmqpElement
# Responses to this method (0-9)
def responses()
- @cache_responses ||= elements.collect("response") { |el| new AmqpMethod(el,self) }
+ @cache_responses ||= elements.collect("response") { |el| AmqpMethod.new(el,self) }
end
# Methods this method responds to (0-9)
@@ -178,7 +182,7 @@ class Generator
if (@outdir != "-")
path=Pathname.new "#{@outdir}/#{file}"
path.parent.mkpath
- path.open('w') { |@out| yield }
+ path.open('w') { |@out| yield }
end
end
diff --git a/qpid/cpp/rubygen/cppgen.rb b/qpid/cpp/rubygen/cppgen.rb
index f58ce3a539..d369d23da1 100755
--- a/qpid/cpp/rubygen/cppgen.rb
+++ b/qpid/cpp/rubygen/cppgen.rb
@@ -128,7 +128,7 @@ class CppGen < Generator
# Write a .cpp file.
def cpp_file(path)
- file (path) do
+ file(path) do
gen Copyright
yield
end
diff --git a/qpid/cpp/rubygen/samples/Operations.rb b/qpid/cpp/rubygen/samples/Operations.rb
index 4d84e33b9f..1c245ca188 100755
--- a/qpid/cpp/rubygen/samples/Operations.rb
+++ b/qpid/cpp/rubygen/samples/Operations.rb
@@ -80,6 +80,6 @@ EOS
end
end
-OperationsGen.new("client",ARGV[0], amqp).generate()
-OperationsGen.new("server",ARGV[0], amqp).generate()
+OperationsGen.new("client",ARGV[0], Amqp).generate()
+OperationsGen.new("server",ARGV[0], Amqp).generate()
diff --git a/qpid/cpp/rubygen/samples/Proxy.rb b/qpid/cpp/rubygen/samples/Proxy.rb
index c63a2a9799..f7765f3729 100755
--- a/qpid/cpp/rubygen/samples/Proxy.rb
+++ b/qpid/cpp/rubygen/samples/Proxy.rb
@@ -148,6 +148,6 @@ EOS
end
-ProxyGen.new("client", ARGV[0], amqp).generate;
-ProxyGen.new("server", ARGV[0], amqp).generate;
+ProxyGen.new("client", ARGV[0], Amqp).generate;
+ProxyGen.new("server", ARGV[0], Amqp).generate;
diff --git a/qpid/cpp/rubygen/templates/Session.rb b/qpid/cpp/rubygen/templates/Session.rb
new file mode 100644
index 0000000000..5289a6af30
--- /dev/null
+++ b/qpid/cpp/rubygen/templates/Session.rb
@@ -0,0 +1,136 @@
+#!/usr/bin/env ruby
+# Usage: output_directory xml_spec_file [xml_spec_file...]
+#
+$: << '..'
+require 'cppgen'
+
+class SessionGen < CppGen
+
+ def initialize(outdir, amqp)
+ super(outdir, amqp)
+ @chassis="server"
+ @classname="Session"
+ end
+
+ def declare_method (m)
+ gen "Response #{m.amqp_parent.name.lcaps}#{m.cppname.caps}("
+ if (m.content())
+ params=m.signature + ["const MethodContent& content"]
+ else
+ params=m.signature
+ end
+ indent { gen params.join(",\n") }
+ gen ");\n\n"
+ end
+
+ def declare_class(c)
+ c.methods_on(@chassis).each { |m| declare_method(m) }
+ end
+
+ def define_method (m)
+ gen "Response Session::#{m.amqp_parent.name.lcaps}#{m.cppname.caps}("
+ if (m.content())
+ params=m.signature + ["const MethodContent& content"]
+ else
+ params=m.signature
+ end
+ indent { gen params.join(",\n") }
+ gen "){\n\n"
+ indent (2) {
+ gen "return impl->send(AMQMethodBody::shared_ptr(new #{m.body_name}("
+ params = ["version"] + m.param_names
+ gen params.join(", ")
+ other_params=[]
+ if (m.content())
+ other_params << "content"
+ end
+ if m.responses().empty?
+ other_params << "false"
+ else
+ other_params << "true"
+ end
+ gen ")), #{other_params.join(", ")});\n"
+ }
+ gen "}\n\n"
+ end
+
+ def define_class(c)
+ c.methods_on(@chassis).each { |m| define_method(m) }
+ end
+
+ def generate()
+ excludes = ["channel", "connection", "session", "execution"]
+
+ h_file("qpid/client/#{@classname}.h") {
+ gen <<EOS
+#include <sstream>
+#include "qpid/framing/amqp_framing.h"
+#include "qpid/framing/ProtocolVersion.h"
+#include "qpid/framing/MethodContent.h"
+#include "ConnectionImpl.h"
+#include "Response.h"
+#include "SessionCore.h"
+
+namespace qpid {
+namespace client {
+
+using std::string;
+using framing::Content;
+using framing::FieldTable;
+using framing::MethodContent;
+using framing::SequenceNumberSet;
+
+class #{@classname} {
+ ConnectionImpl::shared_ptr parent;
+ SessionCore::shared_ptr impl;
+ framing::ProtocolVersion version;
+public:
+ #{@classname}(ConnectionImpl::shared_ptr, SessionCore::shared_ptr);
+ ~#{@classname}();
+
+ ReceivedContent::shared_ptr get() { return impl->get(); }
+ void close() { impl->close(); parent->released(impl); }
+
+EOS
+ indent { @amqp.classes.each { |c| declare_class(c) if !excludes.include?(c.name) } }
+ gen <<EOS
+}; /* class #{@classname} */
+}
+}
+EOS
+}
+
+ # .cpp file
+ cpp_file("qpid/client/#{@classname}.cpp") {
+ gen <<EOS
+#include "#{@classname}.h"
+#include "qpid/framing/AMQMethodBody.h"
+
+using std::string;
+using namespace qpid::framing;
+
+namespace qpid {
+namespace client {
+
+#{@classname}::#{@classname}(ConnectionImpl::shared_ptr _parent, SessionCore::shared_ptr _impl) : parent(_parent), impl(_impl) {}
+
+#{@classname}::~#{@classname}()
+{
+ impl->stop();
+ parent->released(impl);
+}
+
+EOS
+
+ @amqp.classes.each { |c| define_class(c) if !excludes.include?(c.name) }
+
+ gen <<EOS
+}} // namespace qpid::client
+EOS
+ }
+
+ end
+end
+
+SessionGen.new(ARGV[0], Amqp).generate()
+