fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / cppu / source / helper / purpenv / helper_purpenv_Environment.cxx
blobf6dc421b4db691712931c57fc3795742f83b537d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "cppu/helper/purpenv/Environment.hxx"
23 #include "osl/diagnose.h"
24 #include "uno/lbnames.h"
25 #include <cppu/Enterable.hxx>
27 #include "typelib/typedescription.h"
28 #include "osl/interlck.h"
30 #ifdef debug
31 # define LOG_LIFECYCLE_cppu_helper_purpenv_Base
32 #endif
34 #ifdef LOG_LIFECYCLE_cppu_helper_purpenv_Base
35 # include <iostream>
36 # define LOG_LIFECYCLE_cppu_helper_purpenv_Base_emit(x) x
38 #else
39 # define LOG_LIFECYCLE_cppu_helper_purpenv_Base_emit(x)
41 #endif
44 extern "C" {
45 typedef void SAL_CALL EnvFun_P (uno_Environment *);
46 typedef void SAL_CALL EnvFun_PP_P(uno_Environment ** ppHardEnv, uno_Environment *);
47 typedef void SAL_CALL ExtEnv_registerProxyInterface (uno_ExtEnvironment *,
48 void ** ppProxy,
49 uno_freeProxyFunc freeProxy,
50 rtl_uString * pOId,
51 typelib_InterfaceTypeDescription * pTypeDescr);
52 typedef void SAL_CALL ExtEnv_revokeInterface (uno_ExtEnvironment *,
53 void * pInterface);
54 typedef void SAL_CALL ExtEnv_getObjectIdentifier (uno_ExtEnvironment *,
55 rtl_uString **,
56 void *);
57 typedef void SAL_CALL ExtEnv_getRegisteredInterface (uno_ExtEnvironment *,
58 void **,
59 rtl_uString *,
60 typelib_InterfaceTypeDescription *);
61 typedef void SAL_CALL ExtEnv_getRegisteredInterfaces(uno_ExtEnvironment *,
62 void *** pppInterfaces,
63 sal_Int32 * pnLen,
64 uno_memAlloc memAlloc);
65 typedef void SAL_CALL ExtEnv_computeObjectIdentifier(uno_ExtEnvironment *,
66 rtl_uString ** ppOId,
67 void * pInterface);
68 typedef void SAL_CALL ExtEnv_acquireInterface (uno_ExtEnvironment *,
69 void * pInterface);
70 typedef void SAL_CALL ExtEnv_releaseInterface (uno_ExtEnvironment *,
71 void * pInterface);
74 class Base : public cppu::Enterable
76 public:
77 explicit Base(uno_Environment * pEnv, cppu::Enterable * pEnterable);
79 void acquireWeak();
80 void releaseWeak();
81 void harden (uno_Environment ** ppHardEnv);
82 void acquire();
83 void release();
85 void registerProxyInterface (void ** ppProxy,
86 uno_freeProxyFunc freeProxy,
87 rtl::OUString const & oid,
88 typelib_InterfaceTypeDescription * pTypeDescr);
89 void revokeInterface (void * pInterface);
90 void getObjectIdentifier (void * pInterface,
91 rtl::OUString * pOid);
92 void getRegisteredInterface (void **,
93 rtl::OUString const & oid,
94 typelib_InterfaceTypeDescription *);
95 void getRegisteredInterfaces(void ***,
96 sal_Int32 * pnLen,
97 uno_memAlloc memAlloc);
98 void computeObjectIdentifier(void * pInterface,
99 rtl::OUString * pOid);
100 void acquireInterface (void * pInterface);
101 void releaseInterface (void * pInterface);
103 virtual void v_enter() SAL_OVERRIDE;
104 virtual void v_leave() SAL_OVERRIDE;
105 virtual void v_callInto_v(uno_EnvCallee * pCallee, va_list * pParam) SAL_OVERRIDE;
106 virtual void v_callOut_v (uno_EnvCallee * pCallee, va_list * pParam) SAL_OVERRIDE;
107 virtual bool v_isValid (rtl::OUString * pReason) SAL_OVERRIDE;
109 protected:
110 oslInterlockedCount m_nRef;
111 uno_Environment * m_pEnv;
112 cppu::Enterable * m_pEnterable;
114 EnvFun_P * m_env_acquire;
115 EnvFun_P * m_env_release;
116 EnvFun_PP_P * m_env_harden;
117 EnvFun_P * m_env_acquireWeak;
118 EnvFun_P * m_env_releaseWeak;
120 ExtEnv_registerProxyInterface * m_env_registerProxyInterface;
121 ExtEnv_revokeInterface * m_env_revokeInterface;
122 ExtEnv_getObjectIdentifier * m_env_getObjectIdentifier;
123 ExtEnv_getRegisteredInterface * m_env_getRegisteredInterface;
124 ExtEnv_getRegisteredInterfaces * m_env_getRegisteredInterfaces;
125 ExtEnv_computeObjectIdentifier * m_env_computeObjectIdentifier;
126 ExtEnv_acquireInterface * m_env_acquireInterface;
127 ExtEnv_releaseInterface * m_env_releaseInterface;
129 virtual ~Base();
132 extern "C" {
133 static void SAL_CALL s_acquire(uno_Environment * pEnv) //SAL_THROW_EXTERN_C()
135 Base * pBase = static_cast<Base *>(pEnv->pReserved);
136 pBase->acquire();
139 static void SAL_CALL s_release(uno_Environment * pEnv) SAL_THROW_EXTERN_C()
141 Base * pBase = static_cast<Base *>(pEnv->pReserved);
142 pBase->release();
145 static void SAL_CALL s_harden(uno_Environment ** ppHardEnv, uno_Environment * pEnv) SAL_THROW_EXTERN_C()
147 Base * pBase = static_cast<Base *>(pEnv->pReserved);
148 pBase->harden(ppHardEnv);
151 static void SAL_CALL s_acquireWeak(uno_Environment * pEnv) SAL_THROW_EXTERN_C()
153 Base * pBase = static_cast<Base *>(pEnv->pReserved);
154 pBase->acquireWeak();
157 static void SAL_CALL s_releaseWeak(uno_Environment * pEnv) SAL_THROW_EXTERN_C()
159 Base * pBase = static_cast<Base *>(pEnv->pReserved);
160 pBase->releaseWeak();
164 static void SAL_CALL s_registerProxyInterface(uno_ExtEnvironment * pExtEnv,
165 void ** ppProxy,
166 uno_freeProxyFunc freeProxy,
167 rtl_uString * pOId,
168 typelib_InterfaceTypeDescription * pTypeDescr)
170 Base * pBase = static_cast<Base *>(pExtEnv->aBase.pReserved);
171 pBase->registerProxyInterface(ppProxy, freeProxy, pOId, pTypeDescr);
174 static void SAL_CALL s_revokeInterface(uno_ExtEnvironment * pExtEnv, void * pInterface)
176 Base * pBase = static_cast<Base *>(pExtEnv->aBase.pReserved);
177 pBase->revokeInterface(pInterface);
180 static void SAL_CALL s_getObjectIdentifier(uno_ExtEnvironment * pExtEnv,
181 rtl_uString ** ppOId,
182 void * pInterface)
184 Base * pBase = static_cast<Base *>(pExtEnv->aBase.pReserved);
185 pBase->getObjectIdentifier(pInterface, reinterpret_cast<rtl::OUString *>(ppOId));
188 static void SAL_CALL s_getRegisteredInterface(uno_ExtEnvironment * pExtEnv,
189 void ** ppInterface,
190 rtl_uString * pOId,
191 typelib_InterfaceTypeDescription * pTypeDescr)
193 Base * pBase = static_cast<Base *>(pExtEnv->aBase.pReserved);
194 pBase->getRegisteredInterface(ppInterface, pOId, pTypeDescr);
197 static void SAL_CALL s_getRegisteredInterfaces(uno_ExtEnvironment * pExtEnv,
198 void *** pppInterface,
199 sal_Int32 * pnLen,
200 uno_memAlloc memAlloc)
202 Base * pBase = static_cast<Base *>(pExtEnv->aBase.pReserved);
203 pBase->getRegisteredInterfaces(pppInterface, pnLen, memAlloc);
206 static void SAL_CALL s_computeObjectIdentifier(uno_ExtEnvironment * pExtEnv,
207 rtl_uString ** ppOId,
208 void * pInterface)
210 Base * pBase = static_cast<Base *>(pExtEnv->aBase.pReserved);
211 pBase->computeObjectIdentifier(pInterface, reinterpret_cast<rtl::OUString *>(ppOId));
214 static void SAL_CALL s_acquireInterface(uno_ExtEnvironment * pExtEnv, void * pInterface) {
215 Base * pBase = static_cast<Base *>(pExtEnv->aBase.pReserved);
216 pBase->acquireInterface(pInterface);
219 static void SAL_CALL s_releaseInterface(uno_ExtEnvironment * pExtEnv, void * pInterface) {
220 Base * pBase = static_cast<Base *>(pExtEnv->aBase.pReserved);
221 pBase->releaseInterface(pInterface);
226 Base::Base(uno_Environment * pEnv, cppu::Enterable * pEnterable)
227 :m_nRef(1),
228 m_pEnv(pEnv),
229 m_pEnterable (pEnterable),
230 m_env_acquire (pEnv->acquire),
231 m_env_release (pEnv->release),
232 m_env_harden (pEnv->harden),
233 m_env_acquireWeak(pEnv->acquireWeak),
234 m_env_releaseWeak(pEnv->releaseWeak),
235 m_env_registerProxyInterface (pEnv->pExtEnv->registerProxyInterface),
236 m_env_revokeInterface (pEnv->pExtEnv->revokeInterface),
237 m_env_getObjectIdentifier (pEnv->pExtEnv->getObjectIdentifier),
238 m_env_getRegisteredInterface (pEnv->pExtEnv->getRegisteredInterface),
239 m_env_getRegisteredInterfaces(pEnv->pExtEnv->getRegisteredInterfaces),
240 m_env_computeObjectIdentifier(pEnv->pExtEnv->computeObjectIdentifier),
241 m_env_acquireInterface (pEnv->pExtEnv->acquireInterface),
242 m_env_releaseInterface (pEnv->pExtEnv->releaseInterface)
244 LOG_LIFECYCLE_cppu_helper_purpenv_Base_emit(fprintf(stderr, "LIFE: %s -> %p\n", "cppu::helper::purpenv::Base::Base(uno_Environment * pEnv)", this));
245 OSL_ENSURE(
246 rtl_ustr_ascii_compare_WithLength(pEnv->pTypeName->buffer, rtl_str_getLength(UNO_LB_UNO), UNO_LB_UNO)
247 == 0,
248 "### wrong environment type!");
250 pEnv->acquire = s_acquire;
251 pEnv->release = s_release;
252 pEnv->harden = s_harden;
253 pEnv->acquireWeak = s_acquireWeak;
254 pEnv->releaseWeak = s_releaseWeak;
256 pEnv->pExtEnv->registerProxyInterface = s_registerProxyInterface;
257 pEnv->pExtEnv->revokeInterface = s_revokeInterface;
258 pEnv->pExtEnv->getObjectIdentifier = s_getObjectIdentifier;
259 pEnv->pExtEnv->getRegisteredInterface = s_getRegisteredInterface;
260 pEnv->pExtEnv->getRegisteredInterfaces = s_getRegisteredInterfaces;
261 pEnv->pExtEnv->computeObjectIdentifier = s_computeObjectIdentifier;
262 pEnv->pExtEnv->acquireInterface = s_acquireInterface;
263 pEnv->pExtEnv->releaseInterface = s_releaseInterface;
265 pEnv->pReserved = this;
268 Base::~Base()
270 LOG_LIFECYCLE_cppu_helper_purpenv_Base_emit(fprintf(stderr, "LIFE: %s -> %p\n", "cppu::helper::purpenv::Base::~Base()", this));
272 m_pEnv->acquire = m_env_acquire;
273 m_pEnv->release = m_env_release;
274 m_pEnv->harden = m_env_harden;
275 m_pEnv->acquireWeak = m_env_acquireWeak;
276 m_pEnv->releaseWeak = m_env_releaseWeak;
278 m_pEnv->pReserved = NULL;
280 delete m_pEnterable;
281 m_pEnv->release(m_pEnv);
284 void Base::acquire()
286 m_env_acquire(m_pEnv);
288 osl_atomic_increment(&m_nRef);
291 void Base::release()
293 if (osl_atomic_decrement(&m_nRef) == 0)
294 delete this;
296 else
297 m_env_release(m_pEnv);
300 void Base::harden(uno_Environment ** ppHardEnv)
302 m_env_harden(ppHardEnv, m_pEnv);
303 osl_atomic_increment(&m_nRef);
306 void Base::acquireWeak()
308 m_env_acquireWeak(m_pEnv);
311 void Base::releaseWeak()
313 m_env_releaseWeak(m_pEnv);
317 extern "C" { static void s_registerProxyInterface_v(va_list * pParam)
319 uno_ExtEnvironment * pExtEnv = va_arg(*pParam, uno_ExtEnvironment *);
320 void ** ppProxy = va_arg(*pParam, void **);
321 uno_freeProxyFunc freeProxy = va_arg(*pParam, uno_freeProxyFunc);
322 rtl_uString * pOId = va_arg(*pParam, rtl_uString *);
323 typelib_InterfaceTypeDescription * pTypeDescr = va_arg(*pParam, typelib_InterfaceTypeDescription *);
324 ExtEnv_registerProxyInterface * pRegisterProxyInterface
325 = va_arg(*pParam, ExtEnv_registerProxyInterface *);
327 pRegisterProxyInterface(pExtEnv, ppProxy, freeProxy, pOId, pTypeDescr);
330 void Base::registerProxyInterface(void ** ppProxy,
331 uno_freeProxyFunc freeProxy,
332 rtl::OUString const & oid,
333 typelib_InterfaceTypeDescription * pTypeDescr)
335 uno_Environment_invoke(m_pEnv,
336 s_registerProxyInterface_v,
337 m_pEnv->pExtEnv,
338 ppProxy,
339 freeProxy,
340 oid.pData,
341 pTypeDescr,
342 m_env_registerProxyInterface);
346 extern "C" { static void s_revokeInterface_v(va_list * pParam)
348 uno_ExtEnvironment * pExtEnv = va_arg(*pParam, uno_ExtEnvironment *);
349 void * pInterface = va_arg(*pParam, void *);
350 ExtEnv_revokeInterface * pRevokeInterface = va_arg(*pParam, ExtEnv_revokeInterface *);
352 pRevokeInterface(pExtEnv, pInterface);
355 void Base::revokeInterface(void * pInterface)
357 uno_Environment_invoke(m_pEnv,
358 s_revokeInterface_v,
359 m_pEnv->pExtEnv,
360 pInterface,
361 m_env_revokeInterface);
365 extern "C" { static void s_getObjectIdentifier_v(va_list * pParam)
367 uno_ExtEnvironment * pExtEnv = va_arg(*pParam, uno_ExtEnvironment *);
368 void * pInterface = va_arg(*pParam, void *);
369 rtl::OUString * pOId = va_arg(*pParam, rtl::OUString *);
370 ExtEnv_getObjectIdentifier * pGetObjectIdentifier
371 = va_arg(*pParam, ExtEnv_getObjectIdentifier *);
373 pGetObjectIdentifier(pExtEnv, reinterpret_cast<rtl_uString **>(pOId), pInterface);
376 void Base::getObjectIdentifier(void * pInterface, rtl::OUString * pOid)
378 uno_Environment_invoke(m_pEnv,
379 s_getObjectIdentifier_v,
380 m_pEnv->pExtEnv,
381 pInterface,
382 pOid,
383 m_env_getObjectIdentifier);
387 extern "C" { static void s_getRegisteredInterface_v(va_list * pParam)
389 uno_ExtEnvironment * pExtEnv = va_arg(*pParam, uno_ExtEnvironment *);
390 void ** ppInterface = va_arg(*pParam, void **);
391 rtl_uString * pOId = va_arg(*pParam, rtl_uString *);
392 typelib_InterfaceTypeDescription * pTypeDescr = va_arg(*pParam, typelib_InterfaceTypeDescription *);
393 ExtEnv_getRegisteredInterface * pGetRegisteredInterface
394 = va_arg(*pParam, ExtEnv_getRegisteredInterface *);
396 pGetRegisteredInterface(pExtEnv, ppInterface, pOId, pTypeDescr);
399 void Base::getRegisteredInterface(void ** ppInterface,
400 rtl::OUString const & oid,
401 typelib_InterfaceTypeDescription * pTypeDescr)
403 uno_Environment_invoke(m_pEnv,
404 s_getRegisteredInterface_v,
405 m_pEnv->pExtEnv,
406 ppInterface,
407 oid.pData,
408 pTypeDescr,
409 m_env_getRegisteredInterface);
413 extern "C" { static void s_getRegisteredInterfaces_v(va_list * pParam)
415 uno_ExtEnvironment * pExtEnv = va_arg(*pParam, uno_ExtEnvironment *);
416 void *** pppInterface = va_arg(*pParam, void ***);
417 sal_Int32 * pnLen = va_arg(*pParam, sal_Int32 *);
418 uno_memAlloc memAlloc = va_arg(*pParam, uno_memAlloc);
419 ExtEnv_getRegisteredInterfaces * pGetRegisteredInterfaces
420 = va_arg(*pParam, ExtEnv_getRegisteredInterfaces *);
422 pGetRegisteredInterfaces(pExtEnv, pppInterface, pnLen, memAlloc);
425 void Base::getRegisteredInterfaces(void *** pppInterface,
426 sal_Int32 * pnLen,
427 uno_memAlloc memAlloc)
429 uno_Environment_invoke(m_pEnv,
430 s_getRegisteredInterfaces_v,
431 m_pEnv->pExtEnv,
432 pppInterface,
433 pnLen,
434 memAlloc,
435 m_env_getRegisteredInterfaces);
439 extern "C" { static void s_computeObjectIdentifier_v(va_list * pParam)
441 uno_ExtEnvironment * pExtEnv = va_arg(*pParam, uno_ExtEnvironment *);
442 void * pInterface = va_arg(*pParam, void *);
443 rtl::OUString * pOId = va_arg(*pParam, rtl::OUString *);
444 ExtEnv_computeObjectIdentifier * pComputeObjectIdentifier
445 = va_arg(*pParam, ExtEnv_computeObjectIdentifier *);
447 pComputeObjectIdentifier(pExtEnv, reinterpret_cast<rtl_uString **>(pOId), pInterface);
450 void Base::computeObjectIdentifier(void * pInterface, rtl::OUString * pOid)
452 uno_Environment_invoke(m_pEnv,
453 s_computeObjectIdentifier_v,
454 m_pEnv->pExtEnv,
455 pInterface,
456 pOid,
457 m_env_computeObjectIdentifier);
461 extern "C" { static void s_acquireInterface_v(va_list * pParam)
463 uno_ExtEnvironment * pExtEnv = va_arg(*pParam, uno_ExtEnvironment *);
464 void * pInterface = va_arg(*pParam, void *);
465 ExtEnv_acquireInterface * pAcquireInterface
466 = va_arg(*pParam, ExtEnv_acquireInterface *);
468 pAcquireInterface(pExtEnv, pInterface);
471 void Base::acquireInterface(void * pInterface)
473 uno_Environment_invoke(m_pEnv, s_acquireInterface_v, m_pEnv->pExtEnv, pInterface, m_env_acquireInterface);
477 extern "C" { static void s_releaseInterface_v(va_list * pParam)
479 uno_ExtEnvironment * pExtEnv = va_arg(*pParam, uno_ExtEnvironment *);
480 void * pInterface = va_arg(*pParam, void *);
481 ExtEnv_releaseInterface * pReleaseInterface
482 = va_arg(*pParam, ExtEnv_releaseInterface *);
484 pReleaseInterface(pExtEnv, pInterface);
487 void Base::releaseInterface(void * pInterface)
489 uno_Environment_invoke(m_pEnv,
490 s_releaseInterface_v,
491 m_pEnv->pExtEnv,
492 pInterface,
493 m_env_releaseInterface);
496 void Base::v_enter()
498 m_pEnterable->enter();
501 void Base::v_leave()
503 m_pEnterable->leave();
506 void Base::v_callInto_v(uno_EnvCallee * pCallee, va_list * pParam)
508 m_pEnterable->callInto_v(pCallee, pParam);
511 void Base::v_callOut_v(uno_EnvCallee * pCallee, va_list * pParam)
513 m_pEnterable->callOut_v(pCallee, pParam);
516 bool Base::v_isValid(rtl::OUString * pReason)
518 return m_pEnterable->isValid(pReason);
521 namespace cppu { namespace helper { namespace purpenv {
523 void Environment_initWithEnterable(uno_Environment * pEnvironment, cppu::Enterable * pEnterable)
525 new Base(pEnvironment, pEnterable);
530 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */