LibreOffice Module comphelper (master)
1
comphelper
source
processfactory
processfactory.cxx
Go to the documentation of this file.
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
namespace
com::sun::star::uno
{
class
XComponentContext; }
29
30
using namespace
::
com::sun::star
;
31
using namespace
com::sun::star::uno
;
32
using namespace
com::sun::star::lang
;
33
using namespace
osl
;
34
35
namespace
comphelper
36
{
37
38
namespace
{
39
40
class
LocalProcessFactory {
41
public
:
42
void
set
(
const
Reference< XMultiServiceFactory >
& xSMgr )
43
{
44
std::unique_lock aGuard(
maMutex
);
45
46
xProcessFactory
=
xSMgr
;
47
}
48
49
Reference< XMultiServiceFactory >
get
()
const
50
{
51
std::unique_lock aGuard(
maMutex
);
52
53
return
xProcessFactory
;
54
}
55
56
private
:
57
mutable
std::mutex
maMutex
;
58
Reference< XMultiServiceFactory >
xProcessFactory
;
59
};
60
61
/*
62
This var preserves only that the above xProcessFactory variable will not be create when
63
the library is loaded.
64
*/
65
LocalProcessFactory localProcessFactory;
66
67
}
68
69
void
setProcessServiceFactory
(
const
Reference< XMultiServiceFactory >
& xSMgr)
70
{
71
localProcessFactory.set(
xSMgr
);
72
}
73
74
Reference< XMultiServiceFactory >
getProcessServiceFactory
()
75
{
76
Reference< XMultiServiceFactory>
xReturn = localProcessFactory.get();
77
if
( !xReturn.is() )
78
{
79
throw
DeploymentException(
"null process service factory"
);
80
}
81
return
xReturn;
82
}
83
84
Reference< XComponentContext >
getComponentContext
(
85
Reference< XMultiServiceFactory >
const
& factory)
86
{
87
Reference< XComponentContext >
xRet;
88
uno::Reference<beans::XPropertySet>
const
xProps( factory, uno::UNO_QUERY );
89
if
(xProps.is()) {
90
static
constexpr
OUStringLiteral DEFAULT_CONTEXT =
u
"DefaultContext"
;
91
try
{
92
xRet.set( xProps->getPropertyValue(DEFAULT_CONTEXT),
93
uno::UNO_QUERY );
94
}
95
catch
(beans::UnknownPropertyException & e) {
96
throw
DeploymentException(
97
"unknown service factory DefaultContext property: "
+ e.Message,
98
Reference<XInterface>
(factory, UNO_QUERY) );
99
}
100
}
101
if
( !xRet.is() )
102
{
103
throw
DeploymentException(
104
"no service factory DefaultContext"
,
105
Reference<XInterface>
(factory, UNO_QUERY) );
106
}
107
return
xRet;
108
}
109
110
Reference< XComponentContext >
getProcessComponentContext
()
111
{
112
return
getComponentContext
(
getProcessServiceFactory
() );
113
}
114
115
}
// namespace comphelper
116
117
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
com::sun::star::uno::Reference
u
float u
xSMgr
Reference< XMultiServiceFactory > xSMgr
set
void set(css::uno::UnoInterfaceReference const &value)
com::sun::star::lang
com::sun::star::uno
com::sun::star
comphelper
comphelper::setProcessServiceFactory
void setProcessServiceFactory(const Reference< XMultiServiceFactory > &xSMgr)
Definition:
processfactory.cxx:69
comphelper::getProcessServiceFactory
Reference< XMultiServiceFactory > getProcessServiceFactory()
This function gets the process service factory.
Definition:
processfactory.cxx:74
comphelper::getProcessComponentContext
Reference< XComponentContext > getProcessComponentContext()
This function gets the process service factory's default component context.
Definition:
processfactory.cxx:110
comphelper::getComponentContext
Reference< XComponentContext > getComponentContext(Reference< XMultiServiceFactory > const &factory)
Definition:
processfactory.cxx:84
osl
get
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
maMutex
std::mutex maMutex
Definition:
processfactory.cxx:57
xProcessFactory
Reference< XMultiServiceFactory > xProcessFactory
Definition:
processfactory.cxx:58
processfactory.hxx
mutex
std::mutex mutex
Definition:
random.cxx:41
Generated on Sun Jul 30 2023 04:30:33 for LibreOffice Module comphelper (master) by
1.9.3