diff options
author | Gordon Sim <gsim@apache.org> | 2007-09-10 18:37:36 +0000 |
---|---|---|
committer | Gordon Sim <gsim@apache.org> | 2007-09-10 18:37:36 +0000 |
commit | fbda2ac45519f7108fc48f483d76d1487c2b3544 (patch) | |
tree | 08a3fc85a9730b42892f3075e18855421b378299 /cpp | |
parent | 002b38eecc23c7e9be56fbab0b643829acbb4bb8 (diff) | |
download | qpid-python-fbda2ac45519f7108fc48f483d76d1487c2b3544.tar.gz |
Support for keyword args in session interface
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@574323 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp')
-rwxr-xr-x | cpp/rubygen/cppgen.rb | 17 | ||||
-rw-r--r-- | cpp/rubygen/templates/Session.rb | 80 | ||||
-rw-r--r-- | cpp/src/qpid/client/ClientChannel.cpp | 26 | ||||
-rw-r--r-- | cpp/src/tests/ClientSessionTest.cpp | 14 |
4 files changed, 101 insertions, 36 deletions
diff --git a/cpp/rubygen/cppgen.rb b/cpp/rubygen/cppgen.rb index c6f06e80c7..0de448869d 100755 --- a/cpp/rubygen/cppgen.rb +++ b/cpp/rubygen/cppgen.rb @@ -68,6 +68,7 @@ class CppType def retcref() @ret="const #{name}&"; self; end def passcref() @param="const #{name}&"; self; end def code(str) @code=str; self; end + def defval(str) @defval=str; self; end def encode(value, buffer) @code ? "#{buffer}.put#{@code}(#{value});" : "#{value}.encode(#{buffer});" @@ -85,6 +86,10 @@ class CppType end end + def default_value() + return @defval ||= "#{name}()" + end + def to_s() name; end; end @@ -107,12 +112,12 @@ end class AmqpDomain @@typemap = { - "bit"=> CppType.new("bool").code("Octet"), - "octet"=>CppType.new("uint8_t").code("Octet"), - "short"=>CppType.new("uint16_t").code("Short"), - "long"=>CppType.new("uint32_t").code("Long"), - "longlong"=>CppType.new("uint64_t").code("LongLong"), - "timestamp"=>CppType.new("uint64_t").code("LongLong"), + "bit"=> CppType.new("bool").code("Octet").defval("false"), + "octet"=>CppType.new("uint8_t").code("Octet").defval("0"), + "short"=>CppType.new("uint16_t").code("Short").defval("0"), + "long"=>CppType.new("uint32_t").code("Long").defval("0"), + "longlong"=>CppType.new("uint64_t").code("LongLong").defval("0"), + "timestamp"=>CppType.new("uint64_t").code("LongLong").defval("0"), "longstr"=>CppType.new("string").passcref.retcref.code("LongString"), "shortstr"=>CppType.new("string").passcref.retcref.code("ShortString"), "table"=>CppType.new("FieldTable").passcref.retcref.code("FieldTable"), diff --git a/cpp/rubygen/templates/Session.rb b/cpp/rubygen/templates/Session.rb index 4cea9f9665..b2932f9a2b 100644 --- a/cpp/rubygen/templates/Session.rb +++ b/cpp/rubygen/templates/Session.rb @@ -23,29 +23,71 @@ class SessionGen < CppGen end def declare_method (m) - gen "#{return_type(m)} #{m.parent.name.lcaps}#{m.name.caps}(" + param_unpackers = m.fields.collect { |f| "args[#{f.cppname}|#{f.cpptype.default_value}]" } if (m.content()) + param_names = m.param_names + ["content"] + param_unpackers << "args[content|DefaultContent(\"\")]" params=m.signature + ["const MethodContent& content"] else + param_names = m.param_names 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) } + if (params.empty?) + gen "#{return_type(m)} #{m.parent.name.lcaps}#{m.name.caps}();\n\n" + else + genl "template <class ArgumentPack> #{return_type(m)} #{m.parent.name.lcaps}#{m.name.caps}(ArgumentPack const& args)" + genl "{" + indent { + genl "return #{m.parent.name.lcaps}#{m.name.caps}(#{param_unpackers.join(",\n")});" + } + genl "}" + + #generate the 'real' methods signature + gen "#{return_type(m)} #{m.parent.name.lcaps}#{m.name.caps}(" + indent { gen params.join(",\n") } + gen ");\n\n" + + #generate some overloaded methods to handle keyword args + boost_max_arity = 8 + if param_names.length > boost_max_arity + keywords = param_names[1..boost_max_arity].collect { |p| "keyword::#{p}" } + else + keywords = param_names.collect { |p| "keyword::#{p}" } + end + genl "typedef boost::parameter::parameters< #{keywords.join(",")} > #{m.parent.name.caps}#{m.name.caps}Params;\n" + + j = 1 + while j <= params.length && j <= boost_max_arity + dummy_args = Array.new(j) { |i| "P#{i} const& p#{i}"} + dummy_names = Array.new(j) { |i| "p#{i}"} + dummy_types = Array.new(j) { |i| "class P#{i}"} + + genl "template <#{dummy_types.join(',')}> #{return_type(m)} #{m.parent.name.lcaps}#{m.name.caps}_(#{dummy_args.join(',')})" + genl "{" + indent { + genl "return #{m.parent.name.lcaps}#{m.name.caps}(#{m.parent.name.caps}#{m.name.caps}Params()(#{dummy_names.join(',')}));" + } + genl "}" + j = j + 1 + end + end + end def define_method (m) - gen "#{return_type(m)} Session::#{m.parent.name.lcaps}#{m.name.caps}(" if (m.content()) params=m.signature + ["const MethodContent& content"] else params=m.signature end - indent { gen params.join(",\n") } - gen "){\n\n" + if (params.empty?) + gen "#{return_type(m)} Session::#{m.parent.name.lcaps}#{m.name.caps}(){\n\n" + else + gen "#{return_type(m)} Session::#{m.parent.name.lcaps}#{m.name.caps}(" + indent { gen params.join(",\n") } + gen "){\n\n" + end indent (2) { gen "return #{return_type(m)}(impl()->send(#{m.body_name}(" params = ["version"] + m.param_names @@ -60,6 +102,17 @@ class SessionGen < CppGen gen "}\n\n" end + def declare_keywords(classes) + #need to assemble a listof all the field names + keywords = classes.collect { |c| c.methods_on(@chassis).collect { |m| m.param_names } }.flatten().uniq() + keywords.each { |k| genl "BOOST_PARAMETER_KEYWORD(keyword, #{k})" } + genl "BOOST_PARAMETER_KEYWORD(keyword, content)" + end + + def declare_class(c) + c.methods_on(@chassis).each { |m| declare_method(m) } + end + def define_class(c) c.methods_on(@chassis).each { |m| define_method(m) } end @@ -68,12 +121,16 @@ class SessionGen < CppGen excludes = ["channel", "connection", "session", "execution"] h_file("qpid/client/#{@classname}.h") { + genl "#define BOOST_PARAMETER_MAX_ARITY 8" + gen <<EOS #include <sstream> +#include <boost/parameter.hpp> #include "qpid/framing/amqp_framing.h" #include "qpid/framing/amqp_structs.h" #include "qpid/framing/ProtocolVersion.h" #include "qpid/framing/MethodContent.h" +#include "qpid/framing/TransferContent.h" #include "qpid/client/ConnectionImpl.h" #include "qpid/client/Response.h" #include "qpid/client/ScopedAssociation.h" @@ -88,6 +145,10 @@ using framing::FieldTable; using framing::MethodContent; using framing::SequenceNumberSet; +EOS + declare_keywords(@amqp.classes.select { |c| !excludes.include?(c.name) }) + genl + gen <<EOS class #{@classname} { ScopedAssociation::shared_ptr assoc; framing::ProtocolVersion version; @@ -103,6 +164,7 @@ public: void close(); Execution& execution() { return impl()->getExecution(); } + typedef framing::TransferContent DefaultContent; EOS indent { @amqp.classes.each { |c| declare_class(c) if !excludes.include?(c.name) } } gen <<EOS diff --git a/cpp/src/qpid/client/ClientChannel.cpp b/cpp/src/qpid/client/ClientChannel.cpp index 1a0fd25bc3..b77840f433 100644 --- a/cpp/src/qpid/client/ClientChannel.cpp +++ b/cpp/src/qpid/client/ClientChannel.cpp @@ -80,7 +80,7 @@ bool Channel::isOpen() const { } void Channel::setQos() { - session.basicQos(0, getPrefetch(), false); + session.basicQos((prefetchCount=getPrefetch(), global=false)); if(isTransactional()) { //I think this is wrong! should only send TxSelect once... session.txSelect(); @@ -92,34 +92,32 @@ void Channel::setPrefetch(uint16_t _prefetch){ setQos(); } -void Channel::declareExchange(Exchange& exchange, bool synch){ - FieldTable args; +void Channel::declareExchange(Exchange& _exchange, bool synch){ ScopedSync s(session, synch); - session.exchangeDeclare(0, exchange.getName(), exchange.getType(), empty, false, false, false, args); + session.exchangeDeclare((exchange=_exchange.getName(), type=_exchange.getType())); } -void Channel::deleteExchange(Exchange& exchange, bool synch){ +void Channel::deleteExchange(Exchange& _exchange, bool synch){ ScopedSync s(session, synch); - session.exchangeDelete(0, exchange.getName(), false); + session.exchangeDelete((exchange=_exchange.getName(), ifUnused=false)); } -void Channel::declareQueue(Queue& queue, bool synch){ - if (queue.getName().empty()) { +void Channel::declareQueue(Queue& _queue, bool synch){ + if (_queue.getName().empty()) { stringstream uniqueName; uniqueName << uniqueId << "-queue-" << ++nameCounter; - queue.setName(uniqueName.str()); + _queue.setName(uniqueName.str()); } - FieldTable args; ScopedSync s(session, synch); - session.queueDeclare(0, queue.getName(), empty, false/*passive*/, queue.isDurable(), - queue.isExclusive(), queue.isAutoDelete(), args); + session.queueDeclare((queue=_queue.getName(), passive=false/*passive*/, durable=_queue.isDurable(), + exclusive=_queue.isExclusive(), autoDelete=_queue.isAutoDelete())); } -void Channel::deleteQueue(Queue& queue, bool ifunused, bool ifempty, bool synch){ +void Channel::deleteQueue(Queue& _queue, bool ifunused, bool ifempty, bool synch){ ScopedSync s(session, synch); - session.queueDelete(0, queue.getName(), ifunused, ifempty); + session.queueDelete((queue=_queue.getName(), ifUnused=ifunused, ifEmpty=ifempty)); } void Channel::bind(const Exchange& exchange, const Queue& queue, const std::string& key, const FieldTable& args, bool synch){ diff --git a/cpp/src/tests/ClientSessionTest.cpp b/cpp/src/tests/ClientSessionTest.cpp index a3d50d0ae9..9f68716104 100644 --- a/cpp/src/tests/ClientSessionTest.cpp +++ b/cpp/src/tests/ClientSessionTest.cpp @@ -50,7 +50,7 @@ class ClientSessionTest : public CppUnit::TestCase { std::string name("my-queue"); std::string alternate("amq.fanout"); - session.queueDeclare(0, name, alternate, false, false, true, true, FieldTable()); + session.queueDeclare((queue=name, alternateExchange=alternate, exclusive=true, autoDelete=true)); TypedResult<QueueQueryResult> result = session.queueQuery(name); CPPUNIT_ASSERT_EQUAL(false, result.get().getDurable()); CPPUNIT_ASSERT_EQUAL(true, result.get().getExclusive()); @@ -59,16 +59,16 @@ class ClientSessionTest : public CppUnit::TestCase void testTransfer() { - std::string queue("my-queue"); + std::string queueName("my-queue"); std::string dest("my-dest"); std::string data("my message"); - session.queueDeclare(0, queue, "", false, false, true, true, FieldTable()); + session.queueDeclare_(queue=queueName, exclusive=true, autoDelete=true); //subcribe to the queue with confirm_mode = 1: - session.messageSubscribe(0, queue, dest, false, 1, 0, false, FieldTable()); + session.messageSubscribe_(queue=queueName, destination=dest, acquireMode=1); //publish a message: - TransferContent content(data); - content.getDeliveryProperties().setRoutingKey("my-queue"); - session.messageTransfer(0, "", 0, 0, content); + TransferContent _content(data); + _content.getDeliveryProperties().setRoutingKey("my-queue"); + session.messageTransfer_(content=_content); //get & test the message: FrameSet::shared_ptr msg = session.get(); CPPUNIT_ASSERT(msg->isA<MessageTransferBody>()); |