bump product version to 6.3.0.0.beta1
[LibreOffice.git] / bridges / source / cpp_uno / shared / component.cxx
blobb8f4d7f6511e5e4783292615ec292c83f1abb287
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 <bridge.hxx>
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>
26 #include <osl/time.h>
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>
39 namespace {
41 const OUString & cppu_cppenv_getStaticOIdPart()
43 static OUString s_aStaticOidPart = []() {
44 OUStringBuffer aRet(64);
45 aRet.append("];");
46 // good guid
47 sal_uInt8 ar[16];
48 ::rtl_getGlobalProcessId(ar);
49 for (unsigned char i : ar)
51 aRet.append(static_cast<sal_Int32>(i), 16);
53 return aRet.makeStringAndClear();
54 }();
55 return s_aStaticOidPart;
60 extern "C" {
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)
72 if (*ppOId)
74 rtl_uString_release( *ppOId );
75 *ppOId = nullptr;
78 try
80 ::com::sun::star::uno::Reference<
81 ::com::sun::star::uno::XInterface > xHome(
82 static_cast< ::com::sun::star::uno::XInterface * >(
83 pInterface ),
84 ::com::sun::star::uno::UNO_QUERY );
85 assert(xHome.is() && "### query to XInterface failed!");
86 if (xHome.is())
88 // interface
89 OUStringBuffer oid( 64 );
90 oid.append( reinterpret_cast< sal_Int64 >(xHome.get()), 16 );
91 oid.append( ';' );
92 // ;environment[context]
93 oid.append( OUString::unacquired(&pEnv->aBase.pTypeName) );
94 oid.append( '[' );
95 oid.append(
96 reinterpret_cast< sal_Int64 >(pEnv->aBase.pContext),
97 16 );
98 // ];good guid
99 oid.append( cppu_cppenv_getStaticOIdPart() );
100 OUString aRet( oid.makeStringAndClear() );
101 ::rtl_uString_acquire( *ppOId = aRet.pData );
104 catch (const ::com::sun::star::uno::RuntimeException & e)
106 SAL_WARN("bridges",
107 "### RuntimeException occurred during queryInterface(): "
108 << e.Message);
113 static void computeObjectIdentifier(
114 uno_ExtEnvironment * pExtEnv, rtl_uString ** ppOId, void * pInterface )
116 uno_Environment_invoke(&pExtEnv->aBase, s_stub_computeObjectIdentifier, pExtEnv, ppOId, pInterface);
119 static void s_stub_acquireInterface(va_list * pParam)
121 /*uno_ExtEnvironment * pExtEnv = */va_arg(*pParam, uno_ExtEnvironment *);
122 void * pCppI = va_arg(*pParam, void *);
124 static_cast< ::com::sun::star::uno::XInterface * >( pCppI )->acquire();
127 static void acquireInterface( uno_ExtEnvironment * pExtEnv, void * pCppI )
129 uno_Environment_invoke(&pExtEnv->aBase, s_stub_acquireInterface, pExtEnv, pCppI);
132 static void s_stub_releaseInterface(va_list * pParam)
134 /*uno_ExtEnvironment * pExtEnv = */va_arg(*pParam, uno_ExtEnvironment *);
135 void * pCppI = va_arg(*pParam, void *);
137 static_cast< ::com::sun::star::uno::XInterface * >( pCppI )->release();
140 static void releaseInterface( uno_ExtEnvironment * pExtEnv, void * pCppI )
142 uno_Environment_invoke(&pExtEnv->aBase, s_stub_releaseInterface, pExtEnv, pCppI);
145 static void environmentDisposing(
146 SAL_UNUSED_PARAMETER uno_Environment * )
150 #ifdef DISABLE_DYNLOADING
151 #define uno_initEnvironment CPPU_ENV_uno_initEnvironment
152 #endif
154 SAL_DLLPUBLIC_EXPORT void uno_initEnvironment(uno_Environment * pCppEnv)
155 SAL_THROW_EXTERN_C()
157 assert(pCppEnv->pExtEnv);
158 assert(
159 ::rtl_ustr_ascii_compare_WithLength(
160 pCppEnv->pTypeName->buffer, rtl_str_getLength(CPPU_CURRENT_LANGUAGE_BINDING_NAME), CPPU_CURRENT_LANGUAGE_BINDING_NAME )
161 == 0
162 && "### wrong environment type!");
163 reinterpret_cast<uno_ExtEnvironment *>(pCppEnv)->computeObjectIdentifier
164 = computeObjectIdentifier;
165 reinterpret_cast<uno_ExtEnvironment *>(pCppEnv)->acquireInterface = acquireInterface;
166 reinterpret_cast<uno_ExtEnvironment *>(pCppEnv)->releaseInterface = releaseInterface;
167 pCppEnv->environmentDisposing = environmentDisposing;
170 #ifdef DISABLE_DYNLOADING
171 #define uno_ext_getMapping CPPU_ENV_uno_ext_getMapping
172 #endif
174 SAL_DLLPUBLIC_EXPORT void uno_ext_getMapping(
175 uno_Mapping ** ppMapping, uno_Environment * pFrom, uno_Environment * pTo)
176 SAL_THROW_EXTERN_C()
178 assert(ppMapping && pFrom && pTo);
179 if (ppMapping && pFrom && pTo && pFrom->pExtEnv && pTo->pExtEnv)
181 uno_Mapping * pMapping = nullptr;
183 OUString from_envTypeName(cppu::EnvDcp::getTypeName(pFrom->pTypeName));
184 OUString to_envTypeName(cppu::EnvDcp::getTypeName(pTo->pTypeName));
186 if (rtl_ustr_ascii_compare(
187 from_envTypeName.pData->buffer,
188 CPPU_CURRENT_LANGUAGE_BINDING_NAME ) == 0 &&
189 rtl_ustr_ascii_compare(
190 to_envTypeName.pData->buffer, UNO_LB_UNO ) == 0)
192 // ref count initially 1
193 pMapping = bridges::cpp_uno::shared::Bridge::createMapping(
194 pFrom->pExtEnv, pTo->pExtEnv, true );
195 ::uno_registerMapping(
196 &pMapping, bridges::cpp_uno::shared::freeMapping,
197 &pFrom->pExtEnv->aBase,
198 &pTo->pExtEnv->aBase, nullptr );
200 else if (rtl_ustr_ascii_compare(
201 to_envTypeName.pData->buffer,
202 CPPU_CURRENT_LANGUAGE_BINDING_NAME ) == 0 &&
203 rtl_ustr_ascii_compare(
204 from_envTypeName.pData->buffer, UNO_LB_UNO ) == 0)
206 // ref count initially 1
207 pMapping = bridges::cpp_uno::shared::Bridge::createMapping(
208 pTo->pExtEnv, pFrom->pExtEnv, false );
209 ::uno_registerMapping(
210 &pMapping, bridges::cpp_uno::shared::freeMapping,
211 &pFrom->pExtEnv->aBase,
212 &pTo->pExtEnv->aBase, nullptr );
215 if (*ppMapping)
217 (*(*ppMapping)->release)( *ppMapping );
219 if (pMapping)
220 *ppMapping = pMapping;
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */