Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/bridges/source/cpp_uno/shared/component.cxx
Line
Count
Source
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
#include <bridge.hxx>
21
22
#include <com/sun/star/uno/Reference.hxx>
23
#include <com/sun/star/uno/RuntimeException.hpp>
24
#include <com/sun/star/uno/XInterface.hpp>
25
#include <rtl/process.h>
26
#include <rtl/ustrbuf.hxx>
27
#include <rtl/ustring.h>
28
#include <rtl/ustring.hxx>
29
#include <sal/log.hxx>
30
#include <sal/types.h>
31
#include <uno/environment.h>
32
#include <uno/lbnames.h>
33
#include <uno/mapping.h>
34
#include <cppu/EnvDcp.hxx>
35
36
37
namespace {
38
39
const OUString & cppu_cppenv_getStaticOIdPart()
40
92.0k
{
41
92.0k
    static OUString s_aStaticOidPart = []() {
42
12
        OUStringBuffer aRet(64);
43
12
        aRet.append("];");
44
        // good guid
45
12
        sal_uInt8 ar[16];
46
12
        ::rtl_getGlobalProcessId(ar);
47
12
        for (unsigned char i : ar)
48
192
        {
49
192
            aRet.append(static_cast<sal_Int32>(i), 16);
50
192
        }
51
12
        return aRet.makeStringAndClear();
52
12
    }();
53
92.0k
    return s_aStaticOidPart;
54
92.0k
}
55
56
}
57
58
extern "C" {
59
60
static void s_stub_computeObjectIdentifier(va_list * pParam)
61
92.0k
{
62
92.0k
    uno_ExtEnvironment  * pEnv       = va_arg(*pParam, uno_ExtEnvironment *);
63
92.0k
    rtl_uString        ** ppOId      = va_arg(*pParam, rtl_uString **);
64
92.0k
    void                * pInterface = va_arg(*pParam, void *);
65
66
67
92.0k
    assert(pEnv && ppOId && pInterface);
68
92.0k
    if (!(pEnv && ppOId && pInterface))
69
0
        return;
70
71
92.0k
    if (*ppOId)
72
0
    {
73
0
        rtl_uString_release( *ppOId );
74
0
        *ppOId = nullptr;
75
0
    }
76
77
92.0k
    try
78
92.0k
    {
79
92.0k
        ::com::sun::star::uno::Reference<
80
92.0k
              ::com::sun::star::uno::XInterface > xHome(
81
92.0k
                  static_cast< css::uno::XInterface * >(
82
92.0k
                      pInterface ),
83
92.0k
                  ::com::sun::star::uno::UNO_QUERY );
84
92.0k
        assert(xHome.is() && "### query to XInterface failed!");
85
92.0k
        if (xHome.is())
86
92.0k
        {
87
            // interface
88
92.0k
            OUString aRet =
89
92.0k
                OUString::number( reinterpret_cast< sal_IntPtr >(xHome.get()), 16 ) +
90
92.0k
                ";" +
91
                // ;environment[context]
92
92.0k
                OUString::unacquired(&pEnv->aBase.pTypeName) +
93
92.0k
                "[" +
94
92.0k
                OUString::number( reinterpret_cast< sal_IntPtr >(pEnv->aBase.pContext), 16 ) +
95
                // ];good guid
96
92.0k
                cppu_cppenv_getStaticOIdPart();
97
92.0k
            *ppOId = aRet.pData;
98
92.0k
            ::rtl_uString_acquire( *ppOId );
99
92.0k
        }
100
92.0k
    }
101
92.0k
    catch (const css::uno::RuntimeException & e)
102
92.0k
    {
103
0
        SAL_WARN("bridges",
104
0
            "### RuntimeException occurred during queryInterface(): "
105
0
            << e.Message);
106
0
    }
107
92.0k
}
108
109
static void computeObjectIdentifier(
110
    uno_ExtEnvironment * pExtEnv, rtl_uString ** ppOId, void * pInterface )
111
92.0k
{
112
92.0k
    uno_Environment_invoke(&pExtEnv->aBase, s_stub_computeObjectIdentifier, pExtEnv, ppOId, pInterface);
113
92.0k
}
114
115
static void s_stub_acquireInterface(va_list * pParam)
116
123k
{
117
123k
    /*uno_ExtEnvironment * pExtEnv = */va_arg(*pParam, uno_ExtEnvironment *);
118
123k
    void               * pCppI   = va_arg(*pParam, void *);
119
120
123k
    static_cast< css::uno::XInterface * >( pCppI )->acquire();
121
123k
}
122
123
static void acquireInterface( uno_ExtEnvironment * pExtEnv, void * pCppI )
124
123k
{
125
123k
    uno_Environment_invoke(&pExtEnv->aBase, s_stub_acquireInterface, pExtEnv, pCppI);
126
123k
}
127
128
static void s_stub_releaseInterface(va_list * pParam)
129
92.1k
{
130
92.1k
    /*uno_ExtEnvironment * pExtEnv = */va_arg(*pParam, uno_ExtEnvironment *);
131
92.1k
    void               * pCppI   = va_arg(*pParam, void *);
132
133
92.1k
    static_cast< css::uno::XInterface * >( pCppI )->release();
134
92.1k
}
135
136
static void releaseInterface( uno_ExtEnvironment * pExtEnv, void * pCppI )
137
92.1k
{
138
92.1k
    uno_Environment_invoke(&pExtEnv->aBase, s_stub_releaseInterface, pExtEnv, pCppI);
139
92.1k
}
140
141
static void environmentDisposing(
142
    SAL_UNUSED_PARAMETER uno_Environment * )
143
37.2k
{
144
37.2k
}
145
146
#ifdef DISABLE_DYNLOADING
147
#define uno_initEnvironment CPPU_ENV_uno_initEnvironment
148
#endif
149
150
SAL_DLLPUBLIC_EXPORT void uno_initEnvironment(uno_Environment * pCppEnv) noexcept
151
37.2k
{
152
37.2k
    assert(pCppEnv->pExtEnv);
153
37.2k
    assert(
154
37.2k
        ::rtl_ustr_ascii_compare_WithLength(
155
37.2k
             pCppEnv->pTypeName->buffer, rtl_str_getLength(CPPU_CURRENT_LANGUAGE_BINDING_NAME), CPPU_CURRENT_LANGUAGE_BINDING_NAME )
156
37.2k
        == 0
157
37.2k
        && "### wrong environment type!");
158
37.2k
    reinterpret_cast<uno_ExtEnvironment *>(pCppEnv)->computeObjectIdentifier
159
37.2k
        = computeObjectIdentifier;
160
37.2k
    reinterpret_cast<uno_ExtEnvironment *>(pCppEnv)->acquireInterface = acquireInterface;
161
37.2k
    reinterpret_cast<uno_ExtEnvironment *>(pCppEnv)->releaseInterface = releaseInterface;
162
37.2k
    pCppEnv->environmentDisposing = environmentDisposing;
163
37.2k
}
164
165
#ifdef DISABLE_DYNLOADING
166
#define uno_ext_getMapping CPPU_ENV_uno_ext_getMapping
167
#endif
168
169
SAL_DLLPUBLIC_EXPORT void uno_ext_getMapping(
170
    uno_Mapping ** ppMapping, uno_Environment * pFrom, uno_Environment * pTo) noexcept
171
73.6k
{
172
73.6k
    assert(ppMapping && pFrom && pTo);
173
73.6k
    if (!(ppMapping && pFrom && pTo && pFrom->pExtEnv && pTo->pExtEnv))
174
0
        return;
175
176
73.6k
    uno_Mapping * pMapping = nullptr;
177
178
73.6k
    OUString from_envTypeName(cppu::EnvDcp::getTypeName(pFrom->pTypeName));
179
73.6k
    OUString to_envTypeName(cppu::EnvDcp::getTypeName(pTo->pTypeName));
180
181
73.6k
    if (rtl_ustr_ascii_compare(
182
73.6k
            from_envTypeName.pData->buffer,
183
73.6k
            CPPU_CURRENT_LANGUAGE_BINDING_NAME ) == 0 &&
184
36.8k
        rtl_ustr_ascii_compare(
185
36.8k
            to_envTypeName.pData->buffer, UNO_LB_UNO ) == 0)
186
36.8k
    {
187
        // ref count initially 1
188
36.8k
        pMapping = bridges::cpp_uno::shared::Bridge::createMapping(
189
36.8k
            pFrom->pExtEnv, pTo->pExtEnv, true );
190
36.8k
        ::uno_registerMapping(
191
36.8k
            &pMapping, bridges::cpp_uno::shared::freeMapping,
192
36.8k
            &pFrom->pExtEnv->aBase,
193
36.8k
            &pTo->pExtEnv->aBase, nullptr );
194
36.8k
    }
195
36.8k
    else if (rtl_ustr_ascii_compare(
196
36.8k
                 to_envTypeName.pData->buffer,
197
36.8k
                 CPPU_CURRENT_LANGUAGE_BINDING_NAME ) == 0 &&
198
36.8k
             rtl_ustr_ascii_compare(
199
36.8k
                 from_envTypeName.pData->buffer, UNO_LB_UNO ) == 0)
200
36.8k
    {
201
        // ref count initially 1
202
36.8k
        pMapping = bridges::cpp_uno::shared::Bridge::createMapping(
203
36.8k
            pTo->pExtEnv, pFrom->pExtEnv, false );
204
36.8k
        ::uno_registerMapping(
205
36.8k
            &pMapping, bridges::cpp_uno::shared::freeMapping,
206
36.8k
            &pFrom->pExtEnv->aBase,
207
36.8k
            &pTo->pExtEnv->aBase, nullptr );
208
36.8k
    }
209
210
73.6k
    if (*ppMapping)
211
0
    {
212
0
        (*(*ppMapping)->release)( *ppMapping );
213
0
    }
214
73.6k
    if (pMapping)
215
73.6k
        *ppMapping = pMapping;
216
73.6k
}
217
218
}
219
220
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */