LibreOffice
LibreOffice 5.4 SDK C/C++ API Reference
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 
59  static bool getUrlFromAddress( oslGenericFunction addr, ::rtl::OUString & libraryUrl){
60  return osl_getModuleURLFromFunctionAddress( addr, &libraryUrl.pData );
61  }
62 
63  Module(): m_Module(NULL){}
64 
65 #ifndef DISABLE_DYNLOADING
66 
67  Module( const ::rtl::OUString& strModuleName, sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT) : m_Module(NULL)
68  {
69  load( strModuleName, nRtldMode);
70  }
71 
72 #endif
73 
75  {
76 #ifndef DISABLE_DYNLOADING
77  osl_unloadModule(m_Module);
78 #endif
79  }
80 
81 #ifndef DISABLE_DYNLOADING
82 
83  bool SAL_CALL load( const ::rtl::OUString& strModuleName,
84  sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT)
85  {
86  unload();
87  m_Module= osl_loadModule( strModuleName.pData, nRtldMode );
88  return is();
89  }
90 
92  bool SAL_CALL loadRelative(
93  ::oslGenericFunction baseModule, ::rtl::OUString const & relativePath,
94  ::sal_Int32 mode = SAL_LOADMODULE_DEFAULT)
95  {
96  unload();
97  m_Module = osl_loadModuleRelative(baseModule, relativePath.pData, mode);
98  return is();
99  }
100 
102  bool SAL_CALL loadRelative(
103  oslGenericFunction baseModule, char const * relativePath,
104  sal_Int32 mode = SAL_LOADMODULE_DEFAULT)
105  {
106  unload();
107  m_Module = osl_loadModuleRelativeAscii(baseModule, relativePath, mode);
108  return is();
109  }
110 
111  void SAL_CALL unload()
112  {
113  if (m_Module)
114  {
115  osl_unloadModule(m_Module);
116  m_Module = NULL;
117  }
118  }
119 
120 #endif
121 
122  bool SAL_CALL is() const
123  {
124  return m_Module != NULL;
125  }
126 
127  void* SAL_CALL getSymbol( const ::rtl::OUString& strSymbolName)
128  {
129  return ( osl_getSymbol( m_Module, strSymbolName.pData ) );
130  }
131 
145  oslGenericFunction SAL_CALL getFunctionSymbol( const ::rtl::OUString& ustrFunctionSymbolName ) const
146  {
147  return ( osl_getFunctionSymbol( m_Module, ustrFunctionSymbolName.pData ) );
148  }
149 
151  oslGenericFunction SAL_CALL getFunctionSymbol(char const * name) const {
152  return osl_getAsciiFunctionSymbol(m_Module, name);
153  }
154 
155  operator oslModule() const
156  {
157  return m_Module;
158  }
159 
167  void release() { m_Module = NULL; }
168 
169 private:
170  oslModule m_Module;
171 
172 };
173 
174 }
175 
176 #endif
177 
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC oslGenericFunction osl_getFunctionSymbol(oslModule Module, rtl_uString *ustrFunctionSymbolName)
Lookup the specified function symbol name.
bool loadRelative(::oslGenericFunction baseModule, ::rtl::OUString const &relativePath, ::sal_Int32 mode=SAL_LOADMODULE_DEFAULT)
Definition: module.hxx:92
SAL_DLLPUBLIC sal_Bool osl_getModuleURLFromFunctionAddress(oslGenericFunction pf, rtl_uString **pustrFunctionURL)
Lookup URL of module which is mapped at the specified function address.
SAL_DLLPUBLIC sal_Bool osl_getModuleURLFromAddress(void *pv, rtl_uString **pustrURL)
Lookup URL of module which is mapped at the specified address.
bool load(const ::rtl::OUString &strModuleName, sal_Int32 nRtldMode=SAL_LOADMODULE_DEFAULT)
Definition: module.hxx:83
Module(const ::rtl::OUString &strModuleName, sal_Int32 nRtldMode=SAL_LOADMODULE_DEFAULT)
Definition: module.hxx:67
static bool getUrlFromAddress(oslGenericFunction addr, ::rtl::OUString &libraryUrl)
Get module URL from the specified function address in the module.
Definition: module.hxx:59
oslGenericFunction getFunctionSymbol(char const *name) const
Definition: module.hxx:151
SAL_DLLPUBLIC oslModule osl_loadModule(rtl_uString *strModuleName, sal_Int32 nRtldMode)
Load a shared library or module.
SAL_DLLPUBLIC oslGenericFunction osl_getAsciiFunctionSymbol(oslModule Module, const sal_Char *pSymbol)
Lookup the specified function symbol name.
#define SAL_LOADMODULE_DEFAULT
Definition: module.h:51
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:392
void * getSymbol(const ::rtl::OUString &strSymbolName)
Definition: module.hxx:127
bool is() const
Definition: module.hxx:122
void * oslModule
Definition: module.h:56
~Module()
Definition: module.hxx:74
void release()
Release the module so that it will not be unloaded from the destructor.
Definition: module.hxx:167
Module()
Definition: module.hxx:63
SAL_DLLPUBLIC oslModule osl_loadModuleRelativeAscii(oslGenericFunction baseModule, char const *relativePath, sal_Int32 mode)
Load a module located relative to some other module.
void unload()
Definition: module.hxx:111
Definition: conditn.hxx:37
bool loadRelative(oslGenericFunction baseModule, char const *relativePath, sal_Int32 mode=SAL_LOADMODULE_DEFAULT)
Definition: module.hxx:102
SAL_DLLPUBLIC void osl_unloadModule(oslModule Module)
Release the module.
Definition: module.hxx:33
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:120
oslGenericFunction getFunctionSymbol(const ::rtl::OUString &ustrFunctionSymbolName) const
Get function address by the function name in the module.
Definition: module.hxx:145
static bool getUrlFromAddress(void *addr, ::rtl::OUString &libraryUrl)
Definition: module.hxx:39
SAL_DLLPUBLIC oslModule osl_loadModuleRelative(oslGenericFunction baseModule, rtl_uString *relativePath, sal_Int32 mode)
Load a module located relative to some other module.
void(* oslGenericFunction)(void)
Generic Function pointer type that will be used as symbol address.
Definition: module.h:62
SAL_DLLPUBLIC void * osl_getSymbol(oslModule Module, rtl_uString *strSymbolName)
lookup the specified symbol name.