summaryrefslogtreecommitdiff
path: root/qpid/cpp/bindings
diff options
context:
space:
mode:
authorCharles E. Rolke <chug@apache.org>2014-01-22 21:54:25 +0000
committerCharles E. Rolke <chug@apache.org>2014-01-22 21:54:25 +0000
commit03c9bd72d51f98d39f006db6d260ae5616fb836d (patch)
tree6fbd6d66bb8a6ba78d9fc071fb84eb5278fa78b1 /qpid/cpp/bindings
parent04560e1d3c28fb21a8f8ae094a62318790474e61 (diff)
downloadqpid-python-03c9bd72d51f98d39f006db6d260ae5616fb836d.tar.gz
QPID-5481: Messaging API Update - 1555202 Logger module added
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1560529 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/bindings')
-rw-r--r--qpid/cpp/bindings/qpid/dotnet/src/Logger.cpp224
-rw-r--r--qpid/cpp/bindings/qpid/dotnet/src/Logger.h134
-rw-r--r--qpid/cpp/bindings/qpid/dotnet/src/msvc10/org.apache.qpid.messaging.vcxproj2
-rw-r--r--qpid/cpp/bindings/qpid/dotnet/src/msvc9/org.apache.qpid.messaging.vcproj8
4 files changed, 368 insertions, 0 deletions
diff --git a/qpid/cpp/bindings/qpid/dotnet/src/Logger.cpp b/qpid/cpp/bindings/qpid/dotnet/src/Logger.cpp
new file mode 100644
index 0000000000..b084db5a6c
--- /dev/null
+++ b/qpid/cpp/bindings/qpid/dotnet/src/Logger.cpp
@@ -0,0 +1,224 @@
+/*
+* 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.
+*/
+
+#include <windows.h>
+#include <string>
+#include <limits>
+#include <vector>
+#include <iostream>
+#include <assert.h>
+
+#include "qpid/messaging/Logger.h"
+#include "qpid/messaging/exceptions.h"
+#include "qpid/types/Variant.h"
+
+#include "Logger.h"
+#include "QpidException.h"
+#include "QpidMarshal.h"
+
+/// <summary>
+/// outputCallbackHost
+/// Native class that holds reference to managed class
+/// and for hosting the native callback procedure.
+/// </summary>
+namespace qpid {
+namespace messaging {
+
+ class outputCallbackHost : public qpid::messaging::LoggerOutput {
+ private:
+ // Reference to managed class
+ gcroot<Org::Apache::Qpid::Messaging::LoggerOutput^> m_loggerOutput;
+
+ public:
+ outputCallbackHost(Org::Apache::Qpid::Messaging::LoggerOutput ^ _m_loggerOutput)
+ : m_loggerOutput(_m_loggerOutput)
+ {
+ }
+ ~outputCallbackHost()
+ {
+ }
+
+ // Native callback entry point called by qpid Logger
+ void log(qpid::messaging::Level level, bool user, const char* file, int line,
+ const char* function, const std::string& message)
+ {
+ m_loggerOutput->Log(level, user, file, line, function, message);
+ }
+ };
+}}
+
+
+namespace Org {
+namespace Apache {
+namespace Qpid {
+namespace Messaging {
+
+///
+/// Managed class with desired delegate
+///
+LoggerOutput::LoggerOutput( LoggerOutputCallback^ callback)
+ : loggerDelegate(callback),
+ interceptor(new qpid::messaging::outputCallbackHost(this))
+{
+ ::qpid::messaging::Logger::setOutput(*interceptor);
+}
+
+LoggerOutput::~LoggerOutput()
+{
+}
+
+// Relay log message to managed code
+void LoggerOutput::Log(
+ qpid::messaging::Level level,
+ bool user,
+ const char* file,
+ int line,
+ const char* function,
+ const std::string& message)
+{
+ // create managed log args
+ Messaging::Level mLevel = (Messaging::Level)level;
+ System::Boolean mUser = user;
+ System::String^ mFile = gcnew String( file );
+ System::Int32 mLine = line;
+ System::String^ mFunction = gcnew String( function );
+ System::String^ mMessage = gcnew String( message.c_str() );
+
+ // pass to delegate
+ loggerDelegate( mLevel, mUser, mFile, mLine, mFunction, mMessage );
+}
+
+
+/// <summary>
+/// Logger a managed wrapper for a ::qpid::messaging::Logger
+/// </summary>
+
+// Constructor
+Logger::Logger()
+{
+ // Sanity check that managed == native enum values
+ assert((int)Messaging::Level::trace == (int)::qpid::messaging::trace);
+ assert((int)Messaging::Level::debug == (int)::qpid::messaging::debug);
+ assert((int)Messaging::Level::info == (int)::qpid::messaging::info);
+ assert((int)Messaging::Level::notice == (int)::qpid::messaging::notice);
+ assert((int)Messaging::Level::warning == (int)::qpid::messaging::warning);
+ assert((int)Messaging::Level::error == (int)::qpid::messaging::error);
+ assert((int)Messaging::Level::critical == (int)::qpid::messaging::critical);
+}
+
+
+// Destructor
+Logger::~Logger()
+{
+ this->!Logger();
+}
+
+
+// Finalizer
+Logger::!Logger()
+{
+}
+
+void Logger::Configure(array<System::String ^> ^ args)
+{
+ Configure(args, "");
+}
+
+void Logger::Configure(array<System::String ^> ^ theArgs, System::String ^ thePrefix)
+{
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ // Marshal the calling args
+ int argc = theArgs->Length;
+
+ std::vector<std::string> cppStrings;
+ for (int i=0; i<argc; i++)
+ {
+ cppStrings.push_back ( QpidMarshal::ToNative( theArgs[i] ) );
+ }
+
+ std::vector<const char *> cStrings;
+ for (int i=0; i<argc; i++)
+ {
+ cStrings.push_back ( cppStrings[i].c_str() );
+ }
+
+ const char** argv = &cStrings[0];
+
+ std::string prefix = QpidMarshal::ToNative(thePrefix);
+
+ // configure
+ ::qpid::messaging::Logger::configure(argc, argv, prefix);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
+}
+
+
+System::String ^ Logger::Usage()
+{
+ return gcnew String(::qpid::messaging::Logger::usage().c_str());
+}
+
+
+// Inject a log message from managed user space into unmanaged
+// Qpid Messaging log stream.
+void Logger::Log(
+ Messaging::Level level,
+ System::String^ file,
+ System::Int32 line,
+ System::String^ function,
+ System::String^ message)
+{
+ // create unmanaged log args
+ qpid::messaging::Level nLevel = (qpid::messaging::Level)level;
+ std::string nFile = QpidMarshal::ToNative(file);
+ int nLine = line;
+ std::string nFunction = QpidMarshal::ToNative(function);
+ const std::string nMessage = QpidMarshal::ToNative(message);
+
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ // pass to native log engine
+ ::qpid::messaging::Logger::log(
+ nLevel, nFile.c_str(), line, nFunction.c_str(), nMessage);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
+}
+}}}}
diff --git a/qpid/cpp/bindings/qpid/dotnet/src/Logger.h b/qpid/cpp/bindings/qpid/dotnet/src/Logger.h
new file mode 100644
index 0000000000..1628fb19ff
--- /dev/null
+++ b/qpid/cpp/bindings/qpid/dotnet/src/Logger.h
@@ -0,0 +1,134 @@
+/*
+* 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.
+*/
+#pragma once
+
+#include <windows.h>
+#include <msclr\lock.h>
+#include <oletx2xa.h>
+#include <string>
+#include <limits>
+
+#include "qpid/messaging/Logger.h"
+
+//
+// Logger is implemented in two classes that roughly correspond
+// to the Logger and LoggerOutput classes defined by the native
+// C++ classes in qpid/messaging/Logger.h. Please refer to the
+// native Logger.h file for more detailed usage information.
+//
+// Logger is a control and status interface to configure logging
+// and to inject log messages.
+//
+// LoggerOutput defines a delegate to accept the Qpid Messaging
+// log message stream. LoggerOutput uses native class
+// outputCallbackHost to receive the native callbacks and forward
+// the log on to the delegate.
+//
+
+/// <summary>
+/// outputCallbackHost
+/// Native class that holds reference to managed class
+/// and for hosting the native callback procedure.
+/// </summary>
+namespace qpid {
+namespace messaging {
+ class outputCallbackHost;
+}}
+
+namespace Org {
+namespace Apache {
+namespace Qpid {
+namespace Messaging {
+
+ /// <summary>
+ /// Level constants
+ /// These correspond exactly to qpid::messaging::Level
+ /// </summary>
+ public enum class Level { trace, debug, info, notice, warning, error, critical };
+
+ /// <summary>
+ /// LoggerOutput relays messages to the managed delegate
+ /// </summary>
+
+ // The managed delegate signature
+ public delegate void LoggerOutputCallback(
+ Messaging::Level level,
+ System::Boolean user,
+ System::String^ file,
+ System::Int32 line,
+ System::String^ function,
+ System::String^ message);
+
+ // Managed class with desired delegate
+ public ref class LoggerOutput
+ {
+ private:
+ // private destructor
+ ~LoggerOutput();
+
+ // delegate
+ LoggerOutputCallback^ loggerDelegate;
+
+ // native class to host native callback
+ qpid::messaging::outputCallbackHost * interceptor;
+
+ public:
+ // function to receive unmanaged log and relay it
+ // to managed delegate
+ void Log(
+ qpid::messaging::Level level,
+ bool user,
+ const char* file,
+ int line,
+ const char* function,
+ const std::string& message);
+
+ // constructor - create with reference to log message delegate
+ LoggerOutput( LoggerOutputCallback^ callback);
+ };
+
+ /// <summary>
+ /// Logger is a managed wrapper for native ::qpid::messaging::Logger
+ /// </summary>
+
+ public ref class Logger
+ {
+ private:
+
+ public:
+ Logger();
+ ~Logger();
+ !Logger();
+
+ // Set logging in qpid messaging
+ void Configure(array<System::String ^> ^ args);
+ void Configure(array<System::String ^> ^ args, System::String ^ prefix);
+
+ // Help string available after calling Configue
+ System::String ^ Usage();
+
+ // Inject a 'user' log message into qpid messaging log stream
+ void Log(
+ Messaging::Level level,
+ System::String^ file,
+ System::Int32 line,
+ System::String^ function,
+ System::String^ message);
+ };
+}}}}
diff --git a/qpid/cpp/bindings/qpid/dotnet/src/msvc10/org.apache.qpid.messaging.vcxproj b/qpid/cpp/bindings/qpid/dotnet/src/msvc10/org.apache.qpid.messaging.vcxproj
index dac5c287c6..c10c2da0dc 100644
--- a/qpid/cpp/bindings/qpid/dotnet/src/msvc10/org.apache.qpid.messaging.vcxproj
+++ b/qpid/cpp/bindings/qpid/dotnet/src/msvc10/org.apache.qpid.messaging.vcxproj
@@ -300,6 +300,7 @@
<ClCompile Include="$(QPID_BUILD_ROOT)\src\windows\generated_src\AssemblyInfo.cpp" />
<ClCompile Include="..\Connection.cpp" />
<ClCompile Include="..\FailoverUpdates.cpp" />
+ <ClCompile Include="..\Logger.cpp" />
<ClCompile Include="..\Message.cpp" />
<ClCompile Include="..\Receiver.cpp" />
<ClCompile Include="..\Sender.cpp" />
@@ -311,6 +312,7 @@
<ClInclude Include="..\Connection.h" />
<ClInclude Include="..\Duration.h" />
<ClInclude Include="..\FailoverUpdates.h" />
+ <ClInclude Include="..\Logger.h" />
<ClInclude Include="..\Message.h" />
<ClInclude Include="..\QpidException.h" />
<ClInclude Include="..\QpidMarshal.h" />
diff --git a/qpid/cpp/bindings/qpid/dotnet/src/msvc9/org.apache.qpid.messaging.vcproj b/qpid/cpp/bindings/qpid/dotnet/src/msvc9/org.apache.qpid.messaging.vcproj
index 9a02d625f5..bae1239e18 100644
--- a/qpid/cpp/bindings/qpid/dotnet/src/msvc9/org.apache.qpid.messaging.vcproj
+++ b/qpid/cpp/bindings/qpid/dotnet/src/msvc9/org.apache.qpid.messaging.vcproj
@@ -542,6 +542,10 @@
>
</File>
<File
+ RelativePath="..\Logger.cpp"
+ >
+ </File>
+ <File
RelativePath="..\Message.cpp"
>
</File>
@@ -584,6 +588,10 @@
>
</File>
<File
+ RelativePath="..\Logger.h"
+ >
+ </File>
+ <File
RelativePath="..\Message.h"
>
</File>