LCOV - code coverage report
Current view: top level - libreoffice/comphelper/source/processfactory - processfactory.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 25 36 69.4 %
Date: 2012-12-27 Functions: 5 6 83.3 %
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             : #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             : #include "com/sun/star/uno/DeploymentException.hpp"
      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       73368 : Reference< XMultiServiceFactory > localProcessFactory( const Reference< XMultiServiceFactory >& xSMgr, sal_Bool bSet )
      40             : {
      41       73368 :     Guard< Mutex > aGuard( Mutex::getGlobalMutex() );
      42             : 
      43       73368 :     static Reference< XMultiServiceFactory > xProcessFactory;
      44       73368 :     if ( bSet )
      45             :     {
      46          38 :         xProcessFactory = xSMgr;
      47             :     }
      48             : 
      49       73368 :     return xProcessFactory;
      50             : }
      51             : 
      52             : 
      53          38 : void setProcessServiceFactory(const Reference< XMultiServiceFactory >& xSMgr)
      54             : {
      55          38 :     localProcessFactory( xSMgr, sal_True );
      56          38 : }
      57             : 
      58       73330 : Reference< XMultiServiceFactory > getProcessServiceFactory()
      59             : {
      60       73330 :     Reference< XMultiServiceFactory> xReturn;
      61       73330 :     xReturn = localProcessFactory( xReturn, sal_False );
      62       73330 :     if ( !xReturn.is() )
      63             :     {
      64             :         throw DeploymentException(
      65           0 :             "null process service factory", Reference< XInterface >() );
      66             :     }
      67       73330 :     return xReturn;
      68             : }
      69             : 
      70      101659 : Reference< XComponentContext > getComponentContext(
      71             :     Reference< XMultiServiceFactory > const & factory)
      72             : {
      73      101659 :     Reference< XComponentContext > xRet;
      74      101659 :     uno::Reference<beans::XPropertySet> const xProps( factory, uno::UNO_QUERY );
      75      101659 :     if (xProps.is()) {
      76             :         try {
      77      101659 :             xRet.set( xProps->getPropertyValue( rtl::OUString(
      78      101659 :                               RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ),
      79      101659 :                       uno::UNO_QUERY );
      80             :         }
      81           0 :         catch (beans::UnknownPropertyException & e) {
      82             :             throw DeploymentException(
      83           0 :                 "unknown service factory DefaultContext property: " + e.Message,
      84           0 :                 Reference< XInterface >( factory, UNO_QUERY ) );
      85             :         }
      86             :     }
      87      101659 :     if ( !xRet.is() )
      88             :     {
      89             :         throw DeploymentException(
      90             :             "no service factory DefaultContext",
      91           0 :             Reference< XInterface >( factory, UNO_QUERY ) );
      92             :     }
      93      101659 :     return xRet;
      94             : }
      95             : 
      96       58848 : Reference< XComponentContext > getProcessComponentContext()
      97             : {
      98       58848 :     return getComponentContext( getProcessServiceFactory() );
      99             : }
     100             : 
     101             : } // namespace comphelper
     102             : 
     103             : extern "C" {
     104           0 : uno::XComponentContext * comphelper_getProcessComponentContext()
     105             : {
     106           0 :     uno::Reference<uno::XComponentContext> xRet;
     107           0 :     xRet = ::comphelper::getProcessComponentContext();
     108           0 :     if (xRet.is())
     109           0 :         xRet->acquire();
     110           0 :     return xRet.get();
     111             : }
     112             : } // extern "C"
     113             : 
     114             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10