UDK 3.2.7 C/C++ API Reference
osl/module.hxx
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /*************************************************************************
00003  *
00004  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
00005  *
00006  * Copyright 2000, 2010 Oracle and/or its affiliates.
00007  *
00008  * OpenOffice.org - a multi-platform office productivity suite
00009  *
00010  * This file is part of OpenOffice.org.
00011  *
00012  * OpenOffice.org is free software: you can redistribute it and/or modify
00013  * it under the terms of the GNU Lesser General Public License version 3
00014  * only, as published by the Free Software Foundation.
00015  *
00016  * OpenOffice.org is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Lesser General Public License version 3 for more details
00020  * (a copy is included in the LICENSE file that accompanied this code).
00021  *
00022  * You should have received a copy of the GNU Lesser General Public License
00023  * version 3 along with OpenOffice.org.  If not, see
00024  * <http://www.openoffice.org/license.html>
00025  * for a copy of the LGPLv3 License.
00026  *
00027  ************************************************************************/
00028 
00029 #ifndef _OSL_MODULE_HXX_
00030 #define _OSL_MODULE_HXX_
00031 
00032 #include <rtl/ustring.hxx>
00033 #include <osl/module.h>
00034 
00035 namespace osl
00036 {
00037 
00038 class Module
00039 {
00040     Module( const Module&);
00041     Module& operator = ( const Module&);
00042 
00043 public:
00044     static sal_Bool getUrlFromAddress(void * addr, ::rtl::OUString & libraryUrl) {
00045         return osl_getModuleURLFromAddress(addr, &libraryUrl.pData);
00046     }
00047 
00069     static sal_Bool getUrlFromAddress( oslGenericFunction addr, ::rtl::OUString & libraryUrl){
00070         return osl_getModuleURLFromFunctionAddress( addr, &libraryUrl.pData );
00071     }
00072 
00073     Module(): m_Module(0){}
00074 
00075     Module( const ::rtl::OUString& strModuleName, sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT) : m_Module(0)
00076     {
00077         load( strModuleName, nRtldMode);
00078     }
00079 
00080     ~Module()
00081     {
00082         osl_unloadModule(m_Module);
00083     }
00084 
00085     sal_Bool SAL_CALL load( const ::rtl::OUString& strModuleName,
00086         sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT)
00087     {
00088         unload();
00089         m_Module= osl_loadModule( strModuleName.pData, nRtldMode );
00090         return is();
00091     }
00092 
00094     sal_Bool SAL_CALL loadRelative(
00095         ::oslGenericFunction baseModule, ::rtl::OUString const & relativePath,
00096         ::sal_Int32 mode = SAL_LOADMODULE_DEFAULT)
00097     {
00098         unload();
00099         m_Module = osl_loadModuleRelative(baseModule, relativePath.pData, mode);
00100         return is();
00101     }
00102 
00104     sal_Bool SAL_CALL loadRelative(
00105         oslGenericFunction baseModule, char const * relativePath,
00106         sal_Int32 mode = SAL_LOADMODULE_DEFAULT)
00107     {
00108         unload();
00109         m_Module = osl_loadModuleRelativeAscii(baseModule, relativePath, mode);
00110         return is();
00111     }
00112 
00113     void SAL_CALL unload()
00114     {
00115         if (m_Module)
00116         {
00117             osl_unloadModule(m_Module);
00118             m_Module = 0;
00119         }
00120     }
00121 
00122     sal_Bool SAL_CALL is() const
00123     {
00124            return m_Module != NULL;
00125     }
00126 
00127     void* SAL_CALL getSymbol( const ::rtl::OUString& strSymbolName)
00128     {
00129     return ( osl_getSymbol( m_Module, strSymbolName.pData ) );
00130     }
00131 
00150     oslGenericFunction SAL_CALL getFunctionSymbol( const ::rtl::OUString& ustrFunctionSymbolName ) const
00151     {
00152         return ( osl_getFunctionSymbol( m_Module, ustrFunctionSymbolName.pData ) );
00153     }
00154 
00156     oslGenericFunction SAL_CALL getFunctionSymbol(char const * name) const {
00157         return osl_getAsciiFunctionSymbol(m_Module, name);
00158     }
00159 
00160     operator oslModule() const
00161     {
00162         return m_Module;
00163     }
00164 
00165 private:
00166     oslModule m_Module;
00167 
00168 };
00169 
00170 }
00171 
00172 #endif
00173 
00174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines