File: | stoc/source/proxy_factory/proxyfac.cxx |
Location: | line 226, column 11 |
Description: | Access to field 'registerProxyInterface' results in a dereference of a null pointer (loaded from variable 'uno_env') |
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 | ||||
21 | #include "osl/diagnose.h" | |||
22 | #include "osl/interlck.h" | |||
23 | #include "osl/doublecheckedlocking.h" | |||
24 | #include "osl/mutex.hxx" | |||
25 | #include "rtl/ref.hxx" | |||
26 | #include "uno/dispatcher.hxx" | |||
27 | #include "uno/data.h" | |||
28 | #include "uno/mapping.hxx" | |||
29 | #include "uno/environment.hxx" | |||
30 | #include "typelib/typedescription.hxx" | |||
31 | #include "cppuhelper/exc_hlp.hxx" | |||
32 | #include "cppuhelper/implbase2.hxx" | |||
33 | #include "cppuhelper/implementationentry.hxx" | |||
34 | #include "cppuhelper/factory.hxx" | |||
35 | #include "com/sun/star/lang/XServiceInfo.hpp" | |||
36 | #include "com/sun/star/registry/XRegistryKey.hpp" | |||
37 | #include "com/sun/star/reflection/XProxyFactory.hpp" | |||
38 | #include "com/sun/star/uno/RuntimeException.hpp" | |||
39 | ||||
40 | #define OUSTR(x)::rtl::OUString( (&(x)[0]), ((sal_Int32)((sizeof (x) / sizeof ((x)[0]))-1)), (((rtl_TextEncoding) 11)) ) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x)(&(x)[0]), ((sal_Int32)((sizeof (x) / sizeof ((x)[0]))-1) ), (((rtl_TextEncoding) 11)) ) | |||
41 | #define SERVICE_NAME"com.sun.star.reflection.ProxyFactory" "com.sun.star.reflection.ProxyFactory" | |||
42 | #define IMPL_NAME"com.sun.star.comp.reflection.ProxyFactory" "com.sun.star.comp.reflection.ProxyFactory" | |||
43 | ||||
44 | ||||
45 | using namespace ::com::sun::star; | |||
46 | using namespace ::com::sun::star::uno; | |||
47 | using ::rtl::OUString; | |||
48 | ||||
49 | ||||
50 | namespace | |||
51 | { | |||
52 | ||||
53 | static rtl_StandardModuleCount g_moduleCount = MODULE_COUNT_INIT{ {rtl_moduleCount_acquire,rtl_moduleCount_release}, rtl_moduleCount_canUnload , 0, {0, 0}}; | |||
54 | ||||
55 | static OUString proxyfac_getImplementationName() | |||
56 | { | |||
57 | return OUSTR(IMPL_NAME)::rtl::OUString( (&("com.sun.star.comp.reflection.ProxyFactory" )[0]), ((sal_Int32)((sizeof ("com.sun.star.comp.reflection.ProxyFactory" ) / sizeof (("com.sun.star.comp.reflection.ProxyFactory")[0]) )-1)), (((rtl_TextEncoding) 11)) ); | |||
58 | } | |||
59 | ||||
60 | static Sequence< OUString > proxyfac_getSupportedServiceNames() | |||
61 | { | |||
62 | OUString str_name = OUSTR(SERVICE_NAME)::rtl::OUString( (&("com.sun.star.reflection.ProxyFactory" )[0]), ((sal_Int32)((sizeof ("com.sun.star.reflection.ProxyFactory" ) / sizeof (("com.sun.star.reflection.ProxyFactory")[0]))-1)) , (((rtl_TextEncoding) 11)) ); | |||
63 | return Sequence< OUString >( &str_name, 1 ); | |||
64 | } | |||
65 | ||||
66 | //============================================================================== | |||
67 | struct FactoryImpl : public ::cppu::WeakImplHelper2< lang::XServiceInfo, | |||
68 | reflection::XProxyFactory > | |||
69 | { | |||
70 | Environment m_uno_env; | |||
71 | Environment m_cpp_env; | |||
72 | Mapping m_uno2cpp; | |||
73 | Mapping m_cpp2uno; | |||
74 | ||||
75 | UnoInterfaceReference binuno_queryInterface( | |||
76 | UnoInterfaceReference const & unoI, | |||
77 | typelib_InterfaceTypeDescription * pTypeDescr ); | |||
78 | ||||
79 | FactoryImpl(); | |||
80 | virtual ~FactoryImpl(); | |||
81 | ||||
82 | // XServiceInfo | |||
83 | virtual OUString SAL_CALL getImplementationName() | |||
84 | throw (RuntimeException); | |||
85 | virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) | |||
86 | throw (RuntimeException); | |||
87 | virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() | |||
88 | throw (RuntimeException); | |||
89 | ||||
90 | // XProxyFactory | |||
91 | virtual Reference< XAggregation > SAL_CALL createProxy( | |||
92 | Reference< XInterface > const & xTarget ) | |||
93 | throw (RuntimeException); | |||
94 | }; | |||
95 | ||||
96 | //______________________________________________________________________________ | |||
97 | UnoInterfaceReference FactoryImpl::binuno_queryInterface( | |||
98 | UnoInterfaceReference const & unoI, | |||
99 | typelib_InterfaceTypeDescription * pTypeDescr ) | |||
100 | { | |||
101 | // init queryInterface() td | |||
102 | static typelib_TypeDescription * s_pQITD = 0; | |||
103 | if (s_pQITD == 0) | |||
104 | { | |||
105 | ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); | |||
106 | if (s_pQITD == 0) | |||
107 | { | |||
108 | typelib_TypeDescription * pTXInterfaceDescr = 0; | |||
109 | TYPELIB_DANGER_GET({ typelib_TypeDescriptionReference * pMacroTypeRef = (::getCppuType ( reinterpret_cast< Reference< XInterface > const * > (0) ).getTypeLibType()); typelib_TypeDescription ** ppMacroTypeDescr = (&pTXInterfaceDescr); if (((pMacroTypeRef->eTypeClass ) == typelib_TypeClass_INTERFACE_METHOD || (pMacroTypeRef-> eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE)) { typelib_typedescriptionreference_getDescription ( ppMacroTypeDescr, pMacroTypeRef ); } else if (!pMacroTypeRef ->pType || !pMacroTypeRef->pType->pWeakRef) { typelib_typedescriptionreference_getDescription ( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release ( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef ->pType; } } | |||
110 | &pTXInterfaceDescr,{ typelib_TypeDescriptionReference * pMacroTypeRef = (::getCppuType ( reinterpret_cast< Reference< XInterface > const * > (0) ).getTypeLibType()); typelib_TypeDescription ** ppMacroTypeDescr = (&pTXInterfaceDescr); if (((pMacroTypeRef->eTypeClass ) == typelib_TypeClass_INTERFACE_METHOD || (pMacroTypeRef-> eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE)) { typelib_typedescriptionreference_getDescription ( ppMacroTypeDescr, pMacroTypeRef ); } else if (!pMacroTypeRef ->pType || !pMacroTypeRef->pType->pWeakRef) { typelib_typedescriptionreference_getDescription ( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release ( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef ->pType; } } | |||
111 | ::getCppuType( reinterpret_cast< Reference< XInterface >{ typelib_TypeDescriptionReference * pMacroTypeRef = (::getCppuType ( reinterpret_cast< Reference< XInterface > const * > (0) ).getTypeLibType()); typelib_TypeDescription ** ppMacroTypeDescr = (&pTXInterfaceDescr); if (((pMacroTypeRef->eTypeClass ) == typelib_TypeClass_INTERFACE_METHOD || (pMacroTypeRef-> eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE)) { typelib_typedescriptionreference_getDescription ( ppMacroTypeDescr, pMacroTypeRef ); } else if (!pMacroTypeRef ->pType || !pMacroTypeRef->pType->pWeakRef) { typelib_typedescriptionreference_getDescription ( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release ( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef ->pType; } } | |||
112 | const * >(0) ).getTypeLibType() ){ typelib_TypeDescriptionReference * pMacroTypeRef = (::getCppuType ( reinterpret_cast< Reference< XInterface > const * > (0) ).getTypeLibType()); typelib_TypeDescription ** ppMacroTypeDescr = (&pTXInterfaceDescr); if (((pMacroTypeRef->eTypeClass ) == typelib_TypeClass_INTERFACE_METHOD || (pMacroTypeRef-> eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE)) { typelib_typedescriptionreference_getDescription ( ppMacroTypeDescr, pMacroTypeRef ); } else if (!pMacroTypeRef ->pType || !pMacroTypeRef->pType->pWeakRef) { typelib_typedescriptionreference_getDescription ( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release ( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef ->pType; } }; | |||
113 | typelib_TypeDescription * pQITD = 0; | |||
114 | typelib_typedescriptionreference_getDescription( | |||
115 | &pQITD, reinterpret_cast< typelib_InterfaceTypeDescription * >( | |||
116 | pTXInterfaceDescr )->ppAllMembers[ 0 ] ); | |||
117 | TYPELIB_DANGER_RELEASE( pTXInterfaceDescr ){ if ((((pTXInterfaceDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || ((pTXInterfaceDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE )) typelib_typedescription_release( pTXInterfaceDescr ); }; | |||
118 | OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); | |||
119 | s_pQITD = pQITD; | |||
120 | } | |||
121 | } | |||
122 | else | |||
123 | { | |||
124 | OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); | |||
125 | } | |||
126 | ||||
127 | void * args[ 1 ]; | |||
128 | args[ 0 ] = &reinterpret_cast< typelib_TypeDescription * >( | |||
129 | pTypeDescr )->pWeakRef; | |||
130 | uno_Any ret_val, exc_space; | |||
131 | uno_Any * exc = &exc_space; | |||
132 | ||||
133 | unoI.dispatch( s_pQITD, &ret_val, args, &exc ); | |||
134 | ||||
135 | if (exc == 0) | |||
136 | { | |||
137 | UnoInterfaceReference ret; | |||
138 | if (ret_val.pType->eTypeClass == typelib_TypeClass_INTERFACE) | |||
139 | { | |||
140 | ret.set( *reinterpret_cast< uno_Interface ** >(ret_val.pData), | |||
141 | SAL_NO_ACQUIRE ); | |||
142 | typelib_typedescriptionreference_release( ret_val.pType ); | |||
143 | } | |||
144 | else | |||
145 | { | |||
146 | uno_any_destruct( &ret_val, 0 ); | |||
147 | } | |||
148 | return ret; | |||
149 | } | |||
150 | else | |||
151 | { | |||
152 | // exception occurred: | |||
153 | OSL_ENSURE(do { if (true && (!(typelib_typedescriptionreference_isAssignableFrom ( ::getCppuType( reinterpret_cast< RuntimeException const * >(0) ).getTypeLibType(), exc->pType )))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/stoc/source/proxy_factory/proxyfac.cxx" ":" "158" ": "), "%s", "### RuntimeException expected!"); } } while (false) | |||
154 | typelib_typedescriptionreference_isAssignableFrom(do { if (true && (!(typelib_typedescriptionreference_isAssignableFrom ( ::getCppuType( reinterpret_cast< RuntimeException const * >(0) ).getTypeLibType(), exc->pType )))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/stoc/source/proxy_factory/proxyfac.cxx" ":" "158" ": "), "%s", "### RuntimeException expected!"); } } while (false) | |||
155 | ::getCppuType( reinterpret_cast<do { if (true && (!(typelib_typedescriptionreference_isAssignableFrom ( ::getCppuType( reinterpret_cast< RuntimeException const * >(0) ).getTypeLibType(), exc->pType )))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/stoc/source/proxy_factory/proxyfac.cxx" ":" "158" ": "), "%s", "### RuntimeException expected!"); } } while (false) | |||
156 | RuntimeException const * >(0) ).getTypeLibType(),do { if (true && (!(typelib_typedescriptionreference_isAssignableFrom ( ::getCppuType( reinterpret_cast< RuntimeException const * >(0) ).getTypeLibType(), exc->pType )))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/stoc/source/proxy_factory/proxyfac.cxx" ":" "158" ": "), "%s", "### RuntimeException expected!"); } } while (false) | |||
157 | exc->pType ),do { if (true && (!(typelib_typedescriptionreference_isAssignableFrom ( ::getCppuType( reinterpret_cast< RuntimeException const * >(0) ).getTypeLibType(), exc->pType )))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/stoc/source/proxy_factory/proxyfac.cxx" ":" "158" ": "), "%s", "### RuntimeException expected!"); } } while (false) | |||
158 | "### RuntimeException expected!" )do { if (true && (!(typelib_typedescriptionreference_isAssignableFrom ( ::getCppuType( reinterpret_cast< RuntimeException const * >(0) ).getTypeLibType(), exc->pType )))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/stoc/source/proxy_factory/proxyfac.cxx" ":" "158" ": "), "%s", "### RuntimeException expected!"); } } while (false); | |||
159 | Any cpp_exc; | |||
160 | uno_type_copyAndConvertData( | |||
161 | &cpp_exc, exc, ::getCppuType( &cpp_exc ).getTypeLibType(), | |||
162 | m_uno2cpp.get() ); | |||
163 | uno_any_destruct( exc, 0 ); | |||
164 | ::cppu::throwException( cpp_exc ); | |||
165 | OSL_ASSERT( 0 )do { if (true && (!(0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.osl"), ("/usr/local/src/libreoffice/stoc/source/proxy_factory/proxyfac.cxx" ":" "165" ": "), "OSL_ASSERT: %s", "0"); } } while (false); // way of no return | |||
166 | return UnoInterfaceReference(); // for dummy | |||
167 | } | |||
168 | } | |||
169 | ||||
170 | //============================================================================== | |||
171 | struct ProxyRoot : public ::cppu::OWeakAggObject | |||
172 | { | |||
173 | // XAggregation | |||
174 | virtual Any SAL_CALL queryAggregation( Type const & rType ) | |||
175 | throw (RuntimeException); | |||
176 | ||||
177 | virtual ~ProxyRoot(); | |||
178 | inline ProxyRoot( ::rtl::Reference< FactoryImpl > const & factory, | |||
179 | Reference< XInterface > const & xTarget ); | |||
180 | ||||
181 | ::rtl::Reference< FactoryImpl > m_factory; | |||
182 | ||||
183 | private: | |||
184 | UnoInterfaceReference m_target; | |||
185 | }; | |||
186 | ||||
187 | //============================================================================== | |||
188 | struct binuno_Proxy : public uno_Interface | |||
189 | { | |||
190 | oslInterlockedCount m_nRefCount; | |||
191 | ::rtl::Reference< ProxyRoot > m_root; | |||
192 | UnoInterfaceReference m_target; | |||
193 | OUString m_oid; | |||
194 | TypeDescription m_typeDescr; | |||
195 | ||||
196 | inline binuno_Proxy( | |||
197 | ::rtl::Reference< ProxyRoot > const & root, | |||
198 | UnoInterfaceReference const & target, | |||
199 | OUString const & oid, TypeDescription const & typeDescr ); | |||
200 | }; | |||
201 | ||||
202 | extern "C" | |||
203 | { | |||
204 | ||||
205 | //------------------------------------------------------------------------------ | |||
206 | static void SAL_CALL binuno_proxy_free( | |||
207 | uno_ExtEnvironment * pEnv, void * pProxy ) | |||
208 | { | |||
209 | (void) pEnv; // avoid warning about unused parameter | |||
210 | binuno_Proxy * proxy = static_cast< binuno_Proxy * >( | |||
211 | reinterpret_cast< uno_Interface * >( pProxy ) ); | |||
212 | OSL_ASSERT( proxy->m_root->m_factory->m_uno_env.get()->pExtEnv == pEnv )do { if (true && (!(proxy->m_root->m_factory-> m_uno_env.get()->pExtEnv == pEnv))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/stoc/source/proxy_factory/proxyfac.cxx" ":" "212" ": "), "OSL_ASSERT: %s", "proxy->m_root->m_factory->m_uno_env.get()->pExtEnv == pEnv" ); } } while (false); | |||
213 | delete proxy; | |||
214 | } | |||
215 | ||||
216 | //------------------------------------------------------------------------------ | |||
217 | static void SAL_CALL binuno_proxy_acquire( uno_Interface * pUnoI ) | |||
218 | { | |||
219 | binuno_Proxy * that = static_cast< binuno_Proxy * >( pUnoI ); | |||
220 | if (osl_incrementInterlockedCount( &that->m_nRefCount ) == 1) | |||
221 | { | |||
222 | // rebirth of zombie | |||
223 | uno_ExtEnvironment * uno_env = | |||
224 | that->m_root->m_factory->m_uno_env.get()->pExtEnv; | |||
225 | OSL_ASSERT( uno_env != 0 )do { if (true && (!(uno_env != 0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/stoc/source/proxy_factory/proxyfac.cxx" ":" "225" ": "), "OSL_ASSERT: %s", "uno_env != 0"); } } while (false); | |||
226 | (*uno_env->registerProxyInterface)( | |||
| ||||
227 | uno_env, reinterpret_cast< void ** >( &pUnoI ), binuno_proxy_free, | |||
228 | that->m_oid.pData, | |||
229 | reinterpret_cast< typelib_InterfaceTypeDescription * >( | |||
230 | that->m_typeDescr.get() ) ); | |||
231 | OSL_ASSERT( that == static_cast< binuno_Proxy * >( pUnoI ) )do { if (true && (!(that == static_cast< binuno_Proxy * >( pUnoI )))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.osl"), ("/usr/local/src/libreoffice/stoc/source/proxy_factory/proxyfac.cxx" ":" "231" ": "), "OSL_ASSERT: %s", "that == static_cast< binuno_Proxy * >( pUnoI )" ); } } while (false); | |||
232 | } | |||
233 | } | |||
234 | ||||
235 | //------------------------------------------------------------------------------ | |||
236 | static void SAL_CALL binuno_proxy_release( uno_Interface * pUnoI ) | |||
237 | { | |||
238 | binuno_Proxy * that = static_cast< binuno_Proxy * >( pUnoI ); | |||
239 | if (osl_decrementInterlockedCount( &that->m_nRefCount ) == 0) | |||
240 | { | |||
241 | uno_ExtEnvironment * uno_env = | |||
242 | that->m_root->m_factory->m_uno_env.get()->pExtEnv; | |||
243 | OSL_ASSERT( uno_env != 0 )do { if (true && (!(uno_env != 0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/stoc/source/proxy_factory/proxyfac.cxx" ":" "243" ": "), "OSL_ASSERT: %s", "uno_env != 0"); } } while (false); | |||
244 | (*uno_env->revokeInterface)( uno_env, pUnoI ); | |||
245 | } | |||
246 | } | |||
247 | ||||
248 | //------------------------------------------------------------------------------ | |||
249 | static void SAL_CALL binuno_proxy_dispatch( | |||
250 | uno_Interface * pUnoI, const typelib_TypeDescription * pMemberType, | |||
251 | void * pReturn, void * pArgs [], uno_Any ** ppException ) | |||
252 | { | |||
253 | binuno_Proxy * that = static_cast< binuno_Proxy * >( pUnoI ); | |||
254 | switch (reinterpret_cast< typelib_InterfaceMemberTypeDescription const * >( | |||
| ||||
255 | pMemberType )->nPosition) | |||
256 | { | |||
257 | case 0: // queryInterface() | |||
258 | { | |||
259 | try | |||
260 | { | |||
261 | Type const & rType = | |||
262 | *reinterpret_cast< Type const * >( pArgs[ 0 ] ); | |||
263 | Any ret( that->m_root->queryInterface( rType ) ); | |||
264 | uno_type_copyAndConvertData( | |||
265 | pReturn, &ret, ::getCppuType( &ret ).getTypeLibType(), | |||
266 | that->m_root->m_factory->m_cpp2uno.get() ); | |||
267 | *ppException = 0; // no exc | |||
268 | } | |||
269 | catch (RuntimeException &) | |||
270 | { | |||
271 | Any exc( ::cppu::getCaughtException() ); | |||
272 | uno_type_any_constructAndConvert( | |||
273 | *ppException, const_cast< void * >(exc.getValue()), | |||
274 | exc.getValueTypeRef(), | |||
275 | that->m_root->m_factory->m_cpp2uno.get() ); | |||
276 | } | |||
277 | break; | |||
278 | } | |||
279 | case 1: // acquire() | |||
280 | binuno_proxy_acquire( pUnoI ); | |||
281 | *ppException = 0; // no exc | |||
282 | break; | |||
283 | case 2: // release() | |||
284 | binuno_proxy_release( pUnoI ); | |||
285 | *ppException = 0; // no exc | |||
286 | break; | |||
287 | default: | |||
288 | that->m_target.dispatch( pMemberType, pReturn, pArgs, ppException ); | |||
289 | break; | |||
290 | } | |||
291 | } | |||
292 | ||||
293 | } | |||
294 | ||||
295 | //______________________________________________________________________________ | |||
296 | inline binuno_Proxy::binuno_Proxy( | |||
297 | ::rtl::Reference< ProxyRoot > const & root, | |||
298 | UnoInterfaceReference const & target, | |||
299 | OUString const & oid, TypeDescription const & typeDescr ) | |||
300 | : m_nRefCount( 1 ), | |||
301 | m_root( root ), | |||
302 | m_target( target ), | |||
303 | m_oid( oid ), | |||
304 | m_typeDescr( typeDescr ) | |||
305 | { | |||
306 | uno_Interface::acquire = binuno_proxy_acquire; | |||
307 | uno_Interface::release = binuno_proxy_release; | |||
308 | uno_Interface::pDispatcher = binuno_proxy_dispatch; | |||
309 | } | |||
310 | ||||
311 | //______________________________________________________________________________ | |||
312 | ProxyRoot::~ProxyRoot() | |||
313 | { | |||
314 | } | |||
315 | ||||
316 | //______________________________________________________________________________ | |||
317 | inline ProxyRoot::ProxyRoot( | |||
318 | ::rtl::Reference< FactoryImpl > const & factory, | |||
319 | Reference< XInterface > const & xTarget ) | |||
320 | : m_factory( factory ) | |||
321 | { | |||
322 | m_factory->m_cpp2uno.mapInterface( | |||
323 | reinterpret_cast< void ** >( &m_target.m_pUnoI ), xTarget.get(), | |||
324 | ::getCppuType( &xTarget ) ); | |||
325 | OSL_ENSURE( m_target.is(), "### mapping interface failed!" )do { if (true && (!(m_target.is()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/stoc/source/proxy_factory/proxyfac.cxx" ":" "325" ": "), "%s", "### mapping interface failed!"); } } while (false); | |||
326 | } | |||
327 | ||||
328 | //______________________________________________________________________________ | |||
329 | Any ProxyRoot::queryAggregation( Type const & rType ) | |||
330 | throw (RuntimeException) | |||
331 | { | |||
332 | Any ret( OWeakAggObject::queryAggregation( rType ) ); | |||
333 | if (! ret.hasValue()) | |||
334 | { | |||
335 | typelib_TypeDescription * pTypeDescr = 0; | |||
336 | TYPELIB_DANGER_GET( &pTypeDescr, rType.getTypeLibType() ){ typelib_TypeDescriptionReference * pMacroTypeRef = (rType.getTypeLibType ()); typelib_TypeDescription ** ppMacroTypeDescr = (&pTypeDescr ); if (((pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || (pMacroTypeRef->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE )) { typelib_typedescriptionreference_getDescription( ppMacroTypeDescr , pMacroTypeRef ); } else if (!pMacroTypeRef->pType || !pMacroTypeRef ->pType->pWeakRef) { typelib_typedescriptionreference_getDescription ( ppMacroTypeDescr, pMacroTypeRef ); if (*ppMacroTypeDescr) typelib_typedescription_release ( *ppMacroTypeDescr ); } else { *ppMacroTypeDescr = pMacroTypeRef ->pType; } }; | |||
337 | try | |||
338 | { | |||
339 | Reference< XInterface > xProxy; | |||
340 | uno_ExtEnvironment * cpp_env = m_factory->m_cpp_env.get()->pExtEnv; | |||
341 | OSL_ASSERT( cpp_env != 0 )do { if (true && (!(cpp_env != 0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/stoc/source/proxy_factory/proxyfac.cxx" ":" "341" ": "), "OSL_ASSERT: %s", "cpp_env != 0"); } } while (false); | |||
342 | ||||
343 | // mind a new delegator, calculate current root: | |||
344 | Reference< XInterface > xRoot( | |||
345 | static_cast< OWeakObject * >(this), UNO_QUERY_THROW ); | |||
346 | OUString oid; | |||
347 | (*cpp_env->getObjectIdentifier)( cpp_env, &oid.pData, xRoot.get() ); | |||
348 | OSL_ASSERT( !oid.isEmpty() )do { if (true && (!(!oid.isEmpty()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/stoc/source/proxy_factory/proxyfac.cxx" ":" "348" ": "), "OSL_ASSERT: %s", "!oid.isEmpty()"); } } while (false); | |||
349 | ||||
350 | (*cpp_env->getRegisteredInterface)( | |||
351 | cpp_env, reinterpret_cast< void ** >( &xProxy ), | |||
352 | oid.pData, reinterpret_cast< | |||
353 | typelib_InterfaceTypeDescription * >(pTypeDescr) ); | |||
354 | if (! xProxy.is()) | |||
355 | { | |||
356 | // perform query on target: | |||
357 | UnoInterfaceReference proxy_target( | |||
358 | m_factory->binuno_queryInterface( | |||
359 | m_target, reinterpret_cast< | |||
360 | typelib_InterfaceTypeDescription * >(pTypeDescr) ) ); | |||
361 | if (proxy_target.is()) | |||
362 | { | |||
363 | // ensure root's object entries: | |||
364 | UnoInterfaceReference root; | |||
365 | m_factory->m_cpp2uno.mapInterface( | |||
366 | reinterpret_cast< void ** >( &root.m_pUnoI ), | |||
367 | xRoot.get(), ::getCppuType( &xRoot ) ); | |||
368 | ||||
369 | UnoInterfaceReference proxy( | |||
370 | // ref count initially 1: | |||
371 | new binuno_Proxy( this, proxy_target, oid, pTypeDescr ), | |||
372 | SAL_NO_ACQUIRE ); | |||
373 | uno_ExtEnvironment * uno_env = | |||
374 | m_factory->m_uno_env.get()->pExtEnv; | |||
375 | OSL_ASSERT( uno_env != 0 )do { if (true && (!(uno_env != 0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/stoc/source/proxy_factory/proxyfac.cxx" ":" "375" ": "), "OSL_ASSERT: %s", "uno_env != 0"); } } while (false); | |||
376 | (*uno_env->registerProxyInterface)( | |||
377 | uno_env, reinterpret_cast< void ** >( &proxy.m_pUnoI ), | |||
378 | binuno_proxy_free, oid.pData, | |||
379 | reinterpret_cast< typelib_InterfaceTypeDescription * >( | |||
380 | pTypeDescr ) ); | |||
381 | ||||
382 | m_factory->m_uno2cpp.mapInterface( | |||
383 | reinterpret_cast< void ** >( &xProxy ), | |||
384 | proxy.get(), pTypeDescr ); | |||
385 | } | |||
386 | } | |||
387 | if (xProxy.is()) | |||
388 | ret.setValue( &xProxy, pTypeDescr ); | |||
389 | } | |||
390 | catch (...) // finally | |||
391 | { | |||
392 | TYPELIB_DANGER_RELEASE( pTypeDescr ){ if ((((pTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || ((pTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE )) typelib_typedescription_release( pTypeDescr ); }; | |||
393 | throw; | |||
394 | } | |||
395 | TYPELIB_DANGER_RELEASE( pTypeDescr ){ if ((((pTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || ((pTypeDescr)->eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE )) typelib_typedescription_release( pTypeDescr ); }; | |||
396 | } | |||
397 | return ret; | |||
398 | } | |||
399 | ||||
400 | //############################################################################## | |||
401 | ||||
402 | //______________________________________________________________________________ | |||
403 | FactoryImpl::FactoryImpl() | |||
404 | { | |||
405 | OUString uno = OUSTR(UNO_LB_UNO)::rtl::OUString( (&("uno")[0]), ((sal_Int32)((sizeof ("uno" ) / sizeof (("uno")[0]))-1)), (((rtl_TextEncoding) 11)) ); | |||
406 | OUString cpp = OUSTR(CPPU_CURRENT_LANGUAGE_BINDING_NAME)::rtl::OUString( (&("gcc3")[0]), ((sal_Int32)((sizeof ("gcc3" ) / sizeof (("gcc3")[0]))-1)), (((rtl_TextEncoding) 11)) ); | |||
407 | ||||
408 | uno_getEnvironment( | |||
409 | reinterpret_cast< uno_Environment ** >( &m_uno_env ), uno.pData, 0 ); | |||
410 | OSL_ENSURE( m_uno_env.is(), "### cannot get binary uno env!" )do { if (true && (!(m_uno_env.is()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/stoc/source/proxy_factory/proxyfac.cxx" ":" "410" ": "), "%s", "### cannot get binary uno env!"); } } while (false); | |||
411 | ||||
412 | uno_getEnvironment( | |||
413 | reinterpret_cast< uno_Environment ** >( &m_cpp_env ), cpp.pData, 0 ); | |||
414 | OSL_ENSURE( m_cpp_env.is(), "### cannot get C++ uno env!" )do { if (true && (!(m_cpp_env.is()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/stoc/source/proxy_factory/proxyfac.cxx" ":" "414" ": "), "%s", "### cannot get C++ uno env!"); } } while (false); | |||
415 | ||||
416 | uno_getMapping( | |||
417 | reinterpret_cast< uno_Mapping ** >( &m_uno2cpp ), | |||
418 | m_uno_env.get(), m_cpp_env.get(), 0 ); | |||
419 | OSL_ENSURE( m_uno2cpp.is(), "### cannot get bridge uno <-> C++!" )do { if (true && (!(m_uno2cpp.is()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/stoc/source/proxy_factory/proxyfac.cxx" ":" "419" ": "), "%s", "### cannot get bridge uno <-> C++!" ); } } while (false); | |||
420 | ||||
421 | uno_getMapping( | |||
422 | reinterpret_cast< uno_Mapping ** >( &m_cpp2uno ), | |||
423 | m_cpp_env.get(), m_uno_env.get(), 0 ); | |||
424 | OSL_ENSURE( m_cpp2uno.is(), "### cannot get bridge C++ <-> uno!" )do { if (true && (!(m_cpp2uno.is()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/stoc/source/proxy_factory/proxyfac.cxx" ":" "424" ": "), "%s", "### cannot get bridge C++ <-> uno!" ); } } while (false); | |||
425 | ||||
426 | g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); | |||
427 | } | |||
428 | ||||
429 | //______________________________________________________________________________ | |||
430 | FactoryImpl::~FactoryImpl() | |||
431 | { | |||
432 | g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); | |||
433 | } | |||
434 | ||||
435 | // XProxyFactory | |||
436 | //______________________________________________________________________________ | |||
437 | Reference< XAggregation > FactoryImpl::createProxy( | |||
438 | Reference< XInterface > const & xTarget ) | |||
439 | throw (RuntimeException) | |||
440 | { | |||
441 | return new ProxyRoot( this, xTarget ); | |||
442 | } | |||
443 | ||||
444 | // XServiceInfo | |||
445 | //______________________________________________________________________________ | |||
446 | OUString FactoryImpl::getImplementationName() | |||
447 | throw (RuntimeException) | |||
448 | { | |||
449 | return proxyfac_getImplementationName(); | |||
450 | } | |||
451 | ||||
452 | //______________________________________________________________________________ | |||
453 | sal_Bool FactoryImpl::supportsService( const OUString & rServiceName ) | |||
454 | throw (RuntimeException) | |||
455 | { | |||
456 | Sequence< OUString > const & rSNL = getSupportedServiceNames(); | |||
457 | OUString const * pArray = rSNL.getConstArray(); | |||
458 | for ( sal_Int32 nPos = rSNL.getLength(); nPos--; ) | |||
459 | { | |||
460 | if (rServiceName.equals( pArray[ nPos ] )) | |||
461 | return true; | |||
462 | } | |||
463 | return false; | |||
464 | } | |||
465 | ||||
466 | //______________________________________________________________________________ | |||
467 | Sequence< OUString > FactoryImpl::getSupportedServiceNames() | |||
468 | throw(::com::sun::star::uno::RuntimeException) | |||
469 | { | |||
470 | return proxyfac_getSupportedServiceNames(); | |||
471 | } | |||
472 | ||||
473 | //============================================================================== | |||
474 | static Reference< XInterface > SAL_CALL proxyfac_create( | |||
475 | SAL_UNUSED_PARAMETER__attribute__ ((unused)) Reference< XComponentContext > const & ) | |||
476 | throw (Exception) | |||
477 | { | |||
478 | Reference< XInterface > xRet; | |||
479 | { | |||
480 | ::osl::MutexGuard guard( ::osl::Mutex::getGlobalMutex() ); | |||
481 | static WeakReference < XInterface > rwInstance; | |||
482 | xRet = rwInstance; | |||
483 | ||||
484 | if (! xRet.is()) | |||
485 | { | |||
486 | xRet = static_cast< ::cppu::OWeakObject * >(new FactoryImpl); | |||
487 | rwInstance = xRet; | |||
488 | } | |||
489 | } | |||
490 | return xRet; | |||
491 | } | |||
492 | ||||
493 | static ::cppu::ImplementationEntry g_entries [] = | |||
494 | { | |||
495 | { | |||
496 | proxyfac_create, proxyfac_getImplementationName, | |||
497 | proxyfac_getSupportedServiceNames, ::cppu::createSingleComponentFactory, | |||
498 | &g_moduleCount.modCnt, 0 | |||
499 | }, | |||
500 | { 0, 0, 0, 0, 0, 0 } | |||
501 | }; | |||
502 | ||||
503 | } | |||
504 | ||||
505 | extern "C" | |||
506 | { | |||
507 | ||||
508 | SAL_DLLPUBLIC_EXPORT__attribute__ ((visibility("default"))) sal_Bool SAL_CALL component_canUnload( TimeValue * pTime ) | |||
509 | { | |||
510 | return g_moduleCount.canUnload( &g_moduleCount, pTime ); | |||
511 | } | |||
512 | ||||
513 | SAL_DLLPUBLIC_EXPORT__attribute__ ((visibility("default"))) void * SAL_CALL component_getFactory( | |||
514 | const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey ) | |||
515 | { | |||
516 | return ::cppu::component_getFactoryHelper( | |||
517 | pImplName, pServiceManager, pRegistryKey, g_entries ); | |||
518 | } | |||
519 | ||||
520 | } | |||
521 | ||||
522 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |