1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir /** @HTML */ 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #ifndef _OSL_MODULE_HXX_ 31*cdf0e10cSrcweir #define _OSL_MODULE_HXX_ 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <rtl/ustring.hxx> 34*cdf0e10cSrcweir #include <osl/module.h> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir namespace osl 37*cdf0e10cSrcweir { 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir class Module 40*cdf0e10cSrcweir { 41*cdf0e10cSrcweir Module( const Module&); 42*cdf0e10cSrcweir Module& operator = ( const Module&); 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir public: 45*cdf0e10cSrcweir static sal_Bool getUrlFromAddress(void * addr, ::rtl::OUString & libraryUrl) { 46*cdf0e10cSrcweir return osl_getModuleURLFromAddress(addr, &libraryUrl.pData); 47*cdf0e10cSrcweir } 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir /** Get module URL from the specified function address in the module. 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir Similar to getUrlFromAddress, but use a function address to get URL of the Module. 52*cdf0e10cSrcweir Use Function pointer as symbol address to conceal type conversion. 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir @param addr 55*cdf0e10cSrcweir [in] function address in oslGenericFunction format. 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir @param libraryUrl 58*cdf0e10cSrcweir [in|out] receives the URL of the module. 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir @return 61*cdf0e10cSrcweir <dl> 62*cdf0e10cSrcweir <dt>sal_True</dt> 63*cdf0e10cSrcweir <dd>on success</dd> 64*cdf0e10cSrcweir <dt>sal_False</dt> 65*cdf0e10cSrcweir <dd>can not get the URL from the specified function address or the parameter is invalid.</dd> 66*cdf0e10cSrcweir </dl> 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir @see getUrlFromAddress 69*cdf0e10cSrcweir */ 70*cdf0e10cSrcweir static sal_Bool getUrlFromAddress( oslGenericFunction addr, ::rtl::OUString & libraryUrl){ 71*cdf0e10cSrcweir return osl_getModuleURLFromFunctionAddress( addr, &libraryUrl.pData ); 72*cdf0e10cSrcweir } 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir Module(): m_Module(0){} 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir Module( const ::rtl::OUString& strModuleName, sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT) : m_Module(0) 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir load( strModuleName, nRtldMode); 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir ~Module() 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir osl_unloadModule(m_Module); 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir sal_Bool SAL_CALL load( const ::rtl::OUString& strModuleName, 87*cdf0e10cSrcweir sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT) 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir unload(); 90*cdf0e10cSrcweir m_Module= osl_loadModule( strModuleName.pData, nRtldMode ); 91*cdf0e10cSrcweir return is(); 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir /// @since UDK 3.2.8 95*cdf0e10cSrcweir sal_Bool SAL_CALL loadRelative( 96*cdf0e10cSrcweir ::oslGenericFunction baseModule, ::rtl::OUString const & relativePath, 97*cdf0e10cSrcweir ::sal_Int32 mode = SAL_LOADMODULE_DEFAULT) 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir unload(); 100*cdf0e10cSrcweir m_Module = osl_loadModuleRelative(baseModule, relativePath.pData, mode); 101*cdf0e10cSrcweir return is(); 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir void SAL_CALL unload() 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir if (m_Module) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir osl_unloadModule(m_Module); 109*cdf0e10cSrcweir m_Module = 0; 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir sal_Bool SAL_CALL is() const 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir return m_Module != NULL; 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir void* SAL_CALL getSymbol( const ::rtl::OUString& strSymbolName) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir return ( osl_getSymbol( m_Module, strSymbolName.pData ) ); 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir /** Get function address by the function name in the module. 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir getFunctionSymbol is an alternative function for getSymbol. 126*cdf0e10cSrcweir Use Function pointer as symbol address to conceal type conversion. 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir @param ustrFunctionSymbolName 129*cdf0e10cSrcweir [in] Function name to be looked up. 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir @return 132*cdf0e10cSrcweir <dl> 133*cdf0e10cSrcweir <dt>oslGenericFunction format function address</dt> 134*cdf0e10cSrcweir <dd>on success</dd> 135*cdf0e10cSrcweir <dt>NULL</dt> 136*cdf0e10cSrcweir <dd>lookup failed or parameter is somewhat invalid</dd> 137*cdf0e10cSrcweir </dl> 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir @see getSymbol 140*cdf0e10cSrcweir */ 141*cdf0e10cSrcweir oslGenericFunction SAL_CALL getFunctionSymbol( const ::rtl::OUString& ustrFunctionSymbolName ) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir return ( osl_getFunctionSymbol( m_Module, ustrFunctionSymbolName.pData ) ); 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir operator oslModule() const 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir return m_Module; 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir private: 152*cdf0e10cSrcweir oslModule m_Module; 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir }; 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir #endif 159