etch-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vei...@apache.org
Subject svn commit: r1578873 - in /etch/trunk/binding-cpp: compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/ runtime/include/support/ runtime/include/transport/ runtime/src/main/support/ runtime/src/main/transport/ runtime/src/test/support/ ru...
Date Tue, 18 Mar 2014 13:34:55 GMT
Author: veithm
Date: Tue Mar 18 13:34:54 2014
New Revision: 1578873

URL: http://svn.apache.org/r1578873
Log:
Changing mailbox parameter from native pointer to smartpointer

The SmartPointer is needed as due to multi threading it is not know
who should delete the mailbox at the end. Either the generated code needs
to delete it or the stack itself. This problem is solved by using
smartpointers.

Change-Id: I2c1ac6ca3ed126afa438e700f5849ffdaf03b2bb

Modified:
    etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_cpp.vm
    etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_h.vm
    etch/trunk/binding-cpp/runtime/include/support/EtchAsyncResult.h
    etch/trunk/binding-cpp/runtime/include/support/EtchAsyncResultNone.h
    etch/trunk/binding-cpp/runtime/include/support/EtchDeliveryService.h
    etch/trunk/binding-cpp/runtime/include/support/EtchRemoteBase.h
    etch/trunk/binding-cpp/runtime/include/transport/EtchDefaultDeliveryService.h
    etch/trunk/binding-cpp/runtime/include/transport/EtchMailboxManager.h
    etch/trunk/binding-cpp/runtime/include/transport/EtchPlainMailboxManager.h
    etch/trunk/binding-cpp/runtime/src/main/support/EtchAsyncResultNone.cpp
    etch/trunk/binding-cpp/runtime/src/main/support/EtchPlainMailbox.cpp
    etch/trunk/binding-cpp/runtime/src/main/support/EtchRemoteBase.cpp
    etch/trunk/binding-cpp/runtime/src/main/transport/EtchDefaultDeliveryService.cpp
    etch/trunk/binding-cpp/runtime/src/main/transport/EtchPlainMailboxManager.cpp
    etch/trunk/binding-cpp/runtime/src/test/support/EtchPlainMailboxTest.cpp
    etch/trunk/binding-cpp/runtime/src/test/support/EtchRemoteBaseTest.cpp
    etch/trunk/binding-cpp/runtime/src/test/transport/EtchDefaultDeliveryServiceTest.cpp
    etch/trunk/binding-cpp/runtime/src/test/transport/EtchPlainMailboxManagerTest.cpp

Modified: etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_cpp.vm
URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_cpp.vm?rev=1578873&r1=1578872&r2=1578873&view=diff
==============================================================================
--- etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_cpp.vm
(original)
+++ etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_cpp.vm
Tue Mar 18 13:34:54 2014
@@ -35,7 +35,7 @@ using namespace $namespace;
 #foreach($n in $intf.iterator())
 #if($n.isMsgDir($mc))
 #if(!$n.isHidden())
-$clname::$n.name()AsyncResultRemote::$n.name()AsyncResultRemote($clname* base, EtchMailbox*
mailbox) 
+$clname::$n.name()AsyncResultRemote::$n.name()AsyncResultRemote($clname* base, capu::SmartPointer<EtchMailbox>
mailbox)
   : #if($n.hasReturn())EtchAsyncResult<$helper.getEtchTypeName($n.type(), false)>(base->mRuntime,
mailbox)#{else}EtchAsyncResultNone(base->mRuntime, mailbox)#end {
   mBase = base;
 }
@@ -101,7 +101,7 @@ $intfname::$n.name()AsyncResultPtr $clna
   msg->put($vfname::$p.vname($helper)(), obj$ObjCount);
 #end
 
-  EtchMailbox* mb = NULL; 
+  capu::SmartPointer<EtchMailbox> mb = NULL;
   status = base->begincall(msg, mb);
   $n.name()AsyncResultRemote* result = new $n.name()AsyncResultRemote(base, mb);
 

