diff options
author | Alan Conway <aconway@apache.org> | 2008-05-26 18:10:05 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2008-05-26 18:10:05 +0000 |
commit | ce7678789fe3e8c5caebb59a26aa418fbb95e5d3 (patch) | |
tree | affd8e2de460cba285e7c25e15f5c3d94444f905 /cpp/rubygen | |
parent | 0b56077cbb8b6e9cdd982cbdeaa3ec6fe1bd5434 (diff) | |
download | qpid-python-ce7678789fe3e8c5caebb59a26aa418fbb95e5d3.tar.gz |
Changes to Session API:
- Session is synchronous, no futures.
- AsyncSession is async, returns futures.
- Conversion functions sync(s) async(s) return a sync/async view of session s.
- Connection::newSession - takes name, no timeout
- SessionBase::getId - returns SessionId not UUID.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@660258 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/rubygen')
-rw-r--r-- | cpp/rubygen/framing.0-10/Session.rb | 172 |
1 files changed, 109 insertions, 63 deletions
diff --git a/cpp/rubygen/framing.0-10/Session.rb b/cpp/rubygen/framing.0-10/Session.rb index a2f06bfcd7..d679b1c0bc 100644 --- a/cpp/rubygen/framing.0-10/Session.rb +++ b/cpp/rubygen/framing.0-10/Session.rb @@ -25,6 +25,33 @@ class CppGen end end +# Sync vs. async APIs +module SyncAsync + def sync_prefix() @async ? "Async" : "" end + def sync_adjective() @async ? "asynchronous" : "synchronous" end + def sync_convert() @async ? "async" : "sync" end + + + def decl_ctor_opeq() + genl + genl "#{@classname}();" + genl "#{@classname}(const #{@version_base}& other);" + genl "#{@classname}& operator=(const #{@version_base}& other);" + end + + def defn_ctor_opeq(inline="") + genl + genl "#{inline} #{@classname}::#{@classname}() {}" + scope("#{inline} #{@classname}::#{@classname}(const #{@version_base}& other) {") { + genl "*this = other;" + } + scope("#{inline} #{@classname}& #{@classname}::operator=(const #{@version_base}& other) {") { + genl "impl = static_cast<const #{@classname}&>(other).impl;" + genl "return *this;" + } + end +end + class ContentField # For extra content parameters def cppname() "content" end def signature() "const MethodContent& content" end @@ -49,55 +76,52 @@ class AmqpMethod fields_c.map { |f| "arg::keyword_tags::"+f.cppname }.join(',') + ">" end - def return_type() - return "TypedResult<qpid::framing::#{result.cpptype.ret_by_val}>" if (result) - return "Response" if (not responses().empty?) - return "Completion" + + def return_type(async) + if (async) + return "TypedResult<qpid::framing::#{result.cpptype.ret_by_val}>" if (result) + return "Completion" + else + return "qpid::framing::#{result.cpptype.ret_by_val}" if (result) + return "void" + end end + def session_function() "#{parent.name.lcaps}#{name.caps}"; end end class SessionNoKeywordGen < CppGen - - def initialize(outdir, amqp) + include SyncAsync + + def initialize(outdir, amqp, async) super(outdir, amqp) + @async=async @chassis="server" @namespace,@classname,@file= - parse_classname "qpid::client::no_keyword::Session_#{@amqp.version.bars}" + parse_classname "qpid::client::no_keyword::#{sync_prefix}Session_#{@amqp.version.bars}" + @version_base="SessionBase_#{@amqp.major}_#{@amqp.minor}" end def generate() h_file(@file) { - include "qpid/client/SessionBase.h" - - namespace("qpid::client") { - genl "using std::string;" - genl "using framing::Content;" - genl "using framing::FieldTable;" - genl "using framing::MethodContent;" - genl "using framing::SequenceNumber;" - genl "using framing::SequenceSet;" - genl "using framing::Uuid;" - #the following are nasty... would be better to dynamically - #include such statements based on params required - genl "using framing::Xid;" - genl - namespace("no_keyword") { - doxygen_comment { - genl "AMQP #{@amqp.version} session API." - genl @amqp.class_("session").doc + include "qpid/client/#{@version_base}.h" + namespace(@namespace) { + doxygen_comment { + genl "AMQP #{@amqp.version} #{sync_adjective} session API." + genl @amqp.class_("session").doc + # FIXME aconway 2008-05-23: additional doc on sync/async use. + } + cpp_class(@classname, "public #{@version_base}") { + public + decl_ctor_opeq() + session_methods.each { |m| + genl + doxygen(m) + args=m.sig_c_default.join(", ") + genl "#{m.return_type(@async)} #{m.session_function}(#{args});" } - cpp_class(@classname, "public SessionBase") { - public - genl "Session_#{@amqp.version.bars}() {}" - genl "Session_#{@amqp.version.bars}(shared_ptr<SessionImpl> core) : SessionBase(core) {}" - session_methods.each { |m| - genl - doxygen(m) - args=m.sig_c_default.join(", ") - genl "#{m.return_type} #{m.session_function}(#{args});" - } - }}}} + } + }} cpp_file(@file) { include @classname @@ -108,32 +132,47 @@ class SessionNoKeywordGen < CppGen genl sig=m.signature_c.join(", ") func="#{@classname}::#{m.session_function}" - scope("#{m.return_type} #{func}(#{sig}) {") { - args=(["ProtocolVersion()"]+m.param_names).join(", ") - body="#{m.body_name}(#{args})" - sendargs=body + scope("#{m.return_type(@async)} #{func}(#{sig}) {") { + args=(["ProtocolVersion(#{@amqp.major},#{@amqp.minor})"]+m.param_names).join(", ") + genl "#{m.body_name} body(#{args});"; + genl "body.setSync(#{@async ? 'false':'true'});" + sendargs="body" sendargs << ", content" if m.content - genl "return #{m.return_type}(impl->send(#{sendargs}), impl);" - }}}} + async_retval="#{m.return_type(true)}(impl->send(#{sendargs}), impl)" + if @async then + genl "return #{async_retval};" + else + if m.result + genl "return #{async_retval}.get();" + else + genl "#{async_retval}.wait();" + end + end + }} + defn_ctor_opeq() + }} end end class SessionGen < CppGen + include SyncAsync - def initialize(outdir, amqp) + def initialize(outdir, amqp, async) super(outdir, amqp) + @async=async @chassis="server" - session="Session_#{@amqp.version.bars}" + session="#{sync_prefix}Session_#{@amqp.version.bars}" @base="no_keyword::#{session}" @fqclass=FqClass.new "qpid::client::#{session}" @classname=@fqclass.name @fqbase=FqClass.new("qpid::client::#{@base}") + @version_base="SessionBase_#{@amqp.major}_#{@amqp.minor}" end - def gen_keyword_decl(m, prefix) + def gen_keyword_decl(m) return if m.fields_c.empty? # Inherited function will do. - scope("BOOST_PARAMETER_MEMFUN(#{m.return_type}, #{m.session_function}, 0, #{m.fields_c.size}, #{m.argpack_name}) {") { - scope("return #{prefix}#{m.session_function}(",");") { + scope("BOOST_PARAMETER_MEMFUN(#{m.return_type(@async)}, #{m.session_function}, 0, #{m.fields_c.size}, #{m.argpack_name}) {") { + scope("return #{@base}::#{m.session_function}(",");") { gen m.fields_c.map { |f| f.unpack() }.join(",\n") } } @@ -143,20 +182,21 @@ class SessionGen < CppGen def generate() keyword_methods=session_methods.reject { |m| m.fields_c.empty? } max_arity = keyword_methods.map{ |m| m.fields_c.size }.max + + h_file("qpid/client/arg.h") { + # Generate keyword tag declarations. + genl "#define BOOST_PARAMETER_MAX_ARITY #{max_arity}" + include "<boost/parameter.hpp>" + namespace("qpid::client::arg") { + keyword_methods.map{ |m| m.param_names_c }.flatten.uniq.each { |k| + genl "BOOST_PARAMETER_KEYWORD(keyword_tags, #{k})" + }} + } h_file(@fqclass.file) { include @fqbase.file - genl - genl "#define BOOST_PARAMETER_MAX_ARITY #{max_arity}" - include "<boost/parameter.hpp>" - genl + include "qpid/client/arg" namespace("qpid::client") { - # Generate keyword tag declarations. - namespace("arg") { - keyword_methods.map{ |m| m.param_names_c }.flatten.uniq.each { |k| - genl "BOOST_PARAMETER_KEYWORD(keyword_tags, #{k})" - }} - genl # Doxygen comment. doxygen_comment { genl "AMQP #{@amqp.version} session API with keyword arguments." @@ -183,17 +223,23 @@ EOS } # Session class. cpp_class(@classname,"public #{@base}") { + public + decl_ctor_opeq() private - genl "#{@classname}(shared_ptr<SessionImpl> core) : #{ @base}(core) {}" keyword_methods.each { |m| typedef m.argpack_type, m.argpack_name } genl "friend class Connection;" public - genl "#{@classname}() {}" - keyword_methods.each { |m| gen_keyword_decl(m,@base+"::") } - }}} + keyword_methods.each { |m| gen_keyword_decl(m) } + } + genl "/** Conversion to #{@classname} from another session type */" + genl "inline #{@classname} #{sync_convert}(const #{@version_base}& other) { return #{@clasname}(other); }" + defn_ctor_opeq("inline") + }} end end -SessionNoKeywordGen.new(ARGV[0], $amqp).generate() -SessionGen.new(ARGV[0], $amqp).generate() +SessionNoKeywordGen.new(ARGV[0], $amqp, true).generate() +SessionNoKeywordGen.new(ARGV[0], $amqp, false).generate() +SessionGen.new(ARGV[0], $amqp, true).generate() +SessionGen.new(ARGV[0], $amqp, false).generate() |