Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/bridges/source/cpp_uno/shared/unointerfaceproxy.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 <unointerfaceproxy.hxx>
21
22
#include <bridge.hxx>
23
24
#include <com/sun/star/uno/XInterface.hpp>
25
#include <utility>
26
#include <typelib/typedescription.h>
27
#include <uno/dispatcher.h>
28
29
namespace bridges::cpp_uno::shared {
30
31
void freeUnoInterfaceProxy(uno_ExtEnvironment * pEnv, void * pProxy)
32
123k
{
33
123k
    UnoInterfaceProxy * pThis =
34
123k
        static_cast< UnoInterfaceProxy * >(
35
123k
            static_cast< uno_Interface * >( pProxy ) );
36
123k
    if (pEnv != pThis->pBridge->getUnoEnv()) {
37
0
        assert(false);
38
0
    }
39
40
123k
    (*pThis->pBridge->getCppEnv()->revokeInterface)(
41
123k
        pThis->pBridge->getCppEnv(), pThis->pCppI );
42
123k
    pThis->pCppI->release();
43
123k
    ::typelib_typedescription_release(&pThis->pTypeDescr->aBase);
44
123k
    pThis->pBridge->release();
45
46
#if OSL_DEBUG_LEVEL > 1
47
    *(int *)pProxy = 0xdeadbabe;
48
#endif
49
123k
    delete pThis;
50
123k
}
51
52
void acquireProxy(uno_Interface * pUnoI)
53
0
{
54
0
    if (++static_cast< UnoInterfaceProxy * >( pUnoI )->nRef != 1)
55
0
        return;
56
57
    // rebirth of proxy zombie
58
    // register at uno env
59
#if OSL_DEBUG_LEVEL > 1
60
    void * pThis = pUnoI;
61
#endif
62
0
    (*static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv()->
63
0
     registerProxyInterface)(
64
0
         static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv(),
65
0
         reinterpret_cast< void ** >( &pUnoI ), freeUnoInterfaceProxy,
66
0
         static_cast< UnoInterfaceProxy * >( pUnoI )->oid.pData,
67
0
         static_cast< UnoInterfaceProxy * >( pUnoI )->pTypeDescr );
68
#if OSL_DEBUG_LEVEL > 1
69
    assert(pThis == pUnoI);
70
#endif
71
0
}
72
73
void releaseProxy(uno_Interface * pUnoI)
74
123k
{
75
123k
    if (! --static_cast< UnoInterfaceProxy * >( pUnoI )->nRef )
76
123k
    {
77
        // revoke from uno env on last release
78
123k
        (*static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv()->
79
123k
         revokeInterface)(
80
123k
             static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv(),
81
123k
             pUnoI );
82
123k
    }
83
123k
}
84
85
UnoInterfaceProxy * UnoInterfaceProxy::create(
86
    bridges::cpp_uno::shared::Bridge * pBridge,
87
    css::uno::XInterface * pCppI,
88
    typelib_InterfaceTypeDescription * pTypeDescr,
89
    OUString const & rOId)
90
123k
{
91
123k
    return new UnoInterfaceProxy(pBridge, pCppI, pTypeDescr, rOId);
92
123k
}
93
94
UnoInterfaceProxy::UnoInterfaceProxy(
95
    bridges::cpp_uno::shared::Bridge * pBridge_,
96
    css::uno::XInterface * pCppI_,
97
    typelib_InterfaceTypeDescription * pTypeDescr_, OUString aOId_)
98
123k
    : nRef( 1 )
99
123k
    , pBridge( pBridge_ )
100
123k
    , pCppI( pCppI_ )
101
123k
    , pTypeDescr( pTypeDescr_ )
102
123k
    , oid(std::move( aOId_ ))
103
123k
{
104
123k
    pBridge->acquire();
105
123k
    ::typelib_typedescription_acquire(&pTypeDescr->aBase);
106
123k
    if (!pTypeDescr->aBase.bComplete)
107
12
        ::typelib_typedescription_complete(
108
12
            reinterpret_cast<typelib_TypeDescription **>(&pTypeDescr));
109
123k
    assert(pTypeDescr->aBase.bComplete);
110
123k
    pCppI->acquire();
111
123k
    (*pBridge->getCppEnv()->registerInterface)(
112
123k
        pBridge->getCppEnv(), reinterpret_cast< void ** >( &pCppI ), oid.pData,
113
123k
        pTypeDescr );
114
115
    // uno_Interface
116
123k
    acquire = acquireProxy;
117
123k
    release = releaseProxy;
118
123k
    pDispatcher = unoInterfaceProxyDispatch;
119
123k
}
120
121
UnoInterfaceProxy::~UnoInterfaceProxy()
122
123k
{}
123
124
}
125
126
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */