You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ch...@apache.org on 2011/12/21 18:56:00 UTC

svn commit: r1221824 [1/2] - /qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/

Author: chug
Date: Wed Dec 21 17:55:59 2011
New Revision: 1221824

URL: http://svn.apache.org/viewvc?rev=1221824&view=rev
Log:
QPID-3193 Major update provides locks and checks for disposed objects.

* White space police: tabs, trailing white, reformat source per Visual Studio ^k ^f.
* Changed native object pointer names to nativeObjPtr for all classes.
* Reviewed at https://reviews.apache.org/r/3239
* No macros - all code expanded in-line.
* msclr::lock scoped locks use per-object private lock and not 'this'.
* References to native functions of disposed (.NET Dispose, C++ delete) objects throws ObjectDisposedException.
* Each object gets an IsDisposed property for diagnostic purposes.
* Unused file Duration.cpp is deleted.

Removed:
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Duration.cpp
Modified:
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Address.cpp
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Address.h
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Connection.cpp
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Connection.h
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Duration.h
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/FailoverUpdates.cpp
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/FailoverUpdates.h
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Message.cpp
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Message.h
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/QpidException.h
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/QpidMarshal.h
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/QpidTypeCheck.h
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/ReadMe.txt
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Receiver.cpp
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Receiver.h
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Sender.cpp
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Sender.h
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Session.cpp
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Session.h
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/TypeTranslator.cpp
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/TypeTranslator.h
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/resource1.h

