Qpid .NET Messaging API  0.26
 All Classes Namespaces Files Functions Variables Typedefs
Address.h
Go to the documentation of this file.
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 
20 #pragma once
21 
22 #include <windows.h>
23 #include <msclr\lock.h>
24 #include <oletx2xa.h>
25 #include <string>
26 #include <limits>
27 
28 #include "qpid/messaging/Address.h"
29 
30 #include "QpidMarshal.h"
31 #include "QpidTypeCheck.h"
32 #include "TypeTranslator.h"
33 
34 namespace Org {
35 namespace Apache {
36 namespace Qpid {
37 namespace Messaging {
38 
42 
43  public ref class Address
44  {
45  private:
46  // The kept object in the Messaging C++ DLL
47  ::qpid::messaging::Address * nativeObjPtr;
48 
49  // per-instance lock object
50  System::Object ^ privateLock;
51 
52  // Disallow use after object is destroyed
53  void ThrowIfDisposed();
54 
55  public:
56  Address();
57 
58  Address(System::String ^ address);
59 
60  Address(System::String ^ name,
61  System::String ^ subject,
62  System::Collections::Generic::Dictionary<
63  System::String ^, System::Object ^> ^ options);
64 
65  Address(System::String ^ name,
66  System::String ^ subject,
67  System::Collections::Generic::Dictionary<
68  System::String ^, System::Object ^> ^ options,
69  System::String ^ type);
70 
71  // copy constructor
72  Address(const Address ^ address);
73  Address(const Address % address);
74 
75  // unmanaged clone
76  Address(const ::qpid::messaging::Address & addrp);
77 
78  // System destructor/finalizer entry points
79  ~Address();
80  !Address();
81 
82  // assignment operator
83  Address % operator=(const Address % rhs)
84  {
85  msclr::lock lk(privateLock);
86  ThrowIfDisposed();
87 
88  if (this == %rhs)
89  {
90  // Self assignment, do nothing
91  }
92  else
93  {
94  if (NULL != nativeObjPtr)
95  delete nativeObjPtr;
96  nativeObjPtr = new ::qpid::messaging::Address(
97  *(const_cast<Address %>(rhs).NativeAddress) );
98  }
99  return *this;
100  }
101 
102  //
103  // IsDisposed
104  //
105  property bool IsDisposed
106  {
107  bool get()
108  {
109  return NULL == nativeObjPtr;
110  }
111  }
112 
113 
114  //
115  // NativeAddress
116  //
117  property ::qpid::messaging::Address * NativeAddress
118  {
119  ::qpid::messaging::Address * get ()
120  {
121  return nativeObjPtr;
122  }
123  }
124 
125  //
126  // name
127  //
128  property System::String ^ Name
129  {
130  System::String ^ get ()
131  {
132  msclr::lock lk(privateLock);
133  ThrowIfDisposed();
134 
135  return gcnew System::String(nativeObjPtr->getName().c_str());
136  }
137 
138  void set (System::String ^ name)
139  {
140  msclr::lock lk(privateLock);
141  ThrowIfDisposed();
142 
143  nativeObjPtr->::qpid::messaging::Address::setName(QpidMarshal::ToNative(name));
144  }
145  }
146 
147 
148  //
149  // subject
150  //
151  property System::String ^ Subject
152  {
153  System::String ^ get ()
154  {
155  msclr::lock lk(privateLock);
156  ThrowIfDisposed();
157 
158  return gcnew System::String(nativeObjPtr->getSubject().c_str());
159  }
160 
161  void set (System::String ^ subject)
162  {
163  msclr::lock lk(privateLock);
164  ThrowIfDisposed();
165 
166  nativeObjPtr->setSubject(QpidMarshal::ToNative(subject));
167  }
168  }
169 
170 
171  //
172  // options
173  //
174  property System::Collections::Generic::Dictionary<
175  System::String ^, System::Object ^> ^ Options
176  {
177  System::Collections::Generic::Dictionary<
178  System::String ^, System::Object ^> ^ get ()
179  {
180  msclr::lock lk(privateLock);
181  ThrowIfDisposed();
182 
183  ::qpid::types::Variant::Map map;
184  System::Collections::Generic::Dictionary<
185  System::String ^, System::Object ^> ^ newMap =
186  gcnew System::Collections::Generic::Dictionary<
187  System::String ^, System::Object ^>;
188  map = nativeObjPtr->getOptions();
189  TypeTranslator::NativeToManaged(map, newMap);
190  return newMap;
191  }
192 
193 
194  void set (System::Collections::Generic::Dictionary<
195  System::String ^, System::Object ^> ^ options)
196  {
197  msclr::lock lk(privateLock);
198  ThrowIfDisposed();
199 
200  ::qpid::types::Variant::Map map;
201  TypeTranslator::ManagedToNative(options, map);
202  nativeObjPtr->setOptions(map);
203  }
204  }
205 
206 
207  //
208  // type
209  //
210  property System::String ^ Type
211  {
212  System::String ^ get ()
213  {
214  msclr::lock lk(privateLock);
215  ThrowIfDisposed();
216 
217  return gcnew System::String(nativeObjPtr->getType().c_str());
218  }
219 
220 
221  void set (System::String ^ type)
222  {
223  msclr::lock lk(privateLock);
224  ThrowIfDisposed();
225 
226  nativeObjPtr->setType(QpidMarshal::ToNative(type));
227  }
228  }
229 
230  System::String ^ ToStr();
231  };
232 }}}}
Address is a managed wrapper for a qpid::messaging::Address
Definition: Address.h:43
static std::string ToNative(System::String^managed)
Convert managed String into native UTF8-encoded string TODO: figure out some encoding other than UTF-...
Definition: QpidMarshal.h:46
Address operator=(const Address%rhs)
Definition: Address.h:83
Address()
Definition: Address.cpp:52
property bool IsDisposed
Definition: Address.h:106
~Address()
Definition: Address.cpp:225