Qpid .NET Messaging API  0.22
Sender.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/Sender.h"
00028 #include "qpid/messaging/Session.h"
00029 #include "qpid/messaging/Message.h"
00030 
00031 namespace qpid {
00032 namespace messaging {
00033     // Dummy class to satisfy linker
00034     class SenderImpl {};
00035 }}
00036 
00037 namespace Org {
00038 namespace Apache {
00039 namespace Qpid {
00040 namespace Messaging {
00041 
00045 
00046     ref class Session;
00047     ref class Message;
00048 
00049     public ref class Sender
00050     {
00051     private:
00052         // The kept object in the Messaging C++ DLL
00053         ::qpid::messaging::Sender * nativeObjPtr;
00054 
00055         // The session that created this Sender
00056         Session ^ parentSession;
00057 
00058         // per-instance lock object
00059         System::Object ^ privateLock;
00060 
00061         // Disallow use after object is destroyed
00062         void ThrowIfDisposed();
00063 
00064     public:
00065         // unmanaged clone
00066         Sender(const ::qpid::messaging::Sender & s,
00067             Session ^ sessRef);
00068 
00069         // copy constructor
00070         Sender(const Sender ^ sender);
00071         Sender(const Sender % sender);
00072 
00073         ~Sender();
00074         !Sender();
00075 
00076         // assignment operator
00077         Sender % operator=(const Sender % rhs)
00078         {
00079             msclr::lock lk(privateLock);
00080             ThrowIfDisposed();
00081 
00082             if (this == %rhs)
00083             {
00084                 // Self assignment, do nothing
00085             }
00086             else
00087             {
00088                 if (NULL != nativeObjPtr)
00089                     delete nativeObjPtr;
00090                 nativeObjPtr = new ::qpid::messaging::Sender(
00091                     *(const_cast<Sender %>(rhs).NativeSender));
00092                 parentSession = rhs.parentSession;
00093             }
00094             return *this;
00095         }
00096 
00097         //
00098         // IsDisposed
00099         //
00100         property bool IsDisposed
00101         {
00102             bool get()
00103             {
00104                 return NULL == nativeObjPtr;
00105             }
00106         }
00107 
00108 
00109         //
00110         // NativeSender
00111         //
00112         property ::qpid::messaging::Sender * NativeSender
00113         {
00114             ::qpid::messaging::Sender * get ()
00115             {
00116                 return nativeObjPtr;
00117             }
00118         }
00119 
00120 
00121         // Send(message)
00122         void Send(Message ^ mmsgp);
00123         void Send(Message ^ mmsgp, bool sync);
00124 
00125         void Close();
00126 
00127         property System::UInt32 Capacity
00128         {
00129             System::UInt32 get ()
00130             {
00131                 msclr::lock lk(privateLock);
00132                 ThrowIfDisposed();
00133 
00134                 return nativeObjPtr->getCapacity();
00135             }
00136             void set (System::UInt32 capacity)
00137             {
00138                 msclr::lock lk(privateLock);
00139                 ThrowIfDisposed();
00140 
00141                 nativeObjPtr->setCapacity(capacity);
00142             }
00143         }
00144 
00145         property System::UInt32 Unsettled
00146         {
00147             System::UInt32 get ()
00148             {
00149                 msclr::lock lk(privateLock);
00150                 ThrowIfDisposed();
00151 
00152                 return nativeObjPtr->getUnsettled();
00153             }
00154         }
00155 
00156         property System::UInt32 Available
00157         {
00158             System::UInt32 get ()
00159             {
00160                 msclr::lock lk(privateLock);
00161                 ThrowIfDisposed();
00162 
00163                 return nativeObjPtr->getAvailable();
00164             }
00165         }
00166 
00167         property System::String ^ Name
00168         {
00169             System::String ^ get ()
00170             {
00171                 msclr::lock lk(privateLock);
00172                 ThrowIfDisposed();
00173 
00174                 return gcnew System::String(nativeObjPtr->getName().c_str());
00175             }
00176         }
00177 
00178         //
00179         // Session
00180         //
00181         property Org::Apache::Qpid::Messaging::Session ^ Session
00182         {
00183             Org::Apache::Qpid::Messaging::Session ^ get ()
00184             {
00185                 msclr::lock lk(privateLock);
00186                 ThrowIfDisposed();
00187 
00188                 return parentSession;
00189             }
00190         }
00191     };
00192 }}}}