LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/include/osl - module.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 38 38 100.0 %
Date: 2013-07-09 Functions: 14 14 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef _OSL_MODULE_HXX_
      21             : #define _OSL_MODULE_HXX_
      22             : 
      23             : #include <rtl/ustring.hxx>
      24             : #include <osl/module.h>
      25             : 
      26             : namespace osl
      27             : {
      28             : 
      29             : class Module
      30             : {
      31             :     Module( const Module&);
      32             :     Module& operator = ( const Module&);
      33             : 
      34             : public:
      35         122 :     static sal_Bool getUrlFromAddress(void * addr, ::rtl::OUString & libraryUrl) {
      36         122 :         return osl_getModuleURLFromAddress(addr, &libraryUrl.pData);
      37             :     }
      38             : 
      39             :     /** Get module URL from the specified function address in the module.
      40             : 
      41             :         Similar to getUrlFromAddress, but use a function address to get URL of the Module.
      42             :         Use Function pointer as symbol address to conceal type conversion.
      43             : 
      44             :         @param addr
      45             :         [in] function address in oslGenericFunction format.
      46             : 
      47             :         @param libraryUrl
      48             :         [in|out] receives the URL of the module.
      49             : 
      50             :         @return
      51             :         <dl>
      52             :         <dt>sal_True</dt>
      53             :         <dd>on success</dd>
      54             :         <dt>sal_False</dt>
      55             :         <dd>can not get the URL from the specified function address or the parameter is invalid.</dd>
      56             :         </dl>
      57             : 
      58             :         @see getUrlFromAddress
      59             :     */
      60       21965 :     static sal_Bool getUrlFromAddress( oslGenericFunction addr, ::rtl::OUString & libraryUrl){
      61       21965 :         return osl_getModuleURLFromFunctionAddress( addr, &libraryUrl.pData );
      62             :     }
      63             : 
      64         949 :     Module(): m_Module(0){}
      65             : 
      66             : #ifndef DISABLE_DYNLOADING
      67             : 
      68         189 :     Module( const ::rtl::OUString& strModuleName, sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT) : m_Module(0)
      69             :     {
      70         189 :         load( strModuleName, nRtldMode);
      71         189 :     }
      72             : 
      73             : #endif
      74             : 
      75        1130 :     ~Module()
      76             :     {
      77             : #ifndef DISABLE_DYNLOADING
      78        1130 :         osl_unloadModule(m_Module);
      79             : #endif
      80        1130 :     }
      81             : 
      82             : #ifndef DISABLE_DYNLOADING
      83             : 
      84         402 :     sal_Bool SAL_CALL load( const ::rtl::OUString& strModuleName,
      85             :         sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT)
      86             :     {
      87         402 :         unload();
      88         402 :         m_Module= osl_loadModule( strModuleName.pData, nRtldMode );
      89         402 :         return is();
      90             :     }
      91             : 
      92             :     /// @since UDK 3.2.8
      93         256 :     sal_Bool SAL_CALL loadRelative(
      94             :         ::oslGenericFunction baseModule, ::rtl::OUString const & relativePath,
      95             :         ::sal_Int32 mode = SAL_LOADMODULE_DEFAULT)
      96             :     {
      97         256 :         unload();
      98         256 :         m_Module = osl_loadModuleRelative(baseModule, relativePath.pData, mode);
      99         256 :         return is();
     100             :     }
     101             : 
     102             :     /// @since LibreOffice 3.5
     103          30 :     sal_Bool SAL_CALL loadRelative(
     104             :         oslGenericFunction baseModule, char const * relativePath,
     105             :         sal_Int32 mode = SAL_LOADMODULE_DEFAULT)
     106             :     {
     107          30 :         unload();
     108          30 :         m_Module = osl_loadModuleRelativeAscii(baseModule, relativePath, mode);
     109          30 :         return is();
     110             :     }
     111             : 
     112         698 :     void SAL_CALL unload()
     113             :     {
     114         698 :         if (m_Module)
     115             :         {
     116          10 :             osl_unloadModule(m_Module);
     117          10 :             m_Module = 0;
     118             :         }
     119         698 :     }
     120             : 
     121             : #endif
     122             : 
     123         926 :     sal_Bool SAL_CALL is() const
     124             :     {
     125         926 :            return m_Module != NULL;
     126             :     }
     127             : 
     128           2 :     void* SAL_CALL getSymbol( const ::rtl::OUString& strSymbolName)
     129             :     {
     130           2 :     return ( osl_getSymbol( m_Module, strSymbolName.pData ) );
     131             :     }
     132             : 
     133             :     /** Get function address by the function name in the module.
     134             : 
     135             :         getFunctionSymbol is an alternative function for getSymbol.
     136             :         Use Function pointer as symbol address to conceal type conversion.
     137             : 
     138             :         @param ustrFunctionSymbolName
     139             :         [in] Function name to be looked up.
     140             : 
     141             :         @return
     142             :         <dl>
     143             :         <dt>oslGenericFunction format function address</dt>
     144             :         <dd>on success</dd>
     145             :         <dt>NULL</dt>
     146             :         <dd>lookup failed or parameter is somewhat invalid</dd>
     147             :         </dl>
     148             : 
     149             :         @see getSymbol
     150             :     */
     151      146715 :     oslGenericFunction SAL_CALL getFunctionSymbol( const ::rtl::OUString& ustrFunctionSymbolName ) const
     152             :     {
     153      146715 :         return ( osl_getFunctionSymbol( m_Module, ustrFunctionSymbolName.pData ) );
     154             :     }
     155             : 
     156             :     /// @since LibreOffice 3.5
     157          34 :     oslGenericFunction SAL_CALL getFunctionSymbol(char const * name) const {
     158          34 :         return osl_getAsciiFunctionSymbol(m_Module, name);
     159             :     }
     160             : 
     161         114 :     operator oslModule() const
     162             :     {
     163         114 :         return m_Module;
     164             :     }
     165             : 
     166             : private:
     167             :     oslModule m_Module;
     168             : 
     169             : };
     170             : 
     171             : }
     172             : 
     173             : #endif
     174             : 
     175             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10