Author: aconway
Date: Mon Aug 27 13:39:35 2007
New Revision: 570236

URL: http://svn.apache.org/viewvc?rev=570236&view=rev
Log:

        * src/qpid/framing/FrameDefaultVisitor.h:
        A visitor for all concrete frame body types.

        * src/qpid/broker/SessionState.h: 3 states - closed, active, suspended.

        * src/qpid/broker/SessionAdapter.h, .cpp: Session handler, implements
        session class commands. In progres..    

        * rubygen/templates/MethodBodyDefaultVisitor.rb: 
        A visitor for all method body types.

Added:
    incubator/qpid/trunk/qpid/cpp/rubygen/templates/MethodBodyDefaultVisitor.rb 
  (with props)
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SessionAdapter.cpp   (with 
props)
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SessionAdapter.h   (with 
props)
Modified:
    incubator/qpid/trunk/qpid/cpp/rubygen/cppgen.rb
    incubator/qpid/trunk/qpid/cpp/src/Makefile.am
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SessionState.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SuspendedSessions.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FrameDefaultVisitor.h
    incubator/qpid/trunk/qpid/cpp/src/tests/Session.cpp

Modified: incubator/qpid/trunk/qpid/cpp/rubygen/cppgen.rb
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/rubygen/cppgen.rb?rev=570236&r1=570235&r2=570236&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/rubygen/cppgen.rb (original)
+++ incubator/qpid/trunk/qpid/cpp/rubygen/cppgen.rb Mon Aug 27 13:39:35 2007
@@ -221,5 +221,11 @@
   def public() outdent { genl "public:" } end
   def private() outdent { genl "private:" } end
   def protected() outdent { genl "protected:" } end
+
+  # Returns [namespace, classname, filename]
+  def parse_classname(full_cname)
+    names=full_cname.split("::")
+    return names[0..-2].join('::'), names[-1], names.join("/") 
+  end
 end
 

Added: 
incubator/qpid/trunk/qpid/cpp/rubygen/templates/MethodBodyDefaultVisitor.rb
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/rubygen/templates/MethodBodyDefaultVisitor.rb?rev=570236&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/rubygen/templates/MethodBodyDefaultVisitor.rb 
(added)
+++ incubator/qpid/trunk/qpid/cpp/rubygen/templates/MethodBodyDefaultVisitor.rb 
Mon Aug 27 13:39:35 2007
@@ -0,0 +1,34 @@
+#!/usr/bin/env ruby
+$: << ".."                      # Include .. in load path
+require 'cppgen'
+
+class MethodBodyDefaultVisitorGen < CppGen
+  
+  def initialize(outdir, amqp)
+    super(outdir, amqp)
+    @namespace, @classname, @filename = 
parse_classname("qpid::framing::MethodBodyDefaultVisitor")
+  end
+
+  def generate()
+    h_file(@filename) {
+      include "qpid/framing/MethodBodyConstVisitor"
+      namespace(@namespace) { 
+        genl
+        cpp_class(@classname, "public MethodBodyConstVisitor") {
+          genl "public:"
+          genl "virtual void defaultVisit() = 0;"
+          @amqp.methods_.each { |m|
+            genl "virtual void visit(const #{m.body_name}&);" }
+        }}}
+
+    cpp_file(@filename) {
+      include(@filename)
+      namespace(@namespace) {
+        @amqp.methods_.each { |m|
+          genl "void [EMAIL PROTECTED]::visit(const #{m.body_name}&) { 
defaultVisit(); }"
+        }}}
+  end
+end
+
+MethodBodyDefaultVisitorGen.new(Outdir, Amqp).generate();
+

Propchange: 
incubator/qpid/trunk/qpid/cpp/rubygen/templates/MethodBodyDefaultVisitor.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/qpid/trunk/qpid/cpp/rubygen/templates/MethodBodyDefaultVisitor.rb
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/qpid/trunk/qpid/cpp/src/Makefile.am
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/Makefile.am?rev=570236&r1=570235&r2=570236&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/Makefile.am (original)
+++ incubator/qpid/trunk/qpid/cpp/src/Makefile.am Mon Aug 27 13:39:35 2007
@@ -192,9 +192,11 @@
   qpid/broker/RecoveredEnqueue.cpp \
   qpid/broker/RecoveredDequeue.cpp \
   qpid/broker/Reference.cpp \
-  qpid/broker/Session.h \
+  qpid/broker/SessionState.h \
   qpid/broker/SuspendedSessions.h \
   qpid/broker/SuspendedSessions.cpp \
+  qpid/broker/SessionAdapter.h \
+  qpid/broker/SessionAdapter.cpp \
   qpid/broker/SemanticHandler.cpp \
   qpid/broker/Timer.cpp \
   qpid/broker/TopicExchange.cpp \

