Qpid .NET Messaging API  0.24
 All Classes Namespaces Files Functions Variables Typedefs
Message.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 #pragma once
20 
21 #include <windows.h>
22 #include <msclr\lock.h>
23 #include <oletx2xa.h>
24 #include <string>
25 #include <limits>
26 
27 #include "qpid/messaging/Message.h"
28 
29 #include "QpidMarshal.h"
30 #include "Address.h"
31 #include "Duration.h"
32 #include "TypeTranslator.h"
33 
34 namespace Org {
35 namespace Apache {
36 namespace Qpid {
37 namespace Messaging {
38 
39  ref class Address;
40  ref class Duration;
41 
45 
46  public ref class Message
47  {
48 
49  private:
50  // The kept object in the Messaging C++ DLL
51  ::qpid::messaging::Message * nativeObjPtr;
52 
53  // per-instance lock object
54  System::Object ^ privateLock;
55 
56  // Disallow use after object is destroyed
57  void ThrowIfDisposed();
58 
59  public:
60  // Create empty message
61  Message();
62 
63  // Create from String
64  Message(System::String ^ theStr);
65 
66  // Create from object
67  Message(System::Object ^ theValue);
68 
69  // Create from byte array
70  Message(array<System::Byte> ^ bytes);
71 
72  // Create from byte array slice
73  Message(array<System::Byte> ^ bytes, int offset, int size);
74 
75  // System destructor/finalizer entry points
76  ~Message();
77  !Message();
78 
79  // Copy constructor
80  Message(const Message ^ message);
81  Message(const Message % message);
82 
83  // unmanaged clone
84  Message(const ::qpid::messaging::Message & msgp);
85 
86  // assignment operator
87  Message % operator=(const Message % rhs)
88  {
89  msclr::lock lk(privateLock);
90  ThrowIfDisposed();
91 
92  if (this == %rhs)
93  {
94  // Self assignment, do nothing
95  }
96  else
97  {
98  if (NULL != nativeObjPtr)
99  delete nativeObjPtr;
100  nativeObjPtr = new ::qpid::messaging::Message(
101  *(const_cast<Message %>(rhs).NativeMessage) );
102  }
103  return *this;
104  }
105 
106  //
107  // IsDisposed
108  //
109  property bool IsDisposed
110  {
111  bool get()
112  {
113  return NULL == nativeObjPtr;
114  }
115  }
116 
117 
118  //
119  // NativeMessage
120  //
121  property ::qpid::messaging::Message * NativeMessage
122  {
123  ::qpid::messaging::Message * get ()
124  {
125  return nativeObjPtr;
126  }
127  }
128 
129  //
130  // ReplyTo
131  //
132  property Address ^ ReplyTo
133  {
134  void set (Address ^ address)
135  {
136  msclr::lock lk(privateLock);
137  ThrowIfDisposed();
138 
139  nativeObjPtr->setReplyTo(*(address->NativeAddress));
140  }
141 
142  Address ^ get ()
143  {
144  msclr::lock lk(privateLock);
145  ThrowIfDisposed();
146 
147  const ::qpid::messaging::Address & addrp =
148  nativeObjPtr->::qpid::messaging::Message::getReplyTo();
149 
150  return gcnew Address(addrp);
151  }
152  }
153 
154  //
155  // Subject
156  //
157  property System::String ^ Subject
158  {
159  void set (System::String ^ subject)
160  {
161  msclr::lock lk(privateLock);
162  ThrowIfDisposed();
163 
164  nativeObjPtr->setSubject(QpidMarshal::ToNative(subject));
165  }
166 
167  System::String ^ get ()
168  {
169  msclr::lock lk(privateLock);
170  ThrowIfDisposed();
171 
172  return gcnew String(nativeObjPtr->getSubject().c_str());
173  }
174  }
175 
176 
177  //
178  // ContentType
179  //
180  property System::String ^ ContentType
181  {
182  void set (System::String ^ ct)
183  {
184  msclr::lock lk(privateLock);
185  ThrowIfDisposed();
186 
187  nativeObjPtr->setContentType(QpidMarshal::ToNative(ct));
188  }
189 
190  System::String ^ get ()
191  {
192  msclr::lock lk(privateLock);
193  ThrowIfDisposed();
194 
195  return gcnew String(nativeObjPtr->::qpid::messaging::Message::getContentType().c_str());
196  }
197  }
198 
199 
200  //
201  // MessageId
202  //
203  property System::String ^ MessageId
204  {
205  void set (System::String ^ messageId)
206  {
207  msclr::lock lk(privateLock);
208  ThrowIfDisposed();
209 
210  nativeObjPtr->setMessageId(QpidMarshal::ToNative(messageId));
211  }
212 
213  System::String ^ get ()
214  {
215  msclr::lock lk(privateLock);
216  ThrowIfDisposed();
217 
218  return gcnew String(nativeObjPtr->getMessageId().c_str());
219  }
220  }
221 
222 
223  //
224  // UserId
225  //
226  property System::String ^ UserId
227  {
228  void set (System::String ^ uId)
229  {
230  msclr::lock lk(privateLock);
231  ThrowIfDisposed();
232 
233  nativeObjPtr->setUserId(QpidMarshal::ToNative(uId));
234  }
235 
236  System::String ^ get ()
237  {
238  msclr::lock lk(privateLock);
239  ThrowIfDisposed();
240 
241  return gcnew String(nativeObjPtr->getUserId().c_str());
242  }
243  }
244 
245 
246  //
247  // CorrelationId
248  //
249  property System::String ^ CorrelationId
250  {
251  void set (System::String ^ correlationId)
252  {
253  msclr::lock lk(privateLock);
254  ThrowIfDisposed();
255 
256  nativeObjPtr->setCorrelationId(QpidMarshal::ToNative(correlationId));
257  }
258 
259  System::String ^ get ()
260  {
261  msclr::lock lk(privateLock);
262  ThrowIfDisposed();
263 
264  return gcnew String(nativeObjPtr->getCorrelationId().c_str());
265  }
266  }
267 
268 
269  //
270  // Priority
271  //
272  property unsigned char Priority
273  {
274  void set (unsigned char priority)
275  {
276  msclr::lock lk(privateLock);
277  ThrowIfDisposed();
278 
279  nativeObjPtr->setPriority(priority);
280  }
281 
282  unsigned char get ()
283  {
284  msclr::lock lk(privateLock);
285  ThrowIfDisposed();
286 
287  return nativeObjPtr->getPriority();
288  }
289  }
290 
291 
292  //
293  // Ttl
294  //
295  property Duration ^ Ttl
296  {
297  void set (Duration ^ ttl)
298  {
299  msclr::lock lk(privateLock);
300  ThrowIfDisposed();
301 
302  ::qpid::messaging::Duration dur(ttl->Milliseconds);
303 
304  nativeObjPtr->setTtl(dur);
305  }
306 
307  Duration ^ get ()
308  {
309  msclr::lock lk(privateLock);
310  ThrowIfDisposed();
311 
312  Duration ^ dur = gcnew Duration(nativeObjPtr->getTtl().getMilliseconds());
313 
314  return dur;
315  }
316  }
317 
318  //
319  // Durable
320  //
321  property bool Durable
322  {
323  void set (bool durable)
324  {
325  msclr::lock lk(privateLock);
326  ThrowIfDisposed();
327 
328  nativeObjPtr->setDurable(durable);
329  }
330 
331  bool get ()
332  {
333  msclr::lock lk(privateLock);
334  ThrowIfDisposed();
335 
336  return nativeObjPtr->getDurable();
337  }
338  }
339 
340  //
341  // Redelivered
342  //
343  property bool Redelivered
344  {
345  bool get ()
346  {
347  msclr::lock lk(privateLock);
348  ThrowIfDisposed();
349 
350  return nativeObjPtr->getRedelivered();
351  }
352 
353  void set (bool redelivered)
354  {
355  msclr::lock lk(privateLock);
356  ThrowIfDisposed();
357 
358  nativeObjPtr->setRedelivered(redelivered);
359  }
360  }
361 
362  //
363  // Property
364  //
365  void Message::SetProperty(System::String ^ name, System::Object ^ value);
366 
367  //
368  // Properties
369  //
370  property System::Collections::Generic::Dictionary<
371  System::String^, System::Object^> ^ Properties
372  {
373  System::Collections::Generic::Dictionary<
374  System::String^, System::Object^> ^ get ()
375  {
376  msclr::lock lk(privateLock);
377  ThrowIfDisposed();
378 
379  ::qpid::types::Variant::Map map;
380 
381  map = nativeObjPtr->getProperties();
382 
383  System::Collections::Generic::Dictionary<
384  System::String^, System::Object^> ^ dict =
385  gcnew System::Collections::Generic::Dictionary<
386  System::String^, System::Object^> ;
387 
388 
389  TypeTranslator::NativeToManaged(map, dict);
390 
391  return dict;
392  }
393 
394 
395  void set (System::Collections::Generic::Dictionary<
396  System::String^, System::Object^> ^ properties)
397  {
398  msclr::lock lk(privateLock);
399  ThrowIfDisposed();
400 
401  for each (System::Collections::Generic::KeyValuePair
402  <System::String^, System::Object^> kvp in properties)
403  {
404  SetProperty(kvp.Key, kvp.Value);
405  }
406  }
407  }
408 
409 
410  void SetContent(System::String ^ content);
411 
412  void SetContent(cli::array<System::Byte> ^ bytes);
413 
414  void SetContent(cli::array<System::Byte> ^ bytes, int offset, int size);
415 
416  //TODO:: void setContent(Bytes{} bytes, offset, length);
417 
418  // get content as string
419  System::String ^ GetContent();
420 
421  // get content as dictionary
422  void GetContent(System::Collections::Generic::Dictionary<
423  System::String^,
424  System::Object^> ^ dict);
425 
426  // get content as map
427  void GetContent(System::Collections::ObjectModel::Collection<
428  System::Object^> ^);
429 
430  // get content as bytes
431  void GetContent(cli::array<System::Byte> ^ arr);
432 
433  //
434  // ContentSize
435  //
436  property System::UInt64 ContentSize
437  {
438  System::UInt64 get ()
439  {
440  msclr::lock lk(privateLock);
441  ThrowIfDisposed();
442 
443  return nativeObjPtr->getContentSize();
444  }
445  }
446 
447 
448  // A message has been returned to managed code through GetContent().
449  // Display the content of that System::Object as a string.
450  System::String ^ AsString(System::Object ^ obj);
451 
452  System::String ^ MapAsString(System::Collections::Generic::Dictionary<
453  System::String^, System::Object^> ^ dict);
454 
455  System::String ^ ListAsString(System::Collections::ObjectModel::Collection<
456  System::Object^> ^ list);
457 
458  //TODO: EncodingException
459 
460  // Note: encode/decode functions are in TypeTranslator
461  };
462 }}}}