Line data Source code
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 "bridges/cpp_uno/shared/bridge.hxx"
21 :
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/diagnose.h"
26 : #include "osl/mutex.hxx"
27 : #include "osl/time.h"
28 : #include "rtl/process.h"
29 : #include "rtl/ustrbuf.hxx"
30 : #include "rtl/ustring.h"
31 : #include "rtl/ustring.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"
37 :
38 : namespace bridges { namespace cpp_uno { namespace shared {
39 :
40 : } } }
41 :
42 : namespace {
43 :
44 : #if (defined(__GNUC__) && defined(__APPLE__))
45 : static OUString * s_pStaticOidPart = 0;
46 : #endif
47 :
48 0 : const OUString & SAL_CALL cppu_cppenv_getStaticOIdPart() SAL_THROW(())
49 : {
50 : #if ! (defined(__GNUC__) && defined(__APPLE__))
51 : static OUString * s_pStaticOidPart = 0;
52 : #endif
53 0 : if (! s_pStaticOidPart)
54 : {
55 0 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
56 0 : if (! s_pStaticOidPart)
57 : {
58 0 : OUStringBuffer aRet( 64 );
59 0 : aRet.append( "];" );
60 : // good guid
61 : sal_uInt8 ar[16];
62 0 : ::rtl_getGlobalProcessId( ar );
63 0 : for ( sal_Int32 i = 0; i < 16; ++i )
64 : {
65 0 : aRet.append( (sal_Int32)ar[i], 16 );
66 : }
67 : #if (defined(__GNUC__) && defined(__APPLE__))
68 : s_pStaticOidPart = new OUString( aRet.makeStringAndClear() );
69 : #else
70 : static OUString s_aStaticOidPart(
71 0 : aRet.makeStringAndClear() );
72 0 : s_pStaticOidPart = &s_aStaticOidPart;
73 : #endif
74 0 : }
75 : }
76 0 : return *s_pStaticOidPart;
77 : }
78 :
79 : }
80 :
81 : extern "C" {
82 :
83 0 : static void s_stub_computeObjectIdentifier(va_list * pParam)
84 : SAL_THROW(())
85 : {
86 0 : uno_ExtEnvironment * pEnv = va_arg(*pParam, uno_ExtEnvironment *);
87 0 : rtl_uString ** ppOId = va_arg(*pParam, rtl_uString **);
88 0 : void * pInterface = va_arg(*pParam, void *);
89 :
90 :
91 : OSL_ENSURE( pEnv && ppOId && pInterface, "### null ptr!" );
92 0 : if (pEnv && ppOId && pInterface)
93 : {
94 0 : if (*ppOId)
95 : {
96 0 : rtl_uString_release( *ppOId );
97 0 : *ppOId = 0;
98 : }
99 :
100 : try
101 : {
102 : ::com::sun::star::uno::Reference<
103 : ::com::sun::star::uno::XInterface > xHome(
104 : reinterpret_cast< ::com::sun::star::uno::XInterface * >(
105 : pInterface ),
106 0 : ::com::sun::star::uno::UNO_QUERY );
107 : OSL_ENSURE( xHome.is(), "### query to XInterface failed!" );
108 0 : if (xHome.is())
109 : {
110 : // interface
111 0 : OUStringBuffer oid( 64 );
112 0 : oid.append( reinterpret_cast< sal_Int64 >(xHome.get()), 16 );
113 0 : oid.append( ';' );
114 : // ;environment[context]
115 : oid.append(
116 : *reinterpret_cast< OUString const * >(
117 0 : &((uno_Environment *) pEnv)->pTypeName ) );
118 0 : oid.append( '[' );
119 : oid.append(
120 : reinterpret_cast< sal_Int64 >(
121 : ((uno_Environment *)pEnv)->pContext),
122 0 : 16 );
123 : // ];good guid
124 0 : oid.append( cppu_cppenv_getStaticOIdPart() );
125 0 : OUString aRet( oid.makeStringAndClear() );
126 0 : ::rtl_uString_acquire( *ppOId = aRet.pData );
127 0 : }
128 : }
129 0 : catch (const ::com::sun::star::uno::RuntimeException &)
130 : {
131 : OSL_FAIL(
132 : "### RuntimeException occurred during queryInterface()!" );
133 : }
134 : }
135 0 : }
136 :
137 0 : static void SAL_CALL computeObjectIdentifier(
138 : uno_ExtEnvironment * pExtEnv, rtl_uString ** ppOId, void * pInterface )
139 : SAL_THROW(())
140 : {
141 0 : uno_Environment_invoke(&pExtEnv->aBase, s_stub_computeObjectIdentifier, pExtEnv, ppOId, pInterface);
142 0 : }
143 :
144 28 : static void s_stub_acquireInterface(va_list * pParam)
145 : SAL_THROW(())
146 : {
147 28 : /*uno_ExtEnvironment * pExtEnv = */va_arg(*pParam, uno_ExtEnvironment *);
148 28 : void * pCppI = va_arg(*pParam, void *);
149 :
150 28 : reinterpret_cast< ::com::sun::star::uno::XInterface * >( pCppI )->acquire();
151 28 : }
152 :
153 28 : static void SAL_CALL acquireInterface( uno_ExtEnvironment * pExtEnv, void * pCppI )
154 : SAL_THROW(())
155 : {
156 28 : uno_Environment_invoke(&pExtEnv->aBase, s_stub_acquireInterface, pExtEnv, pCppI);
157 28 : }
158 :
159 2 : static void s_stub_releaseInterface(va_list * pParam)
160 : SAL_THROW(())
161 : {
162 2 : /*uno_ExtEnvironment * pExtEnv = */va_arg(*pParam, uno_ExtEnvironment *);
163 2 : void * pCppI = va_arg(*pParam, void *);
164 :
165 2 : reinterpret_cast< ::com::sun::star::uno::XInterface * >( pCppI )->release();
166 2 : }
167 :
168 2 : static void SAL_CALL releaseInterface( uno_ExtEnvironment * pExtEnv, void * pCppI )
169 : SAL_THROW(())
170 : {
171 2 : uno_Environment_invoke(&pExtEnv->aBase, s_stub_releaseInterface, pExtEnv, pCppI);
172 2 : }
173 :
174 2 : static void SAL_CALL environmentDisposing(
175 : SAL_UNUSED_PARAMETER uno_Environment * ) SAL_THROW(())
176 : {
177 2 : }
178 :
179 : #ifdef DISABLE_DYNLOADING
180 : #define uno_initEnvironment CPPU_ENV_uno_initEnvironment
181 : #endif
182 :
183 3 : SAL_DLLPUBLIC_EXPORT void SAL_CALL uno_initEnvironment(uno_Environment * pCppEnv)
184 : SAL_THROW_EXTERN_C()
185 : {
186 : OSL_ENSURE( pCppEnv->pExtEnv, "### expected extended environment!" );
187 : OSL_ENSURE(
188 : ::rtl_ustr_ascii_compare_WithLength(
189 : pCppEnv->pTypeName->buffer, rtl_str_getLength(CPPU_CURRENT_LANGUAGE_BINDING_NAME), CPPU_CURRENT_LANGUAGE_BINDING_NAME )
190 : == 0,
191 : "### wrong environment type!" );
192 : ((uno_ExtEnvironment *)pCppEnv)->computeObjectIdentifier
193 3 : = computeObjectIdentifier;
194 3 : ((uno_ExtEnvironment *)pCppEnv)->acquireInterface = acquireInterface;
195 3 : ((uno_ExtEnvironment *)pCppEnv)->releaseInterface = releaseInterface;
196 3 : pCppEnv->environmentDisposing = environmentDisposing;
197 3 : }
198 :
199 : #ifdef DISABLE_DYNLOADING
200 : #define uno_ext_getMapping CPPU_ENV_uno_ext_getMapping
201 : #endif
202 :
203 0 : SAL_DLLPUBLIC_EXPORT void SAL_CALL uno_ext_getMapping(
204 : uno_Mapping ** ppMapping, uno_Environment * pFrom, uno_Environment * pTo)
205 : SAL_THROW_EXTERN_C()
206 : {
207 : OSL_ASSERT( ppMapping && pFrom && pTo );
208 0 : if (ppMapping && pFrom && pTo && pFrom->pExtEnv && pTo->pExtEnv)
209 : {
210 0 : uno_Mapping * pMapping = 0;
211 :
212 0 : OUString from_envTypeName(cppu::EnvDcp::getTypeName(pFrom->pTypeName));
213 0 : OUString to_envTypeName(cppu::EnvDcp::getTypeName(pTo->pTypeName));
214 :
215 0 : if (0 == rtl_ustr_ascii_compare(
216 : from_envTypeName.pData->buffer,
217 0 : CPPU_CURRENT_LANGUAGE_BINDING_NAME ) &&
218 : 0 == rtl_ustr_ascii_compare(
219 0 : to_envTypeName.pData->buffer, UNO_LB_UNO ))
220 : {
221 : // ref count initially 1
222 : pMapping = bridges::cpp_uno::shared::Bridge::createMapping(
223 0 : pFrom->pExtEnv, pTo->pExtEnv, true );
224 : ::uno_registerMapping(
225 : &pMapping, bridges::cpp_uno::shared::freeMapping,
226 : (uno_Environment *)pFrom->pExtEnv,
227 0 : (uno_Environment *)pTo->pExtEnv, 0 );
228 : }
229 0 : else if (0 == rtl_ustr_ascii_compare(
230 : to_envTypeName.pData->buffer,
231 0 : CPPU_CURRENT_LANGUAGE_BINDING_NAME ) &&
232 : 0 == rtl_ustr_ascii_compare(
233 0 : from_envTypeName.pData->buffer, UNO_LB_UNO ))
234 : {
235 : // ref count initially 1
236 : pMapping = bridges::cpp_uno::shared::Bridge::createMapping(
237 0 : pTo->pExtEnv, pFrom->pExtEnv, false );
238 : ::uno_registerMapping(
239 : &pMapping, bridges::cpp_uno::shared::freeMapping,
240 : (uno_Environment *)pFrom->pExtEnv,
241 0 : (uno_Environment *)pTo->pExtEnv, 0 );
242 : }
243 :
244 0 : if (*ppMapping)
245 : {
246 0 : (*(*ppMapping)->release)( *ppMapping );
247 : }
248 0 : if (pMapping)
249 0 : *ppMapping = pMapping;
250 : }
251 0 : }
252 :
253 : }
254 :
255 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|