LCOV - code coverage report
Current view: top level - cppu/source/helper/purpenv - helper_purpenv_Mapping.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 56 60 93.3 %
Date: 2015-06-13 12:38:46 Functions: 12 12 100.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 "cppu/helper/purpenv/Mapping.hxx"
      22             : 
      23             : #include "Proxy.hxx"
      24             : 
      25             : #include "osl/interlck.h"
      26             : #include "uno/environment.hxx"
      27             : #include "uno/dispatcher.h"
      28             : #include "typelib/typedescription.h"
      29             : 
      30             : 
      31             : #ifdef debug
      32             : # define LOG_LIFECYCLE_cppu_helper_purpenv_Mapping
      33             : #endif
      34             : 
      35             : #ifdef LOG_LIFECYCLE_cppu_helper_purpenv_Mapping
      36             : #  include <iostream>
      37             : #  define LOG_LIFECYCLE_cppu_helper_purpenv_Mapping_emit(x) x
      38             : 
      39             : #else
      40             : #  define LOG_LIFECYCLE_cppu_helper_purpenv_Mapping_emit(x)
      41             : 
      42             : #endif
      43             : 
      44             : 
      45             : using namespace com::sun::star;
      46             : 
      47             : 
      48             : class Mapping : public uno_Mapping
      49             : {
      50             :     uno::Environment   m_from;
      51             :     uno::Environment   m_to;
      52             : 
      53             :     oslInterlockedCount m_nCount;
      54             : 
      55             :     cppu::helper::purpenv::ProbeFun * m_probeFun;
      56             :     void                            * m_pContext;
      57             : 
      58             : public:
      59             :     explicit  Mapping(uno_Environment                 * pFrom,
      60             :                       uno_Environment                 * pTo,
      61             :                       cppu::helper::purpenv::ProbeFun * probeFun,
      62             :                       void                            * pProbeContext);
      63             :     virtual  ~Mapping();
      64             : 
      65             :     void mapInterface(
      66             :         uno_Interface                    ** ppOut,
      67             :         uno_Interface                     * pUnoI,
      68             :         typelib_InterfaceTypeDescription  * pTypeDescr);
      69             : 
      70             :     void acquire();
      71             :     void release();
      72             : };
      73             : 
      74       98561 : static void SAL_CALL s_mapInterface(
      75             :     uno_Mapping                       * puno_Mapping,
      76             :     void                             ** ppOut,
      77             :     void                              * pUnoI,
      78             :     typelib_InterfaceTypeDescription  * pTypeDescr )
      79             :     SAL_THROW_EXTERN_C()
      80             : {
      81       98561 :     Mapping * pMapping = static_cast<Mapping *>(puno_Mapping);
      82             :     pMapping->mapInterface(
      83             :         reinterpret_cast<uno_Interface **>(ppOut),
      84       98561 :         static_cast<uno_Interface *>(pUnoI), pTypeDescr);
      85       98561 : }
      86             : 
      87             : extern "C" {
      88      385734 : static void SAL_CALL s_acquire(uno_Mapping * puno_Mapping)
      89             :     SAL_THROW_EXTERN_C()
      90             : {
      91      385734 :     Mapping * pMapping = static_cast<Mapping *>(puno_Mapping);
      92      385734 :     pMapping->acquire();
      93      385734 : }
      94             : 
      95      385700 : static void SAL_CALL s_release(uno_Mapping * puno_Mapping)
      96             :     SAL_THROW_EXTERN_C()
      97             : {
      98      385700 :     Mapping * pMapping = static_cast<Mapping * >(puno_Mapping);
      99      385700 :     pMapping->release();
     100      385700 : }
     101             : 
     102             : 
     103       98561 : static void s_getIdentifier_v(va_list * pParam)
     104             : {
     105       98561 :     uno_ExtEnvironment *  pEnv  = va_arg(*pParam, uno_ExtEnvironment *);
     106       98561 :     rtl_uString        ** ppOid = va_arg(*pParam, rtl_uString **);
     107       98561 :     uno_Interface      *  pUnoI = va_arg(*pParam, uno_Interface *);
     108             : 
     109       98561 :     pEnv->getObjectIdentifier(pEnv, ppOid, pUnoI);
     110       98561 : }
     111             : 
     112           2 : static void SAL_CALL s_free(uno_Mapping * puno_Mapping)
     113             :     SAL_THROW_EXTERN_C()
     114             : {
     115           2 :     Mapping * pMapping = static_cast<Mapping *>(puno_Mapping);
     116           2 :     delete pMapping;
     117           2 : }
     118             : }
     119             : 
     120          10 : Mapping::Mapping(uno_Environment                 * pFrom,
     121             :                  uno_Environment                 * pTo,
     122             :                  cppu::helper::purpenv::ProbeFun * probeFun,
     123             :                  void                            * pProbeContext
     124             : )
     125             :     : m_from    (pFrom),
     126             :       m_to      (pTo),
     127             :       m_nCount  (1),
     128             :       m_probeFun(probeFun),
     129          10 :       m_pContext(pProbeContext)
     130             : {
     131             :     LOG_LIFECYCLE_cppu_helper_purpenv_Mapping_emit(fprintf(stderr, "LIFE: %s -> %p\n", "Mapping::Mapping(uno_Environment * pFrom, uno_Environment * pTo)", this));
     132             : 
     133          10 :     uno_Mapping::acquire      = s_acquire;
     134          10 :     uno_Mapping::release      = s_release;
     135          10 :     uno_Mapping::mapInterface = s_mapInterface;
     136          10 : }
     137             : 
     138           4 : Mapping::~Mapping()
     139             : {
     140             :     LOG_LIFECYCLE_cppu_helper_purpenv_Mapping_emit(fprintf(stderr, "LIFE: %s -> %p\n", "Mapping::~Mapping()", this));
     141           4 : }
     142             : 
     143             : 
     144       98561 : void Mapping::mapInterface(
     145             :     uno_Interface                    ** ppOut,
     146             :     uno_Interface                     * pUnoI,
     147             :     typelib_InterfaceTypeDescription  * pTypeDescr)
     148             : {
     149             :     OSL_ASSERT(ppOut && pTypeDescr);
     150       98561 :     if (*ppOut)
     151             :     {
     152           0 :         (*ppOut)->release(*ppOut);
     153           0 :         *ppOut = 0;
     154             :     }
     155             : 
     156       98561 :     if (!pUnoI)
     157       98561 :         return;
     158             : 
     159             :     // get object id of uno interface to be wrapped
     160             :     // need to enter environment because of potential "queryInterface" call
     161       98561 :     rtl_uString * pOId = 0;
     162       98561 :     uno_Environment_invoke(m_from.get(), s_getIdentifier_v, m_from.get(), &pOId, pUnoI);
     163             :     OSL_ASSERT(pOId);
     164             : 
     165             :      // try to get any known interface from target environment
     166       98561 :     m_to.get()->pExtEnv->getRegisteredInterface(m_to.get()->pExtEnv, reinterpret_cast<void **>(ppOut), pOId, pTypeDescr);
     167             : 
     168       98561 :     if (!*ppOut) // not yet there, register new proxy interface
     169             :     {
     170             :         // try to publish a new proxy (ref count initially 1)
     171             :         uno_Interface * pProxy = new Proxy(this,
     172       96425 :                                            m_from.get(),
     173       96425 :                                            m_to.get(),
     174             :                                            pUnoI,
     175             :                                            pTypeDescr,
     176             :                                            pOId,
     177             :                                            m_probeFun,
     178      289275 :                                            m_pContext);
     179             : 
     180             :         // proxy may be exchanged during registration
     181      192850 :         m_to.get()->pExtEnv->registerProxyInterface(m_to.get()->pExtEnv,
     182             :                                                     reinterpret_cast<void **>(&pProxy),
     183             :                                                     Proxy_free,
     184             :                                                     pOId,
     185      192850 :                                                     pTypeDescr);
     186             : 
     187       96425 :         *ppOut = pProxy;
     188             :     }
     189             : 
     190       98561 :     rtl_uString_release(pOId);
     191             : }
     192             : 
     193             : 
     194      385734 : void Mapping::acquire()
     195             : {
     196      385734 :     if (osl_atomic_increment(&m_nCount) == 1)
     197             :     {
     198           0 :         uno_Mapping * pMapping = this;
     199             : 
     200           0 :         ::uno_registerMapping(&pMapping, s_free, m_from.get(), m_to.get(), NULL);
     201             :     }
     202      385734 : }
     203             : 
     204      385700 : void Mapping::release()
     205             : {
     206      385700 :     if (osl_atomic_decrement(&m_nCount) == 0)
     207           2 :         ::uno_revokeMapping(this);
     208      385700 : }
     209             : 
     210             : 
     211             : namespace cppu { namespace helper { namespace purpenv {
     212             : 
     213          10 : void createMapping(uno_Mapping     ** ppMapping,
     214             :                    uno_Environment  * pFrom,
     215             :                    uno_Environment  * pTo,
     216             :                    ProbeFun         * probeFun,
     217             :                    void             * pContext
     218             :  )
     219             : {
     220          10 :     *ppMapping = new Mapping(pFrom, pTo, probeFun, pContext);
     221             : 
     222          10 :     ::uno_registerMapping(ppMapping, s_free, pFrom, pTo, NULL);
     223          10 : }
     224             : 
     225             : }}}
     226             : 
     227             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11