LCOV - code coverage report
Current view: top level - cppu/source/LogBridge - LogBridge.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 90 0.0 %
Date: 2014-04-14 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 "osl/thread.hxx"
      24             : #include "uno/dispatcher.h"
      25             : #include "typelib/typedescription.hxx"
      26             : #include "cppu/helper/purpenv/Environment.hxx"
      27             : #include "cppu/helper/purpenv/Mapping.hxx"
      28             : #include "cppu/EnvDcp.hxx"
      29             : #include "uno/environment.hxx"
      30             : #include <com/sun/star/uno/Type.hxx>
      31             : 
      32             : namespace
      33             : {
      34             : class LogBridge : public cppu::Enterable
      35             : {
      36             :     osl::Mutex          m_mutex;
      37             :     sal_Int32           m_count;
      38             :     oslThreadIdentifier m_threadId;
      39             : 
      40             :     virtual  ~LogBridge(void);
      41             : 
      42             : public:
      43             :     explicit LogBridge(void);
      44             : 
      45             :     virtual void v_callInto_v(uno_EnvCallee * pCallee, va_list * pParam) SAL_OVERRIDE;
      46             :     virtual void v_callOut_v (uno_EnvCallee * pCallee, va_list * pParam) SAL_OVERRIDE;
      47             : 
      48             :     virtual void v_enter(void) SAL_OVERRIDE;
      49             :     virtual void v_leave(void) SAL_OVERRIDE;
      50             : 
      51             :     virtual bool v_isValid(rtl::OUString * pReason) SAL_OVERRIDE;
      52             : };
      53             : 
      54           0 : LogBridge::LogBridge(void)
      55             :     : m_count   (0)
      56           0 :       ,m_threadId(0)
      57             : {
      58           0 : }
      59             : 
      60           0 : LogBridge::~LogBridge(void)
      61             : {
      62             :     OSL_ASSERT(m_count >= 0);
      63           0 : }
      64             : 
      65           0 : void LogBridge::v_callInto_v(uno_EnvCallee * pCallee, va_list * pParam)
      66             : {
      67           0 :     enter();
      68           0 :     pCallee(pParam);
      69           0 :     leave();
      70           0 : }
      71             : 
      72           0 : void LogBridge::v_callOut_v(uno_EnvCallee * pCallee, va_list * pParam)
      73             : {
      74             :     OSL_ASSERT(m_count > 0);
      75             : 
      76           0 :     -- m_count;
      77           0 :     pCallee(pParam);
      78           0 :     ++ m_count;
      79             : 
      80           0 :     if (!m_threadId)
      81           0 :         m_threadId = osl::Thread::getCurrentIdentifier();
      82           0 : }
      83             : 
      84           0 : void LogBridge::v_enter(void)
      85             : {
      86           0 :     m_mutex.acquire();
      87             : 
      88             :     OSL_ASSERT(m_count >= 0);
      89             : 
      90           0 :     if (m_count == 0)
      91           0 :         m_threadId = osl::Thread::getCurrentIdentifier();
      92             : 
      93           0 :     ++ m_count;
      94           0 : }
      95             : 
      96           0 : void LogBridge::v_leave(void)
      97             : {
      98             :     OSL_ASSERT(m_count > 0);
      99             : 
     100           0 :     -- m_count;
     101           0 :     if (!m_count)
     102           0 :         m_threadId = 0;
     103             : 
     104             : 
     105           0 :     m_mutex.release();
     106           0 : }
     107             : 
     108           0 : bool LogBridge::v_isValid(rtl::OUString * pReason)
     109             : {
     110           0 :     bool result = m_count > 0;
     111           0 :     if (!result)
     112             :     {
     113           0 :         *pReason = rtl::OUString("not entered");
     114             :     }
     115             :     else
     116             :     {
     117           0 :         result = m_threadId == osl::Thread::getCurrentIdentifier();
     118             : 
     119           0 :         if (!result)
     120           0 :             *pReason = rtl::OUString("wrong thread");
     121             :     }
     122             : 
     123           0 :     if (result)
     124           0 :         *pReason = rtl::OUString("OK");
     125             : 
     126           0 :     return result;
     127             : }
     128             : 
     129           0 :     void traceValue(typelib_TypeDescriptionReference* _pTypeRef,void* pArg)
     130             :     {
     131           0 :         switch(_pTypeRef->eTypeClass)
     132             :         {
     133             :             case typelib_TypeClass_STRING:
     134             :                 {
     135           0 :                     const ::rtl::OString sValue( ::rtl::OUStringToOString(*static_cast< ::rtl::OUString*>(pArg),osl_getThreadTextEncoding()));
     136           0 :                     SAL_INFO("cppu", "" << sValue.getStr());
     137             :                 }
     138           0 :                 break;
     139             :             case typelib_TypeClass_BOOLEAN:
     140             :                SAL_INFO("cppu", "" << *static_cast<sal_Bool*>(pArg));
     141           0 :                 break;
     142             :             case typelib_TypeClass_BYTE:
     143             :                SAL_INFO("cppu", "" << *static_cast<sal_Int8*>(pArg));
     144           0 :                 break;
     145             :             case typelib_TypeClass_CHAR:
     146             :                SAL_INFO("cppu", "" << *static_cast<sal_Char*>(pArg));
     147           0 :                 break;
     148             :             case typelib_TypeClass_SHORT:
     149             :             case typelib_TypeClass_UNSIGNED_SHORT:
     150             :                SAL_INFO("cppu", "" << *static_cast<sal_Int16*>(pArg));
     151           0 :                 break;
     152             :             case typelib_TypeClass_LONG:
     153             :             case typelib_TypeClass_UNSIGNED_LONG:
     154             :             case typelib_TypeClass_ENUM:
     155             :                SAL_INFO("cppu", "" << *static_cast<sal_Int32*>(pArg));
     156           0 :                 break;
     157             :             case typelib_TypeClass_HYPER:
     158             :             case typelib_TypeClass_UNSIGNED_HYPER:
     159             :                SAL_INFO("cppu", "" << *static_cast<sal_Int64*>(pArg));
     160           0 :                 break;
     161             :             case typelib_TypeClass_FLOAT:
     162             :                SAL_INFO("cppu", "" << *static_cast<float*>(pArg));
     163           0 :                 break;
     164             :             case typelib_TypeClass_DOUBLE:
     165             :                SAL_INFO("cppu", "" << *static_cast<double*>(pArg));
     166           0 :                 break;
     167             :             case typelib_TypeClass_TYPE:
     168             :                 {
     169           0 :                     const ::rtl::OString sValue( ::rtl::OUStringToOString(((com::sun::star::uno::Type*)pArg)->getTypeName(),osl_getThreadTextEncoding()));
     170           0 :                    SAL_INFO("cppu", "" << sValue.getStr());
     171             :                 }
     172           0 :                 break;
     173             :             case typelib_TypeClass_ANY:
     174           0 :                 if ( static_cast<uno_Any*>(pArg)->pData )
     175           0 :                     traceValue(static_cast<uno_Any*>(pArg)->pType,static_cast<uno_Any*>(pArg)->pData);
     176             :                 else
     177             :                    SAL_INFO("cppu", "void");
     178           0 :                 break;
     179             :             case typelib_TypeClass_EXCEPTION:
     180             :                SAL_INFO("cppu", "exception");
     181           0 :                 break;
     182             :             case typelib_TypeClass_INTERFACE:
     183             :                 {
     184           0 :                     const ::rtl::OString sValue( ::rtl::OUStringToOString(_pTypeRef->pTypeName,osl_getThreadTextEncoding()));
     185           0 :                    SAL_INFO("cppu", "" << sValue.getStr() << "0x" << std::hex << pArg);
     186             :                 }
     187           0 :                 break;
     188             :             case typelib_TypeClass_VOID:
     189             :                SAL_INFO("cppu", "void");
     190           0 :                 break;
     191             :             default:
     192             :                SAL_INFO("cppu", "0x" << std::hex << pArg);
     193           0 :                 break;
     194             :         } // switch(pParams[i].pTypeRef->eTypeClass)
     195           0 :     }
     196             : }
     197             : 
     198           0 : void LogProbe(
     199             :     bool                                pre,
     200             :     SAL_UNUSED_PARAMETER void         * /*pThis*/,
     201             :     SAL_UNUSED_PARAMETER void         * /*pContext*/,
     202             :     typelib_TypeDescriptionReference  * pReturnTypeRef,
     203             :     typelib_MethodParameter           * pParams,
     204             :     sal_Int32                           nParams,
     205             :     typelib_TypeDescription     const * pMemberType,
     206             :     void                              * pReturn,
     207             :     void                              * pArgs[],
     208             :     uno_Any                          ** ppException )
     209             : {
     210           0 :     ::rtl::OString sTemp;
     211           0 :     if ( pMemberType && pMemberType->pTypeName )
     212           0 :         sTemp = ::rtl::OUStringToOString(pMemberType->pTypeName,RTL_TEXTENCODING_ASCII_US);
     213           0 :     if ( pre  )
     214             :     {
     215             :         SAL_INFO("cppu", "{ LogBridge () " << sTemp.getStr() );
     216           0 :         if ( nParams )
     217             :         {
     218             :            SAL_INFO("cppu", "\n| : ( LogBridge ");
     219           0 :             for(sal_Int32 i = 0;i < nParams;++i)
     220             :             {
     221           0 :                 if ( i > 0 )
     222             :                    SAL_INFO("cppu", ",");
     223           0 :                 traceValue(pParams[i].pTypeRef,pArgs[i]);
     224             : 
     225             :             }
     226             :            SAL_INFO("cppu", ")");
     227             :         } // if ( nParams )
     228             :        SAL_INFO("cppu", "\n");
     229             :     }
     230           0 :     else if ( !pre )
     231             :     {
     232             :         SAL_INFO("cppu", "} LogBridge () " << sTemp.getStr());
     233           0 :         if ( ppException && *ppException )
     234             :         {
     235             :            SAL_INFO("cppu", " exception occurred : ");
     236           0 :             typelib_TypeDescription * pElementTypeDescr = 0;
     237           0 :             TYPELIB_DANGER_GET( &pElementTypeDescr, (*ppException)->pType );
     238           0 :             const ::rtl::OString sValue( ::rtl::OUStringToOString(pElementTypeDescr->pTypeName,osl_getThreadTextEncoding()));
     239             :            SAL_INFO("cppu", "" << sValue.getStr());
     240           0 :             TYPELIB_DANGER_RELEASE( pElementTypeDescr );
     241             :         }
     242           0 :         else if ( pReturnTypeRef )
     243             :         {
     244             :            SAL_INFO("cppu", " return : ");
     245           0 :             traceValue(pReturnTypeRef,pReturn);
     246             :         } // if ( pReturn && pReturnTypeRef )
     247             : 
     248             :        SAL_INFO("cppu", "\n");
     249           0 :     }
     250           0 : }
     251             : 
     252             : #ifdef DISABLE_DYNLOADING
     253             : 
     254             : #define uno_initEnvironment log_uno_uno_initEnvironment
     255             : #define uno_ext_getMapping log_uno_uno_ext_getMapping
     256             : 
     257             : #endif
     258             : 
     259           0 : extern "C" void SAL_DLLPUBLIC_EXPORT SAL_CALL uno_initEnvironment(uno_Environment * pEnv)
     260             :     SAL_THROW_EXTERN_C()
     261             : {
     262           0 :     cppu::helper::purpenv::Environment_initWithEnterable(pEnv, new LogBridge());
     263           0 : }
     264             : 
     265           0 : extern "C" void SAL_DLLPUBLIC_EXPORT SAL_CALL uno_ext_getMapping(uno_Mapping     ** ppMapping,
     266             :                                    uno_Environment  * pFrom,
     267             :                                    uno_Environment  * pTo )
     268             : {
     269           0 :     cppu::helper::purpenv::createMapping(ppMapping, pFrom, pTo,LogProbe);
     270           0 : }
     271             : 
     272             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10