LCOV - code coverage report
Current view: top level - binaryurp/source - proxy.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 84 92 91.3 %
Date: 2012-08-25 Functions: 14 14 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 39 66 59.1 %

           Branch data     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                 :            : #include "sal/config.h"
      21                 :            : 
      22                 :            : #include <cassert>
      23                 :            : #include <exception>
      24                 :            : #include <vector>
      25                 :            : 
      26                 :            : #include "cppuhelper/exc_hlp.hxx"
      27                 :            : #include "rtl/ref.hxx"
      28                 :            : #include "rtl/ustring.hxx"
      29                 :            : #include "sal/types.h"
      30                 :            : #include "typelib/typedescription.h"
      31                 :            : #include "typelib/typedescription.hxx"
      32                 :            : #include "uno/any2.h"
      33                 :            : #include "uno/dispatcher.h"
      34                 :            : #include "uno/dispatcher.hxx"
      35                 :            : 
      36                 :            : #include "binaryany.hxx"
      37                 :            : #include "bridge.hxx"
      38                 :            : #include "proxy.hxx"
      39                 :            : 
      40                 :            : namespace binaryurp {
      41                 :            : 
      42                 :            : namespace {
      43                 :            : 
      44                 :            : namespace css = com::sun::star;
      45                 :            : 
      46                 :      49536 : extern "C" void SAL_CALL proxy_acquireInterface(uno_Interface * pInterface) {
      47                 :            :     assert(pInterface != 0);
      48                 :      49536 :     static_cast< Proxy * >(pInterface)->do_acquire();
      49                 :      49536 : }
      50                 :            : 
      51                 :      53336 : extern "C" void SAL_CALL proxy_releaseInterface(uno_Interface * pInterface) {
      52                 :            :     assert(pInterface != 0);
      53                 :      53336 :     static_cast< Proxy * >(pInterface)->do_release();
      54                 :      53336 : }
      55                 :            : 
      56                 :      13604 : extern "C" void SAL_CALL proxy_dispatchInterface(
      57                 :            :     uno_Interface * pUnoI, typelib_TypeDescription const * pMemberType,
      58                 :            :     void * pReturn, void ** pArgs, uno_Any ** ppException)
      59                 :            : {
      60                 :            :     assert(pUnoI != 0);
      61                 :            :     static_cast< Proxy * >(pUnoI)->do_dispatch(
      62                 :      13604 :         pMemberType, pReturn, pArgs, ppException);
      63                 :      13604 : }
      64                 :            : 
      65                 :            : }
      66                 :            : 
      67                 :       3814 : Proxy::Proxy(
      68                 :            :     rtl::Reference< Bridge > const & bridge, OUString const & oid,
      69                 :            :     css::uno::TypeDescription const & type):
      70                 :       3814 :     bridge_(bridge), oid_(oid), type_(type), references_(1)
      71                 :            : {
      72                 :            :     assert(bridge.is());
      73                 :       3814 :     acquire = &proxy_acquireInterface;
      74                 :       3814 :     release = &proxy_releaseInterface;
      75                 :       3814 :     pDispatcher = &proxy_dispatchInterface;
      76                 :       3814 : }
      77                 :            : 
      78                 :       3800 : OUString Proxy::getOid() const {
      79                 :       3800 :     return oid_;
      80                 :            : }
      81                 :            : 
      82                 :       3800 : css::uno::TypeDescription Proxy::getType() const {
      83                 :       3800 :     return type_;
      84                 :            : }
      85                 :            : 
      86                 :      49536 : void Proxy::do_acquire() {
      87         [ -  + ]:      49536 :     if (osl_incrementInterlockedCount(&references_) == 1) {
      88                 :          0 :         bridge_->resurrectProxy(*this);
      89                 :            :     }
      90                 :      49536 : }
      91                 :            : 
      92                 :      53336 : void Proxy::do_release() {
      93         [ +  + ]:      53336 :     if (osl_decrementInterlockedCount(&references_) == 0) {
      94                 :       3800 :         bridge_->revokeProxy(*this);
      95                 :            :     }
      96                 :      53336 : }
      97                 :            : 
      98                 :       3800 : void Proxy::do_free() {
      99                 :       3800 :     bridge_->freeProxy(*this);
     100         [ +  - ]:       3800 :     delete this;
     101                 :       3800 : }
     102                 :            : 
     103                 :      13604 : void Proxy::do_dispatch(
     104                 :            :     typelib_TypeDescription const * member, void * returnValue,
     105                 :            :     void ** arguments, uno_Any ** exception) const
     106                 :            : {
     107                 :            :     try {
     108                 :            :         try {
     109         [ +  + ]:      13604 :             do_dispatch_throw(member, returnValue, arguments, exception);
     110         [ +  - ]:          2 :         } catch (const std::exception & e) {
     111                 :            :             throw css::uno::RuntimeException(
     112                 :            :                 (OUString(
     113                 :            :                     RTL_CONSTASCII_USTRINGPARAM("caught C++ exception: ")) +
     114                 :            :                  rtl::OStringToOUString(
     115                 :          0 :                      rtl::OString(e.what()), RTL_TEXTENCODING_ASCII_US)),
     116   [ #  #  #  #  :          0 :                 css::uno::Reference< css::uno::XInterface >());
                   #  # ]
     117                 :            :                 // best-effort string conversion
     118                 :            :         }
     119         [ -  + ]:          4 :     } catch (const css::uno::RuntimeException &) {
     120         [ -  + ]:          2 :         css::uno::Any exc(cppu::getCaughtException());
     121                 :            :         uno_copyAndConvertData(
     122                 :            :             *exception, &exc,
     123                 :          2 :             (css::uno::TypeDescription(cppu::UnoType< css::uno::Any >::get()).
     124                 :            :              get()),
     125         [ -  + ]:          4 :             bridge_->getCppToBinaryMapping().get());
     126                 :            :     }
     127                 :      13604 : }
     128                 :            : 
     129                 :     141584 : bool Proxy::isProxy(
     130                 :            :     rtl::Reference< Bridge > const & bridge,
     131                 :            :     css::uno::UnoInterfaceReference const & object, OUString * oid)
     132                 :            : {
     133                 :            :     assert(object.is());
     134                 :            :     return object.m_pUnoI->acquire == &proxy_acquireInterface &&
     135 [ +  + ][ +  - ]:     141584 :         static_cast< Proxy * >(object.m_pUnoI)->isProxy(bridge, oid);
     136                 :            : }
     137                 :            : 
     138                 :       3800 : Proxy::~Proxy() {}
     139                 :            : 
     140                 :      13604 : void Proxy::do_dispatch_throw(
     141                 :            :     typelib_TypeDescription const * member, void * returnValue,
     142                 :            :     void ** arguments, uno_Any ** exception) const
     143                 :            : {
     144                 :            :     //TODO: Optimize queryInterface:
     145                 :            :     assert(member != 0);
     146                 :      13604 :     bool setter = false;
     147         [ +  - ]:      13604 :     std::vector< BinaryAny > inArgs;
     148      [ +  +  - ]:      13604 :     switch (member->eTypeClass) {
     149                 :            :     case typelib_TypeClass_INTERFACE_ATTRIBUTE:
     150                 :       1801 :         setter = returnValue == 0;
     151         [ -  + ]:       1801 :         if (setter) {
     152                 :            :             inArgs.push_back(
     153                 :            :                 BinaryAny(
     154                 :            :                     css::uno::TypeDescription(
     155                 :            :                         reinterpret_cast<
     156                 :            :                             typelib_InterfaceAttributeTypeDescription const * >(
     157                 :            :                                 member)->
     158                 :            :                         pAttributeTypeRef),
     159         [ #  # ]:          0 :                     arguments[0]));
     160                 :            :         }
     161                 :       1801 :         break;
     162                 :            :     case typelib_TypeClass_INTERFACE_METHOD:
     163                 :            :         {
     164                 :            :             typelib_InterfaceMethodTypeDescription const * mtd =
     165                 :            :                 reinterpret_cast<
     166                 :      11803 :                     typelib_InterfaceMethodTypeDescription const * >(member);
     167         [ +  + ]:      22969 :             for (sal_Int32 i = 0; i != mtd->nParams; ++i) {
     168         [ +  + ]:      11166 :                 if (mtd->pParams[i].bIn) {
     169                 :            :                     inArgs.push_back(
     170                 :            :                         BinaryAny(
     171                 :      11156 :                             css::uno::TypeDescription(mtd->pParams[i].pTypeRef),
     172         [ +  - ]:      11156 :                             arguments[i]));
     173                 :            :                 }
     174                 :            :             }
     175                 :      11803 :             break;
     176                 :            :         }
     177                 :            :     default:
     178                 :            :         assert(false); // this cannot happen
     179                 :          0 :         break;
     180                 :            :     }
     181                 :      13604 :     BinaryAny ret;
     182         [ +  - ]:      13604 :     std::vector< BinaryAny > outArgs;
     183   [ +  +  +  + ]:      27206 :     if (bridge_->makeCall(
     184                 :            :             oid_,
     185                 :            :             css::uno::TypeDescription(
     186                 :            :                 const_cast< typelib_TypeDescription * >(member)),
     187                 :      27208 :             setter, inArgs, &ret, &outArgs))
     188                 :            :     {
     189                 :            :         assert(ret.getType().get()->eTypeClass == typelib_TypeClass_EXCEPTION);
     190                 :            :         uno_any_construct(
     191                 :         32 :             *exception, ret.getValue(ret.getType()), ret.getType().get(), 0);
     192                 :            :     } else {
     193      [ +  +  - ]:      13570 :         switch (member->eTypeClass) {
     194                 :            :         case typelib_TypeClass_INTERFACE_ATTRIBUTE:
     195         [ +  - ]:       1801 :             if (!setter) {
     196                 :            :                 css::uno::TypeDescription t(
     197                 :            :                     reinterpret_cast<
     198                 :            :                         typelib_InterfaceAttributeTypeDescription const * >(
     199                 :            :                             member)->
     200                 :       1801 :                     pAttributeTypeRef);
     201                 :       1801 :                 uno_copyData(returnValue, ret.getValue(t), t.get(), 0);
     202                 :            :             }
     203                 :       1801 :             break;
     204                 :            :         case typelib_TypeClass_INTERFACE_METHOD:
     205                 :            :             {
     206                 :            :                 typelib_InterfaceMethodTypeDescription const * mtd =
     207                 :            :                     reinterpret_cast<
     208                 :            :                         typelib_InterfaceMethodTypeDescription const * >(
     209                 :      11769 :                             member);
     210                 :      11769 :                 css::uno::TypeDescription t(mtd->pReturnTypeRef);
     211         [ +  + ]:      11769 :                 if (t.get()->eTypeClass != typelib_TypeClass_VOID) {
     212                 :       1909 :                     uno_copyData(returnValue, ret.getValue(t), t.get(), 0);
     213                 :            :                 }
     214                 :      11769 :                 std::vector< BinaryAny >::iterator i(outArgs.begin());
     215         [ +  + ]:      22933 :                 for (sal_Int32 j = 0; j != mtd->nParams; ++j) {
     216         [ +  + ]:      11164 :                     if (mtd->pParams[j].bOut) {
     217                 :         10 :                         css::uno::TypeDescription pt(mtd->pParams[j].pTypeRef);
     218         [ -  + ]:         10 :                         if (mtd->pParams[j].bIn) {
     219                 :            :                             uno_assignData(
     220                 :          0 :                                 arguments[j], pt.get(), i++->getValue(pt),
     221         [ #  # ]:          0 :                                 pt.get(), 0, 0, 0);
     222                 :            :                         } else {
     223                 :            :                             uno_copyData(
     224         [ +  - ]:         10 :                                 arguments[j], i++->getValue(pt), pt.get(), 0);
     225                 :         10 :                         }
     226                 :            :                     }
     227                 :            :                 }
     228                 :            :                 assert(i == outArgs.end());
     229                 :      11769 :                 break;
     230                 :            :             }
     231                 :            :         default:
     232                 :            :             assert(false); // this cannot happen
     233                 :          0 :             break;
     234                 :            :         }
     235                 :      13570 :         *exception = 0;
     236                 :      13604 :     }
     237                 :      13602 : }
     238                 :            : 
     239                 :        264 : bool Proxy::isProxy(
     240                 :            :     rtl::Reference< Bridge > const & bridge, OUString * oid) const
     241                 :            : {
     242                 :            :     assert(oid != 0);
     243         [ +  - ]:        264 :     if (bridge == bridge_) {
     244                 :        264 :         *oid = oid_;
     245                 :        264 :         return true;
     246                 :            :     } else {
     247                 :        264 :         return false;
     248                 :            :     }
     249                 :            : }
     250                 :            : 
     251                 :            : }
     252                 :            : 
     253                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10