1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: helper_purpenv_Environment.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_cppu.hxx"
34 #include "cppu/helper/purpenv/Environment.hxx"
36 #include "osl/diagnose.h"
37 #include "uno/lbnames.h"
39 #include "typelib/typedescription.h"
40 #include "osl/interlck.h"
43 # define LOG_LIFECYCLE_cppu_helper_purpenv_Base
46 #ifdef LOG_LIFECYCLE_cppu_helper_purpenv_Base
48 # define LOG_LIFECYCLE_cppu_helper_purpenv_Base_emit(x) x
51 # define LOG_LIFECYCLE_cppu_helper_purpenv_Base_emit(x)
57 typedef void SAL_CALL
EnvFun_P (uno_Environment
*);
58 typedef void SAL_CALL
EnvFun_PP_P(uno_Environment
** ppHardEnv
, uno_Environment
*);
59 typedef void SAL_CALL
ExtEnv_registerProxyInterface (uno_ExtEnvironment
*,
61 uno_freeProxyFunc freeProxy
,
63 typelib_InterfaceTypeDescription
* pTypeDescr
);
64 typedef void SAL_CALL
ExtEnv_revokeInterface (uno_ExtEnvironment
*,
66 typedef void SAL_CALL
ExtEnv_getObjectIdentifier (uno_ExtEnvironment
*,
69 typedef void SAL_CALL
ExtEnv_getRegisteredInterface (uno_ExtEnvironment
*,
72 typelib_InterfaceTypeDescription
*);
73 typedef void SAL_CALL
ExtEnv_getRegisteredInterfaces(uno_ExtEnvironment
*,
74 void *** pppInterfaces
,
76 uno_memAlloc memAlloc
);
77 typedef void SAL_CALL
ExtEnv_computeObjectIdentifier(uno_ExtEnvironment
*,
80 typedef void SAL_CALL
ExtEnv_acquireInterface (uno_ExtEnvironment
*,
82 typedef void SAL_CALL
ExtEnv_releaseInterface (uno_ExtEnvironment
*,
86 class Base
: public cppu::Enterable
89 explicit Base(uno_Environment
* pEnv
, cppu::Enterable
* pEnterable
);
91 void acquireWeak(void);
92 void releaseWeak(void);
93 void harden (uno_Environment
** ppHardEnv
);
97 void registerProxyInterface (void ** ppProxy
,
98 uno_freeProxyFunc freeProxy
,
99 rtl::OUString
const & oid
,
100 typelib_InterfaceTypeDescription
* pTypeDescr
);
101 void revokeInterface (void * pInterface
);
102 void getObjectIdentifier (void * pInterface
,
103 rtl::OUString
* pOid
);
104 void getRegisteredInterface (void **,
105 rtl::OUString
const & oid
,
106 typelib_InterfaceTypeDescription
*);
107 void getRegisteredInterfaces(void ***,
109 uno_memAlloc memAlloc
);
110 void computeObjectIdentifier(void * pInterface
,
111 rtl::OUString
* pOid
);
112 void acquireInterface (void * pInterface
);
113 void releaseInterface (void * pInterface
);
115 virtual void v_enter (void);
116 virtual void v_leave (void);
117 virtual void v_callInto_v(uno_EnvCallee
* pCallee
, va_list * pParam
);
118 virtual void v_callOut_v (uno_EnvCallee
* pCallee
, va_list * pParam
);
119 virtual int v_isValid (rtl::OUString
* pReason
);
122 oslInterlockedCount m_nRef
;
123 uno_Environment
* m_pEnv
;
124 cppu::Enterable
* m_pEnterable
;
126 EnvFun_P
* m_env_acquire
;
127 EnvFun_P
* m_env_release
;
128 EnvFun_PP_P
* m_env_harden
;
129 EnvFun_P
* m_env_acquireWeak
;
130 EnvFun_P
* m_env_releaseWeak
;
132 ExtEnv_registerProxyInterface
* m_env_registerProxyInterface
;
133 ExtEnv_revokeInterface
* m_env_revokeInterface
;
134 ExtEnv_getObjectIdentifier
* m_env_getObjectIdentifier
;
135 ExtEnv_getRegisteredInterface
* m_env_getRegisteredInterface
;
136 ExtEnv_getRegisteredInterfaces
* m_env_getRegisteredInterfaces
;
137 ExtEnv_computeObjectIdentifier
* m_env_computeObjectIdentifier
;
138 ExtEnv_acquireInterface
* m_env_acquireInterface
;
139 ExtEnv_releaseInterface
* m_env_releaseInterface
;
145 static void SAL_CALL
s_acquire(uno_Environment
* pEnv
) //SAL_THROW_EXTERN_C()
147 Base
* pBase
= static_cast<Base
*>(pEnv
->pReserved
);
151 static void SAL_CALL
s_release(uno_Environment
* pEnv
) SAL_THROW_EXTERN_C()
153 Base
* pBase
= static_cast<Base
*>(pEnv
->pReserved
);
157 static void SAL_CALL
s_harden(uno_Environment
** ppHardEnv
, uno_Environment
* pEnv
) SAL_THROW_EXTERN_C()
159 Base
* pBase
= static_cast<Base
*>(pEnv
->pReserved
);
160 pBase
->harden(ppHardEnv
);
163 static void SAL_CALL
s_acquireWeak(uno_Environment
* pEnv
) SAL_THROW_EXTERN_C()
165 Base
* pBase
= static_cast<Base
*>(pEnv
->pReserved
);
166 pBase
->acquireWeak();
169 static void SAL_CALL
s_releaseWeak(uno_Environment
* pEnv
) SAL_THROW_EXTERN_C()
171 Base
* pBase
= static_cast<Base
*>(pEnv
->pReserved
);
172 pBase
->releaseWeak();
176 static void SAL_CALL
s_registerProxyInterface(uno_ExtEnvironment
* pExtEnv
,
178 uno_freeProxyFunc freeProxy
,
180 typelib_InterfaceTypeDescription
* pTypeDescr
)
182 Base
* pBase
= static_cast<Base
*>(pExtEnv
->aBase
.pReserved
);
183 pBase
->registerProxyInterface(ppProxy
, freeProxy
, pOId
, pTypeDescr
);
186 static void SAL_CALL
s_revokeInterface(uno_ExtEnvironment
* pExtEnv
, void * pInterface
)
188 Base
* pBase
= static_cast<Base
*>(pExtEnv
->aBase
.pReserved
);
189 pBase
->revokeInterface(pInterface
);
192 static void SAL_CALL
s_getObjectIdentifier(uno_ExtEnvironment
* pExtEnv
,
193 rtl_uString
** ppOId
,
196 Base
* pBase
= static_cast<Base
*>(pExtEnv
->aBase
.pReserved
);
197 pBase
->getObjectIdentifier(pInterface
, reinterpret_cast<rtl::OUString
*>(ppOId
));
200 static void SAL_CALL
s_getRegisteredInterface(uno_ExtEnvironment
* pExtEnv
,
203 typelib_InterfaceTypeDescription
* pTypeDescr
)
205 Base
* pBase
= static_cast<Base
*>(pExtEnv
->aBase
.pReserved
);
206 pBase
->getRegisteredInterface(ppInterface
, pOId
, pTypeDescr
);
209 static void SAL_CALL
s_getRegisteredInterfaces(uno_ExtEnvironment
* pExtEnv
,
210 void *** pppInterface
,
212 uno_memAlloc memAlloc
)
214 Base
* pBase
= static_cast<Base
*>(pExtEnv
->aBase
.pReserved
);
215 pBase
->getRegisteredInterfaces(pppInterface
, pnLen
, memAlloc
);
218 static void SAL_CALL
s_computeObjectIdentifier(uno_ExtEnvironment
* pExtEnv
,
219 rtl_uString
** ppOId
,
222 Base
* pBase
= static_cast<Base
*>(pExtEnv
->aBase
.pReserved
);
223 pBase
->computeObjectIdentifier(pInterface
, reinterpret_cast<rtl::OUString
*>(ppOId
));
226 static void SAL_CALL
s_acquireInterface(uno_ExtEnvironment
* pExtEnv
, void * pInterface
) {
227 Base
* pBase
= static_cast<Base
*>(pExtEnv
->aBase
.pReserved
);
228 pBase
->acquireInterface(pInterface
);
231 static void SAL_CALL
s_releaseInterface(uno_ExtEnvironment
* pExtEnv
, void * pInterface
) {
232 Base
* pBase
= static_cast<Base
*>(pExtEnv
->aBase
.pReserved
);
233 pBase
->releaseInterface(pInterface
);
238 Base::Base(uno_Environment
* pEnv
, cppu::Enterable
* pEnterable
)
241 m_pEnterable (pEnterable
),
242 m_env_acquire (pEnv
->acquire
),
243 m_env_release (pEnv
->release
),
244 m_env_harden (pEnv
->harden
),
245 m_env_acquireWeak(pEnv
->acquireWeak
),
246 m_env_releaseWeak(pEnv
->releaseWeak
),
247 m_env_registerProxyInterface (pEnv
->pExtEnv
->registerProxyInterface
),
248 m_env_revokeInterface (pEnv
->pExtEnv
->revokeInterface
),
249 m_env_getObjectIdentifier (pEnv
->pExtEnv
->getObjectIdentifier
),
250 m_env_getRegisteredInterface (pEnv
->pExtEnv
->getRegisteredInterface
),
251 m_env_getRegisteredInterfaces(pEnv
->pExtEnv
->getRegisteredInterfaces
),
252 m_env_computeObjectIdentifier(pEnv
->pExtEnv
->computeObjectIdentifier
),
253 m_env_acquireInterface (pEnv
->pExtEnv
->acquireInterface
),
254 m_env_releaseInterface (pEnv
->pExtEnv
->releaseInterface
)
256 LOG_LIFECYCLE_cppu_helper_purpenv_Base_emit(fprintf(stderr
, "LIFE: %s -> %p\n", "cppu::helper::purpenv::Base::Base(uno_Environment * pEnv)", this));
258 rtl_ustr_ascii_compare_WithLength(pEnv
->pTypeName
->buffer
, rtl_str_getLength(UNO_LB_UNO
), UNO_LB_UNO
)
260 "### wrong environment type!");
262 pEnv
->acquire
= s_acquire
;
263 pEnv
->release
= s_release
;
264 pEnv
->harden
= s_harden
;
265 pEnv
->acquireWeak
= s_acquireWeak
;
266 pEnv
->releaseWeak
= s_releaseWeak
;
268 pEnv
->pExtEnv
->registerProxyInterface
= s_registerProxyInterface
;
269 pEnv
->pExtEnv
->revokeInterface
= s_revokeInterface
;
270 pEnv
->pExtEnv
->getObjectIdentifier
= s_getObjectIdentifier
;
271 pEnv
->pExtEnv
->getRegisteredInterface
= s_getRegisteredInterface
;
272 pEnv
->pExtEnv
->getRegisteredInterfaces
= s_getRegisteredInterfaces
;
273 pEnv
->pExtEnv
->computeObjectIdentifier
= s_computeObjectIdentifier
;
274 pEnv
->pExtEnv
->acquireInterface
= s_acquireInterface
;
275 pEnv
->pExtEnv
->releaseInterface
= s_releaseInterface
;
277 pEnv
->pReserved
= this;
282 LOG_LIFECYCLE_cppu_helper_purpenv_Base_emit(fprintf(stderr
, "LIFE: %s -> %p\n", "cppu::helper::purpenv::Base::~Base()", this));
284 m_pEnv
->acquire
= m_env_acquire
;
285 m_pEnv
->release
= m_env_release
;
286 m_pEnv
->harden
= m_env_harden
;
287 m_pEnv
->acquireWeak
= m_env_acquireWeak
;
288 m_pEnv
->releaseWeak
= m_env_releaseWeak
;
290 m_pEnv
->pReserved
= NULL
;
293 m_pEnv
->release(m_pEnv
);
296 void Base::acquire(void)
298 m_env_acquire(m_pEnv
);
300 osl_incrementInterlockedCount(&m_nRef
);
303 void Base::release(void)
305 if (osl_decrementInterlockedCount(&m_nRef
) == 0)
309 m_env_release(m_pEnv
);
312 void Base::harden(uno_Environment
** ppHardEnv
)
314 m_env_harden(ppHardEnv
, m_pEnv
);
315 osl_incrementInterlockedCount(&m_nRef
);
318 void Base::acquireWeak(void)
320 m_env_acquireWeak(m_pEnv
);
323 void Base::releaseWeak(void)
325 m_env_releaseWeak(m_pEnv
);
329 extern "C" { static void s_registerProxyInterface_v(va_list * pParam
)
331 uno_ExtEnvironment
* pExtEnv
= va_arg(*pParam
, uno_ExtEnvironment
*);
332 void ** ppProxy
= va_arg(*pParam
, void **);
333 uno_freeProxyFunc freeProxy
= va_arg(*pParam
, uno_freeProxyFunc
);
334 rtl_uString
* pOId
= va_arg(*pParam
, rtl_uString
*);
335 typelib_InterfaceTypeDescription
* pTypeDescr
= va_arg(*pParam
, typelib_InterfaceTypeDescription
*);
336 ExtEnv_registerProxyInterface
* pRegisterProxyInterface
337 = va_arg(*pParam
, ExtEnv_registerProxyInterface
*);
339 pRegisterProxyInterface(pExtEnv
, ppProxy
, freeProxy
, pOId
, pTypeDescr
);
342 void Base::registerProxyInterface(void ** ppProxy
,
343 uno_freeProxyFunc freeProxy
,
344 rtl::OUString
const & oid
,
345 typelib_InterfaceTypeDescription
* pTypeDescr
)
347 uno_Environment_invoke(m_pEnv
,
348 s_registerProxyInterface_v
,
354 m_env_registerProxyInterface
);
358 extern "C" { static void s_revokeInterface_v(va_list * pParam
)
360 uno_ExtEnvironment
* pExtEnv
= va_arg(*pParam
, uno_ExtEnvironment
*);
361 void * pInterface
= va_arg(*pParam
, void *);
362 ExtEnv_revokeInterface
* pRevokeInterface
= va_arg(*pParam
, ExtEnv_revokeInterface
*);
364 pRevokeInterface(pExtEnv
, pInterface
);
367 void Base::revokeInterface(void * pInterface
)
369 uno_Environment_invoke(m_pEnv
,
373 m_env_revokeInterface
);
377 extern "C" { static void s_getObjectIdentifier_v(va_list * pParam
)
379 uno_ExtEnvironment
* pExtEnv
= va_arg(*pParam
, uno_ExtEnvironment
*);
380 void * pInterface
= va_arg(*pParam
, void *);
381 rtl::OUString
* pOId
= va_arg(*pParam
, rtl::OUString
*);
382 ExtEnv_getObjectIdentifier
* pGetObjectIdentifier
383 = va_arg(*pParam
, ExtEnv_getObjectIdentifier
*);
385 pGetObjectIdentifier(pExtEnv
, reinterpret_cast<rtl_uString
**>(pOId
), pInterface
);
388 void Base::getObjectIdentifier(void * pInterface
, rtl::OUString
* pOid
)
390 uno_Environment_invoke(m_pEnv
,
391 s_getObjectIdentifier_v
,
395 m_env_getObjectIdentifier
);
399 extern "C" { static void s_getRegisteredInterface_v(va_list * pParam
)
401 uno_ExtEnvironment
* pExtEnv
= va_arg(*pParam
, uno_ExtEnvironment
*);
402 void ** ppInterface
= va_arg(*pParam
, void **);
403 rtl_uString
* pOId
= va_arg(*pParam
, rtl_uString
*);
404 typelib_InterfaceTypeDescription
* pTypeDescr
= va_arg(*pParam
, typelib_InterfaceTypeDescription
*);
405 ExtEnv_getRegisteredInterface
* pGetRegisteredInterface
406 = va_arg(*pParam
, ExtEnv_getRegisteredInterface
*);
408 pGetRegisteredInterface(pExtEnv
, ppInterface
, pOId
, pTypeDescr
);
411 void Base::getRegisteredInterface(void ** ppInterface
,
412 rtl::OUString
const & oid
,
413 typelib_InterfaceTypeDescription
* pTypeDescr
)
415 uno_Environment_invoke(m_pEnv
,
416 s_getRegisteredInterface_v
,
421 m_env_getRegisteredInterface
);
425 extern "C" { static void s_getRegisteredInterfaces_v(va_list * pParam
)
427 uno_ExtEnvironment
* pExtEnv
= va_arg(*pParam
, uno_ExtEnvironment
*);
428 void *** pppInterface
= va_arg(*pParam
, void ***);
429 sal_Int32
* pnLen
= va_arg(*pParam
, sal_Int32
*);
430 uno_memAlloc memAlloc
= va_arg(*pParam
, uno_memAlloc
);
431 ExtEnv_getRegisteredInterfaces
* pGetRegisteredInterfaces
432 = va_arg(*pParam
, ExtEnv_getRegisteredInterfaces
*);
434 pGetRegisteredInterfaces(pExtEnv
, pppInterface
, pnLen
, memAlloc
);
437 void Base::getRegisteredInterfaces(void *** pppInterface
,
439 uno_memAlloc memAlloc
)
441 uno_Environment_invoke(m_pEnv
,
442 s_getRegisteredInterfaces_v
,
447 m_env_getRegisteredInterfaces
);
451 extern "C" { static void s_computeObjectIdentifier_v(va_list * pParam
)
453 uno_ExtEnvironment
* pExtEnv
= va_arg(*pParam
, uno_ExtEnvironment
*);
454 void * pInterface
= va_arg(*pParam
, void *);
455 rtl::OUString
* pOId
= va_arg(*pParam
, rtl::OUString
*);
456 ExtEnv_computeObjectIdentifier
* pComputeObjectIdentifier
457 = va_arg(*pParam
, ExtEnv_computeObjectIdentifier
*);
459 pComputeObjectIdentifier(pExtEnv
, reinterpret_cast<rtl_uString
**>(pOId
), pInterface
);
462 void Base::computeObjectIdentifier(void * pInterface
, rtl::OUString
* pOid
)
464 uno_Environment_invoke(m_pEnv
,
465 s_computeObjectIdentifier_v
,
469 m_env_computeObjectIdentifier
);
473 extern "C" { static void s_acquireInterface_v(va_list * pParam
)
475 uno_ExtEnvironment
* pExtEnv
= va_arg(*pParam
, uno_ExtEnvironment
*);
476 void * pInterface
= va_arg(*pParam
, void *);
477 ExtEnv_acquireInterface
* pAcquireInterface
478 = va_arg(*pParam
, ExtEnv_acquireInterface
*);
480 pAcquireInterface(pExtEnv
, pInterface
);
483 void Base::acquireInterface(void * pInterface
)
485 uno_Environment_invoke(m_pEnv
, s_acquireInterface_v
, m_pEnv
->pExtEnv
, pInterface
, m_env_acquireInterface
);
489 extern "C" { static void s_releaseInterface_v(va_list * pParam
)
491 uno_ExtEnvironment
* pExtEnv
= va_arg(*pParam
, uno_ExtEnvironment
*);
492 void * pInterface
= va_arg(*pParam
, void *);
493 ExtEnv_releaseInterface
* pReleaseInterface
494 = va_arg(*pParam
, ExtEnv_releaseInterface
*);
496 pReleaseInterface(pExtEnv
, pInterface
);
499 void Base::releaseInterface(void * pInterface
)
501 uno_Environment_invoke(m_pEnv
,
502 s_releaseInterface_v
,
505 m_env_releaseInterface
);
508 void Base::v_enter(void)
510 m_pEnterable
->enter();
513 void Base::v_leave(void)
515 m_pEnterable
->leave();
518 void Base::v_callInto_v(uno_EnvCallee
* pCallee
, va_list * pParam
)
520 m_pEnterable
->callInto_v(pCallee
, pParam
);
523 void Base::v_callOut_v(uno_EnvCallee
* pCallee
, va_list * pParam
)
525 m_pEnterable
->callOut_v(pCallee
, pParam
);
528 int Base::v_isValid(rtl::OUString
* pReason
)
530 return m_pEnterable
->isValid(pReason
);
533 namespace cppu
{ namespace helper
{ namespace purpenv
{
535 void Environment_initWithEnterable(uno_Environment
* pEnvironment
, cppu::Enterable
* pEnterable
)
537 new Base(pEnvironment
, pEnterable
);