Modified: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Address.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Address.cpp?rev=1221824&r1=1221823&r2=1221824&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Address.cpp (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Address.cpp Wed Dec 21 17:55:59 2011
@@ -40,25 +40,34 @@ namespace Messaging {
     /// Address is a managed wrapper for a qpid::messaging::Address
     /// </summary>
 
+    // Disallow access if object has been destroyed.
+    void Address::ThrowIfDisposed()
+    {
+        if (IsDisposed)
+            throw gcnew ObjectDisposedException (GetType()->FullName);
+    }
+
+
     // Create empty
     Address::Address()
     {
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-            addressp = new ::qpid::messaging::Address(QpidMarshal::ToNative(""));
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        try
+        {
+            privateLock = gcnew System::Object();
+            nativeObjPtr = new ::qpid::messaging::Address(QpidMarshal::ToNative(""));
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
     // Create string address
@@ -66,79 +75,82 @@ namespace Messaging {
     {
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-            addressp = new ::qpid::messaging::Address(QpidMarshal::ToNative(address));
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        try
+        {
+            privateLock = gcnew System::Object();
+            nativeObjPtr = new ::qpid::messaging::Address(QpidMarshal::ToNative(address));
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
     // Create with options
-    Address::Address(System::String ^ name, 
-                     System::String ^ subject,
-                     System::Collections::Generic::Dictionary<
-                         System::String ^, System::Object ^> ^ options)
+    Address::Address(System::String ^ name,
+        System::String ^ subject,
+        System::Collections::Generic::Dictionary<
+        System::String ^, System::Object ^> ^ options)
     {
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-            addressp = new ::qpid::messaging::Address();
+        try
+        {
+            privateLock = gcnew System::Object();
+            nativeObjPtr = new ::qpid::messaging::Address();
 
             Name = name;
             Subject = subject;
             Options = options;
             Type = "";
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
     // Create with options and type
-    Address::Address(System::String ^ name, 
-                     System::String ^ subject,
-                     System::Collections::Generic::Dictionary<
-                         System::String ^, System::Object ^> ^ options,
-                     System::String ^ type)
+    Address::Address(System::String ^ name,
+        System::String ^ subject,
+        System::Collections::Generic::Dictionary<
+        System::String ^, System::Object ^> ^ options,
+        System::String ^ type)
     {
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-            addressp = new ::qpid::messaging::Address();
+        try
+        {
+            privateLock = gcnew System::Object();
+            nativeObjPtr = new ::qpid::messaging::Address();
 
             Name = name;
             Subject = subject;
             Options = options;
             Type = type;
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
     // Copy constructor look-alike (C#)
@@ -146,21 +158,22 @@ namespace Messaging {
     {
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-            addressp = new ::qpid::messaging::Address(
-                        *(const_cast<Address ^>(address)->NativeAddress));
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        try
+        {
+            privateLock = gcnew System::Object();
+            nativeObjPtr = new ::qpid::messaging::Address(
+                *(const_cast<Address ^>(address)->NativeAddress));
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
     // Copy constructor implicitly dereferenced (C++)
@@ -168,21 +181,22 @@ namespace Messaging {
     {
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-            addressp = new ::qpid::messaging::Address(
-                        *(const_cast<Address %>(address).NativeAddress));
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        try
+        {
+            privateLock = gcnew System::Object();
+            nativeObjPtr = new ::qpid::messaging::Address(
+                *(const_cast<Address %>(address).NativeAddress));
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
     // unmanaged clone
@@ -190,20 +204,21 @@ namespace Messaging {
     {
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-            addressp = new ::qpid::messaging::Address(addrp);
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        try
+        {
+            privateLock = gcnew System::Object();
+            nativeObjPtr = new ::qpid::messaging::Address(addrp);
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
     // Destructor
@@ -216,12 +231,15 @@ namespace Messaging {
     // Finalizer
     Address::!Address()
     {
-        msclr::lock lk(this);
-
-        if (NULL != addressp)
+        if (NULL != nativeObjPtr)
         {
-            delete addressp;
-            addressp = NULL;
+            privateLock = gcnew System::Object();
+
+            if (NULL != nativeObjPtr)
+            {
+                delete nativeObjPtr;
+                nativeObjPtr = NULL;
+            }
         }
     }
 
@@ -233,20 +251,23 @@ namespace Messaging {
         System::String ^ result = nullptr;
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-            result = gcnew System::String(addressp->str().c_str());
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        try
+        {
+            msclr::lock lk(privateLock);
+            ThrowIfDisposed();
+
+            result = gcnew System::String(nativeObjPtr->str().c_str());
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
         return result;
     }
 }}}}

Modified: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Address.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Address.h?rev=1221824&r1=1221823&r2=1221824&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Address.h (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Address.h Wed Dec 21 17:55:59 2011
@@ -44,23 +44,29 @@ namespace Messaging {
     {
     private:
         // The kept object in the Messaging C++ DLL
-        ::qpid::messaging::Address * addressp;
+        ::qpid::messaging::Address * nativeObjPtr;
+
+        // per-instance lock object
+        System::Object ^ privateLock;
+
+        // Disallow use after object is destroyed
+        void ThrowIfDisposed();
 
     public:
         Address();
-        
+
         Address(System::String ^ address);
 
         Address(System::String ^ name,
-                System::String ^ subject,
-                System::Collections::Generic::Dictionary<
-                    System::String ^, System::Object ^> ^ options);
-                
+            System::String ^ subject,
+            System::Collections::Generic::Dictionary<
+            System::String ^, System::Object ^> ^ options);
+
         Address(System::String ^ name,
-                System::String ^ subject,
-                System::Collections::Generic::Dictionary<
-                    System::String ^, System::Object ^> ^ options,
-                System::String ^ type);
+            System::String ^ subject,
+            System::Collections::Generic::Dictionary<
+            System::String ^, System::Object ^> ^ options,
+            System::String ^ type);
 
         // copy constructor
         Address(const Address ^ address);
@@ -69,29 +75,51 @@ namespace Messaging {
         // unmanaged clone
         Address(const ::qpid::messaging::Address & addrp);
 
+        // System destructor/finalizer entry points
         ~Address();
         !Address();
 
         // assignment operator
         Address % operator=(const Address % rhs)
         {
+            msclr::lock lk(privateLock);
+            ThrowIfDisposed();
+
             if (this == %rhs)
             {
                 // Self assignment, do nothing
             }
             else
             {
-                if (NULL != addressp)
-                    delete addressp;
-                addressp = new ::qpid::messaging::Address(
+                if (NULL != nativeObjPtr)
+                    delete nativeObjPtr;
+                nativeObjPtr = new ::qpid::messaging::Address(
                     *(const_cast<Address %>(rhs).NativeAddress) );
             }
             return *this;
         }
 
+        //
+        // IsDisposed
+        //
+        property bool IsDisposed
+        {
+            bool get()
+            {
+                return NULL == nativeObjPtr;
+            }
+        }
+
+
+        //
+        // NativeAddress
+        //
         property ::qpid::messaging::Address * NativeAddress
         {
-            ::qpid::messaging::Address * get () { return addressp; }
+            ::qpid::messaging::Address * get ()
+            {
+                return nativeObjPtr;
+            }
         }
 
         //
@@ -101,12 +129,18 @@ namespace Messaging {
         {
             System::String ^ get ()
             {
-                return gcnew System::String(addressp->getName().c_str());
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                return gcnew System::String(nativeObjPtr->getName().c_str());
             }
 
             void set (System::String ^ name)
             {
-                addressp->::qpid::messaging::Address::setName(QpidMarshal::ToNative(name));
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                nativeObjPtr->::qpid::messaging::Address::setName(QpidMarshal::ToNative(name));
             }
         }
 
@@ -118,12 +152,18 @@ namespace Messaging {
         {
             System::String ^ get ()
             {
-                return gcnew System::String(addressp->getSubject().c_str());
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                return gcnew System::String(nativeObjPtr->getSubject().c_str());
             }
 
             void set (System::String ^ subject)
             {
-                addressp->setSubject(QpidMarshal::ToNative(subject));
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                nativeObjPtr->setSubject(QpidMarshal::ToNative(subject));
             }
         }
 
@@ -137,23 +177,29 @@ namespace Messaging {
             System::Collections::Generic::Dictionary<
                 System::String ^, System::Object ^> ^ get ()
             {
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
                 ::qpid::types::Variant::Map map;
                 System::Collections::Generic::Dictionary<
-                    System::String ^, System::Object ^> ^ newMap = 
+                    System::String ^, System::Object ^> ^ newMap =
                     gcnew System::Collections::Generic::Dictionary<
-                          System::String ^, System::Object ^>;
-                map = addressp->getOptions();
+                    System::String ^, System::Object ^>;
+                map = nativeObjPtr->getOptions();
                 TypeTranslator::NativeToManaged(map, newMap);
                 return newMap;
             }
 
 
             void set (System::Collections::Generic::Dictionary<
-                                System::String ^, System::Object ^> ^ options)
+                System::String ^, System::Object ^> ^ options)
             {
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
                 ::qpid::types::Variant::Map map;
                 TypeTranslator::ManagedToNative(options, map);
-                addressp->setOptions(map);
+                nativeObjPtr->setOptions(map);
             }
         }
 
@@ -165,13 +211,19 @@ namespace Messaging {
         {
             System::String ^ get ()
             {
-                return gcnew System::String(addressp->getType().c_str());
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                return gcnew System::String(nativeObjPtr->getType().c_str());
             }
 
 
             void set (System::String ^ type)
             {
-                addressp->setType(QpidMarshal::ToNative(type));
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                nativeObjPtr->setType(QpidMarshal::ToNative(type));
             }
         }
 

Modified: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Connection.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Connection.cpp?rev=1221824&r1=1221823&r2=1221824&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Connection.cpp (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Connection.cpp Wed Dec 21 17:55:59 2011
@@ -42,53 +42,63 @@ namespace Messaging {
     /// Connection is a managed wrapper for a qpid::messaging::Connection
     /// </summary>
 
+    // Disallow access if object has been destroyed.
+    void Connection::ThrowIfDisposed()
+    {
+        if (IsDisposed)
+            throw gcnew ObjectDisposedException (GetType()->FullName);
+    }
+
+
     // constructors
     Connection::Connection(System::String ^ url)
     {
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-            connectionp = new ::qpid::messaging::Connection(QpidMarshal::ToNative(url));
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        try
+        {
+            privateLock = gcnew System::Object();
+            nativeObjPtr = new ::qpid::messaging::Connection(QpidMarshal::ToNative(url));
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
 
     Connection::Connection(System::String ^ url,
-                           System::Collections::Generic::Dictionary<
-                               System::String ^, System::Object ^> ^ options)
+        System::Collections::Generic::Dictionary<
+        System::String ^, System::Object ^> ^ options)
     {
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-            connectionp = new ::qpid::messaging::Connection(QpidMarshal::ToNative(url));
+        try
+        {
+            privateLock = gcnew System::Object();
+            nativeObjPtr = new ::qpid::messaging::Connection(QpidMarshal::ToNative(url));
 
             for each (System::Collections::Generic::KeyValuePair<System::String^, System::Object^> kvp in options)
             {
                 SetOption(kvp.Key, kvp.Value);
             }
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
 
@@ -96,21 +106,22 @@ namespace Messaging {
     {
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-            connectionp = new ::qpid::messaging::Connection(QpidMarshal::ToNative(url),
-                    QpidMarshal::ToNative(options));
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        try
+        {
+            privateLock = gcnew System::Object();
+            nativeObjPtr = new ::qpid::messaging::Connection(QpidMarshal::ToNative(url),
+                QpidMarshal::ToNative(options));
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
 
@@ -119,21 +130,22 @@ namespace Messaging {
     {
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-            connectionp = new ::qpid::messaging::Connection(
-                        *(const_cast<Connection ^>(connection)->NativeConnection));
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        try
+        {
+            privateLock = gcnew System::Object();
+            nativeObjPtr = new ::qpid::messaging::Connection(
+                *(const_cast<Connection ^>(connection)->NativeConnection));
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
     // Copy constructor implicitly dereferenced (C++)
@@ -141,21 +153,22 @@ namespace Messaging {
     {
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-            connectionp = new ::qpid::messaging::Connection(
-                        *(const_cast<Connection %>(connection).NativeConnection));
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        try
+        {
+            privateLock = gcnew System::Object();
+            nativeObjPtr = new ::qpid::messaging::Connection(
+                *(const_cast<Connection %>(connection).NativeConnection));
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
 
@@ -169,12 +182,15 @@ namespace Messaging {
     // Finalizer
     Connection::!Connection()
     {
-        msclr::lock lk(this);
-
-        if (NULL != connectionp)
+        if (NULL != nativeObjPtr)
         {
-            delete connectionp;
-            connectionp = NULL;
+            privateLock = gcnew System::Object();
+
+            if (NULL != nativeObjPtr)
+            {
+                delete nativeObjPtr;
+                nativeObjPtr = NULL;
+            }
         }
     }
 
@@ -183,63 +199,72 @@ namespace Messaging {
     {
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
+        try
+        {
+            msclr::lock lk(privateLock);
+            ThrowIfDisposed();
+
             ::qpid::types::Variant entryValue;
             TypeTranslator::ManagedToNativeObject(value, entryValue);
             std::string entryName = QpidMarshal::ToNative(name);
-            connectionp->::qpid::messaging::Connection::setOption(entryName, entryValue);
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+            nativeObjPtr->::qpid::messaging::Connection::setOption(entryName, entryValue);
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
     void Connection::Open()
     {
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-            connectionp->open();
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        try
+        {
+            msclr::lock lk(privateLock);
+            ThrowIfDisposed();
+
+            nativeObjPtr->open();
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
     void Connection::Close()
     {
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-            connectionp->close();
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        try
+        {
+            msclr::lock lk(privateLock);
+            ThrowIfDisposed();
+
+            nativeObjPtr->close();
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
     //
@@ -258,14 +283,17 @@ namespace Messaging {
 
         try
         {
+            msclr::lock lk(privateLock);
+            ThrowIfDisposed();
+
             // create native session
-            ::qpid::messaging::Session sessionp = 
-				connectionp->createTransactionalSession(QpidMarshal::ToNative(name));
+            ::qpid::messaging::Session sessionp =
+                nativeObjPtr->createTransactionalSession(QpidMarshal::ToNative(name));
 
             // create managed session
             newSession = gcnew Session(sessionp, this);
-        } 
-        catch (const ::qpid::types::Exception & error) 
+        }
+        catch (const ::qpid::types::Exception & error)
         {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
@@ -276,9 +304,9 @@ namespace Messaging {
             if (newException != nullptr)
             {
                 if (newSession != nullptr)
-				{
-					delete newSession;
-				}
+                {
+                    delete newSession;
+                }
             }
         }
 
@@ -287,7 +315,7 @@ namespace Messaging {
             throw newException;
         }
 
-		return newSession;
+        return newSession;
     }
 
 
@@ -307,14 +335,17 @@ namespace Messaging {
 
         try
         {
+            msclr::lock lk(privateLock);
+            ThrowIfDisposed();
+
             // create native session
-            ::qpid::messaging::Session sessionp = 
-				connectionp->createSession(QpidMarshal::ToNative(name));
+            ::qpid::messaging::Session sessionp =
+                nativeObjPtr->createSession(QpidMarshal::ToNative(name));
 
             // create managed session
             newSession = gcnew Session(sessionp, this);
-        } 
-        catch (const ::qpid::types::Exception & error) 
+        }
+        catch (const ::qpid::types::Exception & error)
         {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
@@ -324,17 +355,17 @@ namespace Messaging {
             // Clean up and throw on caught exceptions
             if (newException != nullptr)
             {
-				if (newSession != nullptr)
-				{
-					delete newSession;
-				}
+                if (newSession != nullptr)
+                {
+                    delete newSession;
+                }
             }
         }
 
-		if (nullptr != newException) 
-		{
-			throw newException;
-		}
+        if (nullptr != newException)
+        {
+            throw newException;
+        }
 
         return newSession;
     }
@@ -344,17 +375,20 @@ namespace Messaging {
     {
         System::Exception          ^ newException = nullptr;
         Session                    ^ newSession   = nullptr;
-      
+
         try
         {
             const std::string n = QpidMarshal::ToNative(name);
 
-            ::qpid::messaging::Session sess = 
-				connectionp->::qpid::messaging::Connection::getSession(n);
-            
+            msclr::lock lk(privateLock);
+            ThrowIfDisposed();
+
+            ::qpid::messaging::Session sess =
+                nativeObjPtr->::qpid::messaging::Connection::getSession(n);
+
             newSession = gcnew Session(sess, this);
         }
-        catch (const ::qpid::types::Exception & error) 
+        catch (const ::qpid::types::Exception & error)
         {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
@@ -364,17 +398,17 @@ namespace Messaging {
             // Clean up and throw on caught exceptions
             if (newException != nullptr)
             {
-				if (newSession != nullptr)
-				{
-					delete newSession;
-				}
+                if (newSession != nullptr)
+                {
+                    delete newSession;
+                }
             }
         }
 
-		if (nullptr != newException) 
-		{
-			throw newException;
-		}
+        if (nullptr != newException)
+        {
+            throw newException;
+        }
 
         return newSession;
     }

Modified: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Connection.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Connection.h?rev=1221824&r1=1221823&r2=1221824&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Connection.h (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Connection.h Wed Dec 21 17:55:59 2011
@@ -43,14 +43,20 @@ namespace Messaging {
     {
     private:
         // The kept object in the Messaging C++ DLL
-        ::qpid::messaging::Connection * connectionp;
+        ::qpid::messaging::Connection * nativeObjPtr;
+
+        // per-instance lock object
+        System::Object ^ privateLock;
+
+        // Disallow use after object is destroyed
+        void ThrowIfDisposed();
 
     public:
         Connection(System::String ^ url);
 
-        Connection(System::String ^ url, 
-                   System::Collections::Generic::Dictionary<
-                       System::String ^, System::Object ^> ^ options);
+        Connection(System::String ^ url,
+            System::Collections::Generic::Dictionary<
+            System::String ^, System::Object ^> ^ options);
 
         Connection(System::String ^ url, System::String ^ options);
 
@@ -58,8 +64,8 @@ namespace Messaging {
         Connection(const Connection ^ connection);
         Connection(const Connection % connection);
 
-		// unmanaged clone
-		// not defined
+        // unmanaged clone
+        // not defined
 
         ~Connection();
         !Connection();
@@ -67,23 +73,44 @@ namespace Messaging {
         // assignment operator
         Connection % operator=(const Connection % rhs)
         {
+            msclr::lock lk(privateLock);
+            ThrowIfDisposed();
+
             if (this == %rhs)
             {
                 // Self assignment, do nothing
             }
             else
             {
-                if (NULL != connectionp)
-                    delete connectionp;
-                connectionp = new ::qpid::messaging::Connection(
+                if (NULL != nativeObjPtr)
+                    delete nativeObjPtr;
+                nativeObjPtr = new ::qpid::messaging::Connection(
                     *(const_cast<Connection %>(rhs).NativeConnection) );
             }
             return *this;
         }
 
+        //
+        // IsDisposed
+        //
+        property bool IsDisposed
+        {
+            bool get()
+            {
+                return NULL == nativeObjPtr;
+            }
+        }
+
+
+        //
+        // NativeConnection
+        //
         property ::qpid::messaging::Connection * NativeConnection
         {
-            ::qpid::messaging::Connection * get () { return connectionp; }
+            ::qpid::messaging::Connection * get ()
+            {
+                return nativeObjPtr;
+            }
         }
 
         void SetOption(System::String ^ name, System::Object ^ value);
@@ -95,7 +122,10 @@ namespace Messaging {
         {
             System::Boolean get ()
             {
-                return connectionp->isOpen();
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                return nativeObjPtr->isOpen();
             }
         }
 
@@ -113,7 +143,10 @@ namespace Messaging {
         {
             System::String ^ get ()
             {
-                return gcnew System::String(connectionp->getAuthenticatedUsername().c_str());
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                return gcnew System::String(nativeObjPtr->getAuthenticatedUsername().c_str());
             }
         }
     };

Modified: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Duration.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Duration.h?rev=1221824&r1=1221823&r2=1221824&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Duration.h (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Duration.h Wed Dec 21 17:55:59 2011
@@ -43,14 +43,12 @@ namespace Messaging {
     public:
 
         Duration(const Duration % rhs) :
-            milliseconds(rhs.milliseconds)
-        {
-        }
+            milliseconds(rhs.milliseconds) {}
 
-        explicit Duration(System::UInt64 mS) : 
+        explicit Duration(System::UInt64 mS) :
             milliseconds(mS) {}
-        
-        Duration()                           : 
+
+        Duration()                           :
             milliseconds(System::UInt64::MaxValue) {}
 
         property System::UInt64 Milliseconds
@@ -91,12 +89,12 @@ namespace Messaging {
         {
             return a->Milliseconds != b->Milliseconds;
         }
-};
+    };
 
     public ref class DurationConstants sealed
     {
-	private:
-		DurationConstants::DurationConstants() {}
+    private:
+        DurationConstants::DurationConstants() {}
 
     public:
         static Duration ^ FORVER;

Modified: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/FailoverUpdates.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/FailoverUpdates.cpp?rev=1221824&r1=1221823&r2=1221824&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/FailoverUpdates.cpp (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/FailoverUpdates.cpp Wed Dec 21 17:55:59 2011
@@ -38,26 +38,34 @@ namespace Messaging {
     /// FailoverUpdates is a managed wrapper for a qpid::messaging::FailoverUpdates
     /// </summary>
 
+    // Disallow access if object has been destroyed.
+    void FailoverUpdates::ThrowIfDisposed()
+    {
+        if (IsDisposed)
+            throw gcnew ObjectDisposedException (GetType()->FullName);
+    }
+
     // constructors
 
     FailoverUpdates::FailoverUpdates(Connection ^ connection)
     {
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-            failoverupdatesp = new ::qpid::messaging::FailoverUpdates(*(connection->NativeConnection));
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        try
+        {
+            privateLock = gcnew System::Object();
+            nativeObjPtr = new ::qpid::messaging::FailoverUpdates(*(connection->NativeConnection));
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
 
@@ -71,12 +79,15 @@ namespace Messaging {
     // Finalizer
     FailoverUpdates::!FailoverUpdates()
     {
-        msclr::lock lk(this);
-
-        if (NULL != failoverupdatesp)
+        if (NULL != nativeObjPtr)
         {
-            delete failoverupdatesp;
-            failoverupdatesp = NULL;
+            privateLock = gcnew System::Object();
+
+            if (NULL != nativeObjPtr)
+            {
+                delete nativeObjPtr;
+                nativeObjPtr = NULL;
+            }
         }
     }
 }}}}

Modified: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/FailoverUpdates.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/FailoverUpdates.h?rev=1221824&r1=1221823&r2=1221824&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/FailoverUpdates.h (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/FailoverUpdates.h Wed Dec 21 17:55:59 2011
@@ -40,7 +40,13 @@ namespace Messaging {
     {
     private:
         // The kept object in the Messaging C++ DLL
-        ::qpid::messaging::FailoverUpdates * failoverupdatesp;
+        ::qpid::messaging::FailoverUpdates * nativeObjPtr;
+
+        // per-instance lock object
+        System::Object ^ privateLock;
+
+        // Disallow use after object is destroyed
+        void ThrowIfDisposed();
 
     public:
         FailoverUpdates(Connection ^ connection);
@@ -48,16 +54,27 @@ namespace Messaging {
         ~FailoverUpdates();
         !FailoverUpdates();
 
+        //
+        // IsDisposed
+        //
+        property bool IsDisposed
+        {
+            bool get()
+            {
+                return NULL == nativeObjPtr;
+            }
+        }
+
     private:
-		// unmanaged clone
-		// not defined
+        // unmanaged clone
+        // not defined
 
         // copy constructor
         FailoverUpdates(const FailoverUpdates ^ failoverUpdates) {}
         FailoverUpdates(const FailoverUpdates % failoverUpdates) {}
 
         // assignment operator
-        FailoverUpdates % operator=(const FailoverUpdates % rhs) 
+        FailoverUpdates % operator=(const FailoverUpdates % rhs)
         {
             return *this;
         }

Modified: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Message.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Message.cpp?rev=1221824&r1=1221823&r2=1221824&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Message.cpp (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Message.cpp Wed Dec 21 17:55:59 2011
@@ -46,25 +46,34 @@ namespace Messaging {
     /// Message is a managed wrapper for a ::qpid::messaging::Message
     /// </summary>
 
+    // Disallow access if object has been destroyed.
+    void Message::ThrowIfDisposed()
+    {
+        if (IsDisposed)
+            throw gcnew ObjectDisposedException (GetType()->FullName);
+    }
+
+
     // Create empty message
     Message::Message()
     {
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-            messagep = new ::qpid::messaging::Message(QpidMarshal::ToNative(""));
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        try
+        {
+            privateLock = gcnew System::Object();
+            nativeObjPtr = new ::qpid::messaging::Message(QpidMarshal::ToNative(""));
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
     // Create from string
@@ -72,20 +81,21 @@ namespace Messaging {
     {
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-            messagep = new ::qpid::messaging::Message(QpidMarshal::ToNative(theStr));
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        try
+        {
+            privateLock = gcnew System::Object();
+            nativeObjPtr = new ::qpid::messaging::Message(QpidMarshal::ToNative(theStr));
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
     // Create from object
@@ -93,9 +103,10 @@ namespace Messaging {
     {
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-            messagep = new ::qpid::messaging::Message(QpidMarshal::ToNative(""));
+        try
+        {
+            privateLock = gcnew System::Object();
+            nativeObjPtr = new ::qpid::messaging::Message(QpidMarshal::ToNative(""));
 
             if (QpidTypeCheck::ObjectIsMap(theValue))
             {
@@ -108,10 +119,10 @@ namespace Messaging {
                 TypeTranslator::ManagedToNative((QpidMap ^)theValue, newMap);
 
                 // Set message content type
-                messagep->setContentType("ampq/map");
+                nativeObjPtr->setContentType("ampq/map");
 
                 // Insert the map into the message
-                ::qpid::messaging::encode(newMap, *messagep, QpidMarshal::ToNative("amqp/map"));
+                ::qpid::messaging::encode(newMap, *nativeObjPtr, QpidMarshal::ToNative("amqp/map"));
             }
             else if (QpidTypeCheck::ObjectIsList(theValue))
             {
@@ -124,99 +135,103 @@ namespace Messaging {
                 TypeTranslator::ManagedToNative((QpidList ^)theValue, newList);
 
                 // Set message content type
-                messagep->setContentType("ampq/list");
+                nativeObjPtr->setContentType("ampq/list");
 
                 // Insert the list into the message
-                ::qpid::messaging::encode(newList, *messagep, QpidMarshal::ToNative("amqp/list"));
+                ::qpid::messaging::encode(newList, *nativeObjPtr, QpidMarshal::ToNative("amqp/list"));
             }
             else
             {
                 // Create a binary string message
-                messagep->setContent(QpidMarshal::ToNative(theValue->ToString()));
+                nativeObjPtr->setContent(QpidMarshal::ToNative(theValue->ToString()));
             }
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
 
-	// Create from bytes
-	Message::Message(array<System::Byte> ^ bytes)
-	{
+    // Create from bytes
+    Message::Message(array<System::Byte> ^ bytes)
+    {
         System::Exception ^ newException = nullptr;
-        try 
-		{
-		    pin_ptr<unsigned char> pBytes = &bytes[0];
-		    messagep = new ::qpid::messaging::Message((char *)pBytes, bytes->Length);
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        try
+        {
+            privateLock = gcnew System::Object();
+            pin_ptr<unsigned char> pBytes = &bytes[0];
+            nativeObjPtr = new ::qpid::messaging::Message((char *)pBytes, bytes->Length);
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
-	}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
+    }
 
     // Create from byte array slice
-	Message::Message(array<System::Byte> ^ bytes, int offset, int size)
-	{
+    Message::Message(array<System::Byte> ^ bytes, int offset, int size)
+    {
         if ((offset + size) > bytes->Length)
-			throw gcnew QpidException("Message::Message Create from byte array slice: buffer length exceeded");
+            throw gcnew QpidException("Message::Message Create from byte array slice: buffer length exceeded");
 
         System::Exception ^ newException = nullptr;
-        try 
-		{
-		    pin_ptr<unsigned char> pBytes = &bytes[offset];
-		    messagep = new ::qpid::messaging::Message((char *)pBytes, size);
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        try
+        {
+            privateLock = gcnew System::Object();
+            pin_ptr<unsigned char> pBytes = &bytes[offset];
+            nativeObjPtr = new ::qpid::messaging::Message((char *)pBytes, size);
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
-	}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
+    }
 
 
-	// unmanaged clone
+    // unmanaged clone
     Message::Message(const ::qpid::messaging::Message & msgp)
     {
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-            messagep = new ::qpid::messaging::Message(msgp);
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        try
+        {
+            privateLock = gcnew System::Object();
+            nativeObjPtr = new ::qpid::messaging::Message(msgp);
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
 
     // Destructor
+    // Called by .NET Dispose() or C++ delete.
     Message::~Message()
     {
         this->!Message();
@@ -224,14 +239,18 @@ namespace Messaging {
 
 
     // Finalizer
+    // Called by Destructor or by System::GC
     Message::!Message()
     {
-        msclr::lock lk(this);
-
-        if (NULL != messagep)
+        if (NULL != nativeObjPtr)
         {
-            delete messagep;
-            messagep = NULL;
+            privateLock = gcnew System::Object();
+
+            if (NULL != nativeObjPtr)
+            {
+                delete nativeObjPtr;
+                nativeObjPtr = NULL;
+            }
         }
     }
 
@@ -240,21 +259,22 @@ namespace Messaging {
     {
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-            messagep = new ::qpid::messaging::Message(
-                        *(const_cast<Message ^>(message)->NativeMessage));
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        try
+        {
+            privateLock = gcnew System::Object();
+            nativeObjPtr = new ::qpid::messaging::Message(
+                *(const_cast<Message ^>(message)->NativeMessage));
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
     // Copy constructor implicitly dereferenced (C++)
@@ -262,135 +282,151 @@ namespace Messaging {
     {
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-            messagep = new ::qpid::messaging::Message(
-                        *(const_cast<Message %>(message).NativeMessage));
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        try
+        {
+            privateLock = gcnew System::Object();
+            nativeObjPtr = new ::qpid::messaging::Message(
+                *(const_cast<Message %>(message).NativeMessage));
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
     // Property
     void Message::SetProperty(System::String ^ name, System::Object ^ value)
     {
+        msclr::lock lk(privateLock);
+        ThrowIfDisposed();
+
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
+        try
+        {
             ::qpid::types::Variant entryValue;
             TypeTranslator::ManagedToNativeObject(value, entryValue);
 
-            messagep->getProperties()[QpidMarshal::ToNative(name)] = entryValue;
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+            nativeObjPtr->getProperties()[QpidMarshal::ToNative(name)] = entryValue;
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
-	// Content
-	void Message::SetContent(System::String ^ content)
+    // Content
+    void Message::SetContent(System::String ^ content)
     {
+        msclr::lock lk(privateLock);
+        ThrowIfDisposed();
+
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-            messagep->setContent(QpidMarshal::ToNative(content));
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        try
+        {
+            nativeObjPtr->setContent(QpidMarshal::ToNative(content));
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
 
     void Message::SetContent(cli::array<System::Byte> ^ bytes)
     {
+        msclr::lock lk(privateLock);
+        ThrowIfDisposed();
+
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-		    pin_ptr<unsigned char> pBytes = &bytes[0];
-		    messagep->setContent((char *)pBytes, bytes->Length);
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        try
+        {
+            pin_ptr<unsigned char> pBytes = &bytes[0];
+            nativeObjPtr->setContent((char *)pBytes, bytes->Length);
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
 
     void Message::SetContent(cli::array<System::Byte> ^ bytes, int offset, int size)
     {
+        msclr::lock lk(privateLock);
+        ThrowIfDisposed();
+
         if ((offset + size) > bytes->Length)
-			throw gcnew QpidException("Message::SetContent from byte array slice: buffer length exceeded");
+            throw gcnew QpidException("Message::SetContent from byte array slice: buffer length exceeded");
 
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-		    pin_ptr<unsigned char> pBytes = &bytes[offset];
-		    messagep->setContent((char *)pBytes, size);
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        try
+        {
+            pin_ptr<unsigned char> pBytes = &bytes[offset];
+            nativeObjPtr->setContent((char *)pBytes, size);
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
 
     System::String ^ Message::GetContent()
     {
+        msclr::lock lk(privateLock);
+        ThrowIfDisposed();
+
         System::String ^ result = nullptr;
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-            result = gcnew String(messagep->getContent().c_str());
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        try
+        {
+            result = gcnew String(nativeObjPtr->getContent().c_str());
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
 
         return result;
     }
@@ -400,30 +436,33 @@ namespace Messaging {
     // User wants to extract a Dictionary from the message
     //
     void Message::GetContent(System::Collections::Generic::Dictionary<
-                                System::String^, 
-                                System::Object^> ^ dict)
+        System::String^,
+        System::Object^> ^ dict)
     {
+        msclr::lock lk(privateLock);
+        ThrowIfDisposed();
+
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
+        try
+        {
             // Extract the message map from the message
             ::qpid::types::Variant::Map map;
-            
-            ::qpid::messaging::decode(*messagep, map, QpidMarshal::ToNative("amqp/map"));
+
+            ::qpid::messaging::decode(*nativeObjPtr, map, QpidMarshal::ToNative("amqp/map"));
 
             TypeTranslator::NativeToManaged(map, dict);
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
 
@@ -431,121 +470,127 @@ namespace Messaging {
     // User wants to extract a list from the message
     //
     void Message::GetContent(System::Collections::ObjectModel::Collection<
-                        System::Object^> ^ list)
+        System::Object^> ^ list)
     {
+        msclr::lock lk(privateLock);
+        ThrowIfDisposed();
+
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
+        try
+        {
             // allocate a native messaging::List
             ::qpid::types::Variant::List nativeList;
-            
+
             // Extract the list from the message in native format
-            ::qpid::messaging::decode(*messagep, nativeList, QpidMarshal::ToNative("amqp/list"));
+            ::qpid::messaging::decode(*nativeObjPtr, nativeList, QpidMarshal::ToNative("amqp/list"));
 
             // translate native list into user's managed list
             TypeTranslator::NativeToManaged(nativeList, list);
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
     //
     // Return message content to raw byte array.
-    // On entry message size must not be zero and
-	// caller's byte array must be equal to message size.
+    // On entry, message size must not be zero and
+    // caller's byte array size must be equal to message size.
     //
     void Message::GetContent(array<System::Byte> ^ arr)
     {
+        msclr::lock lk(privateLock);
+        ThrowIfDisposed();
+
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-            System::UInt32 size = messagep->getContentSize();
-         
+        try
+        {
+            System::UInt32 size = (System::UInt32) nativeObjPtr->getContentSize();
+
             if (0 == size)
                 throw gcnew QpidException("Message::GetRaw - message size is zero");
 
             if (arr->Length != size)
                 throw gcnew QpidException("Message::GetRaw - receive buffer is wrong size");
 
-            const char * pMsgSrc = messagep->getContentPtr();
-		    pin_ptr<unsigned char> pArr = &arr[0];
-		    memcpy(pArr, pMsgSrc, size);
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+            const char * pMsgSrc = nativeObjPtr->getContentPtr();
+            pin_ptr<unsigned char> pArr = &arr[0];
+            memcpy(pArr, pMsgSrc, size);
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
     }
 
 
-	System::String ^ Message::MapAsString(System::Collections::Generic::Dictionary<
-					           System::String^, System::Object^> ^ dict)
+    System::String ^ Message::MapAsString(System::Collections::Generic::Dictionary<
+        System::String^, System::Object^> ^ dict)
     {
-	    System::Text::StringBuilder ^ sb = gcnew System::Text::StringBuilder("{");
+        System::Text::StringBuilder ^ sb = gcnew System::Text::StringBuilder("{");
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-		    System::String ^ leading = "";
+        try
+        {
+            System::String ^ leading = "";
 
-		    for each (System::Collections::Generic::KeyValuePair
-			         <System::String^, System::Object^> kvp in dict)
+            for each (System::Collections::Generic::KeyValuePair
+                <System::String^, System::Object^> kvp in dict)
             {
                 sb->Append(leading);
                 leading = ", ";
 
-			    if (QpidTypeCheck::ObjectIsMap(kvp.Value))
+                if (QpidTypeCheck::ObjectIsMap(kvp.Value))
                 {
-				    sb->AppendFormat(
-					    "{0}={1}", 
-					    kvp.Key,
-					    MapAsString((System::Collections::Generic::Dictionary<System::String^, System::Object^> ^)kvp.Value));
+                    sb->AppendFormat(
+                        "{0}={1}",
+                        kvp.Key,
+                        MapAsString((System::Collections::Generic::Dictionary<System::String^, System::Object^> ^)kvp.Value));
                 }
-			    else if (QpidTypeCheck::ObjectIsList(kvp.Value))
+                else if (QpidTypeCheck::ObjectIsList(kvp.Value))
                 {
                     sb->AppendFormat(
-					    "{0}={1}", 
-					    kvp.Key,
-					    ListAsString((System::Collections::ObjectModel::Collection<
-							    System::Object^> ^)kvp.Value));
+                        "{0}={1}",
+                        kvp.Key,
+                        ListAsString((System::Collections::ObjectModel::Collection<
+                        System::Object^> ^)kvp.Value));
                 }
                 else if (nullptr == kvp.Value)
                 {
                     sb->AppendFormat(
-					    "{0}=", 
-					    kvp.Key);
+                        "{0}=",
+                        kvp.Key);
                 }
                 else
                     sb->AppendFormat("{0}={1}", kvp.Key, kvp.Value);
             }
-		    sb->Append("}");
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+            sb->Append("}");
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
 
         System::String ^ result = gcnew System::String(sb->ToString());
         return result;
@@ -555,29 +600,29 @@ namespace Messaging {
     /// A function to display a ampq/list message packaged as a List.
     /// </summary>
     /// <param name="list">The AMQP list</param>
-	System::String ^ Message::ListAsString(System::Collections::ObjectModel::Collection<System::Object^> ^ list)
+    System::String ^ Message::ListAsString(System::Collections::ObjectModel::Collection<System::Object^> ^ list)
     {
         System::Text::StringBuilder ^ sb = gcnew System::Text::StringBuilder("[");
         System::Exception ^ newException = nullptr;
 
-        try 
-		{
-		    System::String ^ leading = "";
+        try
+        {
+            System::String ^ leading = "";
 
-		    for each (System::Object ^ obj in list)
+            for each (System::Object ^ obj in list)
             {
                 sb->Append(leading);
                 leading = ", ";
 
-			    if (QpidTypeCheck::ObjectIsMap(obj))
+                if (QpidTypeCheck::ObjectIsMap(obj))
                 {
                     sb->Append(MapAsString((System::Collections::Generic::Dictionary<
-                                    System::String^, System::Object^> ^)obj));
+                        System::String^, System::Object^> ^)obj));
                 }
-			    else if (QpidTypeCheck::ObjectIsList(obj))
+                else if (QpidTypeCheck::ObjectIsList(obj))
                 {
                     sb->Append(ListAsString((System::Collections::ObjectModel::Collection<
-                                    System::Object^> ^)obj));
+                        System::Object^> ^)obj));
                 }
                 else if (nullptr == obj)
                 {
@@ -587,31 +632,31 @@ namespace Messaging {
                     sb->Append(obj->ToString());
             }
             sb->Append("]");
-        } 
-        catch (const ::qpid::types::Exception & error) 
-		{
+        }
+        catch (const ::qpid::types::Exception & error)
+        {
             String ^ errmsg = gcnew String(error.what());
             newException    = gcnew QpidException(errmsg);
         }
 
-		if (newException != nullptr) 
-		{
-	        throw newException;
-		}
+        if (newException != nullptr)
+        {
+            throw newException;
+        }
 
-	    System::String ^ result = gcnew System::String(sb->ToString());
+        System::String ^ result = gcnew System::String(sb->ToString());
         return result;
     }
 
-	System::String ^ Message::AsString(System::Object ^ obj)
-	{
-		if (QpidTypeCheck::ObjectIsMap(obj))
-			return MapAsString((System::Collections::Generic::Dictionary<
-                                System::String^, System::Object^> ^)obj);
-		else if (QpidTypeCheck::ObjectIsList(obj))
-			return ListAsString((System::Collections::ObjectModel::Collection<
-                                System::Object^> ^)obj);
-		else
-			return obj->ToString();
-	}
+    System::String ^ Message::AsString(System::Object ^ obj)
+    {
+        if (QpidTypeCheck::ObjectIsMap(obj))
+            return MapAsString((System::Collections::Generic::Dictionary<
+            System::String^, System::Object^> ^)obj);
+        else if (QpidTypeCheck::ObjectIsList(obj))
+            return ListAsString((System::Collections::ObjectModel::Collection<
+            System::Object^> ^)obj);
+        else
+            return obj->ToString();
+    }
 }}}}

Modified: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Message.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Message.h?rev=1221824&r1=1221823&r2=1221824&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Message.h (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Message.h Wed Dec 21 17:55:59 2011
@@ -48,7 +48,13 @@ namespace Messaging {
 
     private:
         // The kept object in the Messaging C++ DLL
-        ::qpid::messaging::Message * messagep;
+        ::qpid::messaging::Message * nativeObjPtr;
+
+        // per-instance lock object
+        System::Object ^ privateLock;
+
+        // Disallow use after object is destroyed
+        void ThrowIfDisposed();
 
     public:
         // Create empty message
@@ -61,11 +67,12 @@ namespace Messaging {
         Message(System::Object ^ theValue);
 
         // Create from byte array
-		Message(array<System::Byte> ^ bytes);
+        Message(array<System::Byte> ^ bytes);
 
         // Create from byte array slice
-		Message(array<System::Byte> ^ bytes, int offset, int size);
+        Message(array<System::Byte> ^ bytes, int offset, int size);
 
+        // System destructor/finalizer entry points
         ~Message();
         !Message();
 
@@ -73,48 +80,72 @@ namespace Messaging {
         Message(const Message ^ message);
         Message(const Message % message);
 
-	    // unmanaged clone
+        // unmanaged clone
         Message(const ::qpid::messaging::Message & msgp);
 
         // assignment operator
         Message % operator=(const Message % rhs)
         {
+            msclr::lock lk(privateLock);
+            ThrowIfDisposed();
+
             if (this == %rhs)
             {
                 // Self assignment, do nothing
             }
             else
             {
-                if (NULL != messagep)
-                    delete messagep;
-                messagep = new ::qpid::messaging::Message(
+                if (NULL != nativeObjPtr)
+                    delete nativeObjPtr;
+                nativeObjPtr = new ::qpid::messaging::Message(
                     *(const_cast<Message %>(rhs).NativeMessage) );
             }
             return *this;
         }
 
         //
+        // IsDisposed
+        //
+        property bool IsDisposed
+        {
+            bool get()
+            {
+                return NULL == nativeObjPtr;
+            }
+        }
+
+
+        //
         // NativeMessage
         //
         property ::qpid::messaging::Message * NativeMessage
         {
-            ::qpid::messaging::Message * get () { return messagep; }
+            ::qpid::messaging::Message * get ()
+            {
+                return nativeObjPtr;
+            }
         }
 
         //
         // ReplyTo
         //
-        property Address ^ ReplyTo 
+        property Address ^ ReplyTo
         {
             void set (Address ^ address)
             {
-                 messagep->setReplyTo(*(address->NativeAddress));
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                nativeObjPtr->setReplyTo(*(address->NativeAddress));
             }
 
-            Address ^ get () 
+            Address ^ get ()
             {
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
                 const ::qpid::messaging::Address & addrp =
-                    messagep->::qpid::messaging::Message::getReplyTo();
+                    nativeObjPtr->::qpid::messaging::Message::getReplyTo();
 
                 return gcnew Address(addrp);
             }
@@ -127,13 +158,18 @@ namespace Messaging {
         {
             void set (System::String ^ subject)
             {
-                messagep->setSubject(QpidMarshal::ToNative(subject));
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                nativeObjPtr->setSubject(QpidMarshal::ToNative(subject));
             }
-            
-            
+
             System::String ^ get ()
             {
-                return gcnew String(messagep->getSubject().c_str());
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                return gcnew String(nativeObjPtr->getSubject().c_str());
             }
         }
 
@@ -145,15 +181,21 @@ namespace Messaging {
         {
             void set (System::String ^ ct)
             {
-                messagep->setContentType(QpidMarshal::ToNative(ct));
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                nativeObjPtr->setContentType(QpidMarshal::ToNative(ct));
             }
-            
-	        System::String ^ get ()
+
+            System::String ^ get ()
             {
-		        return gcnew String(messagep->::qpid::messaging::Message::getContentType().c_str());
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                return gcnew String(nativeObjPtr->::qpid::messaging::Message::getContentType().c_str());
             }
         }
-    
+
 
         //
         // MessageId
@@ -162,16 +204,22 @@ namespace Messaging {
         {
             void set (System::String ^ messageId)
             {
-                messagep->setMessageId(QpidMarshal::ToNative(messageId));
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                nativeObjPtr->setMessageId(QpidMarshal::ToNative(messageId));
             }
 
             System::String ^ get ()
             {
-                return gcnew String(messagep->getMessageId().c_str());
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                return gcnew String(nativeObjPtr->getMessageId().c_str());
             }
         }
 
-        
+
         //
         // UserId
         //
@@ -179,16 +227,22 @@ namespace Messaging {
         {
             void set (System::String ^ uId)
             {
-                messagep->setUserId(QpidMarshal::ToNative(uId));
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                nativeObjPtr->setUserId(QpidMarshal::ToNative(uId));
             }
-            
+
             System::String ^ get ()
             {
-                return gcnew String(messagep->getUserId().c_str());
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                return gcnew String(nativeObjPtr->getUserId().c_str());
             }
         }
 
-            
+
         //
         // CorrelationId
         //
@@ -196,12 +250,18 @@ namespace Messaging {
         {
             void set (System::String ^ correlationId)
             {
-                messagep->setCorrelationId(QpidMarshal::ToNative(correlationId));
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                nativeObjPtr->setCorrelationId(QpidMarshal::ToNative(correlationId));
             }
-            
+
             System::String ^ get ()
             {
-                return gcnew String(messagep->getCorrelationId().c_str());
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                return gcnew String(nativeObjPtr->getCorrelationId().c_str());
             }
         }
 
@@ -213,14 +273,20 @@ namespace Messaging {
         {
             void set (unsigned char priority)
             {
-                messagep->setPriority(priority);
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                nativeObjPtr->setPriority(priority);
             }
-            
+
             unsigned char get ()
             {
-                return messagep->getPriority();
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                return nativeObjPtr->getPriority();
             }
-        }   
+        }
 
 
         //
@@ -230,14 +296,20 @@ namespace Messaging {
         {
             void set (Duration ^ ttl)
             {
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
                 ::qpid::messaging::Duration dur(ttl->Milliseconds);
 
-                messagep->setTtl(dur);
+                nativeObjPtr->setTtl(dur);
             }
-            
+
             Duration ^ get ()
             {
-                Duration ^ dur = gcnew Duration(messagep->getTtl().getMilliseconds());
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                Duration ^ dur = gcnew Duration(nativeObjPtr->getTtl().getMilliseconds());
 
                 return dur;
             }
@@ -250,12 +322,18 @@ namespace Messaging {
         {
             void set (bool durable)
             {
-                messagep->setDurable(durable);
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                nativeObjPtr->setDurable(durable);
             }
-            
+
             bool get ()
             {
-                return messagep->getDurable();
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                return nativeObjPtr->getDurable();
             }
         }
 
@@ -266,12 +344,18 @@ namespace Messaging {
         {
             bool get ()
             {
-                return messagep->getRedelivered();
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                return nativeObjPtr->getRedelivered();
             }
 
             void set (bool redelivered)
             {
-                messagep->setRedelivered(redelivered);
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                nativeObjPtr->setRedelivered(redelivered);
             }
         }
 
@@ -284,19 +368,22 @@ namespace Messaging {
         // Properties
         //
         property System::Collections::Generic::Dictionary<
-                    System::String^, System::Object^> ^ Properties
+            System::String^, System::Object^> ^ Properties
         {
             System::Collections::Generic::Dictionary<
-                    System::String^, System::Object^> ^ get ()
+                System::String^, System::Object^> ^ get ()
             {
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
                 ::qpid::types::Variant::Map map;
 
-                map = messagep->getProperties();
+                map = nativeObjPtr->getProperties();
 
                 System::Collections::Generic::Dictionary<
                     System::String^, System::Object^> ^ dict =
                     gcnew System::Collections::Generic::Dictionary<
-                              System::String^, System::Object^> ;
+                    System::String^, System::Object^> ;
 
 
                 TypeTranslator::NativeToManaged(map, dict);
@@ -305,15 +392,18 @@ namespace Messaging {
             }
 
 
-	        void set (System::Collections::Generic::Dictionary<
-                    System::String^, System::Object^> ^ properties)
-	        {
-		        for each (System::Collections::Generic::KeyValuePair
-			             <System::String^, System::Object^> kvp in properties)
+            void set (System::Collections::Generic::Dictionary<
+                System::String^, System::Object^> ^ properties)
+            {
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                for each (System::Collections::Generic::KeyValuePair
+                    <System::String^, System::Object^> kvp in properties)
                 {
-			        SetProperty(kvp.Key, kvp.Value);
-		        }
-	        }
+                    SetProperty(kvp.Key, kvp.Value);
+                }
+            }
         }
 
 
@@ -330,12 +420,12 @@ namespace Messaging {
 
         // get content as dictionary
         void GetContent(System::Collections::Generic::Dictionary<
-                            System::String^, 
-                            System::Object^> ^ dict);
+            System::String^,
+            System::Object^> ^ dict);
 
         // get content as map
         void GetContent(System::Collections::ObjectModel::Collection<
-                            System::Object^> ^);
+            System::Object^> ^);
 
         // get content as bytes
         void GetContent(cli::array<System::Byte> ^ arr);
@@ -347,20 +437,23 @@ namespace Messaging {
         {
             System::UInt64 get ()
             {
-                return messagep->getContentSize();
+                msclr::lock lk(privateLock);
+                ThrowIfDisposed();
+
+                return nativeObjPtr->getContentSize();
             }
         }
 
 
-		// A message has been returned to managed code through GetContent().
-		// Display the content of that System::Object as a string.
-		System::String ^ AsString(System::Object ^ obj);
+        // A message has been returned to managed code through GetContent().
+        // Display the content of that System::Object as a string.
+        System::String ^ AsString(System::Object ^ obj);
+
+        System::String ^ MapAsString(System::Collections::Generic::Dictionary<
+            System::String^, System::Object^> ^ dict);
 
-		System::String ^ MapAsString(System::Collections::Generic::Dictionary<
-						System::String^, System::Object^> ^ dict);
-		
-		System::String ^ ListAsString(System::Collections::ObjectModel::Collection<
-			            System::Object^> ^ list);
+        System::String ^ ListAsString(System::Collections::ObjectModel::Collection<
+            System::Object^> ^ list);
 
         //TODO: EncodingException
 

Modified: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/QpidException.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/QpidException.h?rev=1221824&r1=1221823&r2=1221824&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/QpidException.h (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/QpidException.h Wed Dec 21 17:55:59 2011
@@ -31,11 +31,11 @@ public ref class QpidException : System:
 {
  public:
 
- QpidException() 
-	 : System::Exception() {}
+ QpidException()
+    : System::Exception() {}
 
- QpidException(String^ estring) 
-	 : System::Exception(estring) {}
+ QpidException(String^ estring)
+    : System::Exception(estring) {}
 
 };
 

Modified: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/QpidMarshal.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/QpidMarshal.h?rev=1221824&r1=1221823&r2=1221824&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/QpidMarshal.h (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/QpidMarshal.h Wed Dec 21 17:55:59 2011
@@ -34,24 +34,24 @@ namespace Messaging {
 private ref class QpidMarshal
 {
 private:
-	QpidMarshal::QpidMarshal() {}
+    QpidMarshal::QpidMarshal() {}
 
 public:
 
     /// <summary>
     /// Convert managed String into native UTF8-encoded string
-    /// TODO: figure out some encoding other that UTF-8
+    /// TODO: figure out some encoding other than UTF-8
     /// </summary>
 
-    static std::string ToNative (System::String^ managed) 
+    static std::string ToNative (System::String^ managed)
     {
-        if (managed->Length == 0) 
+        if (managed->Length == 0)
         {
             return std::string();
         }
 
         array<unsigned char>^ mbytes = Encoding::UTF8->GetBytes(managed);
-        if (mbytes->Length == 0) 
+        if (mbytes->Length == 0)
         {
             return std::string();
         }

Modified: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/QpidTypeCheck.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/QpidTypeCheck.h?rev=1221824&r1=1221823&r2=1221824&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/QpidTypeCheck.h (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/QpidTypeCheck.h Wed Dec 21 17:55:59 2011
@@ -39,18 +39,18 @@ namespace Messaging {
     /// </summary>
 
     typedef System::Collections::Generic::Dictionary<
-                System::String^, 
-                System::Object^> 
+                System::String^,
+                System::Object^>
                     QpidMap;
 
     typedef System::Collections::ObjectModel::Collection<
-                System::Object^> 
+                System::Object^>
                     QpidList;
 
     private ref class QpidTypeCheckConstants sealed
     {
-	private:
-		QpidTypeCheckConstants::QpidTypeCheckConstants() {}
+    private:
+        QpidTypeCheckConstants::QpidTypeCheckConstants() {}
 
     public:
         static System::Type const ^ const mapTypeP = System::Type::GetType(
@@ -62,8 +62,8 @@ namespace Messaging {
 
     public ref class QpidTypeCheck sealed
     {
-	private:
-		QpidTypeCheck::QpidTypeCheck() {}
+    private:
+        QpidTypeCheck::QpidTypeCheck() {}
 
     public:
 

Modified: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/ReadMe.txt
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/ReadMe.txt?rev=1221824&r1=1221823&r2=1221824&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/ReadMe.txt (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/ReadMe.txt Wed Dec 21 17:55:59 2011
@@ -2,14 +2,14 @@
     DYNAMIC LINK LIBRARY : Org.Apache.Qpid.Messaging Project Overview
 ========================================================================
 
-AppWizard has created this Org.Apache.Qpid.Messaging DLL for you.  
+AppWizard has created this Org.Apache.Qpid.Messaging DLL for you.
 
 This file contains a summary of what you will find in each of the files that
 make up your Org.Apache.Qpid.Messaging application.
 
 Org.Apache.Qpid.Messaging.vcproj
-    This is the main project file for VC++ projects generated using an Application Wizard. 
-    It contains information about the version of Visual C++ that generated the file, and 
+    This is the main project file for VC++ projects generated using an Application Wizard.
+    It contains information about the version of Visual C++ that generated the file, and
     information about the platforms, configurations, and project features selected with the
     Application Wizard.
 
@@ -21,9 +21,9 @@ Sender.[cpp h]
 Session.[cpp h]
     Managed code Interop layer modules to provide access to functions exported by
     qpidcommon.dll.
-    
+
 AssemblyInfo.cpp
-	Contains custom attributes for modifying assembly metadata.
+    Contains custom attributes for modifying assembly metadata.
 
 /////////////////////////////////////////////////////////////////////////////
 Other notes:



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org