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 :
21 : #include "cppu/EnvDcp.hxx"
22 :
23 : #include "sal/alloca.h"
24 : #include "sal/log.hxx"
25 : #include "osl/diagnose.h"
26 : #include "osl/interlck.h"
27 : #include "osl/mutex.hxx"
28 : #include "osl/module.h"
29 : #include "osl/process.h"
30 : #include "rtl/process.h"
31 : #include "rtl/unload.h"
32 : #include "rtl/string.hxx"
33 : #include "rtl/ustring.hxx"
34 : #include "rtl/ustrbuf.hxx"
35 : #include "rtl/instance.hxx"
36 : #include "typelib/typedescription.h"
37 : #include "uno/dispatcher.h"
38 : #include "uno/environment.h"
39 : #include "uno/lbnames.h"
40 : #include "prim.hxx"
41 : #include "destr.hxx"
42 : #include "loadmodule.hxx"
43 :
44 : #include <boost/unordered_map.hpp>
45 : #include <vector>
46 : #include <stdio.h>
47 :
48 :
49 : using ::rtl::OUString;
50 :
51 : namespace
52 : {
53 :
54 : //------------------------------------------------------------------------------
55 19348 : inline static bool td_equals( typelib_InterfaceTypeDescription * pTD1,
56 : typelib_InterfaceTypeDescription * pTD2 )
57 : {
58 : return (pTD1 == pTD2 ||
59 : (((typelib_TypeDescription *)pTD1)->pTypeName->length ==
60 : ((typelib_TypeDescription *)pTD2)->pTypeName->length &&
61 : ::rtl_ustr_compare(
62 : ((typelib_TypeDescription *) pTD1)->pTypeName->buffer,
63 19348 : ((typelib_TypeDescription *) pTD2)->pTypeName->buffer ) == 0));
64 : }
65 :
66 : struct ObjectEntry;
67 : struct uno_DefaultEnvironment;
68 :
69 : //------------------------------------------------------------------------------
70 : struct InterfaceEntry
71 : {
72 : sal_Int32 refCount;
73 : void * pInterface;
74 : uno_freeProxyFunc fpFreeProxy;
75 : typelib_InterfaceTypeDescription * pTypeDescr;
76 : };
77 :
78 27360 : struct ObjectEntry
79 : {
80 : OUString oid;
81 : sal_Int32 nRef;
82 : ::std::vector< InterfaceEntry > aInterfaces;
83 : bool mixedObject;
84 :
85 : inline ObjectEntry( const OUString & rOId_ );
86 :
87 : inline void append(
88 : uno_DefaultEnvironment * pEnv,
89 : void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr,
90 : uno_freeProxyFunc fpFreeProxy );
91 : inline InterfaceEntry * find(
92 : typelib_InterfaceTypeDescription * pTypeDescr );
93 : inline sal_Int32 find( void * iface_ptr, ::std::size_t pos );
94 : };
95 :
96 : //------------------------------------------------------------------------------
97 : struct FctPtrHash :
98 : public ::std::unary_function< const void *, ::std::size_t >
99 : {
100 103504 : ::std::size_t operator () ( const void * pKey ) const
101 103504 : { return (::std::size_t) pKey; }
102 : };
103 :
104 : //------------------------------------------------------------------------------
105 : struct FctOUStringHash :
106 : public ::std::unary_function< const OUString &, ::std::size_t >
107 : {
108 117989 : ::std::size_t operator () ( const OUString & rKey ) const
109 117989 : { return rKey.hashCode(); }
110 : };
111 :
112 : // mapping from environment name to environment
113 : typedef ::boost::unordered_map<
114 : OUString, uno_Environment *, FctOUStringHash,
115 : ::std::equal_to< OUString > > OUString2EnvironmentMap;
116 :
117 : // mapping from ptr to object entry
118 : typedef ::boost::unordered_map<
119 : void *, ObjectEntry *, FctPtrHash,
120 : ::std::equal_to< void * > > Ptr2ObjectMap;
121 : // mapping from oid to object entry
122 : typedef ::boost::unordered_map<
123 : OUString, ObjectEntry *, FctOUStringHash,
124 : ::std::equal_to< OUString > > OId2ObjectMap;
125 :
126 :
127 : //==============================================================================
128 : struct EnvironmentsData
129 : {
130 : ::osl::Mutex mutex;
131 : OUString2EnvironmentMap aName2EnvMap;
132 :
133 114 : EnvironmentsData() : isDisposing(false) {}
134 : ~EnvironmentsData();
135 :
136 : inline void getEnvironment(
137 : uno_Environment ** ppEnv, const OUString & rEnvDcp, void * pContext );
138 : inline void registerEnvironment( uno_Environment ** ppEnv );
139 : inline void getRegisteredEnvironments(
140 : uno_Environment *** pppEnvs, sal_Int32 * pnLen,
141 : uno_memAlloc memAlloc, const OUString & rEnvDcp );
142 :
143 : bool isDisposing;
144 : };
145 :
146 : namespace
147 : {
148 : struct theEnvironmentsData : public rtl::Static< EnvironmentsData, theEnvironmentsData > {};
149 : }
150 :
151 : //==============================================================================
152 : struct uno_DefaultEnvironment : public uno_ExtEnvironment
153 : {
154 : sal_Int32 nRef;
155 : sal_Int32 nWeakRef;
156 :
157 : ::osl::Mutex mutex;
158 : Ptr2ObjectMap aPtr2ObjectMap;
159 : OId2ObjectMap aOId2ObjectMap;
160 :
161 : uno_DefaultEnvironment(
162 : const OUString & rEnvDcp_, void * pContext_ );
163 : ~uno_DefaultEnvironment();
164 : };
165 :
166 : //______________________________________________________________________________
167 27362 : inline ObjectEntry::ObjectEntry( OUString const & rOId_ )
168 : : oid( rOId_ ),
169 : nRef( 0 ),
170 27362 : mixedObject( false )
171 : {
172 27362 : aInterfaces.reserve( 2 );
173 27362 : }
174 :
175 : //______________________________________________________________________________
176 28410 : inline void ObjectEntry::append(
177 : uno_DefaultEnvironment * pEnv,
178 : void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr,
179 : uno_freeProxyFunc fpFreeProxy )
180 : {
181 : InterfaceEntry aNewEntry;
182 28410 : if (! fpFreeProxy)
183 13966 : (*pEnv->acquireInterface)( pEnv, pInterface );
184 28410 : aNewEntry.refCount = 1;
185 28410 : aNewEntry.pInterface = pInterface;
186 28410 : aNewEntry.fpFreeProxy = fpFreeProxy;
187 28410 : typelib_typedescription_acquire( (typelib_TypeDescription *) pTypeDescr );
188 28410 : aNewEntry.pTypeDescr = pTypeDescr;
189 :
190 : ::std::pair< Ptr2ObjectMap::iterator, bool > i(
191 : pEnv->aPtr2ObjectMap.insert( Ptr2ObjectMap::value_type(
192 28410 : pInterface, this ) ) );
193 : SAL_WARN_IF(
194 : !i.second && (find(pInterface, 0) == -1 || i.first->second != this),
195 : "cppu",
196 : "map already contains " << i.first->second << " != " << this << " for "
197 : << pInterface);
198 28410 : aInterfaces.push_back( aNewEntry );
199 28410 : }
200 :
201 : //______________________________________________________________________________
202 12507 : inline InterfaceEntry * ObjectEntry::find(
203 : typelib_InterfaceTypeDescription * pTypeDescr_ )
204 : {
205 : OSL_ASSERT( ! aInterfaces.empty() );
206 12507 : if (aInterfaces.empty())
207 0 : return 0;
208 :
209 : // shortcut common case:
210 : OUString const & type_name =
211 : OUString::unacquired(
212 12507 : &((typelib_TypeDescription *) pTypeDescr_)->pTypeName );
213 12507 : if ( type_name == "com.sun.star.uno.XInterface" )
214 : {
215 7259 : return &aInterfaces[ 0 ];
216 : }
217 :
218 5248 : ::std::size_t nSize = aInterfaces.size();
219 13732 : for ( ::std::size_t nPos = 0; nPos < nSize; ++nPos )
220 : {
221 : typelib_InterfaceTypeDescription * pITD =
222 11371 : aInterfaces[ nPos ].pTypeDescr;
223 39203 : while (pITD)
224 : {
225 19348 : if (td_equals( pITD, pTypeDescr_ ))
226 2887 : return &aInterfaces[ nPos ];
227 16461 : pITD = pITD->pBaseTypeDescription;
228 : }
229 : }
230 2361 : return 0;
231 : }
232 :
233 : //______________________________________________________________________________
234 632 : inline sal_Int32 ObjectEntry::find(
235 : void * iface_ptr, ::std::size_t pos )
236 : {
237 632 : ::std::size_t size = aInterfaces.size();
238 1070 : for ( ; pos < size; ++pos )
239 : {
240 794 : if (aInterfaces[ pos ].pInterface == iface_ptr)
241 356 : return pos;
242 : }
243 276 : return -1;
244 : }
245 :
246 : extern "C"
247 : {
248 :
249 : //------------------------------------------------------------------------------
250 14727 : static void SAL_CALL defenv_registerInterface(
251 : uno_ExtEnvironment * pEnv, void ** ppInterface,
252 : rtl_uString * pOId, typelib_InterfaceTypeDescription * pTypeDescr )
253 : {
254 : OSL_ENSURE( pEnv && ppInterface && pOId && pTypeDescr, "### null ptr!" );
255 14727 : OUString const & rOId = OUString::unacquired( &pOId );
256 :
257 : uno_DefaultEnvironment * that =
258 14727 : static_cast< uno_DefaultEnvironment * >( pEnv );
259 14727 : ::osl::ClearableMutexGuard guard( that->mutex );
260 :
261 : // try to insert dummy 0:
262 : std::pair<OId2ObjectMap::iterator, bool> const insertion(
263 14727 : that->aOId2ObjectMap.insert( OId2ObjectMap::value_type( rOId, (ObjectEntry*)0 ) ) );
264 14727 : if (insertion.second)
265 : {
266 13652 : ObjectEntry * pOEntry = new ObjectEntry( rOId );
267 13652 : insertion.first->second = pOEntry;
268 13652 : ++pOEntry->nRef; // another register call on object
269 13652 : pOEntry->append( that, *ppInterface, pTypeDescr, 0 );
270 : }
271 : else // object entry exists
272 : {
273 1075 : ObjectEntry * pOEntry = insertion.first->second;
274 1075 : ++pOEntry->nRef; // another register call on object
275 1075 : InterfaceEntry * pIEntry = pOEntry->find( pTypeDescr );
276 :
277 1075 : if (pIEntry) // type entry exists
278 : {
279 761 : ++pIEntry->refCount;
280 761 : if (pIEntry->pInterface != *ppInterface)
281 : {
282 0 : void * pInterface = pIEntry->pInterface;
283 0 : (*pEnv->acquireInterface)( pEnv, pInterface );
284 0 : guard.clear();
285 0 : (*pEnv->releaseInterface)( pEnv, *ppInterface );
286 0 : *ppInterface = pInterface;
287 : }
288 : }
289 : else
290 : {
291 314 : pOEntry->append( that, *ppInterface, pTypeDescr, 0 );
292 : }
293 14727 : }
294 14727 : }
295 :
296 : //------------------------------------------------------------------------------
297 14755 : static void SAL_CALL defenv_registerProxyInterface(
298 : uno_ExtEnvironment * pEnv, void ** ppInterface, uno_freeProxyFunc freeProxy,
299 : rtl_uString * pOId, typelib_InterfaceTypeDescription * pTypeDescr )
300 : {
301 : OSL_ENSURE( pEnv && ppInterface && pOId && pTypeDescr && freeProxy,
302 : "### null ptr!" );
303 14755 : OUString const & rOId = OUString::unacquired( &pOId );
304 :
305 : uno_DefaultEnvironment * that =
306 14755 : static_cast< uno_DefaultEnvironment * >( pEnv );
307 14755 : ::osl::ClearableMutexGuard guard( that->mutex );
308 :
309 : // try to insert dummy 0:
310 : std::pair<OId2ObjectMap::iterator, bool> const insertion(
311 14755 : that->aOId2ObjectMap.insert( OId2ObjectMap::value_type( rOId, (ObjectEntry*)0 ) ) );
312 14755 : if (insertion.second)
313 : {
314 13710 : ObjectEntry * pOEntry = new ObjectEntry( rOId );
315 13710 : insertion.first->second = pOEntry;
316 13710 : ++pOEntry->nRef; // another register call on object
317 13710 : pOEntry->append( that, *ppInterface, pTypeDescr, freeProxy );
318 : }
319 : else // object entry exists
320 : {
321 1045 : ObjectEntry * pOEntry = insertion.first->second;
322 :
323 : // first registration was an original, then registerProxyInterface():
324 : pOEntry->mixedObject |=
325 1045 : (!pOEntry->aInterfaces.empty() &&
326 1045 : pOEntry->aInterfaces[ 0 ].fpFreeProxy == 0);
327 :
328 1045 : ++pOEntry->nRef; // another register call on object
329 1045 : InterfaceEntry * pIEntry = pOEntry->find( pTypeDescr );
330 :
331 1045 : if (pIEntry) // type entry exists
332 : {
333 311 : if (pIEntry->pInterface == *ppInterface)
334 : {
335 299 : ++pIEntry->refCount;
336 : }
337 : else
338 : {
339 12 : void * pInterface = pIEntry->pInterface;
340 12 : (*pEnv->acquireInterface)( pEnv, pInterface );
341 12 : --pOEntry->nRef; // manual revoke of proxy to be freed
342 12 : guard.clear();
343 12 : (*freeProxy)( pEnv, *ppInterface );
344 12 : *ppInterface = pInterface;
345 : }
346 : }
347 : else
348 : {
349 734 : pOEntry->append( that, *ppInterface, pTypeDescr, freeProxy );
350 : }
351 14755 : }
352 14755 : }
353 :
354 : //------------------------------------------------------------------------------
355 29468 : static void SAL_CALL s_stub_defenv_revokeInterface(va_list * pParam)
356 : {
357 29468 : uno_ExtEnvironment * pEnv = va_arg(*pParam, uno_ExtEnvironment *);
358 29468 : void * pInterface = va_arg(*pParam, void *);
359 :
360 : OSL_ENSURE( pEnv && pInterface, "### null ptr!" );
361 : uno_DefaultEnvironment * that =
362 29468 : static_cast< uno_DefaultEnvironment * >( pEnv );
363 29468 : ::osl::ClearableMutexGuard guard( that->mutex );
364 :
365 : Ptr2ObjectMap::const_iterator const iFind(
366 29468 : that->aPtr2ObjectMap.find( pInterface ) );
367 : OSL_ASSERT( iFind != that->aPtr2ObjectMap.end() );
368 29468 : ObjectEntry * pOEntry = iFind->second;
369 29468 : if (! --pOEntry->nRef)
370 : {
371 : // cleanup maps
372 27360 : that->aOId2ObjectMap.erase( pOEntry->oid );
373 : sal_Int32 nPos;
374 82852 : for ( nPos = pOEntry->aInterfaces.size(); nPos--; )
375 : {
376 28132 : that->aPtr2ObjectMap.erase( pOEntry->aInterfaces[nPos].pInterface );
377 : }
378 :
379 : // the last proxy interface of the environment might kill this
380 : // environment, because of releasing its language binding!!!
381 27360 : guard.clear();
382 :
383 : // release interfaces
384 82852 : for ( nPos = pOEntry->aInterfaces.size(); nPos--; )
385 : {
386 28132 : InterfaceEntry const & rEntry = pOEntry->aInterfaces[nPos];
387 : typelib_typedescription_release(
388 28132 : (typelib_TypeDescription *) rEntry.pTypeDescr );
389 28132 : if (rEntry.fpFreeProxy) // is proxy or used interface?
390 : {
391 14167 : (*rEntry.fpFreeProxy)( pEnv, rEntry.pInterface );
392 : }
393 : else
394 : {
395 13965 : (*pEnv->releaseInterface)( pEnv, rEntry.pInterface );
396 : }
397 : }
398 :
399 27360 : delete pOEntry;
400 : }
401 2108 : else if (pOEntry->mixedObject)
402 : {
403 : OSL_ASSERT( !pOEntry->aInterfaces.empty() &&
404 : pOEntry->aInterfaces[ 0 ].fpFreeProxy == 0 );
405 :
406 356 : sal_Int32 index = pOEntry->find( pInterface, 1 );
407 : OSL_ASSERT( index > 0 );
408 356 : if (index > 0)
409 : {
410 356 : InterfaceEntry & entry = pOEntry->aInterfaces[ index ];
411 : OSL_ASSERT( entry.pInterface == pInterface );
412 356 : if (entry.fpFreeProxy != 0)
413 : {
414 276 : --entry.refCount;
415 276 : if (entry.refCount == 0)
416 : {
417 276 : uno_freeProxyFunc fpFreeProxy = entry.fpFreeProxy;
418 : typelib_TypeDescription * pTypeDescr =
419 : reinterpret_cast< typelib_TypeDescription * >(
420 276 : entry.pTypeDescr );
421 :
422 : pOEntry->aInterfaces.erase(
423 276 : pOEntry->aInterfaces.begin() + index );
424 276 : if (pOEntry->find( pInterface, index ) < 0)
425 : {
426 : // proxy ptr not registered for another interface:
427 : // remove from ptr map
428 : #if OSL_DEBUG_LEVEL > 0
429 : ::std::size_t erased =
430 : #endif
431 276 : that->aPtr2ObjectMap.erase( pInterface );
432 : OSL_ASSERT( erased == 1 );
433 : }
434 :
435 276 : guard.clear();
436 :
437 276 : typelib_typedescription_release( pTypeDescr );
438 276 : (*fpFreeProxy)( pEnv, pInterface );
439 : }
440 : }
441 : }
442 29468 : }
443 29468 : }
444 :
445 29468 : static void SAL_CALL defenv_revokeInterface(uno_ExtEnvironment * pEnv, void * pInterface)
446 : {
447 29468 : uno_Environment_invoke(&pEnv->aBase, s_stub_defenv_revokeInterface, pEnv, pInterface);
448 29468 : }
449 :
450 : //------------------------------------------------------------------------------
451 23502 : static void SAL_CALL defenv_getObjectIdentifier(
452 : uno_ExtEnvironment * pEnv, rtl_uString ** ppOId, void * pInterface )
453 : {
454 : OSL_ENSURE( pEnv && ppOId && pInterface, "### null ptr!" );
455 23502 : if (*ppOId)
456 : {
457 1271 : ::rtl_uString_release( *ppOId );
458 1271 : *ppOId = 0;
459 : }
460 :
461 : uno_DefaultEnvironment * that =
462 23502 : static_cast< uno_DefaultEnvironment * >( pEnv );
463 23502 : ::osl::ClearableMutexGuard guard( that->mutex );
464 :
465 : Ptr2ObjectMap::const_iterator const iFind(
466 23502 : that->aPtr2ObjectMap.find( pInterface ) );
467 23502 : if (iFind == that->aPtr2ObjectMap.end())
468 : {
469 13973 : guard.clear();
470 13973 : (*pEnv->computeObjectIdentifier)( pEnv, ppOId, pInterface );
471 : }
472 : else
473 : {
474 9529 : rtl_uString * hstr = iFind->second->oid.pData;
475 9529 : rtl_uString_acquire( hstr );
476 9529 : *ppOId = hstr;
477 23502 : }
478 23502 : }
479 :
480 : //------------------------------------------------------------------------------
481 24169 : static void SAL_CALL defenv_getRegisteredInterface(
482 : uno_ExtEnvironment * pEnv, void ** ppInterface,
483 : rtl_uString * pOId, typelib_InterfaceTypeDescription * pTypeDescr )
484 : {
485 : OSL_ENSURE( pEnv && ppInterface && pOId && pTypeDescr, "### null ptr!" );
486 24169 : if (*ppInterface)
487 : {
488 0 : (*pEnv->releaseInterface)( pEnv, *ppInterface );
489 0 : *ppInterface = 0;
490 : }
491 :
492 24169 : OUString const & rOId = OUString::unacquired( &pOId );
493 : uno_DefaultEnvironment * that =
494 24169 : static_cast< uno_DefaultEnvironment * >( pEnv );
495 24169 : ::osl::MutexGuard guard( that->mutex );
496 :
497 : OId2ObjectMap::const_iterator const iFind
498 24169 : ( that->aOId2ObjectMap.find( rOId ) );
499 24169 : if (iFind != that->aOId2ObjectMap.end())
500 : {
501 10387 : InterfaceEntry const * pIEntry = iFind->second->find( pTypeDescr );
502 10387 : if (pIEntry)
503 : {
504 9074 : (*pEnv->acquireInterface)( pEnv, pIEntry->pInterface );
505 9074 : *ppInterface = pIEntry->pInterface;
506 : }
507 24169 : }
508 24169 : }
509 :
510 : //------------------------------------------------------------------------------
511 0 : static void SAL_CALL defenv_getRegisteredInterfaces(
512 : uno_ExtEnvironment * pEnv, void *** pppInterfaces, sal_Int32 * pnLen,
513 : uno_memAlloc memAlloc )
514 : {
515 : OSL_ENSURE( pEnv && pppInterfaces && pnLen && memAlloc, "### null ptr!" );
516 : uno_DefaultEnvironment * that =
517 0 : static_cast< uno_DefaultEnvironment * >( pEnv );
518 0 : ::osl::MutexGuard guard( that->mutex );
519 :
520 0 : sal_Int32 nLen = that->aPtr2ObjectMap.size();
521 0 : sal_Int32 nPos = 0;
522 0 : void ** ppInterfaces = (void **) (*memAlloc)( nLen * sizeof (void *) );
523 :
524 0 : Ptr2ObjectMap::const_iterator iPos( that->aPtr2ObjectMap.begin() );
525 0 : Ptr2ObjectMap::const_iterator const iEnd( that->aPtr2ObjectMap.end() );
526 0 : while (iPos != iEnd)
527 : {
528 0 : (*pEnv->acquireInterface)( pEnv, ppInterfaces[nPos++] = (*iPos).first );
529 0 : ++iPos;
530 : }
531 :
532 0 : *pppInterfaces = ppInterfaces;
533 0 : *pnLen = nLen;
534 0 : }
535 :
536 : //------------------------------------------------------------------------------
537 120613 : static void SAL_CALL defenv_acquire( uno_Environment * pEnv )
538 : {
539 120613 : uno_DefaultEnvironment * that = (uno_DefaultEnvironment *)pEnv;
540 120613 : osl_atomic_increment( &that->nWeakRef );
541 120613 : osl_atomic_increment( &that->nRef );
542 120613 : }
543 :
544 : //------------------------------------------------------------------------------
545 139612 : static void SAL_CALL defenv_release( uno_Environment * pEnv )
546 : {
547 139612 : uno_DefaultEnvironment * that = (uno_DefaultEnvironment *)pEnv;
548 139612 : if (! osl_atomic_decrement( &that->nRef ))
549 : {
550 : // invoke dispose callback
551 8030 : if (pEnv->environmentDisposing)
552 : {
553 1959 : (*pEnv->environmentDisposing)( pEnv );
554 : }
555 :
556 : OSL_ENSURE( that->aOId2ObjectMap.empty(), "### object entries left!" );
557 : }
558 : // free memory if no weak refs left
559 139612 : if (! osl_atomic_decrement( &that->nWeakRef ))
560 : {
561 4 : delete that;
562 : }
563 139612 : }
564 :
565 : //------------------------------------------------------------------------------
566 8127 : static void SAL_CALL defenv_acquireWeak( uno_Environment * pEnv )
567 : {
568 8127 : uno_DefaultEnvironment * that = (uno_DefaultEnvironment *)pEnv;
569 8127 : osl_atomic_increment( &that->nWeakRef );
570 8127 : }
571 :
572 : //------------------------------------------------------------------------------
573 8127 : static void SAL_CALL defenv_releaseWeak( uno_Environment * pEnv )
574 : {
575 8127 : uno_DefaultEnvironment * that = (uno_DefaultEnvironment *)pEnv;
576 8127 : if (! osl_atomic_decrement( &that->nWeakRef ))
577 : {
578 8026 : delete that;
579 : }
580 8127 : }
581 :
582 : //------------------------------------------------------------------------------
583 35177 : static void SAL_CALL defenv_harden(
584 : uno_Environment ** ppHardEnv, uno_Environment * pEnv )
585 : {
586 35177 : if (*ppHardEnv)
587 : {
588 0 : (*(*ppHardEnv)->release)( *ppHardEnv );
589 0 : *ppHardEnv = 0;
590 : }
591 :
592 35177 : EnvironmentsData & rData = theEnvironmentsData::get();
593 :
594 35177 : if (rData.isDisposing)
595 186 : return;
596 :
597 34991 : uno_DefaultEnvironment * that = (uno_DefaultEnvironment *)pEnv;
598 : {
599 34991 : ::osl::MutexGuard guard( rData.mutex );
600 34991 : if (1 == osl_atomic_increment( &that->nRef )) // is dead
601 : {
602 15882 : that->nRef = 0;
603 : return;
604 34991 : }
605 : }
606 19109 : osl_atomic_increment( &that->nWeakRef );
607 19109 : *ppHardEnv = pEnv;
608 : }
609 :
610 : //------------------------------------------------------------------------------
611 0 : static void SAL_CALL defenv_dispose( SAL_UNUSED_PARAMETER uno_Environment * )
612 : {
613 0 : }
614 : }
615 :
616 : //______________________________________________________________________________
617 8131 : uno_DefaultEnvironment::uno_DefaultEnvironment(
618 : const OUString & rEnvDcp_, void * pContext_ )
619 : : nRef( 0 ),
620 8131 : nWeakRef( 0 )
621 : {
622 8131 : uno_Environment * that = reinterpret_cast< uno_Environment * >(this);
623 8131 : that->pReserved = 0;
624 : // functions
625 8131 : that->acquire = defenv_acquire;
626 8131 : that->release = defenv_release;
627 8131 : that->acquireWeak = defenv_acquireWeak;
628 8131 : that->releaseWeak = defenv_releaseWeak;
629 8131 : that->harden = defenv_harden;
630 8131 : that->dispose = defenv_dispose;
631 8131 : that->pExtEnv = this;
632 : // identifier
633 8131 : ::rtl_uString_acquire( rEnvDcp_.pData );
634 8131 : that->pTypeName = rEnvDcp_.pData;
635 8131 : that->pContext = pContext_;
636 :
637 : // will be late initialized
638 8131 : that->environmentDisposing = 0;
639 :
640 8131 : uno_ExtEnvironment::registerInterface = defenv_registerInterface;
641 8131 : uno_ExtEnvironment::registerProxyInterface = defenv_registerProxyInterface;
642 8131 : uno_ExtEnvironment::revokeInterface = defenv_revokeInterface;
643 8131 : uno_ExtEnvironment::getObjectIdentifier = defenv_getObjectIdentifier;
644 8131 : uno_ExtEnvironment::getRegisteredInterface = defenv_getRegisteredInterface;
645 : uno_ExtEnvironment::getRegisteredInterfaces =
646 8131 : defenv_getRegisteredInterfaces;
647 :
648 8131 : }
649 :
650 : //______________________________________________________________________________
651 16060 : uno_DefaultEnvironment::~uno_DefaultEnvironment()
652 : {
653 8030 : ::rtl_uString_release( ((uno_Environment *) this)->pTypeName );
654 8030 : }
655 :
656 : //==============================================================================
657 0 : static void writeLine(
658 : void * stream, const sal_Char * pLine, const sal_Char * pFilter )
659 : {
660 0 : if (pFilter && *pFilter)
661 : {
662 : // lookup pFilter in pLine
663 0 : while (*pLine)
664 : {
665 0 : if (*pLine == *pFilter)
666 : {
667 0 : sal_Int32 nPos = 1;
668 0 : while (pLine[nPos] && pFilter[nPos] == pLine[nPos])
669 : {
670 0 : ++nPos;
671 : }
672 0 : if (! pFilter[nPos])
673 : {
674 0 : if (stream)
675 : {
676 0 : fprintf( (FILE *) stream, "%s\n", pLine );
677 : }
678 : else
679 : {
680 : OSL_TRACE( "%s", pLine );
681 : }
682 : }
683 : }
684 0 : ++pLine;
685 0 : }
686 : }
687 : else
688 : {
689 0 : if (stream)
690 : {
691 0 : fprintf( (FILE *) stream, "%s\n", pLine );
692 : }
693 : else
694 : {
695 0 : fprintf( stderr, "%s\n", pLine );
696 : }
697 : }
698 0 : }
699 :
700 : //==============================================================================
701 0 : static void writeLine(
702 : void * stream, const OUString & rLine, const sal_Char * pFilter )
703 : {
704 : ::rtl::OString aLine( ::rtl::OUStringToOString(
705 0 : rLine, RTL_TEXTENCODING_ASCII_US ) );
706 0 : writeLine( stream, aLine.getStr(), pFilter );
707 0 : }
708 :
709 : //##############################################################################
710 0 : extern "C" CPPU_DLLPUBLIC void SAL_CALL uno_dumpEnvironment(
711 : void * stream, uno_Environment * pEnv, const sal_Char * pFilter )
712 : SAL_THROW_EXTERN_C()
713 : {
714 : OSL_ENSURE( pEnv, "### null ptr!" );
715 0 : ::rtl::OUStringBuffer buf;
716 :
717 0 : if (! pEnv->pExtEnv)
718 : {
719 : writeLine( stream, "###################################"
720 0 : "###########################################", pFilter );
721 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("environment: ") );
722 0 : buf.append( pEnv->pTypeName );
723 0 : writeLine( stream, buf.makeStringAndClear(), pFilter );
724 0 : writeLine( stream, "NO INTERFACE INFORMATION AVAILABLE!", pFilter );
725 0 : return;
726 : }
727 :
728 : writeLine( stream, "########################################"
729 0 : "######################################", pFilter );
730 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("environment dump: ") );
731 0 : buf.append( pEnv->pTypeName );
732 0 : writeLine( stream, buf.makeStringAndClear(), pFilter );
733 :
734 : uno_DefaultEnvironment * that =
735 0 : reinterpret_cast< uno_DefaultEnvironment * >(pEnv);
736 0 : ::osl::MutexGuard guard( that->mutex );
737 :
738 0 : Ptr2ObjectMap ptr2obj( that->aPtr2ObjectMap );
739 0 : OId2ObjectMap::const_iterator iPos( that->aOId2ObjectMap.begin() );
740 0 : while (iPos != that->aOId2ObjectMap.end())
741 : {
742 0 : ObjectEntry * pOEntry = iPos->second;
743 :
744 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("+ ") );
745 0 : if (pOEntry->mixedObject)
746 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("mixed ") );
747 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("object entry: nRef=") );
748 0 : buf.append( pOEntry->nRef, 10 );
749 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("; oid=\"") );
750 0 : buf.append( pOEntry->oid );
751 0 : buf.append( (sal_Unicode) '\"' );
752 0 : writeLine( stream, buf.makeStringAndClear(), pFilter );
753 :
754 0 : for ( ::std::size_t nPos = 0;
755 0 : nPos < pOEntry->aInterfaces.size(); ++nPos )
756 : {
757 0 : const InterfaceEntry & rIEntry = pOEntry->aInterfaces[nPos];
758 :
759 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" - ") );
760 : buf.append(
761 0 : ((typelib_TypeDescription *) rIEntry.pTypeDescr)->pTypeName );
762 0 : if (rIEntry.fpFreeProxy)
763 : {
764 : buf.appendAscii(
765 0 : RTL_CONSTASCII_STRINGPARAM("; proxy free=0x") );
766 : buf.append(
767 0 : reinterpret_cast< sal_IntPtr >(rIEntry.fpFreeProxy), 16 );
768 : }
769 : else
770 : {
771 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("; original") );
772 : }
773 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("; ptr=0x") );
774 : buf.append(
775 0 : reinterpret_cast< sal_IntPtr >(rIEntry.pInterface), 16 );
776 :
777 0 : if (pOEntry->find( rIEntry.pInterface, nPos + 1 ) < 0)
778 : {
779 0 : ::std::size_t erased = ptr2obj.erase( rIEntry.pInterface );
780 0 : if (erased != 1)
781 : {
782 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(
783 0 : " (ptr not found in map!)") );
784 : }
785 : }
786 0 : writeLine( stream, buf.makeStringAndClear(), pFilter );
787 : }
788 0 : ++iPos;
789 : }
790 0 : if (! ptr2obj.empty())
791 0 : writeLine( stream, "ptr map inconsistency!!!", pFilter );
792 : writeLine( stream, "#####################################"
793 0 : "#########################################", pFilter );
794 : }
795 :
796 : //##############################################################################
797 0 : extern "C" CPPU_DLLPUBLIC void SAL_CALL uno_dumpEnvironmentByName(
798 : void * stream, rtl_uString * pEnvDcp, const sal_Char * pFilter )
799 : SAL_THROW_EXTERN_C()
800 : {
801 0 : uno_Environment * pEnv = 0;
802 0 : uno_getEnvironment( &pEnv, pEnvDcp, 0 );
803 0 : if (pEnv)
804 : {
805 0 : ::uno_dumpEnvironment( stream, pEnv, pFilter );
806 0 : (*pEnv->release)( pEnv );
807 : }
808 : else
809 : {
810 0 : ::rtl::OUStringBuffer buf( 32 );
811 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("environment \"") );
812 0 : buf.append( pEnvDcp );
813 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\" does not exist!") );
814 0 : writeLine( stream, buf.makeStringAndClear(), pFilter );
815 : }
816 0 : }
817 :
818 : namespace
819 : {
820 72 : class makeOIdPart
821 : {
822 : private:
823 : OUString m_sOidPart;
824 : public:
825 72 : makeOIdPart()
826 72 : {
827 72 : ::rtl::OUStringBuffer aRet( 64 );
828 72 : aRet.appendAscii( RTL_CONSTASCII_STRINGPARAM("];") );
829 : // pid
830 : oslProcessInfo info;
831 72 : info.Size = sizeof(oslProcessInfo);
832 72 : if (::osl_getProcessInfo( 0, osl_Process_IDENTIFIER, &info ) ==
833 : osl_Process_E_None)
834 : {
835 72 : aRet.append( (sal_Int64)info.Ident, 16 );
836 : }
837 : else
838 : {
839 : aRet.appendAscii(
840 0 : RTL_CONSTASCII_STRINGPARAM("unknown process id") );
841 : }
842 : // good guid
843 : sal_uInt8 ar[16];
844 72 : ::rtl_getGlobalProcessId( ar );
845 72 : aRet.append( (sal_Unicode)';' );
846 1224 : for ( sal_Int32 i = 0; i < 16; ++i )
847 1152 : aRet.append( (sal_Int32)ar[i], 16 );
848 :
849 72 : m_sOidPart = aRet.makeStringAndClear();
850 72 : }
851 5995 : const OUString& getOIdPart() const { return m_sOidPart; }
852 : };
853 :
854 : class theStaticOIdPart : public rtl::Static<makeOIdPart, theStaticOIdPart> {};
855 : }
856 :
857 : //------------------------------------------------------------------------------
858 5995 : inline static const OUString & unoenv_getStaticOIdPart()
859 : {
860 5995 : return theStaticOIdPart::get().getOIdPart();
861 : }
862 :
863 : extern "C"
864 : {
865 :
866 : //------------------------------------------------------------------------------
867 5995 : static void SAL_CALL unoenv_computeObjectIdentifier(
868 : uno_ExtEnvironment * pEnv, rtl_uString ** ppOId, void * pInterface )
869 : {
870 : OSL_ENSURE( pEnv && ppOId && pInterface, "### null ptr!" );
871 5995 : if (*ppOId)
872 : {
873 0 : ::rtl_uString_release( *ppOId );
874 0 : *ppOId = 0;
875 : }
876 :
877 : uno_Interface * pUnoI = (uno_Interface *)
878 : ::cppu::binuno_queryInterface(
879 : pInterface, *typelib_static_type_getByTypeClass(
880 5995 : typelib_TypeClass_INTERFACE ) );
881 5995 : if (0 != pUnoI)
882 : {
883 5995 : (*pUnoI->release)( pUnoI );
884 : // interface
885 5995 : ::rtl::OUStringBuffer oid( 64 );
886 5995 : oid.append( reinterpret_cast< sal_Int64 >(pUnoI), 16 );
887 5995 : oid.append( static_cast< sal_Unicode >(';') );
888 : // environment[context]
889 5995 : oid.append( ((uno_Environment *) pEnv)->pTypeName );
890 5995 : oid.append( static_cast< sal_Unicode >('[') );
891 : oid.append( reinterpret_cast< sal_Int64 >(
892 : reinterpret_cast<
893 5995 : uno_Environment * >(pEnv)->pContext ), 16 );
894 : // process;good guid
895 5995 : oid.append( unoenv_getStaticOIdPart() );
896 5995 : OUString aStr( oid.makeStringAndClear() );
897 5995 : ::rtl_uString_acquire( *ppOId = aStr.pData );
898 : }
899 5995 : }
900 :
901 : //==============================================================================
902 6898 : static void SAL_CALL unoenv_acquireInterface(
903 : SAL_UNUSED_PARAMETER uno_ExtEnvironment *, void * pUnoI_ )
904 : {
905 6898 : uno_Interface * pUnoI = reinterpret_cast< uno_Interface * >(pUnoI_);
906 6898 : (*pUnoI->acquire)( pUnoI );
907 6898 : }
908 :
909 : //==============================================================================
910 6005 : static void SAL_CALL unoenv_releaseInterface(
911 : SAL_UNUSED_PARAMETER uno_ExtEnvironment *, void * pUnoI_ )
912 : {
913 6005 : uno_Interface * pUnoI = reinterpret_cast< uno_Interface * >(pUnoI_);
914 6005 : (*pUnoI->release)( pUnoI );
915 6005 : }
916 : }
917 :
918 : //______________________________________________________________________________
919 228 : EnvironmentsData::~EnvironmentsData()
920 : {
921 114 : ::osl::MutexGuard guard( mutex );
922 114 : isDisposing = true;
923 :
924 900 : for ( OUString2EnvironmentMap::const_iterator iPos( aName2EnvMap.begin() );
925 600 : iPos != aName2EnvMap.end(); ++iPos )
926 : {
927 186 : uno_Environment * pWeak = iPos->second;
928 186 : uno_Environment * pHard = 0;
929 186 : (*pWeak->harden)( &pHard, pWeak );
930 186 : (*pWeak->releaseWeak)( pWeak );
931 :
932 186 : if (pHard)
933 : {
934 : #if OSL_DEBUG_LEVEL > 1
935 : ::uno_dumpEnvironment( 0, pHard, 0 );
936 : #endif
937 0 : (*pHard->dispose)( pHard ); // send explicit dispose
938 0 : (*pHard->release)( pHard );
939 : }
940 114 : }
941 114 : }
942 :
943 : //______________________________________________________________________________
944 27236 : inline void EnvironmentsData::getEnvironment(
945 : uno_Environment ** ppEnv, const OUString & rEnvDcp, void * pContext )
946 : {
947 27236 : if (*ppEnv)
948 : {
949 0 : (*(*ppEnv)->release)( *ppEnv );
950 0 : *ppEnv = 0;
951 : }
952 :
953 : OUString aKey(
954 27236 : OUString::valueOf( reinterpret_cast< sal_IntPtr >(pContext) ) );
955 27236 : aKey += rEnvDcp;
956 :
957 : // try to find registered mapping
958 : OUString2EnvironmentMap::const_iterator const iFind(
959 27236 : aName2EnvMap.find( aKey ) );
960 27236 : if (iFind != aName2EnvMap.end())
961 : {
962 27050 : uno_Environment * pWeak = iFind->second;
963 27050 : (*pWeak->harden)( ppEnv, pWeak );
964 27236 : }
965 27236 : }
966 :
967 : //______________________________________________________________________________
968 8127 : inline void EnvironmentsData::registerEnvironment( uno_Environment ** ppEnv )
969 : {
970 : OSL_ENSURE( ppEnv, "### null ptr!" );
971 8127 : uno_Environment * pEnv = *ppEnv;
972 :
973 : OUString aKey(
974 8127 : OUString::valueOf( reinterpret_cast< sal_IntPtr >(pEnv->pContext) ) );
975 8127 : aKey += pEnv->pTypeName;
976 :
977 : // try to find registered environment
978 : OUString2EnvironmentMap::const_iterator const iFind(
979 8127 : aName2EnvMap.find( aKey ) );
980 8127 : if (iFind == aName2EnvMap.end())
981 : {
982 186 : (*pEnv->acquireWeak)( pEnv );
983 : ::std::pair< OUString2EnvironmentMap::iterator, bool > insertion (
984 : aName2EnvMap.insert(
985 186 : OUString2EnvironmentMap::value_type( aKey, pEnv ) ) );
986 : SAL_WARN_IF( !insertion.second, "cppu", "key " << aKey << " already in env map" );
987 : }
988 : else
989 : {
990 7941 : uno_Environment * pHard = 0;
991 7941 : uno_Environment * pWeak = iFind->second;
992 7941 : (*pWeak->harden)( &pHard, pWeak );
993 7941 : if (pHard)
994 : {
995 0 : if (pEnv)
996 0 : (*pEnv->release)( pEnv );
997 0 : *ppEnv = pHard;
998 : }
999 : else // registered one is dead
1000 : {
1001 7941 : (*pWeak->releaseWeak)( pWeak );
1002 7941 : (*pEnv->acquireWeak)( pEnv );
1003 7941 : aName2EnvMap[ aKey ] = pEnv;
1004 : }
1005 8127 : }
1006 8127 : }
1007 :
1008 : //______________________________________________________________________________
1009 0 : inline void EnvironmentsData::getRegisteredEnvironments(
1010 : uno_Environment *** pppEnvs, sal_Int32 * pnLen, uno_memAlloc memAlloc,
1011 : const OUString & rEnvDcp )
1012 : {
1013 : OSL_ENSURE( pppEnvs && pnLen && memAlloc, "### null ptr!" );
1014 :
1015 : // max size
1016 0 : uno_Environment ** ppFound = (uno_Environment **)alloca(
1017 : sizeof(uno_Environment *) * aName2EnvMap.size() );
1018 0 : sal_Int32 nSize = 0;
1019 :
1020 : // find matching environment
1021 0 : for ( OUString2EnvironmentMap::const_iterator iPos( aName2EnvMap.begin() );
1022 0 : iPos != aName2EnvMap.end(); ++iPos )
1023 : {
1024 0 : uno_Environment * pWeak = iPos->second;
1025 0 : if (rEnvDcp.isEmpty() ||
1026 0 : rEnvDcp.equals( pWeak->pTypeName ))
1027 : {
1028 0 : ppFound[nSize] = 0;
1029 0 : (*pWeak->harden)( &ppFound[nSize], pWeak );
1030 0 : if (ppFound[nSize])
1031 0 : ++nSize;
1032 : }
1033 : }
1034 :
1035 0 : *pnLen = nSize;
1036 0 : if (nSize)
1037 : {
1038 : *pppEnvs = (uno_Environment **) (*memAlloc)(
1039 0 : sizeof (uno_Environment *) * nSize );
1040 : OSL_ASSERT( *pppEnvs );
1041 0 : while (nSize--)
1042 : {
1043 0 : (*pppEnvs)[nSize] = ppFound[nSize];
1044 : }
1045 : }
1046 : else
1047 : {
1048 0 : *pppEnvs = 0;
1049 : }
1050 0 : }
1051 :
1052 2057 : static bool loadEnv(OUString const & cLibStem,
1053 : uno_Environment * pEnv)
1054 : {
1055 : #ifdef DISABLE_DYNLOADING
1056 : oslModule hMod;
1057 : uno_initEnvironmentFunc fpInit;
1058 :
1059 : if ( cLibStem == CPPU_CURRENT_LANGUAGE_BINDING_NAME "_uno" )
1060 : fpInit = CPPU_ENV_uno_initEnvironment;
1061 : #ifdef SOLAR_JAVA
1062 : else if ( cLibStem == "java_uno" )
1063 : fpInit = java_uno_initEnvironment;
1064 : #endif
1065 : else
1066 : {
1067 : #if OSL_DEBUG_LEVEL > 1
1068 : OSL_TRACE( "%s: Unhandled env: %s", __PRETTY_FUNCTION__, OUStringToOString( cLibStem, RTL_TEXTENCODING_ASCII_US).getStr() );
1069 : #endif
1070 : return false;
1071 : }
1072 : // In the DISABLE_DYNLOADING case the functions that hMod is
1073 : // passed to below don't do anything with it anyway.
1074 : hMod = 0;
1075 : #else
1076 : // late init with some code from matching uno language binding
1077 : // will be unloaded by environment
1078 2057 : oslModule hMod = cppu::detail::loadModule( cLibStem );
1079 :
1080 2057 : if (!hMod)
1081 0 : return false;
1082 :
1083 2057 : OUString aSymbolName(RTL_CONSTASCII_USTRINGPARAM(UNO_INIT_ENVIRONMENT));
1084 : uno_initEnvironmentFunc fpInit = (uno_initEnvironmentFunc)
1085 2057 : ::osl_getFunctionSymbol( hMod, aSymbolName.pData );
1086 :
1087 2057 : if (!fpInit)
1088 : {
1089 0 : ::osl_unloadModule( hMod );
1090 0 : return false;
1091 : }
1092 : #endif
1093 :
1094 2057 : (*fpInit)( pEnv ); // init of environment
1095 2057 : ::rtl_registerModuleForUnloading( hMod );
1096 :
1097 2057 : return true;
1098 : }
1099 :
1100 :
1101 : extern "C"
1102 : {
1103 :
1104 : //------------------------------------------------------------------------------
1105 8131 : static uno_Environment * initDefaultEnvironment(
1106 : const OUString & rEnvDcp, void * pContext )
1107 : {
1108 8131 : uno_Environment * pEnv = &(new uno_DefaultEnvironment( rEnvDcp, pContext ))->aBase;
1109 8131 : (*pEnv->acquire)( pEnv );
1110 :
1111 8131 : OUString envTypeName = cppu::EnvDcp::getTypeName(rEnvDcp);
1112 :
1113 : // create default environment
1114 8131 : if ( envTypeName == UNO_LB_UNO )
1115 : {
1116 6074 : uno_DefaultEnvironment * that = (uno_DefaultEnvironment *)pEnv;
1117 6074 : that->computeObjectIdentifier = unoenv_computeObjectIdentifier;
1118 6074 : that->acquireInterface = unoenv_acquireInterface;
1119 6074 : that->releaseInterface = unoenv_releaseInterface;
1120 :
1121 6074 : OUString envPurpose = cppu::EnvDcp::getPurpose(rEnvDcp);
1122 6074 : if (!envPurpose.isEmpty())
1123 : {
1124 0 : rtl::OUString libStem = envPurpose.copy(envPurpose.lastIndexOf(':') + 1);
1125 0 : libStem += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("_uno_uno") );
1126 :
1127 0 : if(!loadEnv(libStem, pEnv))
1128 : {
1129 0 : pEnv->release(pEnv);
1130 0 : return NULL;
1131 0 : }
1132 6074 : }
1133 : }
1134 : else
1135 : {
1136 : // late init with some code from matching uno language binding
1137 2057 : ::rtl::OUStringBuffer aLibName( 16 );
1138 2057 : aLibName.append( envTypeName );
1139 2057 : aLibName.appendAscii( RTL_CONSTASCII_STRINGPARAM("_uno" ) );
1140 2057 : OUString aStr( aLibName.makeStringAndClear() );
1141 :
1142 2057 : if (!loadEnv(aStr, pEnv))
1143 : {
1144 0 : pEnv->release(pEnv);
1145 0 : return NULL;
1146 2057 : }
1147 : }
1148 :
1149 8131 : return pEnv;
1150 : }
1151 :
1152 : //##############################################################################
1153 4 : CPPU_DLLPUBLIC void SAL_CALL uno_createEnvironment(
1154 : uno_Environment ** ppEnv, rtl_uString * pEnvDcp, void * pContext )
1155 : SAL_THROW_EXTERN_C()
1156 : {
1157 : OSL_ENSURE( ppEnv, "### null ptr!" );
1158 4 : if (*ppEnv)
1159 0 : (*(*ppEnv)->release)( *ppEnv );
1160 :
1161 4 : OUString const & rEnvDcp = OUString::unacquired( &pEnvDcp );
1162 4 : *ppEnv = initDefaultEnvironment( rEnvDcp, pContext );
1163 4 : }
1164 :
1165 : //##############################################################################
1166 27236 : void SAL_CALL uno_direct_getEnvironment(
1167 : uno_Environment ** ppEnv, rtl_uString * pEnvDcp, void * pContext )
1168 : SAL_THROW_EXTERN_C()
1169 : {
1170 : OSL_ENSURE( ppEnv, "### null ptr!" );
1171 27236 : OUString const & rEnvDcp = OUString::unacquired( &pEnvDcp );
1172 :
1173 27236 : EnvironmentsData & rData = theEnvironmentsData::get();
1174 :
1175 27236 : ::osl::MutexGuard guard( rData.mutex );
1176 27236 : rData.getEnvironment( ppEnv, rEnvDcp, pContext );
1177 27236 : if (! *ppEnv)
1178 : {
1179 8127 : *ppEnv = initDefaultEnvironment( rEnvDcp, pContext );
1180 8127 : if (*ppEnv)
1181 : {
1182 : // register new environment:
1183 8127 : rData.registerEnvironment( ppEnv );
1184 : }
1185 27236 : }
1186 27236 : }
1187 :
1188 : //##############################################################################
1189 0 : CPPU_DLLPUBLIC void SAL_CALL uno_getRegisteredEnvironments(
1190 : uno_Environment *** pppEnvs, sal_Int32 * pnLen, uno_memAlloc memAlloc,
1191 : rtl_uString * pEnvDcp )
1192 : SAL_THROW_EXTERN_C()
1193 : {
1194 0 : EnvironmentsData & rData = theEnvironmentsData::get();
1195 :
1196 0 : ::osl::MutexGuard guard( rData.mutex );
1197 : rData.getRegisteredEnvironments(
1198 : pppEnvs, pnLen, memAlloc,
1199 0 : (pEnvDcp ? OUString(pEnvDcp) : OUString()) );
1200 0 : }
1201 :
1202 : } // extern "C"
1203 :
1204 : }
1205 :
1206 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|