Author: aconway
Date: Tue Sep  9 07:06:07 2008
New Revision: 693465

URL: http://svn.apache.org/viewvc?rev=693465&view=rev
Log:
Generate c++ enum types for AMQP enums in framing/enum.h.
Modified enum scheme to avoid name clashes: namespace amqp_class { EnumName { 
ENUM_NAME_X=1, ENUM_NAME_X=2 ...}};

Modified:
    incubator/qpid/trunk/qpid/cpp/rubygen/framing.0-10/constants.rb
    incubator/qpid/trunk/qpid/cpp/src/qpid/SessionState.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/SessionHandler.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/ConnectionHandler.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SessionAdapter.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionImpl.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/client/SessionImpl.cpp

Modified: incubator/qpid/trunk/qpid/cpp/rubygen/framing.0-10/constants.rb
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/rubygen/framing.0-10/constants.rb?rev=693465&r1=693464&r2=693465&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/rubygen/framing.0-10/constants.rb (original)
+++ incubator/qpid/trunk/qpid/cpp/rubygen/framing.0-10/constants.rb Tue Sep  9 
07:06:07 2008
@@ -30,7 +30,8 @@
 
   def constants_h()
     h_file("[EMAIL PROTECTED]/constants") {
-      namespace(@namespace) { 
+      namespace(@namespace) {
+        # Constants for class/method names.
         scope("enum AmqpConstant {","};") {
           l=[]
           l.concat @amqp.constants.map { |c| "#{c.name.shout}=#{c.value}" }
@@ -41,35 +42,42 @@
           }
           genl l.join(",\n")
         }
-        define_constants_for(@amqp.domain("segment-type").enum)
-        namespace("execution") {
-          
define_constants_for(@amqp.class_("execution").domain("error-code").enum)
-        }
-        namespace("connection") {
-          
define_constants_for(@amqp.class_("connection").domain("close-code").enum)
-        }
-        namespace("session") {
-          
define_constants_for(@amqp.class_("session").domain("detach-code").enum)
+      }
+    }
+  end
+
+  def enum_h()
+    h_file("[EMAIL PROTECTED]/enum") {
+      # Constants for enum domains.
+      namespace(@namespace) {
+        @amqp.domains.each { |d| define_enum(d.enum) if d.enum }
+        @amqp.classes.each { |c|
+          enums=c.collect_all(AmqpEnum)
+          if !enums.empty? then
+            namespace(c.nsname) { enums.each { |e| define_enum(e) } }
+          end
         }
-        define_constants_for(@amqp.class_("dtx").domain("xa-status").enum)     
   
       }
     }
   end
 
-  def define_constants_for(enum)
-    scope("enum #{enum.parent.name.caps} {","};") {
-      genl enum.choices.collect { |c| "#{c.name.shout}=#{c.value}" 
}.join(",\n")
+  def define_enum(enum)
+    # Generated like this: enum containing_class::Foo { FOO_X, FOO_Y; }
+    name="#{enum.parent.name.caps}"
+    prefix=enum.parent.name.shout+"_" 
+    scope("enum #{name} {","};") {
+      genl enum.choices.collect { |c| "#{prefix}#{c.name.shout}=#{c.value}" 
}.join(",\n")
     }
   end
 
   def define_exception(c, base, package)
-      name=c.name.caps+"Exception"
-      genl
-      doxygen_comment { genl c.doc }
-      struct(c.name.caps+"Exception", base) {
+    name=c.name.caps+"Exception"
+    genl
+    doxygen_comment { genl c.doc }
+    struct(c.name.caps+"Exception", base) {
       genl "std::string getPrefix() const { return \"#{c.name}\"; }"
       genl "#{c.name.caps}Exception(const std::string& msg=std::string()) : 
#{base}(#{c.value}, \"\"+msg) {}"
-      }
+    }
   end
 
   def define_exceptions_for(class_name, domain_name, base)
@@ -119,6 +127,7 @@
 
   def generate()
     constants_h
+    enum_h
     reply_exceptions_h
     reply_exceptions_cpp
   end

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/SessionState.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/SessionState.cpp?rev=693465&r1=693464&r2=693465&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/SessionState.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/SessionState.cpp Tue Sep  9 07:06:07 
2008
@@ -22,6 +22,7 @@
 #include "SessionState.h"
 #include "qpid/framing/reply_exceptions.h"
 #include "qpid/framing/AMQMethodBody.h"
+#include "qpid/framing/enum.h"
 #include "qpid/log/Statement.h"
 #include <boost/bind.hpp>
 #include <numeric>
@@ -37,10 +38,10 @@
 
 namespace {
 bool isControl(const AMQFrame& f) {
-    return f.getMethod() && f.getMethod()->type() == framing::CONTROL;
+    return f.getMethod() && f.getMethod()->type() == 
framing::SEGMENT_TYPE_CONTROL;
 }
 bool isCommand(const AMQFrame& f) {
-    return f.getMethod() && f.getMethod()->type() == framing::COMMAND;
+    return f.getMethod() && f.getMethod()->type() == 
framing::SEGMENT_TYPE_COMMAND;
 }
 } // namespace
 

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/SessionHandler.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/SessionHandler.cpp?rev=693465&r1=693464&r2=693465&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/SessionHandler.cpp 
(original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/SessionHandler.cpp Tue Sep 
 9 07:06:07 2008
@@ -23,6 +23,7 @@
 #include "qpid/SessionState.h"
 #include "qpid/framing/reply_exceptions.h"
 #include "qpid/framing/AllInvoker.h"
+#include "qpid/framing/enum.h"
 #include "qpid/log/Statement.h"
 
 
@@ -92,16 +93,16 @@
     }
     catch(const std::exception& e) {
         QPID_LOG(error, "Unexpected exception: " << e.what());
-        connectionException(connection::FRAMING_ERROR, e.what());
+        connectionException(connection::CLOSE_CODE_FRAMING_ERROR, e.what());
     }
 }
 
 namespace {
 bool isControl(const AMQFrame& f) {
-    return f.getMethod() && f.getMethod()->type() == framing::CONTROL;
+    return f.getMethod() && f.getMethod()->type() == 
framing::SEGMENT_TYPE_CONTROL;
 }
 bool isCommand(const AMQFrame& f) {
-    return f.getMethod() && f.getMethod()->type() == framing::COMMAND;
+    return f.getMethod() && f.getMethod()->type() == 
framing::SEGMENT_TYPE_COMMAND;
 }
 } // namespace
 
@@ -146,14 +147,14 @@
 
 void SessionHandler::detach(const std::string& name) {
     checkName(name);
-    peer.detached(name, session::NORMAL);
+    peer.detached(name, session::DETACH_CODE_NORMAL);
     handleDetach();
 }
 
 void SessionHandler::detached(const std::string& name, uint8_t code) {
     checkName(name);
     ignoring = false;
-    if (code != session::NORMAL)
+    if (code != session::DETACH_CODE_NORMAL)
         channelException(code, "session.detached from peer.");
     else {
         handleDetach();

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/ConnectionHandler.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/ConnectionHandler.cpp?rev=693465&r1=693464&r2=693465&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/ConnectionHandler.cpp 
(original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/ConnectionHandler.cpp Tue Sep 
 9 07:06:07 2008
@@ -26,7 +26,7 @@
 #include "Connection.h"
 #include "qpid/framing/ClientInvoker.h"
 #include "qpid/framing/ServerInvoker.h"
-#include "qpid/framing/constants.h"
+#include "qpid/framing/enum.h"
 #include "qpid/log/Statement.h"
 
 using namespace qpid;
@@ -125,7 +125,7 @@
         QPID_LOG(warning, "Client closed connection with " << replyCode << ": 
" << replyText);
     }
 
-    if (replyCode == framing::connection::CONNECTION_FORCED)
+    if (replyCode == framing::connection::CLOSE_CODE_CONNECTION_FORCED)
         connection.notifyConnectionForced(replyText);
 
     client.closeOk();

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=693465&r1=693464&r2=693465&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SessionAdapter.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SessionAdapter.cpp Tue Sep  9 
07:06:07 2008
@@ -22,7 +22,7 @@
 #include "Queue.h"
 #include "qpid/Exception.h"
 #include "qpid/framing/reply_exceptions.h"
-#include "qpid/framing/constants.h"
+#include "qpid/framing/enum.h"
 #include "qpid/log/Statement.h"
 #include "qpid/amqp_0_10/exceptions.h"
 #include "qpid/framing/SequenceSet.h"
@@ -35,6 +35,7 @@
 
 using namespace qpid;
 using namespace qpid::framing;
+using namespace qpid::framing::dtx;
 
 typedef std::vector<Queue::shared_ptr> QueueVector;
 
@@ -595,7 +596,7 @@
             if (suspend) {
                 throw CommandInvalidException(QPID_MSG("End and suspend cannot 
both be set."));
             } else {
-                return XaResult(XA_RBROLLBACK);
+                return XaResult(XA_STATUS_XA_RBROLLBACK);
             }
         } else {
             if (suspend) {
@@ -603,10 +604,10 @@
             } else {
                 state.endDtx(convert(xid), false);
             }
-            return XaResult(XA_OK);
+            return XaResult(XA_STATUS_XA_OK);
         }
     } catch (const DtxTimeoutException& e) {
-        return XaResult(XA_RBTIMEOUT);        
+        return XaResult(XA_STATUS_XA_RBTIMEOUT);        
     }
 }
 
@@ -623,9 +624,9 @@
         } else {
             state.startDtx(convert(xid), getBroker().getDtxManager(), join);
         }
-        return XaResult(XA_OK);
+        return XaResult(XA_STATUS_XA_OK);
     } catch (const DtxTimeoutException& e) {
-        return XaResult(XA_RBTIMEOUT);        
+        return XaResult(XA_STATUS_XA_RBTIMEOUT);        
     }
 }
 
