Qpid .NET Messaging API  0.22
Receiver.h
Go to the documentation of this file.
00001 /*
00002 * Licensed to the Apache Software Foundation (ASF) under one
00003 * or more contributor license agreements.  See the NOTICE file
00004 * distributed with this work for additional information
00005 * regarding copyright ownership.  The ASF licenses this file
00006 * to you under the Apache License, Version 2.0 (the
00007 * "License"); you may not use this file except in compliance
00008 * with the License.  You may obtain a copy of the License at
00009 *
00010 *   http://www.apache.org/licenses/LICENSE-2.0
00011 *
00012 * Unless required by applicable law or agreed to in writing,
00013 * software distributed under the License is distributed on an
00014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00015 * KIND, either express or implied.  See the License for the
00016 * specific language governing permissions and limitations
00017 * under the License.
00018 */
00019 #pragma once
00020 
00021 #include <windows.h>
00022 #include <msclr\lock.h>
00023 #include <oletx2xa.h>
00024 #include <string>
00025 #include <limits>
00026 
00027 #include "qpid/messaging/Receiver.h"
00028 #include "qpid/messaging/Session.h"
00029 #include "qpid/messaging/Message.h"
00030 #include "qpid/messaging/Duration.h"
00031 
00032 namespace qpid {
00033 namespace messaging {
00034     // Dummy class to satisfy linker
00035     class ReceiverImpl {};
00036 }}
00037 
00038 namespace Org {
00039 namespace Apache {
00040 namespace Qpid {
00041 namespace Messaging {
00042 
00046 
00047     ref class Session;
00048     ref class Message;
00049     ref class Duration;
00050 
00051     public ref class Receiver
00052     {
00053     private:
00054         // The session that created this Receiver
00055         Session ^ parentSession;
00056 
00057         // The kept object in the Messaging C++ DLL
00058         ::qpid::messaging::Receiver * nativeObjPtr;
00059 
00060         // per-instance lock object
00061         System::Object ^ privateLock;
00062 
00063         // Disallow use after object is destroyed
00064         void ThrowIfDisposed();
00065 
00066     public:
00067 
00068         // unmanaged clone
00069         Receiver(const ::qpid::messaging::Receiver & r,
00070             Session ^ sessRef);
00071 
00072         // copy constructor
00073         Receiver(const Receiver ^ receiver);
00074         Receiver(const Receiver % receiver);
00075 
00076         // unmanaged clone
00077         // undefined
00078 
00079         ~Receiver();
00080         !Receiver();
00081 
00082         // assignment operator
00083         Receiver % operator=(const Receiver % rhs)
00084         {
00085             msclr::lock lk(privateLock);
00086             ThrowIfDisposed();
00087 
00088             if (this == %rhs)
00089             {
00090                 // Self assignment, do nothing
00091             }
00092             else
00093             {
00094                 if (NULL != nativeObjPtr)
00095                     delete nativeObjPtr;
00096                 nativeObjPtr = new ::qpid::messaging::Receiver(
00097                     *(const_cast<Receiver %>(rhs).NativeReceiver));
00098                 parentSession = rhs.parentSession;
00099             }
00100             return *this;
00101         }
00102 
00103         //
00104         // IsDisposed
00105         //
00106         property bool IsDisposed
00107         {
00108             bool get()
00109             {
00110                 return NULL == nativeObjPtr;
00111             }
00112         }
00113 
00114 
00115         //
00116         // NativeReceiver
00117         //
00118         property ::qpid::messaging::Receiver * NativeReceiver
00119         {
00120             ::qpid::messaging::Receiver * get ()
00121             {
00122                 return nativeObjPtr;
00123             }
00124         }
00125 
00126         // Get(message)
00127         bool Get(Message ^% mmsgp);
00128         bool Get(Message ^% mmsgp, Duration ^ durationp);
00129 
00130         // message = Get()
00131         Message ^ Get();
00132         Message ^ Get(Duration ^ durationp);
00133 
00134         // Fetch(message)
00135         bool Fetch(Message ^% mmsgp);
00136         bool Fetch(Message ^% mmsgp, Duration ^ duration);
00137 
00138         // message = Fetch()
00139         Message ^ Fetch();
00140         Message ^ Fetch(Duration ^ durationp);
00141 
00142         //
00143         // Capacity
00144         //
00145         property System::UInt32 Capacity
00146         {
00147             void set (System::UInt32 capacity)
00148             {
00149                 msclr::lock lk(privateLock);
00150                 ThrowIfDisposed();
00151 
00152                 nativeObjPtr->setCapacity(capacity);
00153             }
00154 
00155             System::UInt32 get ()
00156             {
00157                 msclr::lock lk(privateLock);
00158                 ThrowIfDisposed();
00159 
00160                 return nativeObjPtr->getCapacity();
00161             }
00162         }
00163 
00164         //
00165         // Available
00166         //
00167         property System::UInt32 Available
00168         {
00169             System::UInt32 get ()
00170             {
00171                 msclr::lock lk(privateLock);
00172                 ThrowIfDisposed();
00173 
00174                 return nativeObjPtr->getAvailable();
00175             }
00176         }
00177 
00178         //
00179         // Unsettled
00180         //
00181         property System::UInt32 Unsettled
00182         {
00183             System::UInt32 get ()
00184             {
00185                 msclr::lock lk(privateLock);
00186                 ThrowIfDisposed();
00187 
00188                 return nativeObjPtr->getUnsettled();
00189             }
00190         }
00191 
00192         void Close();
00193 
00194         //
00195         // IsClosed
00196         //
00197         property System::Boolean IsClosed
00198         {
00199             System::Boolean get ()
00200             {
00201                 msclr::lock lk(privateLock);
00202                 ThrowIfDisposed();
00203 
00204                 return nativeObjPtr->isClosed();
00205             }
00206         }
00207 
00208         //
00209         // Name
00210         //
00211         property System::String ^ Name
00212         {
00213             System::String ^ get ()
00214             {
00215                 msclr::lock lk(privateLock);
00216                 ThrowIfDisposed();
00217 
00218                 return gcnew System::String(nativeObjPtr->getName().c_str());
00219             }
00220         }
00221 
00222         //
00223         // Session
00224         //
00225         property Org::Apache::Qpid::Messaging::Session ^ Session
00226         {
00227             Org::Apache::Qpid::Messaging::Session ^ get ()
00228             {
00229                 msclr::lock lk(privateLock);
00230                 ThrowIfDisposed();
00231 
00232                 return parentSession;
00233             }
00234         }
00235     };
00236 }}}}