LCOV - code coverage report
Current view: top level - cppu/source/helper/purpenv - helper_purpenv_Mapping.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 60 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 "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           0 : static void SAL_CALL s_mapInterface(
      75             :     uno_Mapping                       * puno_Mapping,
      76             :     uno_Interface                    ** ppOut,
      77             :     uno_Interface                     * pUnoI,
      78             :     typelib_InterfaceTypeDescription  * pTypeDescr )
      79             :     SAL_THROW_EXTERN_C()
      80             : {
      81           0 :     Mapping * pMapping = static_cast<Mapping *>(puno_Mapping);
      82           0 :     pMapping->mapInterface(ppOut, pUnoI, pTypeDescr);
      83           0 : }
      84             : 
      85             : extern "C" {
      86           0 : static void SAL_CALL s_acquire(uno_Mapping * puno_Mapping)
      87             :     SAL_THROW_EXTERN_C()
      88             : {
      89           0 :     Mapping * pMapping = static_cast<Mapping *>(puno_Mapping);
      90           0 :     pMapping->acquire();
      91           0 : }
      92             : 
      93           0 : static void SAL_CALL s_release(uno_Mapping * puno_Mapping)
      94             :     SAL_THROW_EXTERN_C()
      95             : {
      96           0 :     Mapping * pMapping = static_cast<Mapping * >(puno_Mapping);
      97           0 :     pMapping->release();
      98           0 : }
      99             : 
     100             : 
     101           0 : static void s_getIdentifier_v(va_list * pParam)
     102             : {
     103           0 :     uno_ExtEnvironment *  pEnv  = va_arg(*pParam, uno_ExtEnvironment *);
     104           0 :     rtl_uString        ** ppOid = va_arg(*pParam, rtl_uString **);
     105           0 :     uno_Interface      *  pUnoI = va_arg(*pParam, uno_Interface *);
     106             : 
     107           0 :     pEnv->getObjectIdentifier(pEnv, ppOid, pUnoI);
     108           0 : }
     109             : 
     110           0 : static void SAL_CALL s_free(uno_Mapping * puno_Mapping)
     111             :     SAL_THROW_EXTERN_C()
     112             : {
     113           0 :     Mapping * pMapping = static_cast<Mapping *>(puno_Mapping);
     114           0 :     delete pMapping;
     115           0 : }
     116             : }
     117             : 
     118           0 : Mapping::Mapping(uno_Environment                 * pFrom,
     119             :                  uno_Environment                 * pTo,
     120             :                  cppu::helper::purpenv::ProbeFun * probeFun,
     121             :                  void                            * pProbeContext
     122             : ) SAL_THROW(())
     123             :     : m_from    (pFrom),
     124             :       m_to      (pTo),
     125             :       m_nCount  (1),
     126             :       m_probeFun(probeFun),
     127           0 :       m_pContext(pProbeContext)
     128             : {
     129             :     LOG_LIFECYCLE_cppu_helper_purpenv_Mapping_emit(fprintf(stderr, "LIFE: %s -> %p\n", "Mapping::Mapping(uno_Environment * pFrom, uno_Environment * pTo) SAL_THROW(())", this));
     130             : 
     131           0 :     uno_Mapping::acquire      = s_acquire;
     132           0 :     uno_Mapping::release      = s_release;
     133           0 :     uno_Mapping::mapInterface = (uno_MapInterfaceFunc)s_mapInterface;
     134           0 : }
     135             : 
     136           0 : Mapping::~Mapping(void)
     137             : {
     138             :     LOG_LIFECYCLE_cppu_helper_purpenv_Mapping_emit(fprintf(stderr, "LIFE: %s -> %p\n", "Mapping::~Mapping(void)", this));
     139           0 : }
     140             : 
     141             : 
     142           0 : void Mapping::mapInterface(
     143             :     uno_Interface                    ** ppOut,
     144             :     uno_Interface                     * pUnoI,
     145             :     typelib_InterfaceTypeDescription  * pTypeDescr)
     146             : {
     147             :     OSL_ASSERT(ppOut && pTypeDescr);
     148           0 :     if (*ppOut)
     149             :     {
     150           0 :         (*ppOut)->release(*ppOut);
     151           0 :         *ppOut = 0;
     152             :     }
     153             : 
     154           0 :     if (!pUnoI)
     155           0 :         return;
     156             : 
     157             :     // get object id of uno interface to be wrapped
     158             :     // need to enter environment because of potential "queryInterface" call
     159           0 :     rtl_uString * pOId = 0;
     160           0 :     uno_Environment_invoke(m_from.get(), s_getIdentifier_v, m_from.get(), &pOId, pUnoI);
     161             :     OSL_ASSERT(pOId);
     162             : 
     163             :      // try to get any known interface from target environment
     164           0 :     m_to.get()->pExtEnv->getRegisteredInterface(m_to.get()->pExtEnv, (void **)ppOut, pOId, pTypeDescr);
     165             : 
     166           0 :     if (!*ppOut) // not yet there, register new proxy interface
     167             :     {
     168             :         // try to publish a new proxy (ref count initially 1)
     169             :         uno_Interface * pProxy = new Proxy(this,
     170           0 :                                            m_from.get(),
     171           0 :                                            m_to.get(),
     172             :                                            pUnoI,
     173             :                                            pTypeDescr,
     174             :                                            pOId,
     175             :                                            m_probeFun,
     176           0 :                                            m_pContext);
     177             : 
     178             :         // proxy may be exchanged during registration
     179           0 :         m_to.get()->pExtEnv->registerProxyInterface(m_to.get()->pExtEnv,
     180             :                                                     (void **)&pProxy,
     181             :                                                     Proxy_free,
     182             :                                                     pOId,
     183           0 :                                                     pTypeDescr);
     184             : 
     185           0 :         *ppOut = pProxy;
     186             :     }
     187             : 
     188           0 :     rtl_uString_release(pOId);
     189             : }
     190             : 
     191             : 
     192           0 : void Mapping::acquire() SAL_THROW(())
     193             : {
     194           0 :     if (osl_atomic_increment(&m_nCount) == 1)
     195             :     {
     196           0 :         uno_Mapping * pMapping = this;
     197             : 
     198           0 :         ::uno_registerMapping(&pMapping, s_free, m_from.get(), m_to.get(), NULL);
     199             :     }
     200           0 : }
     201             : 
     202           0 : void Mapping::release() SAL_THROW(())
     203             : {
     204           0 :     if (osl_atomic_decrement(&m_nCount) == 0)
     205           0 :         ::uno_revokeMapping(this);
     206           0 : }
     207             : 
     208             : 
     209             : namespace cppu { namespace helper { namespace purpenv {
     210             : 
     211           0 : void createMapping(uno_Mapping     ** ppMapping,
     212             :                    uno_Environment  * pFrom,
     213             :                    uno_Environment  * pTo,
     214             :                    ProbeFun         * probeFun,
     215             :                    void             * pContext
     216             :  )
     217             : {
     218           0 :     *ppMapping = new Mapping(pFrom, pTo, probeFun, pContext);
     219             : 
     220           0 :     ::uno_registerMapping(ppMapping, s_free, pFrom, pTo, NULL);
     221           0 : }
     222             : 
     223             : }}}
     224             : 
     225             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10