Qpid .NET Messaging API  0.22
Address.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/Address.h"
00029 
00030 #include "QpidMarshal.h"
00031 #include "QpidTypeCheck.h"
00032 #include "TypeTranslator.h"
00033 
00034 namespace Org {
00035 namespace Apache {
00036 namespace Qpid {
00037 namespace Messaging {
00038 
00042 
00043     public ref class Address
00044     {
00045     private:
00046         // The kept object in the Messaging C++ DLL
00047         ::qpid::messaging::Address * nativeObjPtr;
00048 
00049         // per-instance lock object
00050         System::Object ^ privateLock;
00051 
00052         // Disallow use after object is destroyed
00053         void ThrowIfDisposed();
00054 
00055     public:
00056         Address();
00057 
00058         Address(System::String ^ address);
00059 
00060         Address(System::String ^ name,
00061             System::String ^ subject,
00062             System::Collections::Generic::Dictionary<
00063             System::String ^, System::Object ^> ^ options);
00064 
00065         Address(System::String ^ name,
00066             System::String ^ subject,
00067             System::Collections::Generic::Dictionary<
00068             System::String ^, System::Object ^> ^ options,
00069             System::String ^ type);
00070 
00071         // copy constructor
00072         Address(const Address ^ address);
00073         Address(const Address % address);
00074 
00075         // unmanaged clone
00076         Address(const ::qpid::messaging::Address & addrp);
00077 
00078         // System destructor/finalizer entry points
00079         ~Address();
00080         !Address();
00081 
00082         // assignment operator
00083         Address % operator=(const Address % 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::Address(
00097                     *(const_cast<Address %>(rhs).NativeAddress) );
00098             }
00099             return *this;
00100         }
00101 
00102         //
00103         // IsDisposed
00104         //
00105         property bool IsDisposed
00106         {
00107             bool get()
00108             {
00109                 return NULL == nativeObjPtr;
00110             }
00111         }
00112 
00113 
00114         //
00115         // NativeAddress
00116         //
00117         property ::qpid::messaging::Address * NativeAddress
00118         {
00119             ::qpid::messaging::Address * get ()
00120             {
00121                 return nativeObjPtr;
00122             }
00123         }
00124 
00125         //
00126         // name
00127         //
00128         property System::String ^ Name
00129         {
00130             System::String ^ get ()
00131             {
00132                 msclr::lock lk(privateLock);
00133                 ThrowIfDisposed();
00134 
00135                 return gcnew System::String(nativeObjPtr->getName().c_str());
00136             }
00137 
00138             void set (System::String ^ name)
00139             {
00140                 msclr::lock lk(privateLock);
00141                 ThrowIfDisposed();
00142 
00143                 nativeObjPtr->::qpid::messaging::Address::setName(QpidMarshal::ToNative(name));
00144             }
00145         }
00146 
00147 
00148         //
00149         // subject
00150         //
00151         property System::String ^ Subject
00152         {
00153             System::String ^ get ()
00154             {
00155                 msclr::lock lk(privateLock);
00156                 ThrowIfDisposed();
00157 
00158                 return gcnew System::String(nativeObjPtr->getSubject().c_str());
00159             }
00160 
00161             void set (System::String ^ subject)
00162             {
00163                 msclr::lock lk(privateLock);
00164                 ThrowIfDisposed();
00165 
00166                 nativeObjPtr->setSubject(QpidMarshal::ToNative(subject));
00167             }
00168         }
00169 
00170 
00171         //
00172         // options
00173         //
00174         property  System::Collections::Generic::Dictionary<
00175             System::String ^, System::Object ^> ^ Options
00176         {
00177             System::Collections::Generic::Dictionary<
00178                 System::String ^, System::Object ^> ^ get ()
00179             {
00180                 msclr::lock lk(privateLock);
00181                 ThrowIfDisposed();
00182 
00183                 ::qpid::types::Variant::Map map;
00184                 System::Collections::Generic::Dictionary<
00185                     System::String ^, System::Object ^> ^ newMap =
00186                     gcnew System::Collections::Generic::Dictionary<
00187                     System::String ^, System::Object ^>;
00188                 map = nativeObjPtr->getOptions();
00189                 TypeTranslator::NativeToManaged(map, newMap);
00190                 return newMap;
00191             }
00192 
00193 
00194             void set (System::Collections::Generic::Dictionary<
00195                 System::String ^, System::Object ^> ^ options)
00196             {
00197                 msclr::lock lk(privateLock);
00198                 ThrowIfDisposed();
00199 
00200                 ::qpid::types::Variant::Map map;
00201                 TypeTranslator::ManagedToNative(options, map);
00202                 nativeObjPtr->setOptions(map);
00203             }
00204         }
00205 
00206 
00207         //
00208         // type
00209         //
00210         property System::String ^ Type
00211         {
00212             System::String ^ get ()
00213             {
00214                 msclr::lock lk(privateLock);
00215                 ThrowIfDisposed();
00216 
00217                 return gcnew System::String(nativeObjPtr->getType().c_str());
00218             }
00219 
00220 
00221             void set (System::String ^ type)
00222             {
00223                 msclr::lock lk(privateLock);
00224                 ThrowIfDisposed();
00225 
00226                 nativeObjPtr->setType(QpidMarshal::ToNative(type));
00227             }
00228         }
00229 
00230         System::String ^ ToStr();
00231     };
00232 }}}}