Qpid .NET Messaging API  0.22
Connection.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 
00020 #pragma once
00021 
00022 #include <windows.h>
00023 #include <msclr\lock.h>
00024 #include <oletx2xa.h>
00025 #include <string>
00026 #include <limits>
00027 
00028 #include "qpid/messaging/Connection.h"
00029 #include "qpid/messaging/Session.h"
00030 
00031 namespace Org {
00032 namespace Apache {
00033 namespace Qpid {
00034 namespace Messaging {
00035 
00039 
00040     ref class Session;
00041 
00042     public ref class Connection
00043     {
00044     private:
00045         // The kept object in the Messaging C++ DLL
00046         ::qpid::messaging::Connection * nativeObjPtr;
00047 
00048         // per-instance lock object
00049         System::Object ^ privateLock;
00050 
00051         // Disallow use after object is destroyed
00052         void ThrowIfDisposed();
00053 
00054     public:
00055         Connection(System::String ^ url);
00056 
00057         Connection(System::String ^ url,
00058             System::Collections::Generic::Dictionary<
00059             System::String ^, System::Object ^> ^ options);
00060 
00061         Connection(System::String ^ url, System::String ^ options);
00062 
00063         // copy constructor
00064         Connection(const Connection ^ connection);
00065         Connection(const Connection % connection);
00066 
00067         // unmanaged clone
00068         // not defined
00069 
00070         ~Connection();
00071         !Connection();
00072 
00073         // assignment operator
00074         Connection % operator=(const Connection % rhs)
00075         {
00076             msclr::lock lk(privateLock);
00077             ThrowIfDisposed();
00078 
00079             if (this == %rhs)
00080             {
00081                 // Self assignment, do nothing
00082             }
00083             else
00084             {
00085                 if (NULL != nativeObjPtr)
00086                     delete nativeObjPtr;
00087                 nativeObjPtr = new ::qpid::messaging::Connection(
00088                     *(const_cast<Connection %>(rhs).NativeConnection) );
00089             }
00090             return *this;
00091         }
00092 
00093         //
00094         // IsDisposed
00095         //
00096         property bool IsDisposed
00097         {
00098             bool get()
00099             {
00100                 return NULL == nativeObjPtr;
00101             }
00102         }
00103 
00104 
00105         //
00106         // NativeConnection
00107         //
00108         property ::qpid::messaging::Connection * NativeConnection
00109         {
00110             ::qpid::messaging::Connection * get ()
00111             {
00112                 return nativeObjPtr;
00113             }
00114         }
00115 
00116         void SetOption(System::String ^ name, System::Object ^ value);
00117 
00118         void Open();
00119         void Close();
00120 
00121         property System::Boolean IsOpen
00122         {
00123             System::Boolean get ()
00124             {
00125                 msclr::lock lk(privateLock);
00126                 ThrowIfDisposed();
00127 
00128                 return nativeObjPtr->isOpen();
00129             }
00130         }
00131 
00132         // CreateTransactionalSession()
00133         Session ^ CreateTransactionalSession();
00134         Session ^ CreateTransactionalSession(System::String ^ name);
00135 
00136         // CreateSession()
00137         Session ^ CreateSession();
00138         Session ^ CreateSession(System::String ^ name);
00139 
00140         Session ^ GetSession(System::String ^ name);
00141 
00142         property System::String ^ AuthenticatedUsername
00143         {
00144             System::String ^ get ()
00145             {
00146                 msclr::lock lk(privateLock);
00147                 ThrowIfDisposed();
00148 
00149                 return gcnew System::String(nativeObjPtr->getAuthenticatedUsername().c_str());
00150             }
00151         }
00152     };
00153 }}}}