qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject svn commit: r580440 - in /incubator/qpid/trunk/qpid/cpp/src/qpid/client: Completion.h Connection.cpp Connection.h ConnectionImpl.cpp ConnectionImpl.h Response.h SessionCore.cpp SessionCore.h TypedResult.h
Date Fri, 28 Sep 2007 17:53:17 GMT
Author: aconway
Date: Fri Sep 28 10:53:16 2007
New Revision: 580440

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

Ensure no danbling pointers in client API:
 - Session -shared_ptr-> SessionCore -shared_ptr-> ConnectionImpl
 - Connection -shared_ptr-> ConnectionImpl
 - ConnectionImpl -weak_ptr-> SessionCore

Modified:
    incubator/qpid/trunk/qpid/cpp/src/qpid/client/Completion.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connection.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connection.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionImpl.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionImpl.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/client/Response.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/client/SessionCore.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/client/SessionCore.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/client/TypedResult.h

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/client/Completion.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/Completion.h?rev=580440&r1=580439&r2=580440&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/Completion.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/Completion.h Fri Sep 28 10:53:16 2007
@@ -33,10 +33,10 @@
 {
 protected:
     Future future;
-    SessionCore::shared_ptr session;
+    shared_ptr<SessionCore> session;
 
 public:
-    Completion(Future f, SessionCore::shared_ptr s) : future(f), session(s) {}
+    Completion(Future f, shared_ptr<SessionCore> s) : future(f), session(s) {}
 
     void sync()
     {

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connection.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connection.cpp?rev=580440&r1=580439&r2=580440&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connection.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connection.cpp Fri Sep 28 10:53:16 2007
@@ -72,7 +72,7 @@
 
 Session Connection::newSession(uint32_t detachedLifetime) {
     shared_ptr<SessionCore> core(
-        new SessionCore(*impl, ++channelIdCounter, max_frame_size));
+        new SessionCore(impl, ++channelIdCounter, max_frame_size));
     impl->addSession(core);
     core->open(detachedLifetime);
     return Session(core);
@@ -82,7 +82,7 @@
     shared_ptr<SessionCore> core=session.impl;
     core->setChannel(++channelIdCounter);
     impl->addSession(core);
-    core->resume(*impl);
+    core->resume(impl);
 }
 
 void Connection::close() {

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connection.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connection.h?rev=580440&r1=580439&r2=580440&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connection.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connection.h Fri Sep 28 10:53:16 2007
@@ -57,7 +57,7 @@
     framing::ChannelId channelIdCounter;
     framing::ProtocolVersion version;
     const uint32_t max_frame_size;
-    ConnectionImpl::shared_ptr impl;
+    shared_ptr<ConnectionImpl> impl;
     bool isOpen;
     bool debug;
     

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=580440&r1=580439&r2=580440&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionImpl.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionImpl.cpp Fri Sep 28 10:53:16 2007
@@ -45,8 +45,8 @@
 void ConnectionImpl::addSession(const boost::shared_ptr<SessionCore>& session)
 {
     Mutex::ScopedLock l(lock);
-    boost::shared_ptr<SessionCore>& s = sessions[session->getChannel()];
-    if (s)
+    boost::weak_ptr<SessionCore>& s = sessions[session->getChannel()];
+    if (s.lock())
         throw ChannelBusyException();
     s = session;
 }
@@ -61,7 +61,7 @@
     boost::shared_ptr<SessionCore> s;
     {
         Mutex::ScopedLock l(lock);
-        s = sessions[frame.getChannel()];
+        s = sessions[frame.getChannel()].lock();
     }
     if (!s)
         throw ChannelErrorException();
@@ -120,7 +120,9 @@
 {
     Mutex::ScopedLock l(lock);
     for (SessionMap::iterator i = sessions.begin(); i != sessions.end(); i++) {
-        i->second->closed(code, text);
+        boost::shared_ptr<SessionCore> s = i->second.lock();
+        if (s)
+            s->closed(code, text);
     }
     sessions.clear();
     isClosed = true;

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionImpl.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionImpl.h?rev=580440&r1=580439&r2=580440&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionImpl.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionImpl.h Fri Sep 28 10:53:16 2007
@@ -24,6 +24,7 @@
 
 #include <map>
 #include <boost/shared_ptr.hpp>
+#include <boost/weak_ptr.hpp>
 #include "qpid/framing/FrameHandler.h"
 #include "qpid/sys/Mutex.h"
 #include "qpid/sys/ShutdownHandler.h"
@@ -41,7 +42,7 @@
                        public sys::ShutdownHandler
 
 {
-    typedef std::map<uint16_t, boost::shared_ptr<SessionCore> > SessionMap;
+    typedef std::map<uint16_t, boost::weak_ptr<SessionCore> > SessionMap;
     SessionMap sessions; 
     ConnectionHandler handler;
     boost::shared_ptr<Connector> connector;

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/client/Response.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/Response.h?rev=580440&r1=580439&r2=580440&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/Response.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/Response.h Fri Sep 28 10:53:16 2007
@@ -32,7 +32,7 @@
 class Response : public Completion
 {
 public:
-    Response(Future f, SessionCore::shared_ptr s) : Completion(f, s) {}
+    Response(Future f, shared_ptr<SessionCore> s) : Completion(f, s) {}
 
     template <class T> T& as() 
     {

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/client/SessionCore.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/SessionCore.cpp?rev=580440&r1=580439&r2=580440&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/SessionCore.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/SessionCore.cpp Fri Sep 28 10:53:16 2007
@@ -20,22 +20,25 @@
  */
 
 #include "SessionCore.h"
-#include "qpid/framing/constants.h"
 #include "Future.h"
 #include "FutureResponse.h"
 #include "FutureResult.h"
+#include "ConnectionImpl.h"
+
+#include "qpid/framing/constants.h"
 
 #include <boost/bind.hpp>
 
 using namespace qpid::client;
 using namespace qpid::framing;
 
-SessionCore::SessionCore(FrameHandler& out_, uint16_t ch, uint64_t maxFrameSize)
-    : channel(ch), l2(*this), l3(maxFrameSize), uuid(false), sync(false)
+SessionCore::SessionCore(shared_ptr<ConnectionImpl> conn, uint16_t ch, uint64_t maxFrameSize)
+    : connection(conn), channel(ch), l2(*this), l3(maxFrameSize),
+      uuid(false), sync(false)
 {
     l2.next = &l3;
     l3.out = &out;
-    out.next = &out_;
+    out.next = connection.get();
 }
 
 SessionCore::~SessionCore() {}
@@ -108,8 +111,9 @@
     l2.open(detachedLifetime);
 }
 
-void SessionCore::resume(FrameHandler& out_) {
-    out.next = &out_;
+void SessionCore::resume(shared_ptr<ConnectionImpl> conn) {
+    connection = conn;
+    out.next = connection.get();
     l2.resume();
 }
 

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/client/SessionCore.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/SessionCore.h?rev=580440&r1=580439&r2=580440&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/SessionCore.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/SessionCore.h Fri Sep 28 10:53:16 2007
@@ -36,6 +36,7 @@
 namespace client {
 
 class Future;
+class ConnectionImpl;
 
 /**
  * Session implementation, sets up handler chains.
@@ -50,6 +51,7 @@
         std::string text;
     };
 
+    shared_ptr<ConnectionImpl> connection;
     uint16_t channel;
     SessionHandler l2;
     ExecutionHandler l3;
@@ -62,9 +64,7 @@
     void handleOut(framing::AMQFrame& frame);
 
   public:
-    typedef shared_ptr<SessionCore> shared_ptr;
-    
-    SessionCore(framing::FrameHandler& out, uint16_t channel, uint64_t maxFrameSize);
+    SessionCore(shared_ptr<ConnectionImpl>, uint16_t channel, uint64_t maxFrameSize);
     ~SessionCore();
 
     framing::FrameSet::shared_ptr get();
@@ -83,7 +83,7 @@
     /** Closed by peer */
     void closed(uint16_t code, const std::string& text);
 
-    void resume(framing::FrameHandler& out);
+    void resume(shared_ptr<ConnectionImpl>);
     void suspend();
 
     void setSync(bool);

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/client/TypedResult.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/TypedResult.h?rev=580440&r1=580439&r2=580440&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/TypedResult.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/TypedResult.h Fri Sep 28 10:53:16 2007
@@ -33,7 +33,7 @@
     bool decoded;
 
 public:
-    TypedResult(Future f, SessionCore::shared_ptr s) : Completion(f, s), decoded(false) {}
+    TypedResult(Future f, shared_ptr<SessionCore> s) : Completion(f, s), decoded(false)
{}
 
     T& get() 
     {



Mime
View raw message