@@ -633,9 +634,9 @@
 {
     try {
         bool ok = getBroker().getDtxManager().prepare(convert(xid));
-        return XaResult(ok ? XA_OK : XA_RBROLLBACK);
+        return XaResult(ok ? XA_STATUS_XA_OK : XA_STATUS_XA_RBROLLBACK);
     } catch (const DtxTimeoutException& e) {
-        return XaResult(XA_RBTIMEOUT);        
+        return XaResult(XA_STATUS_XA_RBTIMEOUT);        
     }
 }
 
@@ -644,9 +645,9 @@
 {
     try {
         bool ok = getBroker().getDtxManager().commit(convert(xid), onePhase);
-        return XaResult(ok ? XA_OK : XA_RBROLLBACK);
+        return XaResult(ok ? XA_STATUS_XA_OK : XA_STATUS_XA_RBROLLBACK);
     } catch (const DtxTimeoutException& e) {
-        return XaResult(XA_RBTIMEOUT);        
+        return XaResult(XA_STATUS_XA_RBTIMEOUT);        
     }
 }
 
@@ -655,9 +656,9 @@
 {
     try {
         getBroker().getDtxManager().rollback(convert(xid));
-        return XaResult(XA_OK);
+        return XaResult(XA_STATUS_XA_OK);
     } catch (const DtxTimeoutException& e) {
-        return XaResult(XA_RBTIMEOUT);        
+        return XaResult(XA_STATUS_XA_RBTIMEOUT);        
     }
 }
 

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionImpl.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionImpl.cpp?rev=693465&r1=693464&r2=693465&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionImpl.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionImpl.cpp Tue Sep  9 
07:06:07 2008
@@ -24,7 +24,7 @@
 #include "SessionImpl.h"
 
 #include "qpid/log/Statement.h"
