xref: /aoo41x/main/sal/inc/osl/module.hxx (revision 565d668c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 /** @HTML */
25 
26 #ifndef _OSL_MODULE_HXX_
27 #define _OSL_MODULE_HXX_
28 
29 #include <rtl/ustring.hxx>
30 #include <osl/module.h>
31 
32 namespace osl
33 {
34 
35 class Module
36 {
37     Module( const Module&);
38     Module& operator = ( const Module&);
39 
40 public:
getUrlFromAddress(void * addr,::rtl::OUString & libraryUrl)41     static sal_Bool getUrlFromAddress(void * addr, ::rtl::OUString & libraryUrl) {
42         return osl_getModuleURLFromAddress(addr, &libraryUrl.pData);
43     }
44 
45     /** Get module URL from the specified function address in the module.
46 
47         Similar to getUrlFromAddress, but use a function address to get URL of the Module.
48         Use Function pointer as symbol address to conceal type conversion.
49 
50         @param addr
51         [in] function address in oslGenericFunction format.
52 
53         @param libraryUrl
54         [in|out] receives the URL of the module.
55 
56         @return
57         <dl>
58         <dt>sal_True</dt>
59         <dd>on success</dd>
60         <dt>sal_False</dt>
61         <dd>can not get the URL from the specified function address or the parameter is invalid.</dd>
62         </dl>
63 
64         @see getUrlFromAddress
65     */
getUrlFromAddress(oslGenericFunction addr,::rtl::OUString & libraryUrl)66     static sal_Bool getUrlFromAddress( oslGenericFunction addr, ::rtl::OUString & libraryUrl){
67         return osl_getModuleURLFromFunctionAddress( addr, &libraryUrl.pData );
68     }
69 
Module()70     Module(): m_Module(0){}
71 
Module(const::rtl::OUString & strModuleName,sal_Int32 nRtldMode=SAL_LOADMODULE_DEFAULT)72     Module( const ::rtl::OUString& strModuleName, sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT) : m_Module(0)
73     {
74         load( strModuleName, nRtldMode);
75     }
76 
~Module()77     ~Module()
78     {
79         osl_unloadModule(m_Module);
80     }
81 
load(const::rtl::OUString & strModuleName,sal_Int32 nRtldMode=SAL_LOADMODULE_DEFAULT)82     sal_Bool SAL_CALL load( const ::rtl::OUString& strModuleName,
83         sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT)
84     {
85         unload();
86         m_Module= osl_loadModule( strModuleName.pData, nRtldMode );
87         return is();
88     }
89 
90     /// @since UDK 3.2.8
loadRelative(::oslGenericFunction baseModule,::rtl::OUString const & relativePath,::sal_Int32 mode=SAL_LOADMODULE_DEFAULT)91     sal_Bool SAL_CALL loadRelative(
92         ::oslGenericFunction baseModule, ::rtl::OUString const & relativePath,
93         ::sal_Int32 mode = SAL_LOADMODULE_DEFAULT)
94     {
95         unload();
96         m_Module = osl_loadModuleRelative(baseModule, relativePath.pData, mode);
97         return is();
98     }
99 
unload()100     void SAL_CALL unload()
101     {
102         if (m_Module)
103         {
104             osl_unloadModule(m_Module);
105             m_Module = 0;
106         }
107     }
108 
is() const109 	sal_Bool SAL_CALL is() const
110     {
111        	return m_Module != NULL;
112     }
113 
getSymbol(const::rtl::OUString & strSymbolName)114     void* SAL_CALL getSymbol( const ::rtl::OUString& strSymbolName)
115     {
116 	return ( osl_getSymbol( m_Module, strSymbolName.pData ) );
117     }
118 
119     /** Get function address by the function name in the module.
120 
121         getFunctionSymbol is an alternative function for getSymbol.
122         Use Function pointer as symbol address to conceal type conversion.
123 
124         @param ustrFunctionSymbolName
125         [in] Function name to be looked up.
126 
127         @return
128         <dl>
129         <dt>oslGenericFunction format function address</dt>
130         <dd>on success</dd>
131         <dt>NULL</dt>
132         <dd>lookup failed or parameter is somewhat invalid</dd>
133         </dl>
134 
135         @see getSymbol
136     */
getFunctionSymbol(const::rtl::OUString & ustrFunctionSymbolName)137     oslGenericFunction SAL_CALL getFunctionSymbol( const ::rtl::OUString& ustrFunctionSymbolName )
138     {
139         return ( osl_getFunctionSymbol( m_Module, ustrFunctionSymbolName.pData ) );
140     }
141 
operator oslModule() const142     operator oslModule() const
143     {
144         return m_Module;
145     }
146 
147 private:
148     oslModule m_Module;
149 
150 };
151 
152 }
153 
154 #endif
155