Author: aconway
Date: Thu Apr  3 12:57:14 2008
New Revision: 644461

URL: http://svn.apache.org/viewvc?rev=644461&view=rev
Log:
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

Added:
    incubator/qpid/trunk/qpid/cpp/rubygen/0-10/exceptions.rb   (with props)
Modified:
    incubator/qpid/trunk/qpid/cpp/rubygen/0-10/specification.rb
    incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Map.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SessionAdapter.cpp

Added: incubator/qpid/trunk/qpid/cpp/rubygen/0-10/exceptions.rb
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/rubygen/0-10/exceptions.rb?rev=644461&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/rubygen/0-10/exceptions.rb (added)
+++ incubator/qpid/trunk/qpid/cpp/rubygen/0-10/exceptions.rb Thu Apr  3 
12:57:14 2008
@@ -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::[EMAIL PROTECTED]"
+    @dir="qpid/[EMAIL PROTECTED]"
+  end
+
+  def gen_exceptions()
+    h_file("[EMAIL PROTECTED]/exceptions") { 
+      include "qpid/Exception"
+      include "specification.h"
+      namespace("[EMAIL PROTECTED]") { 
+        @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();
+
+

Propchange: incubator/qpid/trunk/qpid/cpp/rubygen/0-10/exceptions.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/rubygen/0-10/exceptions.rb
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/qpid/trunk/qpid/cpp/rubygen/0-10/specification.rb
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/rubygen/0-10/specification.rb?rev=644461&r1=644460&r2=644461&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/rubygen/0-10/specification.rb (original)
+++ incubator/qpid/trunk/qpid/cpp/rubygen/0-10/specification.rb Thu Apr  3 
12:57:14 2008
@@ -112,31 +112,56 @@
   # 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("[EMAIL PROTECTED]/specification_fwd") { 
+      include "[EMAIL PROTECTED]/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("[EMAIL PROTECTED]/specification") {
-      include "[EMAIL PROTECTED]/built_in_types"
+      include "[EMAIL PROTECTED]/specification_fwd"
       include "[EMAIL PROTECTED]/complex_types"
       include "[EMAIL PROTECTED]/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 @@
   end
 
   def generate
+    gen_specification_fwd
     gen_specification
     gen_proxy
     gen_visitable("Command", @amqp.collect_all(AmqpCommand))

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Map.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Map.cpp?rev=644461&r1=644460&r2=644461&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Map.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Map.cpp Thu Apr  3 
12:57:14 2008
@@ -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 @@
 }
 
 void Map::throwInvalidArg() {
-    throw SessionException(execution::INVALID_ARGUMENT, "Invalid map 
encoding");
+    throw InvalidArgumentException("Invalid map encoding");
 }
 
 }} // namespace qpid::amqp_0_10

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SessionAdapter.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SessionAdapter.cpp?rev=644461&r1=644460&r2=644461&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SessionAdapter.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SessionAdapter.cpp Thu Apr  3 
12:57:14 2008
@@ -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 @@
 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;
 }


Reply via email to