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

Generated by: LCOV version 1.10