LCOV - code coverage report
Current view: top level - comphelper/source/processfactory - processfactory.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 41 42 97.6 %
Date: 2012-08-25 Functions: 8 8 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 34 66 51.5 %

           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 <osl/mutex.hxx>
      21                 :            : #include <comphelper/processfactory.hxx>
      22                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      23                 :            : 
      24                 :            : #include "com/sun/star/beans/XPropertySet.hpp"
      25                 :            : 
      26                 :            : 
      27                 :            : using namespace ::com::sun::star;
      28                 :            : using namespace com::sun::star::uno;
      29                 :            : using namespace com::sun::star::lang;
      30                 :            : using namespace osl;
      31                 :            : 
      32                 :            : namespace comphelper
      33                 :            : {
      34                 :            : 
      35                 :            : /*
      36                 :            :     This function preserves only that the xProcessFactory variable will not be create when
      37                 :            :     the library is loaded.
      38                 :            : */
      39                 :     546266 : Reference< XMultiServiceFactory > localProcessFactory( const Reference< XMultiServiceFactory >& xSMgr, sal_Bool bSet )
      40                 :            : {
      41 [ +  - ][ +  - ]:     546266 :     Guard< Mutex > aGuard( Mutex::getGlobalMutex() );
      42                 :            : 
      43 [ +  + ][ +  - ]:     546266 :     static Reference< XMultiServiceFactory > xProcessFactory;
      44         [ +  + ]:     546266 :     if ( bSet )
      45                 :            :     {
      46         [ +  - ]:        443 :         xProcessFactory = xSMgr;
      47                 :            :     }
      48                 :            : 
      49         [ +  - ]:     546266 :     return xProcessFactory;
      50                 :            : }
      51                 :            : 
      52                 :            : 
      53                 :        443 : void setProcessServiceFactory(const Reference< XMultiServiceFactory >& xSMgr)
      54                 :            : {
      55                 :        443 :     localProcessFactory( xSMgr, sal_True );
      56                 :        443 : }
      57                 :            : 
      58                 :     545823 : Reference< XMultiServiceFactory > getProcessServiceFactory()
      59                 :            : {
      60                 :     545823 :     Reference< XMultiServiceFactory> xReturn;
      61 [ +  - ][ +  - ]:     545823 :     xReturn = localProcessFactory( xReturn, sal_False );
      62                 :     545823 :     return xReturn;
      63                 :            : }
      64                 :            : 
      65                 :         94 : Reference< XInterface > createProcessComponent( const ::rtl::OUString& _rServiceSpecifier ) SAL_THROW( ( RuntimeException ) )
      66                 :            : {
      67                 :         94 :     Reference< XInterface > xComponent;
      68                 :            : 
      69         [ +  - ]:         94 :     Reference< XMultiServiceFactory > xFactory( getProcessServiceFactory() );
      70         [ +  - ]:         94 :     if ( xFactory.is() )
      71 [ +  - ][ +  - ]:         94 :         xComponent = xFactory->createInstance( _rServiceSpecifier );
                 [ +  - ]
      72                 :            : 
      73                 :         94 :     return xComponent;
      74                 :            : }
      75                 :            : 
      76                 :        464 : Reference< XInterface > createProcessComponentWithArguments( const ::rtl::OUString& _rServiceSpecifier,
      77                 :            :         const Sequence< Any >& _rArgs ) SAL_THROW( ( RuntimeException ) )
      78                 :            : {
      79                 :        464 :     Reference< XInterface > xComponent;
      80                 :            : 
      81         [ +  - ]:        464 :     Reference< XMultiServiceFactory > xFactory( getProcessServiceFactory() );
      82         [ +  - ]:        464 :     if ( xFactory.is() )
      83 [ +  - ][ +  + ]:        464 :         xComponent = xFactory->createInstanceWithArguments( _rServiceSpecifier, _rArgs );
                 [ +  - ]
      84                 :            : 
      85                 :        464 :     return xComponent;
      86                 :            : }
      87                 :            : 
      88                 :     227437 : Reference< XComponentContext > getComponentContext(
      89                 :            :     Reference< XMultiServiceFactory > const & factory)
      90                 :            : {
      91                 :     227437 :     Reference< XComponentContext > xRet;
      92         [ +  - ]:     227437 :     uno::Reference<beans::XPropertySet> const xProps( factory, uno::UNO_QUERY );
      93         [ +  - ]:     227437 :     if (xProps.is()) {
      94                 :            :         try {
      95         [ +  - ]:     227437 :             xRet.set( xProps->getPropertyValue( rtl::OUString(
      96                 :     227437 :                               RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ),
      97 [ +  - ][ +  - ]:     227437 :                       uno::UNO_QUERY );
         [ +  - ][ #  # ]
      98                 :            :         }
      99         [ #  # ]:          0 :         catch (beans::UnknownPropertyException const&) {
     100                 :            :         }
     101                 :            :     }
     102                 :     227437 :     return xRet;
     103                 :            : }
     104                 :            : 
     105                 :     206313 : Reference< XComponentContext > getProcessComponentContext()
     106                 :            : {
     107         [ +  - ]:     206313 :     return getComponentContext( getProcessServiceFactory() );
     108                 :            : }
     109                 :            : 
     110                 :            : } // namespace comphelper
     111                 :            : 
     112                 :            : extern "C" {
     113                 :       8412 : uno::XComponentContext * comphelper_getProcessComponentContext()
     114                 :            : {
     115                 :       8412 :     uno::Reference<uno::XComponentContext> xRet;
     116 [ +  - ][ +  - ]:       8412 :     xRet = ::comphelper::getProcessComponentContext();
     117         [ +  - ]:       8412 :     if (xRet.is())
     118         [ +  - ]:       8412 :         xRet->acquire();
     119         [ +  - ]:       8412 :     return xRet.get();
     120                 :            : }
     121                 :            : } // extern "C"
     122                 :            : 
     123                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10