Modified: etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_h.vm
URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_h.vm?rev=1578873&r1=1578872&r2=1578873&view=diff
==============================================================================
--- etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_h.vm
(original)
+++ etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_h.vm
Tue Mar 18 13:34:54 2014
@@ -64,7 +64,7 @@ namespace $namespace {
       /**
        * Create a new instance from $clname class
        */
-      $n.name()AsyncResultRemote($clname* base, EtchMailbox* mailbox);
+      $n.name()AsyncResultRemote($clname* base, capu::SmartPointer<EtchMailbox> mailbox);
 
       /**
        * Destructor

Modified: etch/trunk/binding-cpp/runtime/include/support/EtchAsyncResult.h
URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/include/support/EtchAsyncResult.h?rev=1578873&r1=1578872&r2=1578873&view=diff
==============================================================================
--- etch/trunk/binding-cpp/runtime/include/support/EtchAsyncResult.h (original)
+++ etch/trunk/binding-cpp/runtime/include/support/EtchAsyncResult.h Tue Mar 18 13:34:54 2014
@@ -34,7 +34,7 @@ public:
    * @param runtime
    * @param mailbox
    */
-  EtchAsyncResult(EtchRuntime* runtime = NULL, EtchMailbox* mailbox = NULL)
+  EtchAsyncResult(EtchRuntime* runtime = NULL, capu::SmartPointer<EtchMailbox> mailbox
= NULL)
    : EtchAsyncResultNone(runtime, mailbox), mResult(NULL), mHasResult(false) {
   }
 

Modified: etch/trunk/binding-cpp/runtime/include/support/EtchAsyncResultNone.h
URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/include/support/EtchAsyncResultNone.h?rev=1578873&r1=1578872&r2=1578873&view=diff
==============================================================================
--- etch/trunk/binding-cpp/runtime/include/support/EtchAsyncResultNone.h (original)
+++ etch/trunk/binding-cpp/runtime/include/support/EtchAsyncResultNone.h Tue Mar 18 13:34:54
2014
@@ -36,7 +36,7 @@ public:
    * Constructor
    * @param runtime
    */
-  explicit EtchAsyncResultNone(EtchRuntime* runtime = NULL, EtchMailbox* mailbox = NULL);
+  explicit EtchAsyncResultNone(EtchRuntime* runtime = NULL, capu::SmartPointer<EtchMailbox>
mailbox = NULL);
 
   /**
    * Destructor
@@ -71,7 +71,7 @@ protected:
   void setMailboxStatus();
 
   EtchRuntime* mRuntime;
-  EtchMailbox* mMailbox;
+  capu::SmartPointer<EtchMailbox> mMailbox;
   capu::Mutex mMutex;
   capu::CondVar mCond;
   capu::bool_t mHasMailboxStatus;

Modified: etch/trunk/binding-cpp/runtime/include/support/EtchDeliveryService.h
URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/include/support/EtchDeliveryService.h?rev=1578873&r1=1578872&r2=1578873&view=diff
==============================================================================
--- etch/trunk/binding-cpp/runtime/include/support/EtchDeliveryService.h (original)
+++ etch/trunk/binding-cpp/runtime/include/support/EtchDeliveryService.h Tue Mar 18 13:34:54
2014
@@ -38,7 +38,7 @@ public:
    * @return ETCH_OK if the message was send.
    *         ETCH_ERROR if there is a problem sending.
    */
-  virtual status_t begincall(capu::SmartPointer<EtchMessage> msg, EtchMailbox*&
result) = 0;
+  virtual status_t begincall(capu::SmartPointer<EtchMessage> msg, capu::SmartPointer<EtchMailbox>&
result) = 0;
 
   /**
    * Finishes a call sequence by waiting for the response message.

Modified: etch/trunk/binding-cpp/runtime/include/support/EtchRemoteBase.h
URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/include/support/EtchRemoteBase.h?rev=1578873&r1=1578872&r2=1578873&view=diff
==============================================================================
--- etch/trunk/binding-cpp/runtime/include/support/EtchRemoteBase.h (original)
+++ etch/trunk/binding-cpp/runtime/include/support/EtchRemoteBase.h Tue Mar 18 13:34:54 2014
@@ -71,7 +71,7 @@ public:
    * @return a mailbox which can be used to read the response, using
    * {@link #endcall(Mailbox, Type)}.
    */
-  status_t begincall(capu::SmartPointer<EtchMessage> msg, EtchMailbox *&result);
+  status_t begincall(capu::SmartPointer<EtchMessage> msg, capu::SmartPointer<EtchMailbox>
&result);
 
   /**
    * Finishes a call sequence by waiting for the response message.

Modified: etch/trunk/binding-cpp/runtime/include/transport/EtchDefaultDeliveryService.h
URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/include/transport/EtchDefaultDeliveryService.h?rev=1578873&r1=1578872&r2=1578873&view=diff
==============================================================================
--- etch/trunk/binding-cpp/runtime/include/transport/EtchDefaultDeliveryService.h (original)
+++ etch/trunk/binding-cpp/runtime/include/transport/EtchDefaultDeliveryService.h Tue Mar
18 13:34:54 2014
@@ -122,7 +122,7 @@ public:
   /**
    * @see EtchDeliveryService
    */
-  virtual status_t begincall(capu::SmartPointer<EtchMessage> msg, EtchMailbox*&
result);
+  virtual status_t begincall(capu::SmartPointer<EtchMessage> msg, capu::SmartPointer<EtchMailbox>&
result);
 
   /**
    * @see EtchDeliveryService

Modified: etch/trunk/binding-cpp/runtime/include/transport/EtchMailboxManager.h
URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/include/transport/EtchMailboxManager.h?rev=1578873&r1=1578872&r2=1578873&view=diff
==============================================================================
--- etch/trunk/binding-cpp/runtime/include/transport/EtchMailboxManager.h (original)
+++ etch/trunk/binding-cpp/runtime/include/transport/EtchMailboxManager.h Tue Mar 18 13:34:54
2014
@@ -40,7 +40,7 @@ public:
    * @param result the mailbox which will receive responses to this call.
    * @return status code
    */
-  virtual status_t transportCall(capu::SmartPointer<EtchWho> recipient, capu::SmartPointer<EtchMessage>
msg, EtchMailbox*& result) = 0;
+  virtual status_t transportCall(capu::SmartPointer<EtchWho> recipient, capu::SmartPointer<EtchMessage>
msg, capu::SmartPointer<EtchMailbox>& result) = 0;
 
   /**
    * Removes the mailbox from the set of mailboxes receiving responses to
@@ -48,7 +48,7 @@ public:
    * @param mb a mailbox as returned by {@link #transportCall(Who, Message)}.
    * @return status code
    */
-  virtual status_t unregisterMailbox(EtchMailbox* mb) = 0;
+  virtual status_t unregisterMailbox(EtchLong mailboxId) = 0;
 
   /**
    * Re-delivers dead letter messages from a closed mailbox.

Modified: etch/trunk/binding-cpp/runtime/include/transport/EtchPlainMailboxManager.h
URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/include/transport/EtchPlainMailboxManager.h?rev=1578873&r1=1578872&r2=1578873&view=diff
==============================================================================
--- etch/trunk/binding-cpp/runtime/include/transport/EtchPlainMailboxManager.h (original)
+++ etch/trunk/binding-cpp/runtime/include/transport/EtchPlainMailboxManager.h Tue Mar 18
13:34:54 2014
@@ -59,19 +59,19 @@ public:
    * to messages.
    * @param mb
    */
-  status_t registerMailbox(EtchMailbox* mb);
+  status_t registerMailbox(capu::SmartPointer<EtchMailbox> mb);
 
   /**
    * @see EtchMailboxManager
    */
-  status_t unregisterMailbox(EtchMailbox* mb);
+  status_t unregisterMailbox(EtchLong mailboxId);
 
   /**
    * Returns the mailbox for the specified msgid. This is a testing api.
    * @param msgid
    * @return the mailbox for the specified msgid.
    */
-  status_t getMailbox(EtchLong msgid, EtchMailbox*& result);
+  status_t getMailbox(EtchLong msgid, capu::SmartPointer<EtchMailbox>& result);
 
   ////////////////////////////
   // MessageHandler methods //
@@ -81,7 +81,7 @@ public:
   ///////////////////////////
   // MessageSource methods //
   ///////////////////////////
-  status_t transportCall(capu::SmartPointer<EtchWho> recipient, capu::SmartPointer<EtchMessage>
msg, EtchMailbox*& result);
+  status_t transportCall(capu::SmartPointer<EtchWho> recipient, capu::SmartPointer<EtchMessage>
msg, capu::SmartPointer<EtchMailbox>& result);
   status_t transportMessage(capu::SmartPointer<EtchWho> recipient, capu::SmartPointer<EtchMessage>
message);
 
   ///////////////////////////
@@ -109,7 +109,7 @@ private:
   EtchSessionMessage* mSession;
   EtchTransportMessage* mTransport;
   capu::bool_t mUp;
-  EtchHashTable<EtchLong, EtchMailbox*> mMailboxes;
+  EtchHashTable<EtchLong, capu::SmartPointer<EtchMailbox> > mMailboxes;
   capu::Mutex mMutex;
   EtchIdGenerator mIdGen;
 };

