summaryrefslogtreecommitdiff
path: root/cpp/bindings/qpid/dotnet/src/Connection.cpp
diff options
context:
space:
mode:
authorTed Ross <tross@apache.org>2010-05-28 18:09:10 +0000
committerTed Ross <tross@apache.org>2010-05-28 18:09:10 +0000
commit947b1491d7a39c87c4560126a6e50646aa2a2b24 (patch)
tree19a5c7ac347d807125f8352ef5f2d41810d79281 /cpp/bindings/qpid/dotnet/src/Connection.cpp
parent8d317104053b8258380c47af8d792517c4da10b7 (diff)
downloadqpid-python-947b1491d7a39c87c4560126a6e50646aa2a2b24.tar.gz
QPID-2628 - Patch from Chuck Rolke
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@949245 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/bindings/qpid/dotnet/src/Connection.cpp')
-rw-r--r--cpp/bindings/qpid/dotnet/src/Connection.cpp194
1 files changed, 178 insertions, 16 deletions
diff --git a/cpp/bindings/qpid/dotnet/src/Connection.cpp b/cpp/bindings/qpid/dotnet/src/Connection.cpp
index 58b93f6b24..4936e18c4e 100644
--- a/cpp/bindings/qpid/dotnet/src/Connection.cpp
+++ b/cpp/bindings/qpid/dotnet/src/Connection.cpp
@@ -25,10 +25,13 @@
#include "qpid/messaging/Connection.h"
#include "qpid/messaging/Session.h"
+#include "qpid/messaging/exceptions.h"
#include "QpidMarshal.h"
#include "Connection.h"
#include "Session.h"
+#include "QpidException.h"
+#include "TypeTranslator.h"
namespace org {
namespace apache {
@@ -39,12 +42,25 @@ namespace messaging {
/// Connection is a managed wrapper for a qpid::messaging::Connection
/// </summary>
- // Public constructor
+ // constructors
Connection::Connection(System::String ^ url) :
connectionp(new ::qpid::messaging::Connection(QpidMarshal::ToNative(url)))
{
}
+
+ Connection::Connection(System::String ^ url,
+ System::Collections::Generic::Dictionary<
+ System::String ^, System::Object ^> ^ options) :
+ connectionp(new ::qpid::messaging::Connection(QpidMarshal::ToNative(url)))
+ {
+ for each (System::Collections::Generic::KeyValuePair<System::String^, System::Object^> kvp in options)
+ {
+ setOption(kvp.Key, kvp.Value);
+ }
+ }
+
+
Connection::Connection(System::String ^ url, System::String ^ options) :
connectionp(new ::qpid::messaging::Connection(QpidMarshal::ToNative(url),
QpidMarshal::ToNative(options)))
@@ -77,39 +93,185 @@ namespace messaging {
}
}
- Session ^ Connection::createSession()
+
+ void Connection::setOption(System::String ^ name, System::Object ^ value)
{
- return createSession("");
+ ::qpid::types::Variant entryValue;
+ TypeTranslator::ManagedToNativeObject(value, entryValue);
+ std::string entryName = QpidMarshal::ToNative(name);
+ connectionp->::qpid::messaging::Connection::setOption(entryName, entryValue);
}
+ void Connection::open()
+ {
+ connectionp->open();
+ }
- Session ^ Connection::createSession(System::String ^ name)
+ System::Boolean Connection::isOpen()
{
- // allocate native session
- ::qpid::messaging::Session * sessionp = new ::qpid::messaging::Session;
+ return connectionp->isOpen();
+ }
- // create native session
- *sessionp = connectionp->createSession(QpidMarshal::ToNative(name));
+ void Connection::close()
+ {
+ connectionp->close();
+ }
+
+ //
+ // createTransactionalSession()
+ //
+ Session ^ Connection::createTransactionalSession()
+ {
+ return createTransactionalSession("");
+ }
+
+
+ Session ^ Connection::createTransactionalSession(System::String ^ name)
+ {
+ System::Exception ^ newException = nullptr;
+ ::qpid::messaging::Session * sessionp = NULL;
+ Session ^ newSession = nullptr;
- // create managed session
- Session ^ newSession = gcnew Session(sessionp, this);
+ try
+ {
+ // allocate native session
+ sessionp = new ::qpid::messaging::Session ;
+
+ // create native session
+ *sessionp = connectionp->createTransactionalSession(QpidMarshal::ToNative(name));
+
+ // create managed session
+ newSession = gcnew Session(sessionp, this);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+ catch (const std::exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+ catch ( ... )
+ {
+ newException = gcnew QpidException("Connection::createTransactionalSession unknown error");
+ }
+ finally
+ {
+ // Clean up and throw on caught exceptions
+ if (newException != nullptr)
+ {
+ if (sessionp != NULL)
+ {
+ delete sessionp;
+ }
+ throw newException;
+ }
+ }
return newSession;
}
- void Connection::open()
+ //
+ // createSession()
+ //
+ Session ^ Connection::createSession()
{
- connectionp->open();
+ return createSession("");
}
- bool Connection::isOpen()
+
+ Session ^ Connection::createSession(System::String ^ name)
{
- return connectionp->isOpen();
+ System::Exception ^ newException = nullptr;
+ ::qpid::messaging::Session * sessionp = NULL;
+ Session ^ newSession = nullptr;
+
+ try
+ {
+ // allocate native session
+ sessionp = new ::qpid::messaging::Session ;
+
+ // create native session
+ *sessionp = connectionp->createSession(QpidMarshal::ToNative(name));
+
+ // create managed session
+ newSession = gcnew Session(sessionp, this);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+ catch (const std::exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+ catch ( ... )
+ {
+ newException = gcnew QpidException("Connection::createSession unknown error");
+ }
+ finally
+ {
+ // Clean up and throw on caught exceptions
+ if (newException != nullptr)
+ {
+ if (sessionp != NULL)
+ {
+ delete sessionp;
+ }
+ throw newException;
+ }
+ }
+
+ return newSession;
}
- void Connection::close()
+
+ Session ^ Connection::getSession(System::String ^ name)
{
- connectionp->close();
+ System::Exception ^ newException = nullptr;
+ ::qpid::messaging::Session * sess = NULL;
+ Session ^ newSession = nullptr;
+
+ try
+ {
+ const std::string n = QpidMarshal::ToNative(name);
+
+ *sess = connectionp->::qpid::messaging::Connection::getSession(n);
+
+ newSession = gcnew Session(sess, this);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+ catch (const std::exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+ catch ( ... )
+ {
+ newException = gcnew QpidException("Connection::getSession unknown error");
+ }
+ finally
+ {
+ // Clean up and throw on caught exceptions
+ if (newException != nullptr)
+ {
+ if (sess != NULL)
+ {
+ delete sess;
+ }
+ throw newException;
+ }
+ }
+
+ return newSession;
}
}}}}