From 03c9bd72d51f98d39f006db6d260ae5616fb836d Mon Sep 17 00:00:00 2001 From: "Charles E. Rolke" Date: Wed, 22 Jan 2014 21:54:25 +0000 Subject: 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 --- qpid/cpp/bindings/qpid/dotnet/src/Logger.cpp | 224 +++++++++++++++++++++ qpid/cpp/bindings/qpid/dotnet/src/Logger.h | 134 ++++++++++++ .../src/msvc10/org.apache.qpid.messaging.vcxproj | 2 + .../src/msvc9/org.apache.qpid.messaging.vcproj | 8 + 4 files changed, 368 insertions(+) create mode 100644 qpid/cpp/bindings/qpid/dotnet/src/Logger.cpp create mode 100644 qpid/cpp/bindings/qpid/dotnet/src/Logger.h (limited to 'qpid/cpp/bindings') 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 +#include +#include +#include +#include +#include + +#include "qpid/messaging/Logger.h" +#include "qpid/messaging/exceptions.h" +#include "qpid/types/Variant.h" + +#include "Logger.h" +#include "QpidException.h" +#include "QpidMarshal.h" + +/// +/// outputCallbackHost +/// Native class that holds reference to managed class +/// and for hosting the native callback procedure. +/// +namespace qpid { +namespace messaging { + + class outputCallbackHost : public qpid::messaging::LoggerOutput { + private: + // Reference to managed class + gcroot 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 ); +} + + +/// +/// Logger a managed wrapper for a ::qpid::messaging::Logger +/// + +// 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 ^ args) +{ + Configure(args, ""); +} + +void Logger::Configure(array ^ theArgs, System::String ^ thePrefix) +{ + System::Exception ^ newException = nullptr; + + try + { + // Marshal the calling args + int argc = theArgs->Length; + + std::vector cppStrings; + for (int i=0; i cStrings; + for (int i=0; i +#include +#include +#include +#include + +#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. +// + +/// +/// outputCallbackHost +/// Native class that holds reference to managed class +/// and for hosting the native callback procedure. +/// +namespace qpid { +namespace messaging { + class outputCallbackHost; +}} + +namespace Org { +namespace Apache { +namespace Qpid { +namespace Messaging { + + /// + /// Level constants + /// These correspond exactly to qpid::messaging::Level + /// + public enum class Level { trace, debug, info, notice, warning, error, critical }; + + /// + /// LoggerOutput relays messages to the managed delegate + /// + + // 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); + }; + + /// + /// Logger is a managed wrapper for native ::qpid::messaging::Logger + /// + + public ref class Logger + { + private: + + public: + Logger(); + ~Logger(); + !Logger(); + + // Set logging in qpid messaging + void Configure(array ^ args); + void Configure(array ^ 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 @@ + @@ -311,6 +312,7 @@ + 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 @@ -541,6 +541,10 @@ RelativePath="..\FailoverUpdates.cpp" > + + @@ -583,6 +587,10 @@ RelativePath="..\FailoverUpdates.h" > + + -- cgit v1.2.1