LCOV - code coverage report
Current view: top level - cppu/source/helper/purpenv - helper_purpenv_Mapping.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 49 60 81.7 %
Date: 2014-11-03 Functions: 9 12 75.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(void);
      64             : 
      65             :     void mapInterface(
      66             :         uno_Interface                    ** ppOut,
      67             :         uno_Interface                     * pUnoI,
      68             :         typelib_InterfaceTypeDescription  * pTypeDescr);
      69             : 
      70             :     void acquire(void);
      71             :     void release(void);
      72             : };
      73             : 
      74         436 : 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         436 :     Mapping * pMapping = static_cast<Mapping *>(puno_Mapping);
      82             :     pMapping->mapInterface(
      83             :         reinterpret_cast<uno_Interface **>(ppOut),
      84         436 :         static_cast<uno_Interface *>(pUnoI), pTypeDescr);
      85         436 : }
      86             : 
      87             : extern "C" {
      88        1208 : static void SAL_CALL s_acquire(uno_Mapping * puno_Mapping)
      89             :     SAL_THROW_EXTERN_C()
      90             : {
      91        1208 :     Mapping * pMapping = static_cast<Mapping *>(puno_Mapping);
      92        1208 :     pMapping->acquire();
      93        1208 : }
      94             : 
      95        1124 : static void SAL_CALL s_release(uno_Mapping * puno_Mapping)
      96             :     SAL_THROW_EXTERN_C()
      97             : {
      98        1124 :     Mapping * pMapping = static_cast<Mapping * >(puno_Mapping);
      99        1124 :     pMapping->release();
     100        1124 : }
     101             : 
     102             : 
     103         436 : static void s_getIdentifier_v(va_list * pParam)
     104             : {
     105         436 :     uno_ExtEnvironment *  pEnv  = va_arg(*pParam, uno_ExtEnvironment *);
     106         436 :     rtl_uString        ** ppOid = va_arg(*pParam, rtl_uString **);
     107         436 :     uno_Interface      *  pUnoI = va_arg(*pParam, uno_Interface *);
     108             : 
     109         436 :     pEnv->getObjectIdentifier(pEnv, ppOid, pUnoI);
     110         436 : }
     111             : 
     112           0 : static void SAL_CALL s_free(uno_Mapping * puno_Mapping)
     113             :     SAL_THROW_EXTERN_C()
     114             : {
     115           0 :     Mapping * pMapping = static_cast<Mapping *>(puno_Mapping);
     116           0 :     delete pMapping;
     117           0 : }
     118             : }
     119             : 
     120           8 : 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           8 :       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           8 :     uno_Mapping::acquire      = s_acquire;
     134           8 :     uno_Mapping::release      = s_release;
     135           8 :     uno_Mapping::mapInterface = (uno_MapInterfaceFunc)s_mapInterface;
     136           8 : }
     137             : 
     138           0 : Mapping::~Mapping(void)
     139             : {
     140             :     LOG_LIFECYCLE_cppu_helper_purpenv_Mapping_emit(fprintf(stderr, "LIFE: %s -> %p\n", "Mapping::~Mapping(void)", this));
     141           0 : }
     142             : 
     143             : 
     144         436 : void Mapping::mapInterface(
     145             :     uno_Interface                    ** ppOut,
     146             :     uno_Interface                     * pUnoI,
     147             :     typelib_InterfaceTypeDescription  * pTypeDescr)
     148             : {
     149             :     OSL_ASSERT(ppOut && pTypeDescr);
     150         436 :     if (*ppOut)
     151             :     {
     152           0 :         (*ppOut)->release(*ppOut);
     153           0 :         *ppOut = 0;
     154             :     }
     155             : 
     156         436 :     if (!pUnoI)
     157         436 :         return;
     158             : 
     159             :     // get object id of uno interface to be wrapped
     160             :     // need to enter environment because of potential "queryInterface" call
     161         436 :     rtl_uString * pOId = 0;
     162         436 :     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         436 :     m_to.get()->pExtEnv->getRegisteredInterface(m_to.get()->pExtEnv, (void **)ppOut, pOId, pTypeDescr);
     167             : 
     168         436 :     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         296 :                                            m_from.get(),
     173         296 :                                            m_to.get(),
     174             :                                            pUnoI,
     175             :                                            pTypeDescr,
     176             :                                            pOId,
     177             :                                            m_probeFun,
     178         888 :                                            m_pContext);
     179             : 
     180             :         // proxy may be exchanged during registration
     181         592 :         m_to.get()->pExtEnv->registerProxyInterface(m_to.get()->pExtEnv,
     182             :                                                     (void **)&pProxy,
     183             :                                                     Proxy_free,
     184             :                                                     pOId,
     185         592 :                                                     pTypeDescr);
     186             : 
     187         296 :         *ppOut = pProxy;
     188             :     }
     189             : 
     190         436 :     rtl_uString_release(pOId);
     191             : }
     192             : 
     193             : 
     194        1208 : void Mapping::acquire()
     195             : {
     196        1208 :     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        1208 : }
     203             : 
     204        1124 : void Mapping::release()
     205             : {
     206        1124 :     if (osl_atomic_decrement(&m_nCount) == 0)
     207           0 :         ::uno_revokeMapping(this);
     208        1124 : }
     209             : 
     210             : 
     211             : namespace cppu { namespace helper { namespace purpenv {
     212             : 
     213           8 : void createMapping(uno_Mapping     ** ppMapping,
     214             :                    uno_Environment  * pFrom,
     215             :                    uno_Environment  * pTo,
     216             :                    ProbeFun         * probeFun,
     217             :                    void             * pContext
     218             :  )
     219             : {
     220           8 :     *ppMapping = new Mapping(pFrom, pTo, probeFun, pContext);
     221             : 
     222           8 :     ::uno_registerMapping(ppMapping, s_free, pFrom, pTo, NULL);
     223           8 : }
     224             : 
     225             : }}}
     226             : 
     227             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10