Modified: etch/trunk/binding-cpp/runtime/src/main/support/EtchAsyncResultNone.cpp
URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/src/main/support/EtchAsyncResultNone.cpp?rev=1578873&r1=1578872&r2=1578873&view=diff
==============================================================================
--- etch/trunk/binding-cpp/runtime/src/main/support/EtchAsyncResultNone.cpp (original)
+++ etch/trunk/binding-cpp/runtime/src/main/support/EtchAsyncResultNone.cpp Tue Mar 18 13:34:54
2014
@@ -20,25 +20,24 @@
 
 #define MAILBOX_NOTIFY_TIMEOUT 2000
 
-EtchAsyncResultNone::EtchAsyncResultNone(EtchRuntime* runtime, EtchMailbox* mailbox)
+EtchAsyncResultNone::EtchAsyncResultNone(EtchRuntime* runtime, capu::SmartPointer<EtchMailbox>
mailbox)
   : mRuntime(runtime), mMailbox(mailbox), mHasMailboxStatus(false), mHasException(false),
mException(NULL) {
-    if(mailbox != NULL) {
+    if(mailbox.get() != NULL) {
       mMailbox->registerNotify(this, NULL, MAILBOX_NOTIFY_TIMEOUT);
     }
     
 }
 
 EtchAsyncResultNone::~EtchAsyncResultNone() {
-  if(mMailbox != NULL) {
+  if(mMailbox.get() != NULL) {
     mMailbox->unregisterNotify(this);
     mMailbox->closeDelivery(false);
-    delete mMailbox;
   }
 }
 
 capu::bool_t EtchAsyncResultNone::hasException() {
   mMutex.lock();
-  while(mMailbox != NULL && !mHasMailboxStatus) {
+  while(mMailbox.get() != NULL && !mHasMailboxStatus) {
     mCond.wait(&mMutex);
   }
   mMutex.unlock();

Modified: etch/trunk/binding-cpp/runtime/src/main/support/EtchPlainMailbox.cpp
URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/src/main/support/EtchPlainMailbox.cpp?rev=1578873&r1=1578872&r2=1578873&view=diff
==============================================================================
--- etch/trunk/binding-cpp/runtime/src/main/support/EtchPlainMailbox.cpp (original)
+++ etch/trunk/binding-cpp/runtime/src/main/support/EtchPlainMailbox.cpp Tue Mar 18 13:34:54
2014
@@ -67,15 +67,16 @@ void EtchPlainMailbox::fireNotify() {
   s = mState;
   c = mQueue.isClosed();
   
-  mMutex.unlock();
-
   if (n != NULL) {
     n->mailboxStatus(this, s, c);
   }
+  mMutex.unlock();
 }
 
 status_t EtchPlainMailbox::read(EtchMailbox::EtchElement*& result) {
+  mMutex.lock();
   status_t status = mQueue.get(&result);
+  mMutex.unlock();
   if(ETCH_OK == status) {
     return ETCH_OK;
   }
@@ -84,7 +85,9 @@ status_t EtchPlainMailbox::read(EtchMail
 }
 
 status_t EtchPlainMailbox::read(EtchMailbox::EtchElement *& result, capu::int32_t maxDelay)
{
+  mMutex.lock();
   status_t status = mQueue.get(&result, maxDelay);
+  mMutex.unlock();
   if(status == ETCH_OK) {
     return ETCH_OK;
   }
@@ -99,7 +102,7 @@ status_t EtchPlainMailbox::closeDelivery
     return ETCH_EINVAL;
   }
 
-  mMailboxManager->unregisterMailbox(this);
+  mMailboxManager->unregisterMailbox(getMessageId());
   mQueue.close();
   mMutex.unlock();
 

Modified: etch/trunk/binding-cpp/runtime/src/main/support/EtchRemoteBase.cpp
URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/src/main/support/EtchRemoteBase.cpp?rev=1578873&r1=1578872&r2=1578873&view=diff
==============================================================================
--- etch/trunk/binding-cpp/runtime/src/main/support/EtchRemoteBase.cpp (original)
+++ etch/trunk/binding-cpp/runtime/src/main/support/EtchRemoteBase.cpp Tue Mar 18 13:34:54
2014
@@ -46,7 +46,7 @@ status_t EtchRemoteBase::send(capu::Smar
   return mSvc->transportMessage(NULL, msg);
 }
 
-status_t EtchRemoteBase::begincall(capu::SmartPointer<EtchMessage> msg, EtchMailbox
*&result) {
+status_t EtchRemoteBase::begincall(capu::SmartPointer<EtchMessage> msg, capu::SmartPointer<EtchMailbox>
&result) {
   ETCH_LOG_DEBUG(mRuntime->getLogger(), mRuntime->getLogger().getDeliveryServiceContext(),
"Begin call for the message is initiated");
   return mSvc->begincall(msg, result);
 }

Modified: etch/trunk/binding-cpp/runtime/src/main/transport/EtchDefaultDeliveryService.cpp
URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/src/main/transport/EtchDefaultDeliveryService.cpp?rev=1578873&r1=1578872&r2=1578873&view=diff
==============================================================================
--- etch/trunk/binding-cpp/runtime/src/main/transport/EtchDefaultDeliveryService.cpp (original)
+++ etch/trunk/binding-cpp/runtime/src/main/transport/EtchDefaultDeliveryService.cpp Tue Mar
18 13:34:54 2014
@@ -141,7 +141,7 @@ status_t EtchDefaultDeliveryService::tra
   return mTransport->transportNotify(event);
 }
 
-status_t EtchDefaultDeliveryService::begincall(capu::SmartPointer<EtchMessage> msg,
EtchMailbox*& result) {
+status_t EtchDefaultDeliveryService::begincall(capu::SmartPointer<EtchMessage> msg,
capu::SmartPointer<EtchMailbox> &result) {
   ETCH_LOG_DEBUG(mRuntime->getLogger(), mRuntime->getLogger().getDeliveryServiceContext(),
"Begin call for the message has been initiated");
   return mTransport->transportCall(NULL, msg, result);
 }

Modified: etch/trunk/binding-cpp/runtime/src/main/transport/EtchPlainMailboxManager.cpp
URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/src/main/transport/EtchPlainMailboxManager.cpp?rev=1578873&r1=1578872&r2=1578873&view=diff
==============================================================================
--- etch/trunk/binding-cpp/runtime/src/main/transport/EtchPlainMailboxManager.cpp (original)
+++ etch/trunk/binding-cpp/runtime/src/main/transport/EtchPlainMailboxManager.cpp Tue Mar
18 13:34:54 2014
@@ -28,13 +28,12 @@ EtchPlainMailboxManager::EtchPlainMailbo
 EtchPlainMailboxManager::~EtchPlainMailboxManager() {
   mMutex.lock();
 
-  EtchHashTable<EtchLong, EtchMailbox*>::Iterator it = mMailboxes.begin();
-  EtchHashTable<EtchLong, EtchMailbox*>::HashTableEntry entry;
+  EtchHashTable<EtchLong, capu::SmartPointer<EtchMailbox> >::Iterator it = mMailboxes.begin();
+  EtchHashTable<EtchLong, capu::SmartPointer<EtchMailbox> >::HashTableEntry entry;
 
   while (it.hasNext()) {
     it.next(&entry);
     entry.value->closeDelivery();
-    delete entry.value;
   }
 
   mMutex.unlock();
@@ -48,8 +47,8 @@ status_t EtchPlainMailboxManager::redeli
   return mSession->sessionMessage(sender, msg);
 }
 
-status_t EtchPlainMailboxManager::registerMailbox(EtchMailbox* mb) {
-  if(mb == NULL) {
+status_t EtchPlainMailboxManager::registerMailbox(capu::SmartPointer<EtchMailbox> mb)
{
+  if(mb.get() == NULL) {
     return ETCH_EINVAL;
   }
 
@@ -59,7 +58,7 @@ status_t EtchPlainMailboxManager::regist
     return ETCH_EINVAL;
   }
 
-  EtchMailbox* tmp = NULL;
+  capu::SmartPointer<EtchMailbox> tmp = NULL;
   if (mMailboxes.get(msgid, &tmp) != ETCH_ENOT_EXIST) {
     return ETCH_EINVAL;
   }
@@ -69,38 +68,42 @@ status_t EtchPlainMailboxManager::regist
   return ETCH_OK;
 }
 
-status_t EtchPlainMailboxManager::unregisterMailbox(EtchMailbox* mb) {
-  if(mb == NULL) {
-    return ETCH_EINVAL;
-  }
-
-  EtchMailbox* tmp = NULL;
-  mMailboxes.remove(mb->getMessageId(), &tmp);
+status_t EtchPlainMailboxManager::unregisterMailbox(EtchLong mailboxId) {
+  capu::SmartPointer<EtchMailbox> tmp = NULL;
+  mMutex.lock();
+  mMailboxes.remove(mailboxId, &tmp);
+  mMutex.unlock();
   return ETCH_OK;
 }
 
-status_t EtchPlainMailboxManager::getMailbox(EtchLong msgid, EtchMailbox*& result) {
-  return mMailboxes.get(msgid, &result);
+status_t EtchPlainMailboxManager::getMailbox(EtchLong msgid, capu::SmartPointer<EtchMailbox>&
result) {
+  status_t status = mMailboxes.get(msgid, &result);
+  return status;
 }
 
 status_t EtchPlainMailboxManager::sessionMessage(capu::SmartPointer<EtchWho> sender,
capu::SmartPointer<EtchMessage> msg) {
   capu::int64_t msgid;
   if(msg->getInReplyToMessageId(msgid) == ETCH_OK) {
-    EtchMailbox* mb = NULL;
+    capu::SmartPointer<EtchMailbox> mb = NULL;
     ETCH_LOG_DEBUG(mRuntime->getLogger(), mRuntime->getLogger().getMailboxContext(),
"A message has been received as answer to message identified by msgid " << msgid);
+	mMutex.lock();
     if (getMailbox(msgid, mb) != ETCH_OK) {
-      ETCH_LOG_ERROR(mRuntime->getLogger(), mRuntime->getLogger().getMailboxContext(),
"Unable to get Mailbox fro msgid " << msgid);
+	  mMutex.unlock();
+      ETCH_LOG_ERROR(mRuntime->getLogger(), mRuntime->getLogger().getMailboxContext(),
"Mailbox for Message with msgid " << msgid << "has already been closed and removed.
Dropping message.");
       return ETCH_ERROR;
     }
+    mMutex.unlock();
     ETCH_LOG_DEBUG(mRuntime->getLogger(), mRuntime->getLogger().getMailboxContext(),
"Message has been sent to respective mailbox");
-    return mb->message(sender, msg);
+	status_t status = mb->message(sender, msg);
+	
+    return status;
   }
   // no msgid - pass off to session
   ETCH_LOG_DEBUG(mRuntime->getLogger(), mRuntime->getLogger().getMailboxContext(),
"Message has been sent to upper layer directly as no msgid was given");
   return mSession->sessionMessage(sender, msg);
 }
 
-status_t EtchPlainMailboxManager::transportCall(capu::SmartPointer<EtchWho> recipient,
capu::SmartPointer<EtchMessage> msg, EtchMailbox*& result) {
+status_t EtchPlainMailboxManager::transportCall(capu::SmartPointer<EtchWho> recipient,
capu::SmartPointer<EtchMessage> msg, capu::SmartPointer<EtchMailbox>& result)
{
   capu::int64_t tmp;
   if (msg->getMessageId(tmp) == ETCH_OK) {
     // message has already been sent
@@ -118,10 +121,9 @@ status_t EtchPlainMailboxManager::transp
   }
 
   ETCH_LOG_DEBUG(mRuntime->getLogger(), mRuntime->getLogger().getMailboxContext(),
"A mailbox has been created for msgid " << msgid);
-  EtchMailbox *mb = new EtchPlainMailbox(this, msgid);
+  capu::SmartPointer<EtchMailbox> mb = new EtchPlainMailbox(this, msgid);
   mMutex.lock();
   if (registerMailbox(mb) != ETCH_OK) {
-    delete mb;
     ETCH_LOG_ERROR(mRuntime->getLogger(), mRuntime->getLogger().getMailboxContext(),
"Mailbox registration failed");
     mMutex.unlock();
     return ETCH_ERROR;
@@ -134,7 +136,6 @@ status_t EtchPlainMailboxManager::transp
     return ETCH_OK;
   } else {
     mb->closeDelivery();
-    delete mb;
     mMutex.unlock();
     return ETCH_ERROR;
   }
@@ -183,12 +184,11 @@ status_t EtchPlainMailboxManager::sessio
     ETCH_LOG_TRACE(mRuntime->getLogger(), mRuntime->getLogger().getMailboxContext(),
"Connection is up");
   } else if (event->equals(&EtchSession::DOWN())) {
     mUp = false;
-    EtchHashTable<EtchLong, EtchMailbox*>::Iterator it = mMailboxes.begin();
-    EtchHashTable<EtchLong, EtchMailbox*>::HashTableEntry entry;
+    EtchHashTable<EtchLong, capu::SmartPointer<EtchMailbox> >::Iterator it =
mMailboxes.begin();
+    EtchHashTable<EtchLong, capu::SmartPointer<EtchMailbox> >::HashTableEntry
entry;
     while (it.hasNext()) {
       it.next(&entry);
       entry.value->closeDelivery();
-      delete entry.value;
     }
     ETCH_LOG_TRACE(mRuntime->getLogger(), mRuntime->getLogger().getMailboxContext(),
"Connection is down");
   }

Modified: etch/trunk/binding-cpp/runtime/src/test/support/EtchPlainMailboxTest.cpp
URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/src/test/support/EtchPlainMailboxTest.cpp?rev=1578873&r1=1578872&r2=1578873&view=diff
==============================================================================
--- etch/trunk/binding-cpp/runtime/src/test/support/EtchPlainMailboxTest.cpp (original)
+++ etch/trunk/binding-cpp/runtime/src/test/support/EtchPlainMailboxTest.cpp Tue Mar 18 13:34:54
2014
@@ -30,7 +30,7 @@ public:
   capu::bool_t unregistered;
   EtchList<EtchMailbox::EtchElement *> list;
 
-  virtual status_t unregisterMailbox(EtchMailbox* mb) {
+  virtual status_t unregisterMailbox(EtchLong mailboxId) {
     unregistered = true;
     return ETCH_OK;
   }
@@ -39,11 +39,11 @@ public:
     return list.add(new EtchMailbox::EtchElement(sender, msg));
   }
 
-  MOCK_METHOD2(getMailbox, status_t(EtchLong msgid, EtchMailbox*& result));
+  MOCK_METHOD2(getMailbox, status_t(EtchLong msgid, capu::SmartPointer<EtchMailbox>&
result));
 
   MOCK_METHOD2(sessionMessage, status_t(capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchMessage>
msg));
 
-  MOCK_METHOD3(transportCall, status_t(capu::SmartPointer<EtchWho> recipient, capu::SmartPointer<EtchMessage>
msg, EtchMailbox*& result));
+  MOCK_METHOD3(transportCall, status_t(capu::SmartPointer<EtchWho> recipient, capu::SmartPointer<EtchMessage>
msg, capu::SmartPointer<EtchMailbox>& result));
 
   MOCK_METHOD2(transportMessage, status_t(capu::SmartPointer<EtchWho> recipient, capu::SmartPointer<EtchMessage>
message));
 
@@ -75,11 +75,10 @@ public:
 
 TEST(EtchPlainMessageBoxTest, constructorTest) {
   MockMailboxManager2 manager;
-  EtchMailbox* mailbox = NULL;
+  capu::SmartPointer<EtchMailbox> mailbox = NULL;
   EtchLong id(5);
   mailbox = new EtchPlainMailbox(&manager, id);
-  EXPECT_TRUE(mailbox != NULL);
-  delete mailbox;
+  EXPECT_TRUE(mailbox.get() != NULL);
 }
 
 TEST(EtchPlainMessageBoxTest, closeDeliveryTest) {

Modified: etch/trunk/binding-cpp/runtime/src/test/support/EtchRemoteBaseTest.cpp
URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/src/test/support/EtchRemoteBaseTest.cpp?rev=1578873&r1=1578872&r2=1578873&view=diff
==============================================================================
--- etch/trunk/binding-cpp/runtime/src/test/support/EtchRemoteBaseTest.cpp (original)
+++ etch/trunk/binding-cpp/runtime/src/test/support/EtchRemoteBaseTest.cpp Tue Mar 18 13:34:54
2014
@@ -260,9 +260,9 @@ TEST_F(EtchRemoteBaseTest, beginCallTest
 
   manager->sessionNotify(new EtchString(EtchSession::UP()));
 
-  EtchMailbox *mail = NULL;
+  capu::SmartPointer<EtchMailbox> mail = NULL;
   EXPECT_TRUE(remote->begincall(msg, mail) == ETCH_OK);
-  EXPECT_TRUE(mail != NULL);
+  EXPECT_TRUE(mail.get() != NULL);
 
   factory->types.clear();
 
@@ -314,10 +314,10 @@ TEST_F(EtchRemoteBaseTest, endCallTest) 
 
   manager->sessionNotify(new EtchString(EtchSession::UP()));
 
-  EtchMailbox *mail = NULL;
+  capu::SmartPointer<EtchMailbox> mail = NULL;
   EXPECT_TRUE(remote->begincall(message, mail) == ETCH_OK);
 
-  EXPECT_TRUE(mail != NULL);
+  EXPECT_TRUE(mail.get() != NULL);
 
   capu::int64_t id;
   message->getMessageId(id);
@@ -331,14 +331,13 @@ TEST_F(EtchRemoteBaseTest, endCallTest) 
   //call the sessionMessage of mailbox manager as if it is called from messagizer to deliver
data from
   EXPECT_TRUE(ETCH_OK == manager->sessionMessage(NULL, replymess));
   capu::SmartPointer<EtchObject> result;
-  EXPECT_TRUE(remote->endcall(mail, replyType, result) == ETCH_OK);
-  EXPECT_TRUE(mail != NULL);
+  EXPECT_TRUE(remote->endcall(mail.get(), replyType, result) == ETCH_OK);
+  EXPECT_TRUE(mail.get() != NULL);
   EXPECT_TRUE(result == data);
 
   factory->types.clear();
 
   delete transport;
-  delete mail;
   delete remote;
   delete manager;
   delete service;

Modified: etch/trunk/binding-cpp/runtime/src/test/transport/EtchDefaultDeliveryServiceTest.cpp
URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/src/test/transport/EtchDefaultDeliveryServiceTest.cpp?rev=1578873&r1=1578872&r2=1578873&view=diff
==============================================================================
--- etch/trunk/binding-cpp/runtime/src/test/transport/EtchDefaultDeliveryServiceTest.cpp (original)
+++ etch/trunk/binding-cpp/runtime/src/test/transport/EtchDefaultDeliveryServiceTest.cpp Tue
Mar 18 13:34:54 2014
@@ -175,7 +175,7 @@ TEST_F(EtchDefaultDeliveryServiceTest, b
   mailboxManager->sessionNotify(new EtchString(EtchSession::UP()));
 
   //test begincall
-  EtchMailbox *mail = NULL;
+  capu::SmartPointer<EtchMailbox> mail = NULL;
   EXPECT_TRUE(ETCH_OK == deliveryService->begincall(message, mail));
   EXPECT_EQ(1u, mailboxManager->count());
   EXPECT_TRUE(ETCH_OK == message->getMessageId(id));
@@ -233,7 +233,7 @@ TEST_F(EtchDefaultDeliveryServiceTest, e
   mailboxManager->sessionNotify(new EtchString(EtchSession::UP()));
 
   //performed the call
-  EtchMailbox *mail;
+  capu::SmartPointer<EtchMailbox> mail;
   EXPECT_TRUE(ETCH_OK == deliveryService->begincall(message, mail));
   EXPECT_EQ(1u, mailboxManager->count());
   EXPECT_TRUE(ETCH_OK == message->getMessageId(id));
@@ -256,9 +256,8 @@ TEST_F(EtchDefaultDeliveryServiceTest, e
 
   //wait for the response
   capu::SmartPointer<EtchObject> result;
-  status = deliveryService->endcall(mail, replyType, result);
+  status = deliveryService->endcall(mail.get(), replyType, result);
   EXPECT_EQ(ETCH_OK, status);
-  delete mail;
 
   //check the result
   EXPECT_TRUE(result->equals(data.get()));

Modified: etch/trunk/binding-cpp/runtime/src/test/transport/EtchPlainMailboxManagerTest.cpp
URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/src/test/transport/EtchPlainMailboxManagerTest.cpp?rev=1578873&r1=1578872&r2=1578873&view=diff
==============================================================================
--- etch/trunk/binding-cpp/runtime/src/test/transport/EtchPlainMailboxManagerTest.cpp (original)
+++ etch/trunk/binding-cpp/runtime/src/test/transport/EtchPlainMailboxManagerTest.cpp Tue
Mar 18 13:34:54 2014
@@ -157,7 +157,7 @@ TEST_F(EtchPlainMailboxManagerTest, tran
   EXPECT_TRUE(ETCH_OK == message->getMessageId(id));
   EXPECT_TRUE(ETCH_OK != message->getInReplyToMessageId(id));
 
-  EtchMailbox *mail;
+  capu::SmartPointer<EtchMailbox> mail;
   EXPECT_TRUE(ETCH_OK != manager->getMailbox(id, mail));
 
   message->clear();
@@ -201,7 +201,7 @@ TEST_F(EtchPlainMailboxManagerTest, tran
   EXPECT_TRUE(ETCH_OK == message->getMessageId(id));
   EXPECT_TRUE(ETCH_OK == message->getInReplyToMessageId(id));
   EXPECT_TRUE(id == 1L);
-  EtchMailbox *mail;
+  capu::SmartPointer<EtchMailbox> mail;
   EXPECT_TRUE(ETCH_OK != manager->getMailbox(id, mail));
 
   message->clear();
@@ -239,13 +239,14 @@ TEST_F(EtchPlainMailboxManagerTest, tran
   //in order to notify upper layers that the connection is open
   manager->sessionNotify(new EtchString(EtchSession::UP()));
 
-  EtchMailbox *mail;
+  capu::SmartPointer<EtchMailbox> mail;
   EXPECT_TRUE(ETCH_OK == manager->transportCall(NULL, message, mail));
   EXPECT_EQ(1u, manager->count());
   EXPECT_TRUE(ETCH_OK == message->getMessageId(id));
   EXPECT_TRUE(ETCH_OK != message->getInReplyToMessageId(id));
 
-  EXPECT_TRUE(ETCH_OK == manager->getMailbox(id, mail));
+  capu::SmartPointer<EtchMailbox> out;
+  EXPECT_TRUE(ETCH_OK == manager->getMailbox(id, out));
 
   message->clear();
 
@@ -285,7 +286,7 @@ TEST_F(EtchPlainMailboxManagerTest, repl
   //in order to notify upper layers that the connection is open
   manager->sessionNotify(new EtchString(EtchSession::UP()));
 
-  EtchMailbox *mail;
+  capu::SmartPointer<EtchMailbox> mail;
   EXPECT_TRUE(ETCH_ERROR == manager->transportCall(NULL, message, mail));
   //should not create a mailbox
   EXPECT_EQ(ETCH_OK, message->getMessageId(id));
@@ -333,7 +334,7 @@ TEST_F(EtchPlainMailboxManagerTest, sess
   manager->sessionNotify(new EtchString(EtchSession::UP()));
 
   //perform the call
-  EtchMailbox *mail;
+  capu::SmartPointer<EtchMailbox> mail;
   EXPECT_TRUE(ETCH_OK == manager->transportCall(NULL, message, mail));
   EXPECT_EQ(1u, manager->count());
   EXPECT_TRUE(ETCH_OK == message->getMessageId(id));



Mime
View raw message