-#include "qpid/framing/constants.h"
+#include "qpid/framing/enum.h"
 #include "qpid/framing/reply_exceptions.h"
 
 #include <boost/bind.hpp>
@@ -32,6 +32,7 @@
 
 using namespace qpid::client;
 using namespace qpid::framing;
+using namespace qpid::framing::connection;
 using namespace qpid::sys;
 
 using namespace qpid::framing::connection;//for connection error codes
@@ -46,7 +47,7 @@
     handler.in = boost::bind(&ConnectionImpl::incoming, this, _1);
     handler.out = boost::bind(&Connector::send, boost::ref(connector), _1);
     handler.onClose = boost::bind(&ConnectionImpl::closed, this,
-                                  NORMAL, std::string());
+                                  CLOSE_CODE_NORMAL, std::string());
     connector->setInputHandler(&handler);
     connector->setShutdownHandler(this);
 
@@ -115,7 +116,7 @@
 {
     if (!handler.isOpen()) return;
     handler.close();
-    closed(NORMAL, "Closed by client");
+    closed(CLOSE_CODE_NORMAL, "Closed by client");
 }
 
 
@@ -139,10 +140,10 @@
 void ConnectionImpl::shutdown() {
     Mutex::ScopedLock l(lock);
     // FIXME aconway 2008-06-06: exception use, connection-forced is incorrect 
here.
-    setException(new ConnectionException(CONNECTION_FORCED, CONN_CLOSED));
+    setException(new ConnectionException(CLOSE_CODE_CONNECTION_FORCED, 
CONN_CLOSED));
     if (handler.isClosed()) return;
     handler.fail(CONN_CLOSED);
-    closeInternal(boost::bind(&SessionImpl::connectionBroke, _1, 
CONNECTION_FORCED, CONN_CLOSED));
+    closeInternal(boost::bind(&SessionImpl::connectionBroke, _1, 
CLOSE_CODE_CONNECTION_FORCED, CONN_CLOSED));
 }
 
 void ConnectionImpl::erase(uint16_t ch) {

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/client/SessionImpl.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/SessionImpl.cpp?rev=693465&r1=693464&r2=693465&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/SessionImpl.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/SessionImpl.cpp Tue Sep  9 
07:06:07 2008
@@ -26,7 +26,7 @@
 
 #include "qpid/framing/all_method_bodies.h"
 #include "qpid/framing/ClientInvoker.h"
-#include "qpid/framing/constants.h"
+#include "qpid/framing/enum.h"
 #include "qpid/framing/FrameSet.h"
 #include "qpid/framing/MethodContent.h"
 #include "qpid/framing/SequenceSet.h"
@@ -41,7 +41,7 @@
 namespace client {
 
 using namespace qpid::framing;
-using namespace qpid::framing::session;//for detach codes
+using namespace qpid::framing::session; //for detach codes
 
 typedef sys::Monitor::ScopedLock  Lock;
 typedef sys::Monitor::ScopedUnlock  UnLock;
@@ -52,7 +52,7 @@
                          shared_ptr<ConnectionImpl> conn,
                          uint16_t ch, uint64_t _maxFrameSize)
     : error(OK),
-      code(NORMAL),
+      code(DETACH_CODE_NORMAL),
       text(EMPTY),
       state(INACTIVE),
       detachedLifetime(0),


Reply via email to