1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <com/sun/star/uno/Reference.hxx>
23 #include <com/sun/star/uno/RuntimeException.hpp>
24 #include <com/sun/star/uno/XInterface.hpp>
25 #include <osl/mutex.hxx>
27 #include <rtl/process.h>
28 #include <rtl/ustrbuf.hxx>
29 #include <rtl/ustring.h>
30 #include <rtl/ustring.hxx>
31 #include <sal/log.hxx>
32 #include <sal/types.h>
33 #include <uno/environment.h>
34 #include <uno/lbnames.h>
35 #include <uno/mapping.h>
36 #include <cppu/EnvDcp.hxx>
41 const OUString
& cppu_cppenv_getStaticOIdPart()
43 static OUString s_aStaticOidPart
= []() {
44 OUStringBuffer
aRet(64);
48 ::rtl_getGlobalProcessId(ar
);
49 for (unsigned char i
: ar
)
51 aRet
.append(static_cast<sal_Int32
>(i
), 16);
53 return aRet
.makeStringAndClear();
55 return s_aStaticOidPart
;
62 static void s_stub_computeObjectIdentifier(va_list * pParam
)
64 uno_ExtEnvironment
* pEnv
= va_arg(*pParam
, uno_ExtEnvironment
*);
65 rtl_uString
** ppOId
= va_arg(*pParam
, rtl_uString
**);
66 void * pInterface
= va_arg(*pParam
, void *);
69 assert(pEnv
&& ppOId
&& pInterface
);
70 if (!(pEnv
&& ppOId
&& pInterface
))
75 rtl_uString_release( *ppOId
);
81 ::com::sun::star::uno::Reference
<
82 ::com::sun::star::uno::XInterface
> xHome(
83 static_cast< ::com::sun::star::uno::XInterface
* >(
85 ::com::sun::star::uno::UNO_QUERY
);
86 assert(xHome
.is() && "### query to XInterface failed!");
90 OUStringBuffer
oid( 64 );
91 oid
.append( reinterpret_cast< sal_Int64
>(xHome
.get()), 16 );
93 // ;environment[context]
94 oid
.append( OUString::unacquired(&pEnv
->aBase
.pTypeName
) );
97 reinterpret_cast< sal_Int64
>(pEnv
->aBase
.pContext
),
100 oid
.append( cppu_cppenv_getStaticOIdPart() );
101 OUString
aRet( oid
.makeStringAndClear() );
103 ::rtl_uString_acquire( *ppOId
);
106 catch (const ::com::sun::star::uno::RuntimeException
& e
)
109 "### RuntimeException occurred during queryInterface(): "
114 static void computeObjectIdentifier(
115 uno_ExtEnvironment
* pExtEnv
, rtl_uString
** ppOId
, void * pInterface
)
117 uno_Environment_invoke(&pExtEnv
->aBase
, s_stub_computeObjectIdentifier
, pExtEnv
, ppOId
, pInterface
);
120 static void s_stub_acquireInterface(va_list * pParam
)
122 /*uno_ExtEnvironment * pExtEnv = */va_arg(*pParam
, uno_ExtEnvironment
*);
123 void * pCppI
= va_arg(*pParam
, void *);
125 static_cast< ::com::sun::star::uno::XInterface
* >( pCppI
)->acquire();
128 static void acquireInterface( uno_ExtEnvironment
* pExtEnv
, void * pCppI
)
130 uno_Environment_invoke(&pExtEnv
->aBase
, s_stub_acquireInterface
, pExtEnv
, pCppI
);
133 static void s_stub_releaseInterface(va_list * pParam
)
135 /*uno_ExtEnvironment * pExtEnv = */va_arg(*pParam
, uno_ExtEnvironment
*);
136 void * pCppI
= va_arg(*pParam
, void *);
138 static_cast< ::com::sun::star::uno::XInterface
* >( pCppI
)->release();
141 static void releaseInterface( uno_ExtEnvironment
* pExtEnv
, void * pCppI
)
143 uno_Environment_invoke(&pExtEnv
->aBase
, s_stub_releaseInterface
, pExtEnv
, pCppI
);
146 static void environmentDisposing(
147 SAL_UNUSED_PARAMETER uno_Environment
* )
151 #ifdef DISABLE_DYNLOADING
152 #define uno_initEnvironment CPPU_ENV_uno_initEnvironment
155 SAL_DLLPUBLIC_EXPORT
void uno_initEnvironment(uno_Environment
* pCppEnv
)
158 assert(pCppEnv
->pExtEnv
);
160 ::rtl_ustr_ascii_compare_WithLength(
161 pCppEnv
->pTypeName
->buffer
, rtl_str_getLength(CPPU_CURRENT_LANGUAGE_BINDING_NAME
), CPPU_CURRENT_LANGUAGE_BINDING_NAME
)
163 && "### wrong environment type!");
164 reinterpret_cast<uno_ExtEnvironment
*>(pCppEnv
)->computeObjectIdentifier
165 = computeObjectIdentifier
;
166 reinterpret_cast<uno_ExtEnvironment
*>(pCppEnv
)->acquireInterface
= acquireInterface
;
167 reinterpret_cast<uno_ExtEnvironment
*>(pCppEnv
)->releaseInterface
= releaseInterface
;
168 pCppEnv
->environmentDisposing
= environmentDisposing
;
171 #ifdef DISABLE_DYNLOADING
172 #define uno_ext_getMapping CPPU_ENV_uno_ext_getMapping
175 SAL_DLLPUBLIC_EXPORT
void uno_ext_getMapping(
176 uno_Mapping
** ppMapping
, uno_Environment
* pFrom
, uno_Environment
* pTo
)
179 assert(ppMapping
&& pFrom
&& pTo
);
180 if (!(ppMapping
&& pFrom
&& pTo
&& pFrom
->pExtEnv
&& pTo
->pExtEnv
))
183 uno_Mapping
* pMapping
= nullptr;
185 OUString
from_envTypeName(cppu::EnvDcp::getTypeName(pFrom
->pTypeName
));
186 OUString
to_envTypeName(cppu::EnvDcp::getTypeName(pTo
->pTypeName
));
188 if (rtl_ustr_ascii_compare(
189 from_envTypeName
.pData
->buffer
,
190 CPPU_CURRENT_LANGUAGE_BINDING_NAME
) == 0 &&
191 rtl_ustr_ascii_compare(
192 to_envTypeName
.pData
->buffer
, UNO_LB_UNO
) == 0)
194 // ref count initially 1
195 pMapping
= bridges::cpp_uno::shared::Bridge::createMapping(
196 pFrom
->pExtEnv
, pTo
->pExtEnv
, true );
197 ::uno_registerMapping(
198 &pMapping
, bridges::cpp_uno::shared::freeMapping
,
199 &pFrom
->pExtEnv
->aBase
,
200 &pTo
->pExtEnv
->aBase
, nullptr );
202 else if (rtl_ustr_ascii_compare(
203 to_envTypeName
.pData
->buffer
,
204 CPPU_CURRENT_LANGUAGE_BINDING_NAME
) == 0 &&
205 rtl_ustr_ascii_compare(
206 from_envTypeName
.pData
->buffer
, UNO_LB_UNO
) == 0)
208 // ref count initially 1
209 pMapping
= bridges::cpp_uno::shared::Bridge::createMapping(
210 pTo
->pExtEnv
, pFrom
->pExtEnv
, false );
211 ::uno_registerMapping(
212 &pMapping
, bridges::cpp_uno::shared::freeMapping
,
213 &pFrom
->pExtEnv
->aBase
,
214 &pTo
->pExtEnv
->aBase
, nullptr );
219 (*(*ppMapping
)->release
)( *ppMapping
);
222 *ppMapping
= pMapping
;
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */