summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2008-04-03 19:57:14 +0000
committerAlan Conway <aconway@apache.org>2008-04-03 19:57:14 +0000
commitb1cc93b489819453f07a84f149f0ba44ab6481bc (patch)
treebb7b9c8e51273a3d9a7b18362098a352121b7091
parentcb076892e53f1634d60fe31bca9e0438054bf419 (diff)
downloadqpid-python-b1cc93b489819453f07a84f149f0ba44ab6481bc.tar.gz
rubygen/0-10/exceptions.rb:
- generate exception classes for each error code, e.g. InvalidArgumentException rubygen/0-10/specification.rb - extracted specification_fwd.h from specification.h, contains consts enums, typedefs and forward declarations of classes. src/qpid/amqp_0_10/Map.cpp, src/qpid/broker/SessionAdapter.cpp: - updated to use exceptions.h git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@644461 13f79535-47bb-0310-9956-ffa450edef68
-rwxr-xr-xqpid/cpp/rubygen/0-10/exceptions.rb35
-rwxr-xr-xqpid/cpp/rubygen/0-10/specification.rb50
-rw-r--r--qpid/cpp/src/qpid/amqp_0_10/Map.cpp4
-rw-r--r--qpid/cpp/src/qpid/broker/SessionAdapter.cpp5
4 files changed, 78 insertions, 16 deletions
diff --git a/qpid/cpp/rubygen/0-10/exceptions.rb b/qpid/cpp/rubygen/0-10/exceptions.rb
new file mode 100755
index 0000000000..4f7080690f
--- /dev/null
+++ b/qpid/cpp/rubygen/0-10/exceptions.rb
@@ -0,0 +1,35 @@
+#!/usr/bin/env ruby
+$: << ".." # Include .. in load path
+require 'cppgen'
+
+class GenExceptions < CppGen
+
+ def initialize(outdir, amqp)
+ super(outdir, amqp)
+ @ns="qpid::amqp_#{@amqp.version.bars}"
+ @dir="qpid/amqp_#{@amqp.version.bars}"
+ end
+
+ def gen_exceptions()
+ h_file("#{@dir}/exceptions") {
+ include "qpid/Exception"
+ include "specification.h"
+ namespace("#{@ns}") {
+ @amqp.class_("execution").domain("error-code").enum.choices.each { |c|
+ name=c.name.typename+"Exception"
+ struct(name, "public SessionException") {
+ genl "#{name}(const std::string& msg=std::string()) : SessionException(execution::#{c.name.shout}, msg) {}"
+ }
+ }
+ }
+ }
+ end
+
+ def generate()
+ gen_exceptions
+ end
+end
+
+GenExceptions.new($outdir, $amqp).generate();
+
+
diff --git a/qpid/cpp/rubygen/0-10/specification.rb b/qpid/cpp/rubygen/0-10/specification.rb
index 95eb8f5f5b..549a51fba0 100755
--- a/qpid/cpp/rubygen/0-10/specification.rb
+++ b/qpid/cpp/rubygen/0-10/specification.rb
@@ -112,31 +112,56 @@ class Specification < CppGen
# Types that must be generated early because they are used by other types.
def pregenerate?(x) not @amqp.used_by[x.fqname].empty?; end
- # Generate the log
+ def pregenerate_class?(c)
+ c.children.select{ |t| (t.is_a? AmqpStruct or t.is_a? AmqpDomain) and pregenerate? t}
+ end
+
+ # Typedefs, enums and forward declarations for classes.
+ def gen_specification_fwd()
+ h_file("#{@dir}/specification_fwd") {
+ include "#{@dir}/built_in_types"
+ namespace(@ns) {
+ # Top level
+ @amqp.domains.each { |d|
+ # segment-type and track are are built in
+ domain_h d unless ["track","segment-type"].include?(d.name)
+ }
+ # Domains/structs that must be generated early because they are used by
+ # other definitions:
+ @amqp.classes.select{ |c| pregenerate_class?(c) }.each { |c|
+ namespace(c.nsname) {
+ c.collect_all(AmqpDomain).each { |d| domain_h d if pregenerate? d }
+ c.collect_all(AmqpStruct).each { |s| genl "class #{s.classname};" if pregenerate? s }
+ }
+ }
+ # Now dependent domains/structs and actions
+ each_class_ns { |c|
+ class_h c
+ c.collect_all(AmqpDomain).each { |d| domain_h d unless pregenerate? d}
+ c.collect_all(AmqpStruct).each { |s| genl "class #{s.classname};" unless pregenerate? s }
+ c.collect_all(AmqpAction).each { |a| genl "class #{a.classname};" unless pregenerate? a }
+ }
+ }
+ }
+ end
+
+ # Generate the specification files
def gen_specification()
h_file("#{@dir}/specification") {
- include "#{@dir}/built_in_types"
+ include "#{@dir}/specification_fwd"
include "#{@dir}/complex_types"
include "#{@dir}/Map.h"
include "<boost/call_traits.hpp>"
include "<iosfwd>"
genl "using boost::call_traits;"
namespace(@ns) {
- # Top level
- @amqp.domains.each { |d|
- # segment-type and track are are built in
- domain_h d unless ["track","segment-type"].include?(d.name)
- }
- # Domains and structs that must be generated early because
+ # Structs that must be generated early because
# they are used by other definitions:
each_class_ns { |c|
- class_h c
- c.collect_all(AmqpDomain).each { |d| domain_h d if pregenerate? d }
- c.collect_all(AmqpStruct).each { |s| struct_h s if pregenerate? s }
+ c.collect_all(AmqpStruct).each { |s| struct_h s if pregenerate? s }
}
# Now dependent domains/structs and actions
each_class_ns { |c|
- c.collect_all(AmqpDomain).each { |d| domain_h d unless pregenerate? d}
c.collect_all(AmqpStruct).each { |s| struct_h s unless pregenerate? s}
c.collect_all(AmqpAction).each { |a| action_h a }
}
@@ -270,6 +295,7 @@ class Specification < CppGen
end
def generate
+ gen_specification_fwd
gen_specification
gen_proxy
gen_visitable("Command", @amqp.collect_all(AmqpCommand))
diff --git a/qpid/cpp/src/qpid/amqp_0_10/Map.cpp b/qpid/cpp/src/qpid/amqp_0_10/Map.cpp
index 480b439e40..eecd3eed7d 100644
--- a/qpid/cpp/src/qpid/amqp_0_10/Map.cpp
+++ b/qpid/cpp/src/qpid/amqp_0_10/Map.cpp
@@ -18,7 +18,7 @@
* under the License.
*
*/
-#include "qpid/amqp_0_10/specification.h" // for error constants.
+#include "qpid/amqp_0_10/exceptions.h"
#include "Map.h"
#include <ostream>
@@ -63,7 +63,7 @@ uint32_t Map::contentSize() const {
}
void Map::throwInvalidArg() {
- throw SessionException(execution::INVALID_ARGUMENT, "Invalid map encoding");
+ throw InvalidArgumentException("Invalid map encoding");
}
}} // namespace qpid::amqp_0_10
diff --git a/qpid/cpp/src/qpid/broker/SessionAdapter.cpp b/qpid/cpp/src/qpid/broker/SessionAdapter.cpp
index 3daf15f269..497f381807 100644
--- a/qpid/cpp/src/qpid/broker/SessionAdapter.cpp
+++ b/qpid/cpp/src/qpid/broker/SessionAdapter.cpp
@@ -24,6 +24,7 @@
#include "qpid/framing/reply_exceptions.h"
#include "qpid/framing/constants.h"
#include "qpid/log/Statement.h"
+#include "qpid/amqp_0_10/exceptions.h"
#include <boost/format.hpp>
#include <boost/cast.hpp>
#include <boost/bind.hpp>
@@ -574,11 +575,11 @@ void SessionAdapter::DtxHandlerImpl::setTimeout(const Xid010& xid,
Queue::shared_ptr SessionAdapter::HandlerHelper::getQueue(const string& name) const {
Queue::shared_ptr queue;
if (name.empty()) {
- throw SessionException(531, QPID_MSG("No queue name specified."));
+ throw amqp_0_10::IllegalArgumentException(QPID_MSG("No queue name specified."));
} else {
queue = session.getBroker().getQueues().find(name);
if (!queue)
- throw NotFoundException(QPID_MSG("Queue not found: "<<name));
+ throw amqp_0_10::NotFoundException(QPID_MSG("Queue not found: "<<name));
}
return queue;
}