summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles E. Rolke <chug@apache.org>2014-01-15 23:58:54 +0000
committerCharles E. Rolke <chug@apache.org>2014-01-15 23:58:54 +0000
commit3fa06e444faa9c3a28133abdc9b4b0b784ef8703 (patch)
tree3dbfc7d29651c65b730d5f6c467887ed985a1a55
parente017a338ba50323d87c24147ea1b64d7bd880b97 (diff)
downloadqpid-python-3fa06e444faa9c3a28133abdc9b4b0b784ef8703.tar.gz
QPID-5481: Messaging API Update - 1513536 Message constructor and content getters added
The .NET Binding already had the bytes constructor and the getContentBytes methods. This patch adds getContentObject/setContentObject interfaces. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1558619 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/cpp/bindings/qpid/dotnet/src/Message.cpp51
-rw-r--r--qpid/cpp/bindings/qpid/dotnet/src/Message.h5
-rw-r--r--qpid/cpp/bindings/qpid/dotnet/src/TypeTranslator.cpp245
-rw-r--r--qpid/cpp/bindings/qpid/dotnet/src/TypeTranslator.h5
4 files changed, 162 insertions, 144 deletions
diff --git a/qpid/cpp/bindings/qpid/dotnet/src/Message.cpp b/qpid/cpp/bindings/qpid/dotnet/src/Message.cpp
index ca7d796b9e..24755a7fe3 100644
--- a/qpid/cpp/bindings/qpid/dotnet/src/Message.cpp
+++ b/qpid/cpp/bindings/qpid/dotnet/src/Message.cpp
@@ -404,6 +404,32 @@ namespace Messaging {
}
}
+
+ void Message::SetContentObject(System::Object ^ managedObject)
+ {
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ ::qpid::types::Variant nativeObjValue;
+ TypeTranslator::ManagedToNativeObject(managedObject, nativeObjValue);
+ nativeObjPtr->setContentObject(nativeObjValue);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
+ }
+
System::String ^ Message::GetContent()
{
@@ -539,6 +565,31 @@ namespace Messaging {
}
+ void Message::GetContentObject(System::Object ^ managedObject)
+ {
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ ::qpid::types::Variant nativeObject = nativeObjPtr->getContentObject();
+
+ managedObject = TypeTranslator::NativeToManagedObject(nativeObject);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
+ }
+
System::String ^ Message::MapAsString(System::Collections::Generic::Dictionary<
System::String^, System::Object^> ^ dict)
{
diff --git a/qpid/cpp/bindings/qpid/dotnet/src/Message.h b/qpid/cpp/bindings/qpid/dotnet/src/Message.h
index a0d77b056b..aa436ed48d 100644
--- a/qpid/cpp/bindings/qpid/dotnet/src/Message.h
+++ b/qpid/cpp/bindings/qpid/dotnet/src/Message.h
@@ -413,7 +413,7 @@ namespace Messaging {
void SetContent(cli::array<System::Byte> ^ bytes, int offset, int size);
- //TODO:: void setContent(Bytes{} bytes, offset, length);
+ void SetContentObject(System::Object ^ managedObject);
// get content as string
System::String ^ GetContent();
@@ -430,6 +430,9 @@ namespace Messaging {
// get content as bytes
void GetContent(cli::array<System::Byte> ^ arr);
+ // get content as object
+ void GetContentObject(System::Object ^ object);
+
//
// ContentSize
//
diff --git a/qpid/cpp/bindings/qpid/dotnet/src/TypeTranslator.cpp b/qpid/cpp/bindings/qpid/dotnet/src/TypeTranslator.cpp
index 9e353cad12..3659f7f8b3 100644
--- a/qpid/cpp/bindings/qpid/dotnet/src/TypeTranslator.cpp
+++ b/qpid/cpp/bindings/qpid/dotnet/src/TypeTranslator.cpp
@@ -266,97 +266,11 @@ namespace Messaging {
{
// For each object in the message map,
// create a .NET object and add it to the dictionary.
- for (::qpid::types::Variant::Map::const_iterator i = qpidMap.begin(); i != qpidMap.end(); ++i) {
- // Get the name
+ for (::qpid::types::Variant::Map::const_iterator i = qpidMap.begin(); i != qpidMap.end(); ++i)
+ {
System::String ^ elementName = gcnew String(i->first.c_str());
-
- ::qpid::types::Variant variant = i->second;
- ::qpid::types::VariantType vType = variant.getType();
-
- switch (vType)
- {
- case ::qpid::types::VAR_VOID:
- dict[elementName] = nullptr;
- break;
-
- case ::qpid::types::VAR_BOOL:
- dict[elementName] = variant.asBool();
- break;
-
- case ::qpid::types::VAR_UINT8:
- dict[elementName] = variant.asUint8();
- break;
-
- case ::qpid::types::VAR_UINT16:
- dict[elementName] = variant.asUint16();
- break;
-
- case ::qpid::types::VAR_UINT32:
- dict[elementName] = variant.asUint32();
- break;
-
- case ::qpid::types::VAR_UINT64:
- dict[elementName] = variant.asUint64();
- break;
-
- case ::qpid::types::VAR_INT8:
- dict[elementName] = variant.asInt8();
- break;
-
- case ::qpid::types::VAR_INT16:
- dict[elementName] = variant.asInt16();
- break;
-
- case ::qpid::types::VAR_INT32:
- dict[elementName] = variant.asInt32();
- break;
-
- case ::qpid::types::VAR_INT64:
- dict[elementName] = variant.asInt64();
- break;
-
- case ::qpid::types::VAR_FLOAT:
- dict[elementName] = variant.asFloat();
- break;
-
- case ::qpid::types::VAR_DOUBLE:
- dict[elementName] = variant.asDouble();
- break;
-
- case ::qpid::types::VAR_STRING:
- {
- System::String ^ elementValue = gcnew System::String(variant.asString().c_str());
- dict[elementName] = elementValue;
- break;
- }
- case ::qpid::types::VAR_MAP:
- {
- QpidMap ^ newDict = gcnew QpidMap();
-
- NativeToManaged(variant.asMap(), newDict);
-
- dict[elementName] = newDict;
- break;
- }
-
- case ::qpid::types::VAR_LIST:
- {
- QpidList ^ newList = gcnew QpidList();
-
- NativeToManaged(variant.asList(), newList);
-
- dict[elementName] = newList;
- break;
- }
-
- case ::qpid::types::VAR_UUID:
- {
- System::String ^ elementValue = gcnew System::String(variant.asUuid().str().c_str());
- System::Guid ^ newGuid = System::Guid(elementValue);
- dict[elementName] = newGuid;
- }
- break;
- }
+ ::qpid::types::Variant variant = i->second;
+ dict[elementName] = NativeToManagedObject(variant);
}
}
@@ -370,92 +284,137 @@ namespace Messaging {
for (::qpid::types::Variant::List::const_iterator i = qpidList.begin(); i != qpidList.end(); ++i)
{
::qpid::types::Variant variant = *i;
- ::qpid::types::VariantType vType = variant.getType();
+ (*managedList).Add( NativeToManagedObject(variant) );
+ }
+ }
+
- switch (vType)
+ System::Object ^ TypeTranslator::NativeToManagedObject(
+ ::qpid::types::Variant & nativeObject)
+ {
+ // create a .NET object and return it
+ ::qpid::types::VariantType vType = nativeObject.getType();
+ System::Object ^ managedObject = nullptr;
+
+ switch (vType)
+ {
+ case ::qpid::types::VAR_VOID:
{
- case ::qpid::types::VAR_VOID:
- (*managedList).Add(nullptr);
break;
+ }
- case ::qpid::types::VAR_BOOL:
- (*managedList).Add(variant.asBool());
+ case ::qpid::types::VAR_BOOL:
+ {
+ bool result = nativeObject.asBool();
+ managedObject = result;
break;
+ }
- case ::qpid::types::VAR_UINT8:
- (*managedList).Add(variant.asUint8());
+ case ::qpid::types::VAR_UINT8:
+ {
+ byte result = nativeObject.asUint8();
+ managedObject = result;
break;
+ }
- case ::qpid::types::VAR_UINT16:
- (*managedList).Add(variant.asUint16());
+ case ::qpid::types::VAR_UINT16:
+ {
+ unsigned short result = nativeObject.asUint16();
+ managedObject = result;
break;
+ }
- case ::qpid::types::VAR_UINT32:
- (*managedList).Add(variant.asUint32());
+ case ::qpid::types::VAR_UINT32:
+ {
+ unsigned long result = nativeObject.asUint32();
+ managedObject = result;
break;
+ }
- case ::qpid::types::VAR_UINT64:
- (*managedList).Add(variant.asUint64());
+ case ::qpid::types::VAR_UINT64:
+ {
+ unsigned __int64 result = nativeObject.asUint64();
+ managedObject = result;
break;
+ }
- case ::qpid::types::VAR_INT8:
- (*managedList).Add(variant.asInt8());
+ case ::qpid::types::VAR_INT8:
+ {
+ System::SByte result = nativeObject.asInt8();
+ managedObject = result;
break;
+ }
- case ::qpid::types::VAR_INT16:
- (*managedList).Add(variant.asInt16());
+ case ::qpid::types::VAR_INT16:
+ {
+ short result = nativeObject.asInt16();
+ managedObject = result;
break;
+ }
- case ::qpid::types::VAR_INT32:
- (*managedList).Add(variant.asInt32());
+ case ::qpid::types::VAR_INT32:
+ {
+ long result = nativeObject.asInt32();
+ managedObject = result;
break;
+ }
- case ::qpid::types::VAR_INT64:
- (*managedList).Add(variant.asInt64());
+ case ::qpid::types::VAR_INT64:
+ {
+ __int64 result = nativeObject.asInt64();
+ managedObject = result;
break;
+ }
- case ::qpid::types::VAR_FLOAT:
- (*managedList).Add(variant.asFloat());
+ case ::qpid::types::VAR_FLOAT:
+ {
+ float result = nativeObject.asFloat();
+ managedObject = result;
break;
+ }
- case ::qpid::types::VAR_DOUBLE:
- (*managedList).Add(variant.asDouble());
+ case ::qpid::types::VAR_DOUBLE:
+ {
+ double result = nativeObject.asDouble();
+ managedObject = result;
break;
+ }
- case ::qpid::types::VAR_STRING:
- {
- System::String ^ elementValue = gcnew System::String(variant.asString().c_str());
- (*managedList).Add(elementValue);
- break;
- }
- case ::qpid::types::VAR_MAP:
- {
- QpidMap ^ newDict = gcnew QpidMap();
-
- NativeToManaged(variant.asMap(), newDict);
+ case ::qpid::types::VAR_STRING:
+ {
+ System::String ^ elementValue = gcnew System::String(nativeObject.asString().c_str());
+ managedObject = elementValue;
+ break;
+ }
+ case ::qpid::types::VAR_MAP:
+ {
+ QpidMap ^ newDict = gcnew QpidMap();
- (*managedList).Add(newDict);
- break;
- }
+ NativeToManaged(nativeObject.asMap(), newDict);
- case ::qpid::types::VAR_LIST:
- {
- QpidList ^ newList = gcnew QpidList();
+ managedObject = newDict;
+ break;
+ }
- NativeToManaged(variant.asList(), newList);
+ case ::qpid::types::VAR_LIST:
+ {
+ QpidList ^ newList = gcnew QpidList();
- (*managedList).Add(newList);
- break;
- }
+ NativeToManaged(nativeObject.asList(), newList);
- case ::qpid::types::VAR_UUID:
- {
- System::String ^ elementValue = gcnew System::String(variant.asUuid().str().c_str());
- System::Guid ^ newGuid = System::Guid(elementValue);
- (*managedList).Add(newGuid);
- }
+ managedObject = newList;
break;
}
+
+ case ::qpid::types::VAR_UUID:
+ {
+ System::String ^ elementValue = gcnew System::String(nativeObject.asUuid().str().c_str());
+ System::Guid ^ newGuid = System::Guid(elementValue);
+ managedObject = newGuid;
+ }
+ break;
}
+
+ return managedObject;
}
}}}}
diff --git a/qpid/cpp/bindings/qpid/dotnet/src/TypeTranslator.h b/qpid/cpp/bindings/qpid/dotnet/src/TypeTranslator.h
index 5fdccaab8e..67af712c84 100644
--- a/qpid/cpp/bindings/qpid/dotnet/src/TypeTranslator.h
+++ b/qpid/cpp/bindings/qpid/dotnet/src/TypeTranslator.h
@@ -72,5 +72,10 @@ namespace Messaging {
static void NativeToManaged(
::qpid::types::Variant::List & qpidList,
QpidList ^ managedList);
+
+ // The given object is a qpid Variant
+ // Return it as a managed System::Object
+ static System::Object ^ NativeToManagedObject(
+ ::qpid::types::Variant & nativeObject);
};
}}}}