summaryrefslogtreecommitdiff
path: root/cpp/bindings/qpid/dotnet/src/Receiver.h
diff options
context:
space:
mode:
authorCharles E. Rolke <chug@apache.org>2011-12-21 17:55:59 +0000
committerCharles E. Rolke <chug@apache.org>2011-12-21 17:55:59 +0000
commit206bc27932ca66bf97275a2c344dcbc880a35693 (patch)
tree94a8f72b83d054875da8473184faacbb3a451677 /cpp/bindings/qpid/dotnet/src/Receiver.h
parent3618a37cbd5d04dfe6da99e65283127b451fafc3 (diff)
downloadqpid-python-206bc27932ca66bf97275a2c344dcbc880a35693.tar.gz
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. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1221824 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/bindings/qpid/dotnet/src/Receiver.h')
-rw-r--r--cpp/bindings/qpid/dotnet/src/Receiver.h74
1 files changed, 61 insertions, 13 deletions
diff --git a/cpp/bindings/qpid/dotnet/src/Receiver.h b/cpp/bindings/qpid/dotnet/src/Receiver.h
index 8ddcc9ac01..77b361851e 100644
--- a/cpp/bindings/qpid/dotnet/src/Receiver.h
+++ b/cpp/bindings/qpid/dotnet/src/Receiver.h
@@ -41,7 +41,7 @@ namespace Qpid {
namespace Messaging {
/// <summary>
- /// Mreceiver is a managed wrapper for a ::qpid::messaging::Receiver
+ /// Receiver is a managed wrapper for a ::qpid::messaging::Receiver
/// </summary>
ref class Session;
@@ -55,7 +55,13 @@ namespace Messaging {
Session ^ parentSession;
// The kept object in the Messaging C++ DLL
- ::qpid::messaging::Receiver * receiverp;
+ ::qpid::messaging::Receiver * nativeObjPtr;
+
+ // per-instance lock object
+ System::Object ^ privateLock;
+
+ // Disallow use after object is destroyed
+ void ThrowIfDisposed();
public:
@@ -76,24 +82,45 @@ namespace Messaging {
// assignment operator
Receiver % operator=(const Receiver % rhs)
{
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
if (this == %rhs)
{
// Self assignment, do nothing
}
else
{
- if (NULL != receiverp)
- delete receiverp;
- receiverp = new ::qpid::messaging::Receiver(
+ if (NULL != nativeObjPtr)
+ delete nativeObjPtr;
+ nativeObjPtr = new ::qpid::messaging::Receiver(
*(const_cast<Receiver %>(rhs).NativeReceiver));
parentSession = rhs.parentSession;
}
return *this;
}
+ //
+ // IsDisposed
+ //
+ property bool IsDisposed
+ {
+ bool get()
+ {
+ return NULL == nativeObjPtr;
+ }
+ }
+
+
+ //
+ // NativeReceiver
+ //
property ::qpid::messaging::Receiver * NativeReceiver
{
- ::qpid::messaging::Receiver * get () { return receiverp; }
+ ::qpid::messaging::Receiver * get ()
+ {
+ return nativeObjPtr;
+ }
}
// Get(message)
@@ -119,12 +146,18 @@ namespace Messaging {
{
void set (System::UInt32 capacity)
{
- receiverp->setCapacity(capacity);
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
+ nativeObjPtr->setCapacity(capacity);
}
System::UInt32 get ()
{
- return receiverp->getCapacity();
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
+ return nativeObjPtr->getCapacity();
}
}
@@ -135,7 +168,10 @@ namespace Messaging {
{
System::UInt32 get ()
{
- return receiverp->getAvailable();
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
+ return nativeObjPtr->getAvailable();
}
}
@@ -146,12 +182,15 @@ namespace Messaging {
{
System::UInt32 get ()
{
- return receiverp->getUnsettled();
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
+ return nativeObjPtr->getUnsettled();
}
}
void Close();
-
+
//
// IsClosed
//
@@ -159,7 +198,10 @@ namespace Messaging {
{
System::Boolean get ()
{
- return receiverp->isClosed();
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
+ return nativeObjPtr->isClosed();
}
}
@@ -170,7 +212,10 @@ namespace Messaging {
{
System::String ^ get ()
{
- return gcnew System::String(receiverp->getName().c_str());
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
+ return gcnew System::String(nativeObjPtr->getName().c_str());
}
}
@@ -181,6 +226,9 @@ namespace Messaging {
{
Org::Apache::Qpid::Messaging::Session ^ get ()
{
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
return parentSession;
}
}