LibreOffice
LibreOffice 6.0 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 
56  static bool getUrlFromAddress( oslGenericFunction addr, ::rtl::OUString & libraryUrl){
57  return osl_getModuleURLFromFunctionAddress( addr, &libraryUrl.pData );
58  }
59 
60  Module(): m_Module(NULL){}
61 
62 #ifndef DISABLE_DYNLOADING
63 
64  Module( const ::rtl::OUString& strModuleName, sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT) : m_Module(NULL)
65  {
66  load( strModuleName, nRtldMode);
67  }
68 
69 #endif
70 
72  {
73 #ifndef DISABLE_DYNLOADING
74  osl_unloadModule(m_Module);
75 #endif
76  }
77 
78 #ifndef DISABLE_DYNLOADING
79 
80  bool SAL_CALL load( const ::rtl::OUString& strModuleName,
81  sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT)
82  {
83  unload();
84  m_Module= osl_loadModule( strModuleName.pData, nRtldMode );
85  return is();
86  }
87 
89  bool SAL_CALL loadRelative(
90  ::oslGenericFunction baseModule, ::rtl::OUString const & relativePath,
91  ::sal_Int32 mode = SAL_LOADMODULE_DEFAULT)
92  {
93  unload();
94  m_Module = osl_loadModuleRelative(baseModule, relativePath.pData, mode);
95  return is();
96  }
97 
99  bool SAL_CALL loadRelative(
100  oslGenericFunction baseModule, char const * relativePath,
101  sal_Int32 mode = SAL_LOADMODULE_DEFAULT)
102  {
103  unload();
104  m_Module = osl_loadModuleRelativeAscii(baseModule, relativePath, mode);
105  return is();
106  }
107 
108  void SAL_CALL unload()
109  {
110  if (m_Module)
111  {
112  osl_unloadModule(m_Module);
113  m_Module = NULL;
114  }
115  }
116 
117 #endif
118 
119  bool SAL_CALL is() const
120  {
121  return m_Module != NULL;
122  }
123 
124  void* SAL_CALL getSymbol( const ::rtl::OUString& strSymbolName)
125  {
126  return osl_getSymbol( m_Module, strSymbolName.pData );
127  }
128 
141  oslGenericFunction SAL_CALL getFunctionSymbol( const ::rtl::OUString& ustrFunctionSymbolName ) const
142  {
143  return osl_getFunctionSymbol( m_Module, ustrFunctionSymbolName.pData );
144  }
145 
147  oslGenericFunction SAL_CALL getFunctionSymbol(char const * name) const {
148  return osl_getAsciiFunctionSymbol(m_Module, name);
149  }
150 
151  operator oslModule() const
152  {
153  return m_Module;
154  }
155 
163  void release() { m_Module = NULL; }
164 
165 private:
166  oslModule m_Module;
167 
168 };
169 
170 }
171 
172 #endif
173 
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool load(const ::rtl::OUString &strModuleName, sal_Int32 nRtldMode=SAL_LOADMODULE_DEFAULT)
Definition: module.hxx:80
Module()
Definition: module.hxx:60
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:99
oslGenericFunction getFunctionSymbol(char const *name) const
Definition: module.hxx:147
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:402
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:71
Module(const ::rtl::OUString &strModuleName, sal_Int32 nRtldMode=SAL_LOADMODULE_DEFAULT)
Definition: module.hxx:64
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:56
oslGenericFunction getFunctionSymbol(const ::rtl::OUString &ustrFunctionSymbolName) const
Get function address by the function name in the module.
Definition: module.hxx:141
Definition: module.hxx:33
bool loadRelative(::oslGenericFunction baseModule,::rtl::OUString const &relativePath,::sal_Int32 mode=SAL_LOADMODULE_DEFAULT)
Definition: module.hxx:89
#define SAL_LOADMODULE_DEFAULT
Definition: module.h:51
void unload()
Definition: module.hxx:108
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:120
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:124
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:163
Definition: conditn.hxx:36
SAL_DLLPUBLIC void * osl_getSymbol(oslModule Module, rtl_uString *strSymbolName)
lookup the specified symbol name.
bool is() const
Definition: module.hxx:119
void(* oslGenericFunction)(void)
Generic Function pointer type that will be used as symbol address.
Definition: module.h:63
void * oslModule
Definition: module.h:56