Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/comphelper/source/processfactory/processfactory.cxx
Line
Count
Source
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 <mutex>
21
#include <comphelper/processfactory.hxx>
22
23
#include <com/sun/star/beans/XPropertySet.hpp>
24
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
25
#include <com/sun/star/uno/DeploymentException.hpp>
26
#include <com/sun/star/uno/XComponentContext.hpp>
27
28
using namespace ::com::sun::star;
29
using namespace com::sun::star::uno;
30
using namespace com::sun::star::lang;
31
32
namespace comphelper
33
{
34
35
namespace {
36
37
class LocalProcessFactory {
38
public:
39
    void set( const Reference< XMultiServiceFactory >& xSMgr )
40
106
    {
41
106
        std::unique_lock aGuard( maMutex );
42
43
106
        xProcessFactory = xSMgr;
44
106
    }
45
46
    Reference< XMultiServiceFactory > get() const
47
83.2k
    {
48
83.2k
        std::unique_lock aGuard( maMutex );
49
50
83.2k
        return xProcessFactory;
51
83.2k
    }
52
53
private:
54
    mutable std::mutex maMutex;
55
    Reference< XMultiServiceFactory > xProcessFactory;
56
};
57
58
/*
59
    This var preserves only that the above xProcessFactory variable will not be create when
60
    the library is loaded.
61
*/
62
LocalProcessFactory localProcessFactory;
63
64
}
65
66
void setProcessServiceFactory(const Reference< XMultiServiceFactory >& xSMgr)
67
106
{
68
106
    localProcessFactory.set( xSMgr );
69
106
}
70
71
Reference< XMultiServiceFactory > getProcessServiceFactory()
72
83.2k
{
73
83.2k
    Reference< XMultiServiceFactory> xReturn = localProcessFactory.get();
74
83.2k
    if ( !xReturn.is() )
75
0
    {
76
0
        throw DeploymentException( u"null process service factory"_ustr );
77
0
    }
78
83.2k
    return xReturn;
79
83.2k
}
80
81
Reference< XComponentContext > getComponentContext(
82
    Reference< XMultiServiceFactory > const & factory)
83
60
{
84
60
    Reference< XComponentContext > xRet;
85
60
    uno::Reference<beans::XPropertySet> const xProps( factory, uno::UNO_QUERY );
86
60
    if (xProps.is()) {
87
60
        static constexpr OUStringLiteral DEFAULT_CONTEXT = u"DefaultContext";
88
60
        try {
89
60
            xRet.set( xProps->getPropertyValue(DEFAULT_CONTEXT),
90
60
                      uno::UNO_QUERY );
91
60
        }
92
60
        catch (beans::UnknownPropertyException & e) {
93
0
            throw DeploymentException(
94
0
                "unknown service factory DefaultContext property: " + e.Message,
95
0
                Reference<XInterface>(factory, UNO_QUERY) );
96
0
        }
97
60
    }
98
60
    if ( !xRet.is() )
99
0
    {
100
0
        throw DeploymentException(
101
0
            u"no service factory DefaultContext"_ustr,
102
0
            Reference<XInterface>(factory, UNO_QUERY) );
103
0
    }
104
60
    return xRet;
105
60
}
106
107
const Reference< XComponentContext > & getProcessComponentContext()
108
16.6M
{
109
16.6M
    static const uno::Reference<XComponentContext> processComponentContext = getComponentContext( getProcessServiceFactory() );
110
16.6M
    return processComponentContext;
111
16.6M
}
112
113
} // namespace comphelper
114
115
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */