LCOV - code coverage report
Current view: top level - comphelper/source/processfactory - processfactory.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 24 29 82.8 %
Date: 2014-11-03 Functions: 5 5 100.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             : #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     2260666 : Reference< XMultiServiceFactory > localProcessFactory( const Reference< XMultiServiceFactory >& xSMgr, bool bSet )
      40             : {
      41     2260666 :     Guard< Mutex > aGuard( Mutex::getGlobalMutex() );
      42             : 
      43     2260666 :     static Reference< XMultiServiceFactory > xProcessFactory;
      44     2260666 :     if ( bSet )
      45             :     {
      46         792 :         xProcessFactory = xSMgr;
      47             :     }
      48             : 
      49     2260666 :     return xProcessFactory;
      50             : }
      51             : 
      52             : 
      53         792 : void setProcessServiceFactory(const Reference< XMultiServiceFactory >& xSMgr)
      54             : {
      55         792 :     localProcessFactory( xSMgr, true );
      56         792 : }
      57             : 
      58     2259874 : Reference< XMultiServiceFactory > getProcessServiceFactory()
      59             : {
      60     2259874 :     Reference< XMultiServiceFactory> xReturn;
      61     2259874 :     xReturn = localProcessFactory( xReturn, false );
      62     2259874 :     if ( !xReturn.is() )
      63             :     {
      64           0 :         throw DeploymentException( "null process service factory" );
      65             :     }
      66     2259874 :     return xReturn;
      67             : }
      68             : 
      69     2669918 : Reference< XComponentContext > getComponentContext(
      70             :     Reference< XMultiServiceFactory > const & factory)
      71             : {
      72     2669918 :     Reference< XComponentContext > xRet;
      73     5339836 :     uno::Reference<beans::XPropertySet> const xProps( factory, uno::UNO_QUERY );
      74     2669918 :     if (xProps.is()) {
      75             :         try {
      76     2669918 :             xRet.set( xProps->getPropertyValue("DefaultContext"),
      77     2669918 :                       uno::UNO_QUERY );
      78             :         }
      79           0 :         catch (beans::UnknownPropertyException & e) {
      80             :             throw DeploymentException(
      81           0 :                 "unknown service factory DefaultContext property: " + e.Message,
      82           0 :                 Reference<XInterface>(factory, UNO_QUERY) );
      83             :         }
      84             :     }
      85     2669918 :     if ( !xRet.is() )
      86             :     {
      87             :         throw DeploymentException(
      88             :             "no service factory DefaultContext",
      89           0 :             Reference<XInterface>(factory, UNO_QUERY) );
      90             :     }
      91     5339836 :     return xRet;
      92             : }
      93             : 
      94     2196509 : Reference< XComponentContext > getProcessComponentContext()
      95             : {
      96     2196509 :     return getComponentContext( getProcessServiceFactory() );
      97             : }
      98             : 
      99             : } // namespace comphelper
     100             : 
     101             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10