LCOV - code coverage report
Current view: top level - libreoffice/cppu/source/LogBridge - LogBridge.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 114 0.0 %
Date: 2012-12-27 Functions: 0 12 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include "osl/mutex.hxx"
      22             : #include "osl/thread.h"
      23             : #include "uno/dispatcher.h"
      24             : #include "typelib/typedescription.hxx"
      25             : #include "cppu/helper/purpenv/Environment.hxx"
      26             : #include "cppu/helper/purpenv/Mapping.hxx"
      27             : #include "cppu/EnvDcp.hxx"
      28             : #include "rtl/logfile.hxx"
      29             : #include "uno/environment.hxx"
      30             : #include <com/sun/star/uno/Type.hxx>
      31             : #include <boost/unordered_map.hpp>
      32             : #include <memory>
      33             : 
      34             : namespace
      35             : {
      36             : class LogBridge : public cppu::Enterable
      37             : {
      38             :     osl::Mutex          m_mutex;
      39             :     sal_Int32           m_count;
      40             :     oslThreadIdentifier m_threadId;
      41             : 
      42             :     virtual  ~LogBridge(void);
      43             : 
      44             : public:
      45             :     explicit LogBridge(void);
      46             : 
      47             :     virtual void v_callInto_v(uno_EnvCallee * pCallee, va_list * pParam);
      48             :     virtual void v_callOut_v (uno_EnvCallee * pCallee, va_list * pParam);
      49             : 
      50             :     virtual void v_enter(void);
      51             :     virtual void v_leave(void);
      52             : 
      53             :     virtual int  v_isValid(rtl::OUString * pReason);
      54             : };
      55             : 
      56           0 : LogBridge::LogBridge(void)
      57             :     : m_count   (0)
      58           0 :       ,m_threadId(0)
      59             : {
      60           0 : }
      61             : 
      62           0 : LogBridge::~LogBridge(void)
      63             : {
      64             :     OSL_ASSERT(m_count >= 0);
      65           0 : }
      66             : 
      67           0 : void LogBridge::v_callInto_v(uno_EnvCallee * pCallee, va_list * pParam)
      68             : {
      69           0 :     enter();
      70           0 :     pCallee(pParam);
      71           0 :     leave();
      72           0 : }
      73             : 
      74           0 : void LogBridge::v_callOut_v(uno_EnvCallee * pCallee, va_list * pParam)
      75             : {
      76             :     OSL_ASSERT(m_count > 0);
      77             : 
      78           0 :     -- m_count;
      79           0 :     pCallee(pParam);
      80           0 :     ++ m_count;
      81             : 
      82           0 :     if (!m_threadId)
      83           0 :         m_threadId = osl_getThreadIdentifier(NULL);
      84           0 : }
      85             : 
      86           0 : void LogBridge::v_enter(void)
      87             : {
      88           0 :     m_mutex.acquire();
      89             : 
      90             :     OSL_ASSERT(m_count >= 0);
      91             : 
      92           0 :     if (m_count == 0)
      93           0 :         m_threadId = osl_getThreadIdentifier(NULL);
      94             : 
      95           0 :     ++ m_count;
      96           0 : }
      97             : 
      98           0 : void LogBridge::v_leave(void)
      99             : {
     100             :     OSL_ASSERT(m_count > 0);
     101             : 
     102           0 :     -- m_count;
     103           0 :     if (!m_count)
     104           0 :         m_threadId = 0;
     105             : 
     106             : 
     107           0 :     m_mutex.release();
     108           0 : }
     109             : 
     110           0 : int LogBridge::v_isValid(rtl::OUString * pReason)
     111             : {
     112           0 :     int result = 1;
     113             : 
     114           0 :     result = m_count > 0;
     115           0 :     if (!result)
     116           0 :         *pReason = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("not entered"));
     117             : 
     118             :     else
     119             :     {
     120           0 :         result = m_threadId == osl_getThreadIdentifier(NULL);
     121             : 
     122           0 :         if (!result)
     123           0 :             *pReason = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("wrong thread"));
     124             :     }
     125             : 
     126           0 :     if (result)
     127           0 :         *pReason = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OK"));
     128             : 
     129           0 :     return result;
     130             : }
     131             : 
     132           0 :     void traceValue(typelib_TypeDescriptionReference* _pTypeRef,void* pArg)
     133             :     {
     134           0 :         switch(_pTypeRef->eTypeClass)
     135             :         {
     136             :             case typelib_TypeClass_STRING:
     137             :                 {
     138           0 :                     const ::rtl::OString sValue( ::rtl::OUStringToOString(*static_cast< ::rtl::OUString*>(pArg),osl_getThreadTextEncoding()));
     139           0 :                     rtl_logfile_trace( "%s", sValue.getStr());
     140             :                 }
     141           0 :                 break;
     142             :             case typelib_TypeClass_BOOLEAN:
     143           0 :                 rtl_logfile_trace( "%d", *static_cast<sal_Bool*>(pArg));
     144           0 :                 break;
     145             :             case typelib_TypeClass_BYTE:
     146           0 :                 rtl_logfile_trace( "%d", *static_cast<sal_Int8*>(pArg));
     147           0 :                 break;
     148             :             case typelib_TypeClass_CHAR:
     149           0 :                 rtl_logfile_trace( "%c", *static_cast<sal_Char*>(pArg));
     150           0 :                 break;
     151             :             case typelib_TypeClass_SHORT:
     152             :             case typelib_TypeClass_UNSIGNED_SHORT:
     153           0 :                 rtl_logfile_trace( "%d", *static_cast<sal_Int16*>(pArg));
     154           0 :                 break;
     155             :             case typelib_TypeClass_LONG:
     156             :             case typelib_TypeClass_UNSIGNED_LONG:
     157             :             case typelib_TypeClass_ENUM:
     158           0 :                 rtl_logfile_trace( "%d", *static_cast<sal_Int32*>(pArg));
     159           0 :                 break;
     160             :             case typelib_TypeClass_HYPER:
     161             :             case typelib_TypeClass_UNSIGNED_HYPER:
     162           0 :                 rtl_logfile_trace( "%d", *static_cast<sal_Int64*>(pArg));
     163           0 :                 break;
     164             :             case typelib_TypeClass_FLOAT:
     165           0 :                 rtl_logfile_trace( "%f", *static_cast<float*>(pArg));
     166           0 :                 break;
     167             :             case typelib_TypeClass_DOUBLE:
     168           0 :                 rtl_logfile_trace( "%f", *static_cast<double*>(pArg));
     169           0 :                 break;
     170             :             case typelib_TypeClass_TYPE:
     171             :                 {
     172           0 :                     const ::rtl::OString sValue( ::rtl::OUStringToOString(((com::sun::star::uno::Type*)pArg)->getTypeName(),osl_getThreadTextEncoding()));
     173           0 :                     rtl_logfile_trace( "%s", sValue.getStr());
     174             :                 }
     175           0 :                 break;
     176             :             case typelib_TypeClass_ANY:
     177           0 :                 if ( static_cast<uno_Any*>(pArg)->pData )
     178           0 :                     traceValue(static_cast<uno_Any*>(pArg)->pType,static_cast<uno_Any*>(pArg)->pData);
     179             :                 else
     180           0 :                     rtl_logfile_trace( "void");
     181           0 :                 break;
     182             :             case typelib_TypeClass_EXCEPTION:
     183           0 :                 rtl_logfile_trace( "exception");
     184           0 :                 break;
     185             :             case typelib_TypeClass_INTERFACE:
     186             :                 {
     187           0 :                     const ::rtl::OString sValue( ::rtl::OUStringToOString(_pTypeRef->pTypeName,osl_getThreadTextEncoding()));
     188           0 :                     rtl_logfile_trace( "%s 0x%p", sValue.getStr(),pArg);
     189             :                 }
     190           0 :                 break;
     191             :             case typelib_TypeClass_VOID:
     192           0 :                 rtl_logfile_trace( "void");
     193           0 :                 break;
     194             :             default:
     195           0 :                 rtl_logfile_trace( "0x%p", pArg);
     196           0 :                 break;
     197             :         } // switch(pParams[i].pTypeRef->eTypeClass)
     198           0 :     }
     199             : }
     200             : 
     201           0 : void LogProbe(
     202             :     bool                                pre,
     203             :     SAL_UNUSED_PARAMETER void         * /*pThis*/,
     204             :     SAL_UNUSED_PARAMETER void         * /*pContext*/,
     205             :     typelib_TypeDescriptionReference  * pReturnTypeRef,
     206             :     typelib_MethodParameter           * pParams,
     207             :     sal_Int32                           nParams,
     208             :     typelib_TypeDescription     const * pMemberType,
     209             :     void                              * pReturn,
     210             :     void                              * pArgs[],
     211             :     uno_Any                          ** ppException )
     212             : {
     213           0 :     static ::std::auto_ptr< ::rtl::Logfile> pLogger;
     214           0 :     ::rtl::OString sTemp;
     215           0 :     if ( pMemberType && pMemberType->pTypeName )
     216           0 :         sTemp = ::rtl::OUStringToOString(pMemberType->pTypeName,RTL_TEXTENCODING_ASCII_US);
     217           0 :     if ( pre  )
     218             :     {
     219           0 :         rtl_logfile_longTrace( "{ LogBridge () %s", sTemp.getStr() );
     220           0 :         if ( nParams )
     221             :         {
     222           0 :             rtl_logfile_trace( "\n| : ( LogBridge ");
     223           0 :             for(sal_Int32 i = 0;i < nParams;++i)
     224             :             {
     225           0 :                 if ( i > 0 )
     226           0 :                     rtl_logfile_trace( ",");
     227           0 :                 traceValue(pParams[i].pTypeRef,pArgs[i]);
     228             : 
     229             :             }
     230           0 :             rtl_logfile_trace( ")");
     231             :         } // if ( nParams )
     232           0 :         rtl_logfile_trace( "\n");
     233             :     }
     234           0 :     else if ( !pre )
     235             :     {
     236           0 :         rtl_logfile_longTrace( "} LogBridge () %s",sTemp.getStr());
     237           0 :         if ( ppException && *ppException )
     238             :         {
     239           0 :             rtl_logfile_trace( " excption occurred : ");
     240           0 :             typelib_TypeDescription * pElementTypeDescr = 0;
     241           0 :             TYPELIB_DANGER_GET( &pElementTypeDescr, (*ppException)->pType );
     242           0 :             const ::rtl::OString sValue( ::rtl::OUStringToOString(pElementTypeDescr->pTypeName,osl_getThreadTextEncoding()));
     243           0 :             rtl_logfile_trace( "%s", sValue.getStr());
     244           0 :             TYPELIB_DANGER_RELEASE( pElementTypeDescr );
     245             :         }
     246           0 :         else if ( pReturnTypeRef )
     247             :         {
     248           0 :             rtl_logfile_trace( " return : ");
     249           0 :             traceValue(pReturnTypeRef,pReturn);
     250             :         } // if ( pReturn && pReturnTypeRef )
     251             : 
     252           0 :         rtl_logfile_trace( "\n");
     253           0 :     }
     254           0 : }
     255             : 
     256             : #ifdef DISABLE_DYNLOADING
     257             : 
     258             : #define uno_initEnvironment log_uno_uno_initEnvironment
     259             : #define uno_ext_getMapping log_uno_uno_ext_getMapping
     260             : 
     261             : #endif
     262             : 
     263           0 : extern "C" void SAL_DLLPUBLIC_EXPORT SAL_CALL uno_initEnvironment(uno_Environment * pEnv)
     264             :     SAL_THROW_EXTERN_C()
     265             : {
     266           0 :     cppu::helper::purpenv::Environment_initWithEnterable(pEnv, new LogBridge());
     267           0 : }
     268             : 
     269           0 : extern "C" void SAL_DLLPUBLIC_EXPORT SAL_CALL uno_ext_getMapping(uno_Mapping     ** ppMapping,
     270             :                                    uno_Environment  * pFrom,
     271             :                                    uno_Environment  * pTo )
     272             : {
     273           0 :     cppu::helper::purpenv::createMapping(ppMapping, pFrom, pTo,LogProbe);
     274           0 : }
     275             : 
     276             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10