1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #ifndef INCLUDED_OSL_MODULE_HXX
21 #define INCLUDED_OSL_MODULE_HXX
23 #include "sal/config.h"
27 #include "rtl/ustring.hxx"
28 #include "osl/module.h"
35 Module( const Module
&) SAL_DELETED_FUNCTION
;
36 Module
& operator = ( const Module
&) SAL_DELETED_FUNCTION
;
39 static bool getUrlFromAddress(void * addr
, ::rtl::OUString
& libraryUrl
) {
40 return osl_getModuleURLFromAddress(addr
, &libraryUrl
.pData
);
43 /** Get module URL from the specified function address in the module.
45 Similar to getUrlFromAddress, but use a function address to get URL of the Module.
46 Use Function pointer as symbol address to conceal type conversion.
48 @param[in] addr function address in oslGenericFunction format.
49 @param[in,out] libraryUrl receives the URL of the module.
51 @retval true on success
52 @retval false can not get the URL from the specified function address or the parameter is invalid.
54 @see getUrlFromAddress
56 static bool getUrlFromAddress( oslGenericFunction addr
, ::rtl::OUString
& libraryUrl
){
57 return osl_getModuleURLFromFunctionAddress( addr
, &libraryUrl
.pData
);
60 Module(): m_Module(NULL
){}
62 #ifndef DISABLE_DYNLOADING
64 Module( const ::rtl::OUString
& strModuleName
, sal_Int32 nRtldMode
= SAL_LOADMODULE_DEFAULT
) : m_Module(NULL
)
66 load( strModuleName
, nRtldMode
);
73 #ifndef DISABLE_DYNLOADING
74 osl_unloadModule(m_Module
);
78 #ifndef DISABLE_DYNLOADING
80 bool SAL_CALL
load( const ::rtl::OUString
& strModuleName
,
81 sal_Int32 nRtldMode
= SAL_LOADMODULE_DEFAULT
)
84 m_Module
= osl_loadModule( strModuleName
.pData
, nRtldMode
);
89 bool SAL_CALL
loadRelative(
90 ::oslGenericFunction baseModule
, ::rtl::OUString
const & relativePath
,
91 ::sal_Int32 mode
= SAL_LOADMODULE_DEFAULT
)
94 m_Module
= osl_loadModuleRelative(baseModule
, relativePath
.pData
, mode
);
98 /// @since LibreOffice 3.5
99 bool SAL_CALL
loadRelative(
100 oslGenericFunction baseModule
, char const * relativePath
,
101 sal_Int32 mode
= SAL_LOADMODULE_DEFAULT
)
104 m_Module
= osl_loadModuleRelativeAscii(baseModule
, relativePath
, mode
);
108 void SAL_CALL
unload()
112 osl_unloadModule(m_Module
);
119 bool SAL_CALL
is() const
121 return m_Module
!= NULL
;
124 void* SAL_CALL
getSymbol( const ::rtl::OUString
& strSymbolName
)
126 return osl_getSymbol( m_Module
, strSymbolName
.pData
);
129 /** Get function address by the function name in the module.
131 getFunctionSymbol is an alternative function for getSymbol.
132 Use Function pointer as symbol address to conceal type conversion.
134 @param[in] ustrFunctionSymbolName Function name to be looked up.
136 @retval oslGenericFunction format function address on success
137 @retval NULL lookup failed or parameter is somewhat invalid
141 oslGenericFunction SAL_CALL
getFunctionSymbol( const ::rtl::OUString
& ustrFunctionSymbolName
) const
143 return osl_getFunctionSymbol( m_Module
, ustrFunctionSymbolName
.pData
);
146 /// @since LibreOffice 3.5
147 oslGenericFunction SAL_CALL
getFunctionSymbol(char const * name
) const {
148 return osl_getAsciiFunctionSymbol(m_Module
, name
);
151 operator oslModule() const
156 /** Release the module so that it will not be unloaded from the destructor.
158 This instance returns to the state of a default-constructed instance
161 @since LibreOffice 4.3
163 void release() { m_Module
= NULL
; }
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */