1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <cppu/helper/purpenv/Environment.hxx>
#include <osl/diagnose.h>
#include <sal/log.hxx>
#include <uno/lbnames.h>
#include <cppu/Enterable.hxx>
#include <typelib/typedescription.h>
#include <osl/interlck.h>
#include <memory>
extern "C" {
typedef void EnvFun_P (uno_Environment *);
typedef void EnvFun_PP_P(uno_Environment ** ppHardEnv, uno_Environment *);
typedef void ExtEnv_registerProxyInterface (uno_ExtEnvironment *,
void ** ppProxy,
uno_freeProxyFunc freeProxy,
rtl_uString * pOId,
typelib_InterfaceTypeDescription * pTypeDescr);
typedef void ExtEnv_revokeInterface (uno_ExtEnvironment *,
void * pInterface);
typedef void ExtEnv_getObjectIdentifier (uno_ExtEnvironment *,
rtl_uString **,
void *);
typedef void ExtEnv_getRegisteredInterface (uno_ExtEnvironment *,
void **,
rtl_uString *,
typelib_InterfaceTypeDescription *);
typedef void ExtEnv_getRegisteredInterfaces(uno_ExtEnvironment *,
void *** pppInterfaces,
sal_Int32 * pnLen,
uno_memAlloc memAlloc);
typedef void ExtEnv_computeObjectIdentifier(uno_ExtEnvironment *,
rtl_uString ** ppOId,
void * pInterface);
typedef void ExtEnv_acquireInterface (uno_ExtEnvironment *,
void * pInterface);
typedef void ExtEnv_releaseInterface (uno_ExtEnvironment *,
void * pInterface);
}
namespace {
class Base : public cppu::Enterable
{
public:
explicit Base(uno_Environment * pEnv, cppu::Enterable * pEnterable);
void acquireWeak();
void releaseWeak();
void harden (uno_Environment ** ppHardEnv);
void acquire();
void release();
void registerProxyInterface (void ** ppProxy,
uno_freeProxyFunc freeProxy,
OUString const & oid,
typelib_InterfaceTypeDescription * pTypeDescr);
void revokeInterface (void * pInterface);
void getObjectIdentifier (void * pInterface,
OUString * pOid);
void getRegisteredInterface (void **,
OUString const & oid,
typelib_InterfaceTypeDescription *);
void getRegisteredInterfaces(void ***,
sal_Int32 * pnLen,
uno_memAlloc memAlloc);
void computeObjectIdentifier(void * pInterface,
OUString * pOid);
void acquireInterface (void * pInterface);
void releaseInterface (void * pInterface);
virtual void v_enter() override;
virtual void v_leave() override;
virtual void v_callInto_v(uno_EnvCallee * pCallee, va_list * pParam) override;
virtual void v_callOut_v (uno_EnvCallee * pCallee, va_list * pParam) override;
virtual bool v_isValid (OUString * pReason) override;
protected:
oslInterlockedCount m_nRef;
uno_Environment * m_pEnv;
std::unique_ptr<cppu::Enterable> m_pEnterable;
EnvFun_P * m_env_acquire;
EnvFun_P * m_env_release;
EnvFun_PP_P * m_env_harden;
EnvFun_P * m_env_acquireWeak;
EnvFun_P * m_env_releaseWeak;
ExtEnv_registerProxyInterface * m_env_registerProxyInterface;
ExtEnv_revokeInterface * m_env_revokeInterface;
ExtEnv_getObjectIdentifier * m_env_getObjectIdentifier;
ExtEnv_getRegisteredInterface * m_env_getRegisteredInterface;
ExtEnv_getRegisteredInterfaces * m_env_getRegisteredInterfaces;
ExtEnv_computeObjectIdentifier * m_env_computeObjectIdentifier;
ExtEnv_acquireInterface * m_env_acquireInterface;
ExtEnv_releaseInterface * m_env_releaseInterface;
virtual ~Base() override;
};
}
extern "C" {
static void s_acquire(uno_Environment * pEnv) //SAL_THROW_EXTERN_C()
{
Base * pBase = static_cast<Base *>(pEnv->pReserved);
pBase->acquire();
}
static void s_release(uno_Environment * pEnv) SAL_THROW_EXTERN_C()
{
Base * pBase = static_cast<Base *>(pEnv->pReserved);
pBase->release();
}
static void s_harden(uno_Environment ** ppHardEnv, uno_Environment * pEnv) SAL_THROW_EXTERN_C()
{
Base * pBase = static_cast<Base *>(pEnv->pReserved);
pBase->harden(ppHardEnv);
}
static void s_acquireWeak(uno_Environment * pEnv) SAL_THROW_EXTERN_C()
{
Base * pBase = static_cast<Base *>(pEnv->pReserved);
pBase->acquireWeak();
}
static void s_releaseWeak(uno_Environment * pEnv) SAL_THROW_EXTERN_C()
{
Base * pBase = static_cast<Base *>(pEnv->pReserved);
pBase->releaseWeak();
}
static void s_registerProxyInterface(uno_ExtEnvironment * pExtEnv,
void ** ppProxy,
uno_freeProxyFunc freeProxy,
rtl_uString * pOId,
typelib_InterfaceTypeDescription * pTypeDescr)
{
Base * pBase = static_cast<Base *>(pExtEnv->aBase.pReserved);
pBase->registerProxyInterface(ppProxy, freeProxy, pOId, pTypeDescr);
}
static void s_revokeInterface(uno_ExtEnvironment * pExtEnv, void * pInterface)
{
Base * pBase = static_cast<Base *>(pExtEnv->aBase.pReserved);
pBase->revokeInterface(pInterface);
}
static void s_getObjectIdentifier(uno_ExtEnvironment * pExtEnv,
rtl_uString ** ppOId,
void * pInterface)
{
Base * pBase = static_cast<Base *>(pExtEnv->aBase.pReserved);
pBase->getObjectIdentifier(pInterface, reinterpret_cast<OUString *>(ppOId));
}
static void s_getRegisteredInterface(uno_ExtEnvironment * pExtEnv,
void ** ppInterface,
rtl_uString * pOId,
typelib_InterfaceTypeDescription * pTypeDescr)
{
Base * pBase = static_cast<Base *>(pExtEnv->aBase.pReserved);
pBase->getRegisteredInterface(ppInterface, pOId, pTypeDescr);
}
static void s_getRegisteredInterfaces(uno_ExtEnvironment * pExtEnv,
void *** pppInterface,
sal_Int32 * pnLen,
uno_memAlloc memAlloc)
{
Base * pBase = static_cast<Base *>(pExtEnv->aBase.pReserved);
pBase->getRegisteredInterfaces(pppInterface, pnLen, memAlloc);
}
static void s_computeObjectIdentifier(uno_ExtEnvironment * pExtEnv,
rtl_uString ** ppOId,
void * pInterface)
{
Base * pBase = static_cast<Base *>(pExtEnv->aBase.pReserved);
pBase->computeObjectIdentifier(pInterface, reinterpret_cast<OUString *>(ppOId));
}
static void s_acquireInterface(uno_ExtEnvironment * pExtEnv, void * pInterface) {
Base * pBase = static_cast<Base *>(pExtEnv->aBase.pReserved);
pBase->acquireInterface(pInterface);
}
static void s_releaseInterface(uno_ExtEnvironment * pExtEnv, void * pInterface) {
Base * pBase = static_cast<Base *>(pExtEnv->aBase.pReserved);
pBase->releaseInterface(pInterface);
}
}
Base::Base(uno_Environment * pEnv, cppu::Enterable * pEnterable)
:m_nRef(1),
m_pEnv(pEnv),
m_pEnterable (pEnterable),
m_env_acquire (pEnv->acquire),
m_env_release (pEnv->release),
m_env_harden (pEnv->harden),
m_env_acquireWeak(pEnv->acquireWeak),
m_env_releaseWeak(pEnv->releaseWeak),
m_env_registerProxyInterface (pEnv->pExtEnv->registerProxyInterface),
m_env_revokeInterface (pEnv->pExtEnv->revokeInterface),
m_env_getObjectIdentifier (pEnv->pExtEnv->getObjectIdentifier),
m_env_getRegisteredInterface (pEnv->pExtEnv->getRegisteredInterface),
m_env_getRegisteredInterfaces(pEnv->pExtEnv->getRegisteredInterfaces),
m_env_computeObjectIdentifier(pEnv->pExtEnv->computeObjectIdentifier),
m_env_acquireInterface (pEnv->pExtEnv->acquireInterface),
m_env_releaseInterface (pEnv->pExtEnv->releaseInterface)
{
SAL_INFO("cppu.purpenv", "LIFE: cppu::helper::purpenv::Base::Base(uno_Environment * pEnv) -> " << this);
OSL_ENSURE(
rtl_ustr_ascii_compare_WithLength(pEnv->pTypeName->buffer, rtl_str_getLength(UNO_LB_UNO), UNO_LB_UNO)
== 0,
"### wrong environment type!");
pEnv->acquire = s_acquire;
pEnv->release = s_release;
pEnv->harden = s_harden;
pEnv->acquireWeak = s_acquireWeak;
pEnv->releaseWeak = s_releaseWeak;
pEnv->pExtEnv->registerProxyInterface = s_registerProxyInterface;
pEnv->pExtEnv->revokeInterface = s_revokeInterface;
pEnv->pExtEnv->getObjectIdentifier = s_getObjectIdentifier;
pEnv->pExtEnv->getRegisteredInterface = s_getRegisteredInterface;
pEnv->pExtEnv->getRegisteredInterfaces = s_getRegisteredInterfaces;
pEnv->pExtEnv->computeObjectIdentifier = s_computeObjectIdentifier;
pEnv->pExtEnv->acquireInterface = s_acquireInterface;
pEnv->pExtEnv->releaseInterface = s_releaseInterface;
pEnv->pReserved = this;
}
Base::~Base()
{
SAL_INFO("cppu.purpenv", "LIFE: cppu::helper::purpenv::Base::~Base() -> " << this);
m_pEnv->acquire = m_env_acquire;
m_pEnv->release = m_env_release;
m_pEnv->harden = m_env_harden;
m_pEnv->acquireWeak = m_env_acquireWeak;
m_pEnv->releaseWeak = m_env_releaseWeak;
m_pEnv->pReserved = nullptr;
m_pEnterable.reset();
m_pEnv->release(m_pEnv);
}
void Base::acquire()
{
m_env_acquire(m_pEnv);
osl_atomic_increment(&m_nRef);
}
void Base::release()
{
if (osl_atomic_decrement(&m_nRef) == 0)
delete this;
else
m_env_release(m_pEnv);
}
void Base::harden(uno_Environment ** ppHardEnv)
{
m_env_harden(ppHardEnv, m_pEnv);
osl_atomic_increment(&m_nRef);
}
void Base::acquireWeak()
{
m_env_acquireWeak(m_pEnv);
}
void Base::releaseWeak()
{
m_env_releaseWeak(m_pEnv);
}
extern "C" { static void s_registerProxyInterface_v(va_list * pParam)
{
uno_ExtEnvironment * pExtEnv = va_arg(*pParam, uno_ExtEnvironment *);
void ** ppProxy = va_arg(*pParam, void **);
uno_freeProxyFunc freeProxy = va_arg(*pParam, uno_freeProxyFunc);
rtl_uString * pOId = va_arg(*pParam, rtl_uString *);
typelib_InterfaceTypeDescription * pTypeDescr = va_arg(*pParam, typelib_InterfaceTypeDescription *);
ExtEnv_registerProxyInterface * pRegisterProxyInterface
= va_arg(*pParam, ExtEnv_registerProxyInterface *);
pRegisterProxyInterface(pExtEnv, ppProxy, freeProxy, pOId, pTypeDescr);
}}
void Base::registerProxyInterface(void ** ppProxy,
uno_freeProxyFunc freeProxy,
OUString const & oid,
typelib_InterfaceTypeDescription * pTypeDescr)
{
uno_Environment_invoke(m_pEnv,
s_registerProxyInterface_v,
m_pEnv->pExtEnv,
ppProxy,
freeProxy,
oid.pData,
pTypeDescr,
m_env_registerProxyInterface);
}
extern "C" { static void s_revokeInterface_v(va_list * pParam)
{
uno_ExtEnvironment * pExtEnv = va_arg(*pParam, uno_ExtEnvironment *);
void * pInterface = va_arg(*pParam, void *);
ExtEnv_revokeInterface * pRevokeInterface = va_arg(*pParam, ExtEnv_revokeInterface *);
pRevokeInterface(pExtEnv, pInterface);
}}
void Base::revokeInterface(void * pInterface)
{
uno_Environment_invoke(m_pEnv,
s_revokeInterface_v,
m_pEnv->pExtEnv,
pInterface,
m_env_revokeInterface);
}
extern "C" { static void s_getObjectIdentifier_v(va_list * pParam)
{
uno_ExtEnvironment * pExtEnv = va_arg(*pParam, uno_ExtEnvironment *);
void * pInterface = va_arg(*pParam, void *);
OUString * pOId = va_arg(*pParam, OUString *);
ExtEnv_getObjectIdentifier * pGetObjectIdentifier
= va_arg(*pParam, ExtEnv_getObjectIdentifier *);
pGetObjectIdentifier(pExtEnv, reinterpret_cast<rtl_uString **>(pOId), pInterface);
}}
void Base::getObjectIdentifier(void * pInterface, OUString * pOid)
{
uno_Environment_invoke(m_pEnv,
s_getObjectIdentifier_v,
m_pEnv->pExtEnv,
pInterface,
pOid,
m_env_getObjectIdentifier);
}
extern "C" { static void s_getRegisteredInterface_v(va_list * pParam)
{
uno_ExtEnvironment * pExtEnv = va_arg(*pParam, uno_ExtEnvironment *);
void ** ppInterface = va_arg(*pParam, void **);
rtl_uString * pOId = va_arg(*pParam, rtl_uString *);
typelib_InterfaceTypeDescription * pTypeDescr = va_arg(*pParam, typelib_InterfaceTypeDescription *);
ExtEnv_getRegisteredInterface * pGetRegisteredInterface
= va_arg(*pParam, ExtEnv_getRegisteredInterface *);
pGetRegisteredInterface(pExtEnv, ppInterface, pOId, pTypeDescr);
}}
void Base::getRegisteredInterface(void ** ppInterface,
OUString const & oid,
typelib_InterfaceTypeDescription * pTypeDescr)
{
uno_Environment_invoke(m_pEnv,
s_getRegisteredInterface_v,
m_pEnv->pExtEnv,
ppInterface,
oid.pData,
pTypeDescr,
m_env_getRegisteredInterface);
}
extern "C" { static void s_getRegisteredInterfaces_v(va_list * pParam)
{
uno_ExtEnvironment * pExtEnv = va_arg(*pParam, uno_ExtEnvironment *);
void *** pppInterface = va_arg(*pParam, void ***);
sal_Int32 * pnLen = va_arg(*pParam, sal_Int32 *);
uno_memAlloc memAlloc = va_arg(*pParam, uno_memAlloc);
ExtEnv_getRegisteredInterfaces * pGetRegisteredInterfaces
= va_arg(*pParam, ExtEnv_getRegisteredInterfaces *);
pGetRegisteredInterfaces(pExtEnv, pppInterface, pnLen, memAlloc);
}}
void Base::getRegisteredInterfaces(void *** pppInterface,
sal_Int32 * pnLen,
uno_memAlloc memAlloc)
{
uno_Environment_invoke(m_pEnv,
s_getRegisteredInterfaces_v,
m_pEnv->pExtEnv,
pppInterface,
pnLen,
memAlloc,
m_env_getRegisteredInterfaces);
}
extern "C" { static void s_computeObjectIdentifier_v(va_list * pParam)
{
uno_ExtEnvironment * pExtEnv = va_arg(*pParam, uno_ExtEnvironment *);
void * pInterface = va_arg(*pParam, void *);
OUString * pOId = va_arg(*pParam, OUString *);
ExtEnv_computeObjectIdentifier * pComputeObjectIdentifier
= va_arg(*pParam, ExtEnv_computeObjectIdentifier *);
pComputeObjectIdentifier(pExtEnv, reinterpret_cast<rtl_uString **>(pOId), pInterface);
}}
void Base::computeObjectIdentifier(void * pInterface, OUString * pOid)
{
uno_Environment_invoke(m_pEnv,
s_computeObjectIdentifier_v,
m_pEnv->pExtEnv,
pInterface,
pOid,
m_env_computeObjectIdentifier);
}
extern "C" { static void s_acquireInterface_v(va_list * pParam)
{
uno_ExtEnvironment * pExtEnv = va_arg(*pParam, uno_ExtEnvironment *);
void * pInterface = va_arg(*pParam, void *);
ExtEnv_acquireInterface * pAcquireInterface
= va_arg(*pParam, ExtEnv_acquireInterface *);
pAcquireInterface(pExtEnv, pInterface);
}}
void Base::acquireInterface(void * pInterface)
{
uno_Environment_invoke(m_pEnv, s_acquireInterface_v, m_pEnv->pExtEnv, pInterface, m_env_acquireInterface);
}
extern "C" { static void s_releaseInterface_v(va_list * pParam)
{
uno_ExtEnvironment * pExtEnv = va_arg(*pParam, uno_ExtEnvironment *);
void * pInterface = va_arg(*pParam, void *);
ExtEnv_releaseInterface * pReleaseInterface
= va_arg(*pParam, ExtEnv_releaseInterface *);
pReleaseInterface(pExtEnv, pInterface);
}}
void Base::releaseInterface(void * pInterface)
{
uno_Environment_invoke(m_pEnv,
s_releaseInterface_v,
m_pEnv->pExtEnv,
pInterface,
m_env_releaseInterface);
}
void Base::v_enter()
{
m_pEnterable->enter();
}
void Base::v_leave()
{
m_pEnterable->leave();
}
void Base::v_callInto_v(uno_EnvCallee * pCallee, va_list * pParam)
{
m_pEnterable->callInto_v(pCallee, pParam);
}
void Base::v_callOut_v(uno_EnvCallee * pCallee, va_list * pParam)
{
m_pEnterable->callOut_v(pCallee, pParam);
}
bool Base::v_isValid(OUString * pReason)
{
return m_pEnterable->isValid(pReason);
}
namespace cppu::helper::purpenv {
void Environment_initWithEnterable(uno_Environment * pEnvironment, cppu::Enterable * pEnterable)
{
new Base(pEnvironment, pEnterable);
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|