update dev300-m58
[ooovba.git] / sal / inc / osl / module.hxx
blobf8377a015ce4ad4faaf5497e3312a44e5c34af5e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: module.hxx,v $
10 * $Revision: 1.12 $
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 ************************************************************************/
31 /** @HTML */
33 #ifndef _OSL_MODULE_HXX_
34 #define _OSL_MODULE_HXX_
36 #include <rtl/ustring.hxx>
37 #include <osl/module.h>
39 namespace osl
42 class Module
44 Module( const Module&);
45 Module& operator = ( const Module&);
47 public:
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.
57 @param addr
58 [in] function address in oslGenericFunction format.
60 @param libraryUrl
61 [in|out] receives the URL of the module.
63 @return
64 <dl>
65 <dt>sal_True</dt>
66 <dd>on success</dd>
67 <dt>sal_False</dt>
68 <dd>can not get the URL from the specified function address or the parameter is invalid.</dd>
69 </dl>
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);
84 ~Module()
86 osl_unloadModule(m_Module);
89 sal_Bool SAL_CALL load( const ::rtl::OUString& strModuleName,
90 sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT)
92 unload();
93 m_Module= osl_loadModule( strModuleName.pData, nRtldMode );
94 return is();
97 /// @since UDK 3.2.8
98 sal_Bool SAL_CALL loadRelative(
99 ::oslGenericFunction baseModule, ::rtl::OUString const & relativePath,
100 ::sal_Int32 mode = SAL_LOADMODULE_DEFAULT)
102 unload();
103 m_Module = osl_loadModuleRelative(baseModule, relativePath.pData, mode);
104 return is();
107 void SAL_CALL unload()
109 if (m_Module)
111 osl_unloadModule(m_Module);
112 m_Module = 0;
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.
134 @return
135 <dl>
136 <dt>oslGenericFunction format function address</dt>
137 <dd>on success</dd>
138 <dt>NULL</dt>
139 <dd>lookup failed or parameter is somewhat invalid</dd>
140 </dl>
142 @see getSymbol
144 oslGenericFunction SAL_CALL getFunctionSymbol( const ::rtl::OUString& ustrFunctionSymbolName )
146 return ( osl_getFunctionSymbol( m_Module, ustrFunctionSymbolName.pData ) );
149 operator oslModule() const
151 return m_Module;
154 private:
155 oslModule m_Module;
161 #endif