LCOV - code coverage report
Current view: top level - cppu/source/UnsafeBridge - UnsafeBridge.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 45 0.0 %
Date: 2014-04-11 Functions: 0 10 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             : 
      25             : #include "cppu/helper/purpenv/Environment.hxx"
      26             : #include "cppu/helper/purpenv/Mapping.hxx"
      27             : 
      28             : 
      29             : #ifdef debug
      30             : # define LOG_LIFECYCLE_UnsafeBridge
      31             : #endif
      32             : 
      33             : #ifdef LOG_LIFECYCLE_UnsafeBridge
      34             : #  include <iostream>
      35             : #  define LOG_LIFECYCLE_UnsafeBridge_emit(x) x
      36             : 
      37             : #else
      38             : #  define LOG_LIFECYCLE_UnsafeBridge_emit(x)
      39             : 
      40             : #endif
      41             : 
      42             : 
      43             : class UnsafeBridge : public cppu::Enterable
      44             : {
      45             :     osl::Mutex          m_mutex;
      46             :     sal_Int32           m_count;
      47             :     oslThreadIdentifier m_threadId;
      48             : 
      49             :     virtual  ~UnsafeBridge(void);
      50             : 
      51             : public:
      52             :     explicit UnsafeBridge(void);
      53             : 
      54             :     virtual void v_callInto_v(uno_EnvCallee * pCallee, va_list * pParam) SAL_OVERRIDE;
      55             :     virtual void v_callOut_v (uno_EnvCallee * pCallee, va_list * pParam) SAL_OVERRIDE;
      56             : 
      57             :     virtual void v_enter(void) SAL_OVERRIDE;
      58             :     virtual void v_leave(void) SAL_OVERRIDE;
      59             : 
      60             :     virtual bool v_isValid(rtl::OUString * pReason) SAL_OVERRIDE;
      61             : };
      62             : 
      63           0 : UnsafeBridge::UnsafeBridge(void)
      64             :     : m_count   (0),
      65           0 :       m_threadId(0)
      66             : {
      67             :     LOG_LIFECYCLE_UnsafeBridge_emit(fprintf(stderr, "LIFE: %s -> %p\n", "UnsafeBridge::UnsafeBridge(uno_Environment * pEnv)", this));
      68           0 : }
      69             : 
      70           0 : UnsafeBridge::~UnsafeBridge(void)
      71             : {
      72             :     LOG_LIFECYCLE_UnsafeBridge_emit(fprintf(stderr, "LIFE: %s -> %p\n", "UnsafeBridge::~UnsafeBridge(void)", this));
      73             : 
      74             :     SAL_WARN_IF(m_count < 0, "cppu.unsafebridge", "m_count is less than 0");
      75           0 : }
      76             : 
      77           0 : void UnsafeBridge::v_callInto_v(uno_EnvCallee * pCallee, va_list * pParam)
      78             : {
      79           0 :     enter();
      80           0 :     pCallee(pParam);
      81           0 :     leave();
      82           0 : }
      83             : 
      84           0 : void UnsafeBridge::v_callOut_v(uno_EnvCallee * pCallee, va_list * pParam)
      85             : {
      86             :     SAL_WARN_IF(m_count <= 0, "cppu.unsafebridge", "m_count is less than or equal to 0");
      87             : 
      88           0 :     -- m_count;
      89           0 :     pCallee(pParam);
      90           0 :     ++ m_count;
      91             : 
      92           0 :     if (!m_threadId)
      93           0 :         m_threadId = osl::Thread::getCurrentIdentifier();
      94           0 : }
      95             : 
      96           0 : void UnsafeBridge::v_enter(void)
      97             : {
      98           0 :     m_mutex.acquire();
      99             : 
     100             :     SAL_WARN_IF(m_count < 0, "cppu.unsafebridge", "m_count is less than 0");
     101             : 
     102           0 :     if (m_count == 0)
     103           0 :         m_threadId = osl::Thread::getCurrentIdentifier();
     104             : 
     105           0 :     ++ m_count;
     106           0 : }
     107             : 
     108           0 : void UnsafeBridge::v_leave(void)
     109             : {
     110             :     SAL_WARN_IF(m_count <= 0, "cppu.unsafebridge", "m_count is less than or equal to 0");
     111             : 
     112           0 :     -- m_count;
     113           0 :     if (!m_count)
     114           0 :         m_threadId = 0;
     115             : 
     116             : 
     117           0 :     m_mutex.release();
     118           0 : }
     119             : 
     120           0 : bool UnsafeBridge::v_isValid(rtl::OUString * pReason)
     121             : {
     122           0 :     bool result = m_count > 0;
     123           0 :     if (!result)
     124             :     {
     125           0 :         *pReason = rtl::OUString("not entered");
     126             :     }
     127             :     else
     128             :     {
     129           0 :         result = m_threadId == osl::Thread::getCurrentIdentifier();
     130             : 
     131           0 :         if (!result)
     132           0 :             *pReason = rtl::OUString("wrong thread");
     133             :     }
     134             : 
     135           0 :     if (result)
     136           0 :         *pReason = rtl::OUString("OK");
     137             : 
     138           0 :     return result;
     139             : }
     140             : 
     141           0 : extern "C" void SAL_DLLPUBLIC_EXPORT SAL_CALL uno_initEnvironment(uno_Environment * pEnv)
     142             :     SAL_THROW_EXTERN_C()
     143             : {
     144           0 :     cppu::helper::purpenv::Environment_initWithEnterable(pEnv, new UnsafeBridge());
     145           0 : }
     146             : 
     147           0 : extern "C" void SAL_DLLPUBLIC_EXPORT SAL_CALL uno_ext_getMapping(uno_Mapping     ** ppMapping,
     148             :                                    uno_Environment  * pFrom,
     149             :                                    uno_Environment  * pTo )
     150             : {
     151           0 :     cppu::helper::purpenv::createMapping(ppMapping, pFrom, pTo);
     152           0 : }
     153             : 
     154             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10