Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/osl/module.hxx
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
/*
21
 * This file is part of LibreOffice published API.
22
 */
23
24
#ifndef INCLUDED_OSL_MODULE_HXX
25
#define INCLUDED_OSL_MODULE_HXX
26
27
#include "sal/config.h"
28
29
#include <cstddef>
30
31
#include "rtl/ustring.hxx"
32
#include "osl/module.h"
33
34
namespace osl
35
{
36
37
class Module
38
{
39
    Module( const Module&) SAL_DELETED_FUNCTION;
40
    Module& operator = ( const Module&) SAL_DELETED_FUNCTION;
41
42
public:
43
0
    static bool getUrlFromAddress(void * addr, ::rtl::OUString & libraryUrl) {
44
0
        return osl_getModuleURLFromAddress(addr, &libraryUrl.pData);
45
0
    }
46
47
    /** Get module URL from the specified function address in the module.
48
49
        Similar to getUrlFromAddress, but use a function address to get URL of the Module.
50
        Use Function pointer as symbol address to conceal type conversion.
51
52
        @param[in] addr            function address in oslGenericFunction format.
53
        @param[in,out] libraryUrl  receives the URL of the module.
54
55
        @retval true on success
56
        @retval false can not get the URL from the specified function address or the parameter is invalid.
57
58
        @see getUrlFromAddress
59
    */
60
0
    static bool getUrlFromAddress( oslGenericFunction addr, ::rtl::OUString & libraryUrl){
61
0
        return osl_getModuleURLFromFunctionAddress( addr, &libraryUrl.pData );
62
0
    }
63
64
0
    Module(): m_Module(NULL){}
65
66
#ifndef DISABLE_DYNLOADING
67
68
    Module( const ::rtl::OUString& strModuleName, sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT) : m_Module(NULL)
69
    {
70
        load( strModuleName, nRtldMode);
71
    }
72
73
#endif
74
75
    ~Module()
76
0
    {
77
0
#ifndef DISABLE_DYNLOADING
78
0
        osl_unloadModule(m_Module);
79
0
#endif
80
0
    }
81
82
#ifndef DISABLE_DYNLOADING
83
84
    bool SAL_CALL load( const ::rtl::OUString& strModuleName,
85
        sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT)
86
    {
87
        unload();
88
        m_Module= osl_loadModule( strModuleName.pData, nRtldMode );
89
        return is();
90
    }
91
92
    /// @since UDK 3.2.8
93
    bool SAL_CALL loadRelative(
94
        ::oslGenericFunction baseModule, ::rtl::OUString const & relativePath,
95
        ::sal_Int32 mode = SAL_LOADMODULE_DEFAULT)
96
    {
97
        unload();
98
        m_Module = osl_loadModuleRelative(baseModule, relativePath.pData, mode);
99
        return is();
100
    }
101
102
    /// @since LibreOffice 3.5
103
    bool SAL_CALL loadRelative(
104
        oslGenericFunction baseModule, char const * relativePath,
105
        sal_Int32 mode = SAL_LOADMODULE_DEFAULT)
106
    {
107
        unload();
108
        m_Module = osl_loadModuleRelativeAscii(baseModule, relativePath, mode);
109
        return is();
110
    }
111
112
    void SAL_CALL unload()
113
    {
114
        if (m_Module)
115
        {
116
            osl_unloadModule(m_Module);
117
            m_Module = NULL;
118
        }
119
    }
120
121
#endif
122
123
    bool SAL_CALL is() const
124
0
    {
125
0
           return m_Module != NULL;
126
0
    }
127
128
    void* SAL_CALL getSymbol( const ::rtl::OUString& strSymbolName)
129
0
    {
130
0
        return osl_getSymbol( m_Module, strSymbolName.pData );
131
0
    }
132
133
    /** Get function address by the function name in the module.
134
135
        getFunctionSymbol is an alternative function for getSymbol.
136
        Use Function pointer as symbol address to conceal type conversion.
137
138
        @param[in] ustrFunctionSymbolName  Function name to be looked up.
139
140
        @retval oslGenericFunction format function address on success
141
        @retval NULL lookup failed or parameter is somewhat invalid
142
143
        @see getSymbol
144
    */
145
    oslGenericFunction SAL_CALL getFunctionSymbol( const ::rtl::OUString& ustrFunctionSymbolName ) const
146
0
    {
147
0
        return osl_getFunctionSymbol( m_Module, ustrFunctionSymbolName.pData );
148
0
    }
149
150
    /// @since LibreOffice 3.5
151
0
    oslGenericFunction SAL_CALL getFunctionSymbol(char const * name) const {
152
0
        return osl_getAsciiFunctionSymbol(m_Module, name);
153
0
    }
154
155
    operator oslModule() const
156
0
    {
157
0
        return m_Module;
158
0
    }
159
160
    /** Release the module so that it will not be unloaded from the destructor.
161
162
        This instance returns to the state of a default-constructed instance
163
        again.
164
165
        @since LibreOffice 4.3
166
    */
167
0
    void release() { m_Module = NULL; }
168
169
private:
170
    oslModule m_Module;
171
172
};
173
174
}
175
176
#endif
177
178
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */