1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: module.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 #ifndef _OSL_MODULE_HXX_
34 #define _OSL_MODULE_HXX_
36 #include <rtl/ustring.hxx>
37 #include <osl/module.h>
44 Module( const Module
&);
45 Module
& operator = ( const Module
&);
48 static sal_Bool
getUrlFromAddress(void * addr
, ::rtl::OUString
& libraryUrl
) {
49 return osl_getModuleURLFromAddress(addr
, &libraryUrl
.pData
);
52 /** Get module URL from the specified function address in the module.
54 Similar to getUrlFromAddress, but use a function address to get URL of the Module.
55 Use Function pointer as symbol address to conceal type conversion.
58 [in] function address in oslGenericFunction format.
61 [in|out] receives the URL of the module.
68 <dd>can not get the URL from the specified function address or the parameter is invalid.</dd>
71 @see getUrlFromAddress
73 static sal_Bool
getUrlFromAddress( oslGenericFunction addr
, ::rtl::OUString
& libraryUrl
){
74 return osl_getModuleURLFromFunctionAddress( addr
, &libraryUrl
.pData
);
77 Module(): m_Module(0){}
79 Module( const ::rtl::OUString
& strModuleName
, sal_Int32 nRtldMode
= SAL_LOADMODULE_DEFAULT
) : m_Module(0)
81 load( strModuleName
, nRtldMode
);
86 osl_unloadModule(m_Module
);
89 sal_Bool SAL_CALL
load( const ::rtl::OUString
& strModuleName
,
90 sal_Int32 nRtldMode
= SAL_LOADMODULE_DEFAULT
)
93 m_Module
= osl_loadModule( strModuleName
.pData
, nRtldMode
);
98 sal_Bool SAL_CALL
loadRelative(
99 ::oslGenericFunction baseModule
, ::rtl::OUString
const & relativePath
,
100 ::sal_Int32 mode
= SAL_LOADMODULE_DEFAULT
)
103 m_Module
= osl_loadModuleRelative(baseModule
, relativePath
.pData
, mode
);
107 void SAL_CALL
unload()
111 osl_unloadModule(m_Module
);
116 sal_Bool SAL_CALL
is() const
118 return m_Module
!= NULL
;
121 void* SAL_CALL
getSymbol( const ::rtl::OUString
& strSymbolName
)
123 return ( osl_getSymbol( m_Module
, strSymbolName
.pData
) );
126 /** Get function address by the function name in the module.
128 getFunctionSymbol is an alternative function for getSymbol.
129 Use Function pointer as symbol address to conceal type conversion.
131 @param ustrFunctionSymbolName
132 [in] Function name to be looked up.
136 <dt>oslGenericFunction format function address</dt>
139 <dd>lookup failed or parameter is somewhat invalid</dd>
144 oslGenericFunction SAL_CALL
getFunctionSymbol( const ::rtl::OUString
& ustrFunctionSymbolName
)
146 return ( osl_getFunctionSymbol( m_Module
, ustrFunctionSymbolName
.pData
) );
149 operator oslModule() const