Qpid .NET Messaging API  0.22
Session.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/Session.h"
00028 #include "qpid/messaging/Connection.h"
00029 #include "qpid/messaging/Duration.h"
00030 #include "qpid/messaging/Receiver.h"
00031 #include "qpid/messaging/Sender.h"
00032 
00033 namespace qpid {
00034 namespace messaging {
00035     // Dummy class to satisfy linker
00036     class SessionImpl {};
00037 }}
00038 
00039 namespace Org {
00040 namespace Apache {
00041 namespace Qpid {
00042 namespace Messaging {
00043 
00047 
00048     ref class Address;
00049     ref class Connection;
00050     ref class Duration;
00051     ref class Receiver;
00052     ref class Sender;
00053     ref class Message;
00054 
00055     public ref class Session
00056     {
00057     private:
00058         // The kept object in the Messaging C++ DLL
00059         ::qpid::messaging::Session * nativeObjPtr;
00060 
00061         // The connection that created this session
00062         Connection ^ parentConnectionp;
00063 
00064         // per-instance lock object
00065         System::Object ^ privateLock;
00066 
00067         // Disallow use after object is destroyed
00068         void ThrowIfDisposed();
00069 
00070     public:
00071 
00072         // unmanaged clone
00073         Session(const ::qpid::messaging::Session & nativeObjPtr,
00074             Connection ^ connRef);
00075 
00076         // copy constructor
00077         Session(const Session ^ session);
00078         Session(const Session % session);
00079 
00080         ~Session();
00081         !Session();
00082 
00083         // assignment operator
00084         Session % operator=(const Session % rhs)
00085         {
00086             msclr::lock lk(privateLock);
00087             ThrowIfDisposed();
00088 
00089             if (this == %rhs)
00090             {
00091                 // Self assignment, do nothing
00092             }
00093             else
00094             {
00095                 if (NULL != nativeObjPtr)
00096                     delete nativeObjPtr;
00097                 nativeObjPtr = new ::qpid::messaging::Session(
00098                     *(const_cast<Session %>(rhs).NativeSession) );
00099                 parentConnectionp = rhs.parentConnectionp;
00100             }
00101             return *this;
00102         }
00103 
00104         //
00105         // IsDisposed
00106         //
00107         property bool IsDisposed
00108         {
00109             bool get()
00110             {
00111                 return NULL == nativeObjPtr;
00112             }
00113         }
00114 
00115 
00116         //
00117         // NativeSession
00118         //
00119         property ::qpid::messaging::Session * NativeSession
00120         {
00121             ::qpid::messaging::Session * get ()
00122             {
00123                 return nativeObjPtr;
00124             }
00125         }
00126 
00127         void Close();
00128         void Commit();
00129         void Rollback();
00130         void Acknowledge();
00131         void Acknowledge(bool sync);
00132         void Acknowledge(Message ^ message);
00133         void Acknowledge(Message ^ message, bool sync);
00134         void AcknowledgeUpTo(Message ^ message);
00135         void AcknowledgeUpTo(Message ^ message, bool sync);
00136         void Reject(Message ^);
00137         void Release(Message ^);
00138         void Sync();
00139         void Sync(bool block);
00140 
00141         property System::UInt32 Receivable
00142         {
00143             System::UInt32 get ()
00144             {
00145                 msclr::lock lk(privateLock);
00146                 ThrowIfDisposed();
00147 
00148                 return nativeObjPtr->getReceivable();
00149             }
00150         }
00151 
00152         property System::UInt32 UnsettledAcks
00153         {
00154             System::UInt32 get ()
00155             {
00156                 msclr::lock lk(privateLock);
00157                 ThrowIfDisposed();
00158 
00159                 return nativeObjPtr->getUnsettledAcks();
00160             }
00161         }
00162 
00163         // next(receiver)
00164         bool NextReceiver(Receiver ^ rcvr);
00165         bool NextReceiver(Receiver ^ rcvr, Duration ^ timeout);
00166 
00167         // receiver = next()
00168         Receiver ^ NextReceiver();
00169         Receiver ^ NextReceiver(Duration ^ timeout);
00170 
00171 
00172         Sender   ^ CreateSender(System::String ^ address);
00173         Sender   ^ CreateSender(Address ^ address);
00174 
00175         Receiver ^ CreateReceiver(System::String ^ address);
00176         Receiver ^ CreateReceiver(Address ^ address);
00177 
00178         Sender   ^ GetSender(System::String ^ name);
00179         Receiver ^ GetReceiver(System::String ^ name);
00180 
00181         property Org::Apache::Qpid::Messaging::Connection ^ Connection
00182         {
00183             Org::Apache::Qpid::Messaging::Connection ^ get ()
00184             {
00185                 msclr::lock lk(privateLock);
00186                 ThrowIfDisposed();
00187 
00188                 return parentConnectionp;
00189             }
00190         }
00191 
00192 
00193         property System::Boolean HasError
00194         {
00195             System::Boolean get ()
00196             {
00197                 msclr::lock lk(privateLock);
00198                 ThrowIfDisposed();
00199 
00200                 return nativeObjPtr->hasError();
00201             }
00202         }
00203 
00204         void CheckError();
00205     };
00206 }}}}