Added: 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=570236&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SessionAdapter.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SessionAdapter.cpp Mon Aug 27 
13:39:35 2007
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include "SessionAdapter.h"
+
+namespace qpid {
+namespace broker {
+
+SessionAdapter::SessionAdapter() {
+    // FIXME aconway 2007-08-27: Implement
+}
+
+void  SessionAdapter::visit(const SessionOpenBody&) {
+    // FIXME aconway 2007-08-27: Implement
+}
+
+void  SessionAdapter::visit(const SessionAckBody&) {
+    // FIXME aconway 2007-08-27: Implement
+}
+
+
+void  SessionAdapter::visit(const SessionAttachedBody&) {
+    // FIXME aconway 2007-08-27: Implement
+}
+
+
+void  SessionAdapter::visit(const SessionCloseBody&) {
+    // FIXME aconway 2007-08-27: Implement
+}
+
+
+void  SessionAdapter::visit(const SessionClosedBody&) {
+    // FIXME aconway 2007-08-27: Implement
+}
+
+
+void  SessionAdapter::visit(const SessionDetachedBody&) {
+    // FIXME aconway 2007-08-27: Implement
+}
+
+
+void  SessionAdapter::visit(const SessionFlowBody&) {
+    // FIXME aconway 2007-08-27: Implement
+}
+
+
+void  SessionAdapter::visit(const SessionFlowOkBody&) {
+    // FIXME aconway 2007-08-27: Implement
+}
+
+
+void  SessionAdapter::visit(const SessionHighWaterMarkBody&) {
+    // FIXME aconway 2007-08-27: Implement
+}
+
+
+void  SessionAdapter::visit(const SessionResumeBody&) {
+    // FIXME aconway 2007-08-27: Implement
+}
+
+
+void  SessionAdapter::visit(const SessionSolicitAckBody&) {
+    // FIXME aconway 2007-08-27: Implement
+}
+
+
+void  SessionAdapter::visit(const SessionSuspendBody&) {
+    // FIXME aconway 2007-08-27: Implement
+}
+
+}} // namespace qpid::broker

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SessionAdapter.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SessionAdapter.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SessionAdapter.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SessionAdapter.h?rev=570236&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SessionAdapter.h (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SessionAdapter.h Mon Aug 27 
13:39:35 2007
@@ -0,0 +1,65 @@
+#ifndef QPID_BROKER_SESSIONADAPTER_H
+#define QPID_BROKER_SESSIONADAPTER_H
+
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include "qpid/framing/FrameDefaultVisitor.h"
+#include "qpid/framing/FrameHandler.h"
+#include "qpid/broker/SuspendedSessions.h"
+
+namespace qpid {
+namespace broker {
+
+/**
+ * Session Handler: Handles frames arriving for a session.
+ * Implements AMQP session class commands, forwards other traffic
+ * to the next handler in the chain.
+ */
+class SessionAdapter : public FrameVisitorHandler
+                       
+{
+  public:
+    SessionAdapter(FrameHandler& out, SuspendedSessions&);
+    ~SessionAdapter();
+
+  protected:
+    void visit(const SessionAckBody&);
+    void visit(const SessionAttachedBody&);
+    void visit(const SessionCloseBody&);
+    void visit(const SessionClosedBody&);
+    void visit(const SessionDetachedBody&);
+    void visit(const SessionFlowBody&);
+    void visit(const SessionFlowOkBody&);
+    void visit(const SessionHighWaterMarkBody&);
+    void visit(const SessionOpenBody&);
+    void visit(const SessionResumeBody&);
+    void visit(const SessionSolicitAckBody&);
+    void visit(const SessionSuspendBody&);
+
+  private:
+    SessionState state;
+    SuspendedSessions& suspended;
+    Chain next;
+    FrameHandler& out;
+}} // namespace qpid::broker
+
+#endif  /*!QPID_BROKER_SESSIONADAPTER_H*/

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SessionAdapter.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SessionAdapter.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SessionState.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SessionState.h?rev=570236&r1=570235&r2=570236&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SessionState.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SessionState.h Mon Aug 27 
13:39:35 2007
@@ -10,9 +10,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -33,20 +33,33 @@
 class SessionState
 {
   public:
-    /** Create a new, active session. */
-    SessionState(uint32_t timeoutSeconds)
-        : id(true), active(true), timeout(timeoutSeconds) {}
+    enum State { CLOSED, ACTIVE, SUSPENDED };
+
+    /** Initially in CLOSED state */
+    SessionState() : id(false), state(CLOSED), timeout(0) {}
 
+    /** Make CLOSED session ACTIVE, assigns a new UUID.
+     * [EMAIL PROTECTED] timeout in seconds
+     */
+    void open(u_int32_t timeout_) {
+        state=ACTIVE;  id.generate(); timeout=timeout_;
+    }
+
+    /** Close a session. */
+    void close() { state=CLOSED; id.clear(); timeout=0; }
+
+    State getState() const { return state; }
     const framing::Uuid& getId() const { return id; }
     uint32_t getTimeout() const { return timeout; }
 
-    /** Call SuspendedSessions::resume to re-activate a suspended session. */ 
-    bool isActive() const { return active; }
-
+    bool isOpen() { return state == ACTIVE; }
+    bool isClosed() { return state == CLOSED; }
+    bool isSuspended() { return state == SUSPENDED; }
+    
   private:
   friend class SuspendedSessions;
     framing::Uuid id;
-    bool active;
+    State state;
     uint32_t timeout;
 };
 

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SuspendedSessions.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SuspendedSessions.cpp?rev=570236&r1=570235&r2=570236&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SuspendedSessions.cpp 
(original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/SuspendedSessions.cpp Mon Aug 
27 13:39:35 2007
@@ -31,25 +31,27 @@
 
 void SuspendedSessions::suspend(SessionState& s) {
     Lock l(lock);
-    assert(s.isActive());
-    AbsTime expires(now(), Duration(s.timeout*TIME_SEC));
-    suspended.insert(std::make_pair(expires, s));
-    s.active = false;
+    assert(s.state == SessionState::ACTIVE);
+    if (s.timeout == 0) 
+        s.state = SessionState::CLOSED;
+    else {
+        AbsTime expires(now(), Duration(s.timeout*TIME_SEC));
+        suspended.insert(std::make_pair(expires, s));
+        s.state = SessionState::SUSPENDED;
+    }
 }
 
 SessionState SuspendedSessions::resume(const Uuid& id)
 {
     Lock l(lock);
-    Map::iterator expired = suspended.lower_bound(now());
-    suspended.erase(suspended.begin(), expired);
-
-    Map::iterator resume = std::find_if(
-        suspended.begin(), suspended.end(),
-        bind(&SessionState::getId, bind(&Map::value_type::second, _1))==id);
-    
-    if (resume == suspended.end())
+    Map::iterator notExpired = suspended.lower_bound(now());
+    suspended.erase(suspended.begin(), notExpired);
+    Map::iterator i = suspended.begin();
+    while (i != suspended.end() && i->second.getId() != id)
+        ++i;
+    if (i == suspended.end())
         throw Exception(QPID_MSG("Session timed out or invalid ID: " << id));
-    return resume->second;
+    return i->second;
 }
 
 }} // namespace qpid::broker

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FrameDefaultVisitor.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FrameDefaultVisitor.h?rev=570236&r1=570235&r2=570236&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FrameDefaultVisitor.h 
(original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FrameDefaultVisitor.h Mon 
Aug 27 13:39:35 2007
@@ -23,6 +23,7 @@
 
 #include "qpid/framing/MethodBodyDefaultVisitor.h"
 #include "qpid/framing/AMQBody.h"
+#include "qpid/framing/FrameHandler.h"
 
 namespace qpid {
 namespace framing {
@@ -33,8 +34,8 @@
 class AMQHeartbeatBody;
 
 /**
- * Functor to handle a frame by visiting its content.
- * Combines AMQBodyConstVisitor and MethodBodyDefaultVisitor.
+ * Visitor for all concrete frame body types, combines
+ * AMQBodyConstVisitor and MethodBodyDefaultVisitor.
  * 
  * Derived classes may override visit methods to specify actions.
  * Derived classes must override defaultVisit(), which is called
@@ -47,6 +48,15 @@
     void visit(const AMQContentBody& x) { defaultVisit(); }
     void visit(const AMQHeartbeatBody& x) { defaultVisit(); }
     void visit(const AMQMethodBody& method) { method.accept(*this); }
+};
+
+/**
+ * A FrameHandler that is implemented as a visitor.
+ */
+struct FrameVisitorHandler : public FrameHandler,
+                             protected FrameVisitorHandler
+{
+    void handle(AMQFrame& f) { f.accept(*this); }
 };
 
 

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/Session.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/Session.cpp?rev=570236&r1=570235&r2=570236&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/Session.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/Session.cpp Mon Aug 27 13:39:35 2007
@@ -29,24 +29,28 @@
 BOOST_AUTO_TEST_CASE(testSuspendedSessions) {
     SuspendedSessions suspended;
 
-    SessionState s(0);          // 0 timeout
-    BOOST_CHECK(s.isActive());
+    SessionState s;
+    BOOST_CHECK_EQUAL(s.getState(), SessionState::CLOSED);
+    s.open(0);
+    BOOST_CHECK_EQUAL(s.getState(), SessionState::ACTIVE);
+    BOOST_CHECK(!s.getId().empty());
     suspended.suspend(s);
-    BOOST_CHECK(!s.isActive());
+    BOOST_CHECK(s.getState() == SessionState::CLOSED);
     try {
         s = suspended.resume(s.getId());
         BOOST_FAIL("Expected session to be timed out.");
     } catch (...) {}
 
-    s = SessionState(1);        // New session, 1 sec timeout.
+    s.close();
+    s.open(1);        // New session, 1 sec timeout.
     try {
         suspended.resume(s.getId());
         BOOST_FAIL("Expeced exception: non-existent session.");
     } catch (...) {}
     suspended.suspend(s);
-    BOOST_CHECK(!s.isActive());
+    BOOST_CHECK(s.getState() == SessionState::SUSPENDED);
     s = suspended.resume(s.getId());
-    BOOST_CHECK(s.isActive());
+    BOOST_CHECK(s.getState() == SessionState::ACTIVE);
 
     suspended.suspend(s);       // Real timeout
     sleep(2);


Reply via email to