LibreOffice
LibreOffice 5.3 SDK C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
module.hxx
Go to the documentation of this file.
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 INCLUDED_OSL_MODULE_HXX
21 #define INCLUDED_OSL_MODULE_HXX
22 
23 #include <sal/config.h>
24 
25 #include <cstddef>
26 
27 #include <rtl/ustring.hxx>
28 #include <osl/module.h>
29 
30 namespace osl
31 {
32 
33 class Module
34 {
36  Module& operator = ( const Module&) SAL_DELETED_FUNCTION;
37 
38 public:
39  static bool getUrlFromAddress(void * addr, ::rtl::OUString & libraryUrl) {
40  return osl_getModuleURLFromAddress(addr, &libraryUrl.pData);
41  }
42 
64  static bool getUrlFromAddress( oslGenericFunction addr, ::rtl::OUString & libraryUrl){
65  return osl_getModuleURLFromFunctionAddress( addr, &libraryUrl.pData );
66  }
67 
68  Module(): m_Module(NULL){}
69 
70 #ifndef DISABLE_DYNLOADING
71 
72  Module( const ::rtl::OUString& strModuleName, sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT) : m_Module(NULL)
73  {
74  load( strModuleName, nRtldMode);
75  }
76 
77 #endif
78 
80  {
81 #ifndef DISABLE_DYNLOADING
82  osl_unloadModule(m_Module);
83 #endif
84  }
85 
86 #ifndef DISABLE_DYNLOADING
87 
88  bool SAL_CALL load( const ::rtl::OUString& strModuleName,
89  sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT)
90  {
91  unload();
92  m_Module= osl_loadModule( strModuleName.pData, nRtldMode );
93  return is();
94  }
95 
97  bool SAL_CALL loadRelative(
98  ::oslGenericFunction baseModule, ::rtl::OUString const & relativePath,
99  ::sal_Int32 mode = SAL_LOADMODULE_DEFAULT)
100  {
101  unload();
102  m_Module = osl_loadModuleRelative(baseModule, relativePath.pData, mode);
103  return is();
104  }
105 
107  bool SAL_CALL loadRelative(
108  oslGenericFunction baseModule, char const * relativePath,
109  sal_Int32 mode = SAL_LOADMODULE_DEFAULT)
110  {
111  unload();
112  m_Module = osl_loadModuleRelativeAscii(baseModule, relativePath, mode);
113  return is();
114  }
115 
116  void SAL_CALL unload()
117  {
118  if (m_Module)
119  {
120  osl_unloadModule(m_Module);
121  m_Module = NULL;
122  }
123  }
124 
125 #endif
126 
127  bool SAL_CALL is() const
128  {
129  return m_Module != NULL;
130  }
131 
132  void* SAL_CALL getSymbol( const ::rtl::OUString& strSymbolName)
133  {
134  return ( osl_getSymbol( m_Module, strSymbolName.pData ) );
135  }
136 
155  oslGenericFunction SAL_CALL getFunctionSymbol( const ::rtl::OUString& ustrFunctionSymbolName ) const
156  {
157  return ( osl_getFunctionSymbol( m_Module, ustrFunctionSymbolName.pData ) );
158  }
159 
161  oslGenericFunction SAL_CALL getFunctionSymbol(char const * name) const {
162  return osl_getAsciiFunctionSymbol(m_Module, name);
163  }
164 
165  operator oslModule() const
166  {
167  return m_Module;
168  }
169 
177  void release() { m_Module = NULL; }
178 
179 private:
180  oslModule m_Module;
181 
182 };
183 
184 }
185 
186 #endif
187 
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool load(const ::rtl::OUString &strModuleName, sal_Int32 nRtldMode=SAL_LOADMODULE_DEFAULT)
Definition: module.hxx:88
Module()
Definition: module.hxx:68
SAL_DLLPUBLIC sal_Bool osl_getModuleURLFromFunctionAddress(oslGenericFunction pf, rtl_uString **pustrFunctionURL)
Lookup URL of module which is mapped at the specified function address.
bool loadRelative(oslGenericFunction baseModule, char const *relativePath, sal_Int32 mode=SAL_LOADMODULE_DEFAULT)
Definition: module.hxx:107
oslGenericFunction getFunctionSymbol(char const *name) const
Definition: module.hxx:161
SAL_DLLPUBLIC oslModule osl_loadModuleRelativeAscii(oslGenericFunction baseModule, char const *relativePath, sal_Int32 mode)
Load a module located relative to some other module.
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:410
SAL_DLLPUBLIC oslGenericFunction osl_getAsciiFunctionSymbol(oslModule Module, const sal_Char *pSymbol)
Lookup the specified function symbol name.
SAL_DLLPUBLIC oslModule osl_loadModule(rtl_uString *strModuleName, sal_Int32 nRtldMode)
Load a shared library or module.
SAL_DLLPUBLIC sal_Bool osl_getModuleURLFromAddress(void *pv, rtl_uString **pustrURL)
Lookup URL of module which is mapped at the specified address.
~Module()
Definition: module.hxx:79
void(* oslGenericFunction)(void)
Generic Function pointer type that will be used as symbol address.
Definition: module.h:62
Module(const ::rtl::OUString &strModuleName, sal_Int32 nRtldMode=SAL_LOADMODULE_DEFAULT)
Definition: module.hxx:72
SAL_DLLPUBLIC oslGenericFunction osl_getFunctionSymbol(oslModule Module, rtl_uString *ustrFunctionSymbolName)
Lookup the specified function symbol name.
static bool getUrlFromAddress(oslGenericFunction addr,::rtl::OUString &libraryUrl)
Get module URL from the specified function address in the module.
Definition: module.hxx:64
oslGenericFunction getFunctionSymbol(const ::rtl::OUString &ustrFunctionSymbolName) const
Get function address by the function name in the module.
Definition: module.hxx:155
Definition: module.hxx:33
bool loadRelative(::oslGenericFunction baseModule,::rtl::OUString const &relativePath,::sal_Int32 mode=SAL_LOADMODULE_DEFAULT)
Definition: module.hxx:97
#define SAL_LOADMODULE_DEFAULT
Definition: module.h:51
void unload()
Definition: module.hxx:116
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:106
SAL_DLLPUBLIC void osl_unloadModule(oslModule Module)
Release the module.
static bool getUrlFromAddress(void *addr,::rtl::OUString &libraryUrl)
Definition: module.hxx:39
void * getSymbol(const ::rtl::OUString &strSymbolName)
Definition: module.hxx:132
SAL_DLLPUBLIC oslModule osl_loadModuleRelative(oslGenericFunction baseModule, rtl_uString *relativePath, sal_Int32 mode)
Load a module located relative to some other module.
void release()
Release the module so that it will not be unloaded from the destructor.
Definition: module.hxx:177
SAL_DLLPUBLIC void * osl_getSymbol(oslModule Module, rtl_uString *strSymbolName)
lookup the specified symbol name.
bool is() const
Definition: module.hxx:127
void * oslModule
Definition: module.h:56