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