bump product version to 4.1.6.2
[LibreOffice.git] / comphelper / source / processfactory / processfactory.cxx
blobfe6c96b2af4a208d3b52bc1b14cb28a648a3227a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <osl/mutex.hxx>
21 #include <comphelper/processfactory.hxx>
22 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
24 #include "com/sun/star/beans/XPropertySet.hpp"
25 #include "com/sun/star/uno/DeploymentException.hpp"
27 using namespace ::com::sun::star;
28 using namespace com::sun::star::uno;
29 using namespace com::sun::star::lang;
30 using namespace osl;
32 namespace comphelper
36 This function preserves only that the xProcessFactory variable will not be create when
37 the library is loaded.
39 Reference< XMultiServiceFactory > localProcessFactory( const Reference< XMultiServiceFactory >& xSMgr, sal_Bool bSet )
41 Guard< Mutex > aGuard( Mutex::getGlobalMutex() );
43 static Reference< XMultiServiceFactory > xProcessFactory;
44 if ( bSet )
46 xProcessFactory = xSMgr;
49 return xProcessFactory;
53 void setProcessServiceFactory(const Reference< XMultiServiceFactory >& xSMgr)
55 localProcessFactory( xSMgr, sal_True );
58 Reference< XMultiServiceFactory > getProcessServiceFactory()
60 Reference< XMultiServiceFactory> xReturn;
61 xReturn = localProcessFactory( xReturn, sal_False );
62 if ( !xReturn.is() )
64 throw DeploymentException(
65 "null process service factory", Reference< XInterface >() );
67 return xReturn;
70 Reference< XComponentContext > getComponentContext(
71 Reference< XMultiServiceFactory > const & factory)
73 Reference< XComponentContext > xRet;
74 uno::Reference<beans::XPropertySet> const xProps( factory, uno::UNO_QUERY );
75 if (xProps.is()) {
76 try {
77 xRet.set( xProps->getPropertyValue( OUString("DefaultContext") ),
78 uno::UNO_QUERY );
80 catch (beans::UnknownPropertyException & e) {
81 throw DeploymentException(
82 "unknown service factory DefaultContext property: " + e.Message,
83 Reference< XInterface >( factory, UNO_QUERY ) );
86 if ( !xRet.is() )
88 throw DeploymentException(
89 "no service factory DefaultContext",
90 Reference< XInterface >( factory, UNO_QUERY ) );
92 return xRet;
95 Reference< XComponentContext > getProcessComponentContext()
97 return getComponentContext( getProcessServiceFactory() );
100 } // namespace comphelper
102 extern "C" {
103 uno::XComponentContext * comphelper_getProcessComponentContext()
105 uno::Reference<uno::XComponentContext> xRet;
106 xRet = ::comphelper::getProcessComponentContext();
107 if (xRet.is())
108 xRet->acquire();
109 return xRet.get();
111 } // extern "C"
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */