diff options
author | Ted Ross <tross@apache.org> | 2010-06-25 17:55:46 +0000 |
---|---|---|
committer | Ted Ross <tross@apache.org> | 2010-06-25 17:55:46 +0000 |
commit | cff7dc046568b207c9a08dea221427c54706c747 (patch) | |
tree | 95e7d49125ad4d552a1be163352fd4e04f62152a | |
parent | c3a6e87c3f21009135b5826de6917586477e0589 (diff) | |
download | qpid-python-cff7dc046568b207c9a08dea221427c54706c747.tar.gz |
QPID-2589 - Patch from Chuck Rolke
* Convert c-style Get() functions to c#-style properties.
* Add powershell helloworld example.
* Fix message SetContent to accept byte array or byte array slice.
* Re-code Session GetReceiver and GetSender not to malloc new objects but to create the objects on the stack.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@958052 13f79535-47bb-0310-9956-ffa450edef68
23 files changed, 498 insertions, 378 deletions
diff --git a/cpp/bindings/qpid/dotnet/examples/csharp.direct.receiver/csharp.direct.receiver.cs b/cpp/bindings/qpid/dotnet/examples/csharp.direct.receiver/csharp.direct.receiver.cs index af0b398da6..69f7a0d974 100644 --- a/cpp/bindings/qpid/dotnet/examples/csharp.direct.receiver/csharp.direct.receiver.cs +++ b/cpp/bindings/qpid/dotnet/examples/csharp.direct.receiver/csharp.direct.receiver.cs @@ -58,7 +58,7 @@ namespace CSharpDirect {
connection = new Connection(host);
connection.Open();
- if (!connection.IsOpen()) {
+ if (!connection.IsOpen) {
Console.WriteLine("Failed to open connection to host : {0}", host);
} else {
Session session = connection.CreateSession();
diff --git a/cpp/bindings/qpid/dotnet/examples/csharp.direct.sender/csharp.direct.sender.cs b/cpp/bindings/qpid/dotnet/examples/csharp.direct.sender/csharp.direct.sender.cs index b287af2563..2e80e8c47d 100644 --- a/cpp/bindings/qpid/dotnet/examples/csharp.direct.sender/csharp.direct.sender.cs +++ b/cpp/bindings/qpid/dotnet/examples/csharp.direct.sender/csharp.direct.sender.cs @@ -59,7 +59,7 @@ namespace csharp.direct.sender connection = new Connection(host);
connection.Open();
- if (!connection.IsOpen()) {
+ if (!connection.IsOpen) {
Console.WriteLine("Failed to open connection to host : {0}", host);
} else {
Session session = connection.CreateSession();
diff --git a/cpp/bindings/qpid/dotnet/examples/csharp.example.client/csharp.example.client.cs b/cpp/bindings/qpid/dotnet/examples/csharp.example.client/csharp.example.client.cs index 93459b6684..79b798e540 100644 --- a/cpp/bindings/qpid/dotnet/examples/csharp.example.client/csharp.example.client.cs +++ b/cpp/bindings/qpid/dotnet/examples/csharp.example.client/csharp.example.client.cs @@ -50,7 +50,7 @@ namespace Org.Apache.Qpid.Messaging.Examples { };
Message request = new Message("");
- request.SetReplyTo(responseQueue);
+ request.ReplyTo = responseQueue;
for (int i = 0; i < s.Length; i++) {
request.SetContent(s[i]);
diff --git a/cpp/bindings/qpid/dotnet/examples/csharp.example.drain/csharp.example.drain.cs b/cpp/bindings/qpid/dotnet/examples/csharp.example.drain/csharp.example.drain.cs index 6740e6a076..2d763a306d 100644 --- a/cpp/bindings/qpid/dotnet/examples/csharp.example.drain/csharp.example.drain.cs +++ b/cpp/bindings/qpid/dotnet/examples/csharp.example.drain/csharp.example.drain.cs @@ -47,17 +47,17 @@ namespace Org.Apache.Qpid.Messaging.Examples { while (receiver.Fetch(message, timeout))
{
Dictionary<string, object> properties = new Dictionary<string, object>();
- properties = message.GetProperties();
+ properties = message.Properties;
Console.Write("Message(properties={0}, content='",
message.MapAsString(properties));
- if ("amqp/map" == message.GetContentType())
+ if ("amqp/map" == message.ContentType)
{
Dictionary<string, object> content = new Dictionary<string, object>();
message.GetContent(content);
Console.Write(message.MapAsString(content));
}
- else if ("amqp/list" == message.GetContentType())
+ else if ("amqp/list" == message.ContentType)
{
Collection<object> content = new Collection<object>();
message.GetContent(content);
diff --git a/cpp/bindings/qpid/dotnet/examples/csharp.example.server/csharp.example.server.cs b/cpp/bindings/qpid/dotnet/examples/csharp.example.server/csharp.example.server.cs index af01e4b0f9..4ec56491ac 100644 --- a/cpp/bindings/qpid/dotnet/examples/csharp.example.server/csharp.example.server.cs +++ b/cpp/bindings/qpid/dotnet/examples/csharp.example.server/csharp.example.server.cs @@ -38,7 +38,7 @@ namespace Org.Apache.Qpid.Messaging.Examples { while (true) {
Message request = receiver.Fetch();
- Address address = request.GetReplyTo();
+ Address address = request.ReplyTo;
if (null != address) {
Sender sender = session.CreateSender(address);
diff --git a/cpp/bindings/qpid/dotnet/examples/csharp.example.spout/csharp.example.spout.cs b/cpp/bindings/qpid/dotnet/examples/csharp.example.spout/csharp.example.spout.cs index 7eeece3194..59ba35f12b 100644 --- a/cpp/bindings/qpid/dotnet/examples/csharp.example.spout/csharp.example.spout.cs +++ b/cpp/bindings/qpid/dotnet/examples/csharp.example.spout/csharp.example.spout.cs @@ -29,8 +29,8 @@ using Org.Apache.Qpid.Messaging; namespace Org.Apache.Qpid.Messaging.Examples {
class Spout {
//
- // Sample invocation: csharp.example.drain.exe --broker localhost:5672 --timeout 30 my-queue
- // This pro
+ // Sample invocation: csharp.example.spout.exe --broker localhost:5672 my-queue
+ //
static bool NameVal(string In, out string nameOut, out string valueOut)
{
int pos = In.IndexOf("=");
@@ -83,7 +83,7 @@ namespace Org.Apache.Qpid.Messaging.Examples { else
{
message = new Message(options.Content);
- message.SetContentType("text/plain");
+ message.ContentType = "text/plain";
}
Address replyToAddr = new Address(options.ReplyTo);
@@ -95,7 +95,7 @@ namespace Org.Apache.Qpid.Messaging.Examples { (0 == options.Timeout || stopwatch.Elapsed <= timespan);
count++)
{
- if ("" != options.ReplyTo) message.SetReplyTo(replyToAddr);
+ if ("" != options.ReplyTo) message.ReplyTo = replyToAddr;
string id = options.Id ;
if ("" == id) {
Guid g = Guid.NewGuid();
diff --git a/cpp/bindings/qpid/dotnet/examples/csharp.map.callback.receiver/csharp.map.callback.receiver.cs b/cpp/bindings/qpid/dotnet/examples/csharp.map.callback.receiver/csharp.map.callback.receiver.cs index 2ef78545b6..965b494dc7 100644 --- a/cpp/bindings/qpid/dotnet/examples/csharp.map.callback.receiver/csharp.map.callback.receiver.cs +++ b/cpp/bindings/qpid/dotnet/examples/csharp.map.callback.receiver/csharp.map.callback.receiver.cs @@ -93,14 +93,14 @@ namespace Org.Apache.Qpid.Messaging.Examples /// <param name="message">The Message</param>
public static void ShowMessage(Message message)
{
- if ("amqp/map" == message.GetContentType())
+ if ("amqp/map" == message.ContentType)
{
Console.WriteLine("Received a Dictionary");
Dictionary<string, object> content = new Dictionary<string, object>();
message.GetContent(content);
ShowDictionary(content, 0);
}
- else if ("amqp/list" == message.GetContentType())
+ else if ("amqp/list" == message.ContentType)
{
Console.WriteLine("Received a List");
Collection<object> content = new Collection<object>();
@@ -148,7 +148,7 @@ namespace Org.Apache.Qpid.Messaging.Examples //
// Acknowledge the receipt of all received messages.
//
- receiver.GetSession().Acknowledge();
+ receiver.Session.Acknowledge();
}
@@ -241,7 +241,7 @@ namespace Org.Apache.Qpid.Messaging.Examples //
// Establish a capacity
//
- receiver.SetCapacity(100);
+ receiver.Capacity = 100;
//
// Wait so many seconds for messages to arrive.
diff --git a/cpp/bindings/qpid/dotnet/examples/powershell.example.helloworld/powershell.example.helloworld.ps1 b/cpp/bindings/qpid/dotnet/examples/powershell.example.helloworld/powershell.example.helloworld.ps1 new file mode 100644 index 0000000000..e8c21bc3f6 --- /dev/null +++ b/cpp/bindings/qpid/dotnet/examples/powershell.example.helloworld/powershell.example.helloworld.ps1 @@ -0,0 +1,34 @@ +#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+#
+# Script for 32-bit powershell
+#
+
+[Reflection.Assembly]::LoadFile('W:\cpp\src\Debug\org.apache.qpid.messagingd.dll')
+$conn = new-object Org.Apache.Qpid.Messaging.Connection("localhost:5672")
+$conn.Open()
+$sess = $conn.CreateSession()
+$rcvr = $sess.CreateReceiver("amq.topic")
+$sender = $sess.CreateSender("amq.topic")
+$msg1 = new-object Org.Apache.Qpid.Messaging.Message("Hello world!")
+$sender.Send($msg1)
+$dur = new-object Org.Apache.Qpid.Messaging.Duration(1000)
+$msg2 = $rcvr.Fetch($dur)
+$msg2.GetContent()
diff --git a/cpp/bindings/qpid/dotnet/examples/visualbasic.example.client/visualbasic.example.client.vb b/cpp/bindings/qpid/dotnet/examples/visualbasic.example.client/visualbasic.example.client.vb index 96300ecf66..ccdc0d673c 100644 --- a/cpp/bindings/qpid/dotnet/examples/visualbasic.example.client/visualbasic.example.client.vb +++ b/cpp/bindings/qpid/dotnet/examples/visualbasic.example.client/visualbasic.example.client.vb @@ -48,7 +48,7 @@ Namespace Org.Apache.Qpid.Messaging.Examples s(3) = "And the mome raths outgrabe."
Dim request As Message = New Message("")
- request.SetReplyTo(responseQueue)
+ request.ReplyTo = responseQueue
Dim i As Integer
For i = 0 To s.Length - 1
diff --git a/cpp/bindings/qpid/dotnet/org.apache.qpid.messaging.sln b/cpp/bindings/qpid/dotnet/org.apache.qpid.messaging.sln index 8df1ea6796..38fd6dce24 100644 --- a/cpp/bindings/qpid/dotnet/org.apache.qpid.messaging.sln +++ b/cpp/bindings/qpid/dotnet/org.apache.qpid.messaging.sln @@ -60,6 +60,9 @@ EndProject Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "visualbasic.example.client", "examples\visualbasic.example.client\visualbasic.example.client.vbproj", "{CFEA696E-115B-4AD1-AB56-804E360EDD51}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Hello World", "Hello World", "{4408A2DA-ED2D-44AE-A465-0B6D75E1FF86}"
+ ProjectSection(SolutionItems) = preProject
+ examples\powershell.example.helloworld\powershell.example.helloworld.ps1 = examples\powershell.example.helloworld\powershell.example.helloworld.ps1
+ EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharp.example.helloworld", "examples\csharp.example.helloworld\csharp.example.helloworld.csproj", "{8CC1C265-0507-44A3-9483-8FAF48513F4D}"
EndProject
diff --git a/cpp/bindings/qpid/dotnet/src/Address.cpp b/cpp/bindings/qpid/dotnet/src/Address.cpp index f0bbe13bbb..2da40e6416 100644 --- a/cpp/bindings/qpid/dotnet/src/Address.cpp +++ b/cpp/bindings/qpid/dotnet/src/Address.cpp @@ -58,10 +58,10 @@ namespace Messaging { System::String ^, System::Object ^> ^ options) :
addressp(new ::qpid::messaging::Address())
{
- SetName(name);
- SetSubject(subject);
- SetOptions(options);
- SetType("");
+ Name = name;
+ Subject = subject;
+ Options = options;
+ Type = "";
}
@@ -72,10 +72,10 @@ namespace Messaging { System::String ^ type) :
addressp(new ::qpid::messaging::Address())
{
- SetName(name);
- SetSubject(subject);
- SetOptions(options);
- SetType(type);
+ Name = name;
+ Subject = subject;
+ Options = options;
+ Type = type;
}
@@ -112,71 +112,6 @@ namespace Messaging { //
- // name
- //
- System::String ^ Address::GetName()
- {
- return gcnew System::String(addressp->getName().c_str());
- }
-
- void Address::SetName(System::String ^ name)
- {
- addressp->::qpid::messaging::Address::setName(QpidMarshal::ToNative(name));
- }
-
- //
- // subject
- //
- System::String ^ Address::GetSubject()
- {
- return gcnew System::String(addressp->getSubject().c_str());
- }
-
- void Address::SetSubject(System::String ^ subject)
- {
- addressp->setSubject(QpidMarshal::ToNative(subject));
- }
-
- //
- // options
- //
- System::Collections::Generic::Dictionary<
- System::String ^, System::Object ^> ^ Address::GetOptions()
- {
- ::qpid::types::Variant::Map map;
- System::Collections::Generic::Dictionary<
- System::String ^, System::Object ^> ^ newMap =
- gcnew System::Collections::Generic::Dictionary<
- System::String ^, System::Object ^>;
- map = addressp->getOptions();
- TypeTranslator::NativeToManaged(map, newMap);
- return newMap;
- }
-
-
- void Address::SetOptions(System::Collections::Generic::Dictionary<
- System::String ^, System::Object ^> ^ options)
- {
- ::qpid::types::Variant::Map map;
- TypeTranslator::ManagedToNative(options, map);
- addressp->setOptions(map);
- }
-
- //
- // type
- //
- System::String ^ Address::GetType()
- {
- return gcnew System::String(addressp->getType().c_str());
- }
-
-
- void Address::SetType(System::String ^ type)
- {
- addressp->setName(QpidMarshal::ToNative(type));
- }
-
- //
// ToString
//
System::String ^ Address::ToStr()
diff --git a/cpp/bindings/qpid/dotnet/src/Address.h b/cpp/bindings/qpid/dotnet/src/Address.h index 60e24da2f0..9f940d67ea 100644 --- a/cpp/bindings/qpid/dotnet/src/Address.h +++ b/cpp/bindings/qpid/dotnet/src/Address.h @@ -27,6 +27,10 @@ #include "qpid/messaging/Address.h"
+#include "QpidMarshal.h"
+#include "QpidTypeCheck.h"
+#include "TypeTranslator.h"
+
namespace Org {
namespace Apache {
namespace Qpid {
@@ -73,20 +77,86 @@ namespace Messaging { ::qpid::messaging::Address * get () { return addressp; }
}
- System::String ^ GetName();
- void SetName(System::String ^ name);
+ //
+ // name
+ //
+ property System::String ^ Name
+ {
+ System::String ^ get ()
+ {
+ return gcnew System::String(addressp->getName().c_str());
+ }
+
+ void set (System::String ^ name)
+ {
+ addressp->::qpid::messaging::Address::setName(QpidMarshal::ToNative(name));
+ }
+ }
+
+
+ //
+ // subject
+ //
+ property System::String ^ Subject
+ {
+ System::String ^ get ()
+ {
+ return gcnew System::String(addressp->getSubject().c_str());
+ }
+
+ void set (System::String ^ subject)
+ {
+ addressp->setSubject(QpidMarshal::ToNative(subject));
+ }
+ }
+
- System::String ^ GetSubject();
- void SetSubject(System::String ^ subject);
+ //
+ // options
+ //
+ property System::Collections::Generic::Dictionary<
+ System::String ^, System::Object ^> ^ Options
+ {
+ System::Collections::Generic::Dictionary<
+ System::String ^, System::Object ^> ^ get ()
+ {
+ ::qpid::types::Variant::Map map;
+ System::Collections::Generic::Dictionary<
+ System::String ^, System::Object ^> ^ newMap =
+ gcnew System::Collections::Generic::Dictionary<
+ System::String ^, System::Object ^>;
+ map = addressp->getOptions();
+ TypeTranslator::NativeToManaged(map, newMap);
+ return newMap;
+ }
+
+
+ void set (System::Collections::Generic::Dictionary<
+ System::String ^, System::Object ^> ^ options)
+ {
+ ::qpid::types::Variant::Map map;
+ TypeTranslator::ManagedToNative(options, map);
+ addressp->setOptions(map);
+ }
+ }
- System::Collections::Generic::Dictionary<
- System::String ^, System::Object ^> ^ GetOptions();
- void SetOptions(System::Collections::Generic::Dictionary<
- System::String ^, System::Object ^> ^ options);
+ //
+ // type
+ //
+ property System::String ^ Type
+ {
+ System::String ^ get ()
+ {
+ return gcnew System::String(addressp->getType().c_str());
+ }
+
- System::String ^ GetType();
- void SetType(System::String ^ type);
+ void set (System::String ^ type)
+ {
+ addressp->setName(QpidMarshal::ToNative(type));
+ }
+ }
System::String ^ ToStr();
};
diff --git a/cpp/bindings/qpid/dotnet/src/Connection.cpp b/cpp/bindings/qpid/dotnet/src/Connection.cpp index 590cc5e69a..0e59c4196e 100644 --- a/cpp/bindings/qpid/dotnet/src/Connection.cpp +++ b/cpp/bindings/qpid/dotnet/src/Connection.cpp @@ -107,11 +107,6 @@ namespace Messaging { connectionp->open();
}
- System::Boolean Connection::IsOpen()
- {
- return connectionp->isOpen();
- }
-
void Connection::Close()
{
connectionp->close();
diff --git a/cpp/bindings/qpid/dotnet/src/Connection.h b/cpp/bindings/qpid/dotnet/src/Connection.h index e93e0781f3..8e0f40f803 100644 --- a/cpp/bindings/qpid/dotnet/src/Connection.h +++ b/cpp/bindings/qpid/dotnet/src/Connection.h @@ -62,9 +62,16 @@ namespace Messaging { void SetOption(System::String ^ name, System::Object ^ value);
void Open();
- System::Boolean IsOpen();
void Close();
+ property System::Boolean IsOpen
+ {
+ System::Boolean get ()
+ {
+ return connectionp->isOpen();
+ }
+ }
+
// CreateTransactionalSession()
Session ^ CreateTransactionalSession();
Session ^ CreateTransactionalSession(System::String ^ name);
diff --git a/cpp/bindings/qpid/dotnet/src/Message.cpp b/cpp/bindings/qpid/dotnet/src/Message.cpp index 743afce964..f620a099ca 100644 --- a/cpp/bindings/qpid/dotnet/src/Message.cpp +++ b/cpp/bindings/qpid/dotnet/src/Message.cpp @@ -158,190 +158,36 @@ namespace Messaging { }
}
-
- //
- // ReplyTo
- //
- void Message::SetReplyTo(Address ^ address)
- {
- messagep->setReplyTo(*(address->NativeAddress));
- }
-
- Address ^ Message::GetReplyTo()
- {
- const ::qpid::messaging::Address & addrp =
- messagep->::qpid::messaging::Message::getReplyTo();
-
- return gcnew Address(const_cast<::qpid::messaging::Address *>(&addrp));
- }
-
-
- //
- // Subject
- //
- void Message::SetSubject(System::String ^ subject)
- {
- messagep->setSubject(QpidMarshal::ToNative(subject));
- }
-
- System::String ^ Message::GetSubject()
- {
- return gcnew String(messagep->getSubject().c_str());
- }
-
-
- //
- // ContentType
- //
- void Message::SetContentType(System::String ^ ct)
- {
- messagep->setContentType(QpidMarshal::ToNative(ct));
- }
-
- System::String ^ Message::GetContentType()
- {
- return gcnew String(messagep->::qpid::messaging::Message::getContentType().c_str());
- }
-
-
- //
- // MessageId
- //
- void Message::SetMessageId(System::String ^ messageId)
- {
- messagep->setMessageId(QpidMarshal::ToNative(messageId));
- }
-
- System::String ^ Message::GetMessageId()
- {
- return gcnew String(messagep->getMessageId().c_str());
- }
-
-
- //
- // UserId
- //
- void Message::SetUserId(System::String ^ uId)
- {
- messagep->setUserId(QpidMarshal::ToNative(uId));
- }
-
- System::String ^ Message::GetUserId()
- {
- return gcnew String(messagep->getUserId().c_str());
- }
-
-
- //
- // CorrelationId
- //
- void Message::SetCorrelationId(System::String ^ correlationId)
- {
- messagep->setCorrelationId(QpidMarshal::ToNative(correlationId));
- }
-
- System::String ^ Message::GetCorrelationId()
- {
- return gcnew String(messagep->getCorrelationId().c_str());
- }
-
-
- //
- // Priority
- //
- void Message::SetPriority(unsigned char priority)
- {
- messagep->setPriority(priority);
- }
-
- unsigned char Message::GetPriority()
- {
- return messagep->getPriority();
- }
-
-
- //
- // Ttl
- //
- void Message::SetTtl(Duration ^ ttl)
- {
- ::qpid::messaging::Duration dur(ttl->Milliseconds);
-
- messagep->setTtl(dur);
- }
-
- Duration ^ Message::GetTtl()
+ // Property
+ void Message::SetProperty(System::String ^ name, System::Object ^ value)
{
- Duration ^ dur = gcnew Duration(messagep->getTtl().getMilliseconds());
+ ::qpid::types::Variant entryValue;
+ TypeTranslator::ManagedToNativeObject(value, entryValue);
- return dur;
+ messagep->getProperties()[QpidMarshal::ToNative(name)] = entryValue;
}
- void Message::SetDurable(bool durable)
- {
- messagep->setDurable(durable);
- }
-
- bool Message::GetDurable()
+ // Content
+ void Message::SetContent(System::String ^ content)
{
- return messagep->getDurable();
+ messagep->setContent(QpidMarshal::ToNative(content));
}
- bool Message::GetRedelivered()
+ void Message::SetContent(cli::array<System::Byte> ^ bytes)
{
- return messagep->getRedelivered();
+ pin_ptr<unsigned char> pBytes = &bytes[0];
+ messagep->setContent((char *)pBytes, bytes->Length);
}
- void Message::SetRedelivered(bool redelivered)
- {
- messagep->setRedelivered(redelivered);
- }
- // Properties
- System::Collections::Generic::Dictionary<
- System::String^, System::Object^> ^ Message::GetProperties()
+ void Message::SetContent(cli::array<System::Byte> ^ bytes, int offset, int size)
{
- ::qpid::types::Variant::Map map;
-
- map = messagep->getProperties();
-
- System::Collections::Generic::Dictionary<
- System::String^, System::Object^> ^ dict =
- gcnew System::Collections::Generic::Dictionary<
- System::String^, System::Object^> ;
-
- TypeTranslator::NativeToManaged(map, dict);
-
- return dict;
- }
-
-
- void Message::SetProperty(System::String ^ name, System::Object ^ value)
- {
- ::qpid::types::Variant entryValue;
- TypeTranslator::ManagedToNativeObject(value, entryValue);
-
- messagep->getProperties()[QpidMarshal::ToNative(name)] = entryValue;
- }
-
-
- void Message::SetProperties(System::Collections::Generic::Dictionary<
- System::String^, System::Object^> ^ properties)
- {
- for each (System::Collections::Generic::KeyValuePair
- <System::String^, System::Object^> kvp in properties)
- {
- SetProperty(kvp.Key, kvp.Value);
- }
- }
-
+ if ((offset + size) > bytes->Length)
+ throw gcnew QpidException("Message::SetContent from byte array slice: buffer length exceeded");
-
- // Content
- void Message::SetContent(System::String ^ content)
- {
- messagep->setContent(QpidMarshal::ToNative(content));
+ pin_ptr<unsigned char> pBytes = &bytes[offset];
+ messagep->setContent((char *)pBytes, size);
}
@@ -388,7 +234,7 @@ namespace Messaging { // On entry message size must not be zero and
// caller's byte array must be equal to message size.
//
- void Message::GetRaw(array<System::Byte> ^ arr)
+ void Message::GetContent(array<System::Byte> ^ arr)
{
System::UInt32 size = messagep->getContentSize();
@@ -404,12 +250,6 @@ namespace Messaging { }
- System::UInt64 Message::GetContentSize()
- {
- return messagep->getContentSize();
- }
-
-
System::String ^ Message::MapAsString(System::Collections::Generic::Dictionary<
System::String^, System::Object^> ^ dict)
{
diff --git a/cpp/bindings/qpid/dotnet/src/Message.h b/cpp/bindings/qpid/dotnet/src/Message.h index 99d0b8667e..d5b4beb406 100644 --- a/cpp/bindings/qpid/dotnet/src/Message.h +++ b/cpp/bindings/qpid/dotnet/src/Message.h @@ -26,6 +26,11 @@ #include "qpid/messaging/Message.h"
+#include "QpidMarshal.h"
+#include "Address.h"
+#include "Duration.h"
+#include "TypeTranslator.h"
+
namespace Org {
namespace Apache {
namespace Qpid {
@@ -78,46 +83,227 @@ namespace Messaging { ::qpid::messaging::Message * get () { return messagep; }
}
- void SetReplyTo(Address ^ address);
- Address ^ GetReplyTo();
+ //
+ // ReplyTo
+ //
+ property Address ^ ReplyTo
+ {
+ void set (Address ^ address)
+ {
+ messagep->setReplyTo(*(address->NativeAddress));
+ }
+
+ Address ^ get ()
+ {
+ const ::qpid::messaging::Address & addrp =
+ messagep->::qpid::messaging::Message::getReplyTo();
+
+ return gcnew Address(const_cast<::qpid::messaging::Address *>(&addrp));
+ }
+ }
+
+ //
+ // Subject
+ //
+ property System::String ^ Subject
+ {
+ void set (System::String ^ subject)
+ {
+ messagep->setSubject(QpidMarshal::ToNative(subject));
+ }
+
+
+ System::String ^ get ()
+ {
+ return gcnew String(messagep->getSubject().c_str());
+ }
+ }
- void SetSubject(System::String ^ subject);
- System::String ^ GetSubject();
- void SetContentType(System::String ^ ct);
- System::String ^ GetContentType();
-
- void SetMessageId(System::String ^ messageId);
- System::String ^ GetMessageId();
-
- void SetUserId(System::String ^ uId);
- System::String ^ GetUserId();
+ //
+ // ContentType
+ //
+ property System::String ^ ContentType
+ {
+ void set (System::String ^ ct)
+ {
+ messagep->setContentType(QpidMarshal::ToNative(ct));
+ }
+
+ System::String ^ get ()
+ {
+ return gcnew String(messagep->::qpid::messaging::Message::getContentType().c_str());
+ }
+ }
+
+
+ //
+ // MessageId
+ //
+ property System::String ^ MessageId
+ {
+ void set (System::String ^ messageId)
+ {
+ messagep->setMessageId(QpidMarshal::ToNative(messageId));
+ }
+
+ System::String ^ get ()
+ {
+ return gcnew String(messagep->getMessageId().c_str());
+ }
+ }
+
- void SetCorrelationId(System::String ^ correlationId);
- System::String ^ GetCorrelationId();
+ //
+ // UserId
+ //
+ property System::String ^ UserId
+ {
+ void set (System::String ^ uId)
+ {
+ messagep->setUserId(QpidMarshal::ToNative(uId));
+ }
+
+ System::String ^ get ()
+ {
+ return gcnew String(messagep->getUserId().c_str());
+ }
+ }
- void SetPriority(unsigned char priority);
- unsigned char GetPriority();
+
+ //
+ // CorrelationId
+ //
+ property System::String ^ CorrelationId
+ {
+ void set (System::String ^ correlationId)
+ {
+ messagep->setCorrelationId(QpidMarshal::ToNative(correlationId));
+ }
+
+ System::String ^ get ()
+ {
+ return gcnew String(messagep->getCorrelationId().c_str());
+ }
+ }
- void SetTtl(Duration ^ ttl);
- Duration ^ GetTtl();
- void SetDurable(bool durable);
- bool GetDurable();
+ //
+ // Priority
+ //
+ property unsigned char Priority
+ {
+ void set (unsigned char priority)
+ {
+ messagep->setPriority(priority);
+ }
+
+ unsigned char get ()
+ {
+ return messagep->getPriority();
+ }
+ }
+
+
+ //
+ // Ttl
+ //
+ property Duration ^ Ttl
+ {
+ void set (Duration ^ ttl)
+ {
+ ::qpid::messaging::Duration dur(ttl->Milliseconds);
+
+ messagep->setTtl(dur);
+ }
+
+ Duration ^ get ()
+ {
+ Duration ^ dur = gcnew Duration(messagep->getTtl().getMilliseconds());
+
+ return dur;
+ }
+ }
+
+ //
+ // Durable
+ //
+ property bool Durable
+ {
+ void set (bool durable)
+ {
+ messagep->setDurable(durable);
+ }
+
+ bool get ()
+ {
+ return messagep->getDurable();
+ }
+ }
+
+ //
+ // Redelivered
+ //
+ property bool Redelivered
+ {
+ bool get ()
+ {
+ return messagep->getRedelivered();
+ }
+
+ void set (bool redelivered)
+ {
+ messagep->setRedelivered(redelivered);
+ }
+ }
+
+ //
+ // Property
+ //
+ void Message::SetProperty(System::String ^ name, System::Object ^ value);
+
+ //
+ // Properties
+ //
+ property System::Collections::Generic::Dictionary<
+ System::String^, System::Object^> ^ Properties
+ {
+ System::Collections::Generic::Dictionary<
+ System::String^, System::Object^> ^ get ()
+ {
+ ::qpid::types::Variant::Map map;
- bool GetRedelivered();
- void SetRedelivered(bool redelivered);
+ map = messagep->getProperties();
- System::Collections::Generic::Dictionary<
- System::String^, System::Object^> ^ GetProperties();
+ System::Collections::Generic::Dictionary<
+ System::String^, System::Object^> ^ dict =
+ gcnew System::Collections::Generic::Dictionary<
+ System::String^, System::Object^> ;
- void SetProperty(System::String ^ name, System::Object ^ value);
+ TypeTranslator::NativeToManaged(map, dict);
+
+ return dict;
+ }
+
+
+ void set (System::Collections::Generic::Dictionary<
+ System::String^, System::Object^> ^ properties)
+ {
+ for each (System::Collections::Generic::KeyValuePair
+ <System::String^, System::Object^> kvp in properties)
+ {
+ SetProperty(kvp.Key, kvp.Value);
+ }
+ }
+ }
- void SetProperties(System::Collections::Generic::Dictionary<
- System::String^, System::Object^> ^ properties);
void SetContent(System::String ^ content);
+ void SetContent(cli::array<System::Byte> ^ bytes);
+
+ void SetContent(cli::array<System::Byte> ^ bytes, int offset, int size);
+
//TODO:: void setContent(Bytes{} bytes, offset, length);
// get content as string
@@ -133,9 +319,19 @@ namespace Messaging { System::Object^> ^);
// get content as bytes
- void GetRaw(cli::array<System::Byte> ^ arr);
+ void GetContent(cli::array<System::Byte> ^ arr);
+
+ //
+ // ContentSize
+ //
+ property System::UInt64 ContentSize
+ {
+ System::UInt64 get ()
+ {
+ return messagep->getContentSize();
+ }
+ }
- System::UInt64 GetContentSize();
// A message has been returned to managed code through GetContent().
// Display the content of that System::Object as a string.
diff --git a/cpp/bindings/qpid/dotnet/src/Receiver.cpp b/cpp/bindings/qpid/dotnet/src/Receiver.cpp index 15f8572a53..96df8cc53d 100644 --- a/cpp/bindings/qpid/dotnet/src/Receiver.cpp +++ b/cpp/bindings/qpid/dotnet/src/Receiver.cpp @@ -44,7 +44,7 @@ namespace Messaging { /// </summary>
Receiver::Receiver(::qpid::messaging::Receiver * r,
- Session ^ sessRef) :
+ Org::Apache::Qpid::Messaging::Session ^ sessRef) :
receiverp(r),
parentSession(sessRef)
{
@@ -227,38 +227,8 @@ namespace Messaging { return newMessage;
}
- void Receiver::SetCapacity(System::UInt32 capacity)
- {
- receiverp->setCapacity(capacity);
- }
-
- System::UInt32 Receiver::GetCapacity()
- {
- return receiverp->getCapacity();
- }
-
- System::UInt32 Receiver::GetAvailable()
- {
- return receiverp->getAvailable();
- }
-
- System::UInt32 Receiver::GetUnsettled()
- {
- return receiverp->getUnsettled();
- }
-
void Receiver::Close()
{
receiverp->close();
}
-
- System::String ^ Receiver::GetName()
- {
- return gcnew System::String(receiverp->getName().c_str());
- }
-
- Session ^ Receiver::GetSession()
- {
- return parentSession;
- }
}}}}
diff --git a/cpp/bindings/qpid/dotnet/src/Receiver.h b/cpp/bindings/qpid/dotnet/src/Receiver.h index 0dc2f6120f..436f3f2668 100644 --- a/cpp/bindings/qpid/dotnet/src/Receiver.h +++ b/cpp/bindings/qpid/dotnet/src/Receiver.h @@ -88,12 +88,66 @@ namespace Messaging { Message ^ Fetch();
Message ^ Fetch(Duration ^ durationp);
- void SetCapacity(System::UInt32 capacity);
- System::UInt32 GetCapacity();
- System::UInt32 GetAvailable();
- System::UInt32 GetUnsettled();
+ //
+ // Capacity
+ //
+ property System::UInt32 Capacity
+ {
+ void set (System::UInt32 capacity)
+ {
+ receiverp->setCapacity(capacity);
+ }
+
+ System::UInt32 get ()
+ {
+ return receiverp->getCapacity();
+ }
+ }
+
+ //
+ // Available
+ //
+ property System::UInt32 Available
+ {
+ System::UInt32 get ()
+ {
+ return receiverp->getAvailable();
+ }
+ }
+
+ //
+ // Unsettled
+ //
+ property System::UInt32 Unsettled
+ {
+ System::UInt32 get ()
+ {
+ return receiverp->getUnsettled();
+ }
+ }
+
void Close();
- System::String ^ GetName();
- Session ^ GetSession();
+
+ //
+ // Name
+ //
+ property System::String ^ Name
+ {
+ System::String ^ get ()
+ {
+ return gcnew System::String(receiverp->getName().c_str());
+ }
+ }
+
+ //
+ // Session
+ //
+ property Org::Apache::Qpid::Messaging::Session ^ Session
+ {
+ Org::Apache::Qpid::Messaging::Session ^ get ()
+ {
+ return parentSession;
+ }
+ }
};
}}}}
diff --git a/cpp/bindings/qpid/dotnet/src/Sender.cpp b/cpp/bindings/qpid/dotnet/src/Sender.cpp index e0911b38db..0d394f8ef9 100644 --- a/cpp/bindings/qpid/dotnet/src/Sender.cpp +++ b/cpp/bindings/qpid/dotnet/src/Sender.cpp @@ -40,7 +40,7 @@ namespace Messaging { /// </summary>
Sender::Sender(::qpid::messaging::Sender * s,
- Session ^ sessRef) :
+ Org::Apache::Qpid::Messaging::Session ^ sessRef) :
senderp(s),
parentSession(sessRef)
{
@@ -96,9 +96,4 @@ namespace Messaging { {
senderp->close();
}
-
- Session ^ Sender::GetSession()
- {
- return parentSession;
- }
}}}}
diff --git a/cpp/bindings/qpid/dotnet/src/Sender.h b/cpp/bindings/qpid/dotnet/src/Sender.h index 705c7d5b65..de114ab2f1 100644 --- a/cpp/bindings/qpid/dotnet/src/Sender.h +++ b/cpp/bindings/qpid/dotnet/src/Sender.h @@ -95,6 +95,15 @@ namespace Messaging { }
}
- Session ^ GetSession();
+ //
+ // Session
+ //
+ property Org::Apache::Qpid::Messaging::Session ^ Session
+ {
+ Org::Apache::Qpid::Messaging::Session ^ get ()
+ {
+ return parentSession;
+ }
+ }
};
}}}}
diff --git a/cpp/bindings/qpid/dotnet/src/Session.cpp b/cpp/bindings/qpid/dotnet/src/Session.cpp index 04fbb61e87..d5f4584a70 100644 --- a/cpp/bindings/qpid/dotnet/src/Session.cpp +++ b/cpp/bindings/qpid/dotnet/src/Session.cpp @@ -46,7 +46,8 @@ namespace Messaging { /// </summary>
// constructor
- Session::Session(::qpid::messaging::Session * sp, Connection ^ connRef) :
+ Session::Session(::qpid::messaging::Session * sp,
+ Org::Apache::Qpid::Messaging::Connection ^ connRef) :
sessionp(sp),
parentConnectionp(connRef)
{
@@ -444,11 +445,10 @@ namespace Messaging { Sender ^ Session::GetSender(System::String ^ name)
{
- ::qpid::messaging::Sender * sender = new ::qpid::messaging::Sender;
+ ::qpid::messaging::Sender sender = ::qpid::messaging::Sender(
+ sessionp->::qpid::messaging::Session::getSender(QpidMarshal::ToNative(name)) );
- *sender = sessionp->::qpid::messaging::Session::getSender(QpidMarshal::ToNative(name));
-
- Sender ^ newSender = gcnew Sender(sender, this);
+ Sender ^ newSender = gcnew Sender(&sender, this);
return newSender;
}
@@ -457,22 +457,16 @@ namespace Messaging { Receiver ^ Session::GetReceiver(System::String ^ name)
{
- ::qpid::messaging::Receiver * receiver = new ::qpid::messaging::Receiver;
-
- *receiver = sessionp->::qpid::messaging::Session::getReceiver(QpidMarshal::ToNative(name));
+ ::qpid::messaging::Receiver receiver = ::qpid::messaging::Receiver(
+ sessionp->::qpid::messaging::Session::getReceiver(QpidMarshal::ToNative(name)) );
- Receiver ^ newReceiver = gcnew Receiver(receiver, this);
+ Receiver ^ newReceiver = gcnew Receiver(&receiver, this);
return newReceiver;
}
- Connection ^ Session::GetConnection()
- {
- return parentConnectionp;
- }
-
void Session::CheckError()
{
sessionp->checkError();
diff --git a/cpp/bindings/qpid/dotnet/src/Session.h b/cpp/bindings/qpid/dotnet/src/Session.h index 4b84eec55f..a5affc67b6 100644 --- a/cpp/bindings/qpid/dotnet/src/Session.h +++ b/cpp/bindings/qpid/dotnet/src/Session.h @@ -110,7 +110,14 @@ namespace Messaging { Sender ^ GetSender(System::String ^ name);
Receiver ^ GetReceiver(System::String ^ name);
- Connection ^ GetConnection();
+ property Org::Apache::Qpid::Messaging::Connection ^ Connection
+ {
+ Org::Apache::Qpid::Messaging::Connection ^ get ()
+ {
+ return parentConnectionp;
+ }
+ }
+
property System::Boolean HasError
{
diff --git a/cpp/bindings/qpid/dotnet/test/messaging.test/messaging.test.cs b/cpp/bindings/qpid/dotnet/test/messaging.test/messaging.test.cs index 2e0e481581..c1b3035470 100644 --- a/cpp/bindings/qpid/dotnet/test/messaging.test/messaging.test.cs +++ b/cpp/bindings/qpid/dotnet/test/messaging.test/messaging.test.cs @@ -74,12 +74,12 @@ namespace Org.Apache.Qpid.Messaging //
Message m2 = new Message("rarey");
- UInt64 m2Size = m2.GetContentSize();
+ UInt64 m2Size = m2.ContentSize;
byte[] myRaw = new byte [m2Size];
- m2.GetRaw(myRaw);
+ m2.GetContent(myRaw);
Console.WriteLine("Got raw array size {0}", m2Size);
for (UInt64 i = 0; i < m2Size; i++)
Console.Write("{0} ", myRaw[i].ToString());
@@ -93,9 +93,9 @@ namespace Org.Apache.Qpid.Messaging rawData[i] = i;
Message m3 = new Message(rawData);
- byte[] rawDataReadback = new byte[m3.GetContentSize()];
- m3.GetRaw(rawDataReadback);
- for (UInt64 i = 0; i < m3.GetContentSize(); i++)
+ byte[] rawDataReadback = new byte[m3.ContentSize];
+ m3.GetContent(rawDataReadback);
+ for (UInt64 i = 0; i < m3.ContentSize; i++)
Console.Write("{0} ", rawDataReadback[i].ToString());
Console.WriteLine();
@@ -108,13 +108,24 @@ namespace Org.Apache.Qpid.Messaging Message m4 = new Message(rawData4, 246, 10);
- byte[] rawDataReadback4 = new byte[m4.GetContentSize()];
- m4.GetRaw(rawDataReadback4);
- for (UInt64 i = 0; i < m4.GetContentSize(); i++)
+ byte[] rawDataReadback4 = new byte[m4.ContentSize];
+ m4.GetContent(rawDataReadback4);
+ for (UInt64 i = 0; i < m4.ContentSize; i++)
Console.Write("{0} ", rawDataReadback4[i].ToString());
Console.WriteLine();
//
+ // Set content from array slice
+ //
+ m4.SetContent(rawData4, 100, 5);
+
+ byte[] rawDataReadback4a = new byte[m4.ContentSize];
+ m4.GetContent(rawDataReadback4a);
+ for (UInt64 i = 0; i < m4.ContentSize; i++)
+ Console.Write("{0} ", rawDataReadback4a[i].ToString());
+ Console.WriteLine();
+
+ //
// Guid factoids
//
Guid myGuid = new Guid("000102030405060708090a0b0c0d0e0f");
|