You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ch...@apache.org on 2014/01/22 22:54:25 UTC

svn commit: r1560529 - in /qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src: Logger.cpp Logger.h msvc10/org.apache.qpid.messaging.vcxproj msvc9/org.apache.qpid.messaging.vcproj

Author: chug
Date: Wed Jan 22 21:54:25 2014
New Revision: 1560529

URL: http://svn.apache.org/r1560529
Log:
QPID-5481: Messaging API Update - 1555202 Logger module added

Added:
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Logger.cpp
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Logger.h
Modified:
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/msvc10/org.apache.qpid.messaging.vcxproj
    qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/msvc9/org.apache.qpid.messaging.vcproj

Added: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Logger.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Logger.cpp?rev=1560529&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Logger.cpp (added)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Logger.cpp Wed Jan 22 21:54:25 2014
@@ -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;
+    }
+}
+}}}}

Added: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Logger.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Logger.h?rev=1560529&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Logger.h (added)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/Logger.h Wed Jan 22 21:54:25 2014
@@ -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);
+    };
+}}}}

Modified: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/msvc10/org.apache.qpid.messaging.vcxproj
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/msvc10/org.apache.qpid.messaging.vcxproj?rev=1560529&r1=1560528&r2=1560529&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/msvc10/org.apache.qpid.messaging.vcxproj (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/msvc10/org.apache.qpid.messaging.vcxproj Wed Jan 22 21:54:25 2014
@@ -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" />

Modified: qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/msvc9/org.apache.qpid.messaging.vcproj
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/msvc9/org.apache.qpid.messaging.vcproj?rev=1560529&r1=1560528&r2=1560529&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/msvc9/org.apache.qpid.messaging.vcproj (original)
+++ qpid/trunk/qpid/cpp/bindings/qpid/dotnet/src/msvc9/org.apache.qpid.messaging.vcproj Wed Jan 22 21:54:25 2014
@@ -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>



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org