AlterOffice
AlterOffice 3.4 SDK C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 
4 #ifndef INCLUDED_OSL_MODULE_HXX
5 #define INCLUDED_OSL_MODULE_HXX
6 
7 #include "sal/config.h"
8 
9 #include <cstddef>
10 
11 #include "rtl/ustring.hxx"
12 #include "osl/module.h"
13 
14 namespace osl
15 {
16 
17 class Module
18 {
20  Module& operator = ( const Module&) SAL_DELETED_FUNCTION;
21 
22 public:
23  static bool getUrlFromAddress(void * addr, ::rtl::OUString & libraryUrl) {
24  return osl_getModuleURLFromAddress(addr, &libraryUrl.pData);
25  }
26 
40  static bool getUrlFromAddress( oslGenericFunction addr, ::rtl::OUString & libraryUrl){
41  return osl_getModuleURLFromFunctionAddress( addr, &libraryUrl.pData );
42  }
43 
44  Module(): m_Module(NULL){}
45 
46 #ifndef DISABLE_DYNLOADING
47 
48  Module( const ::rtl::OUString& strModuleName, sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT) : m_Module(NULL)
49  {
50  load( strModuleName, nRtldMode);
51  }
52 
53 #endif
54 
56  {
57 #ifndef DISABLE_DYNLOADING
58  osl_unloadModule(m_Module);
59 #endif
60  }
61 
62 #ifndef DISABLE_DYNLOADING
63 
64  bool SAL_CALL load( const ::rtl::OUString& strModuleName,
65  sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT)
66  {
67  unload();
68  m_Module= osl_loadModule( strModuleName.pData, nRtldMode );
69  return is();
70  }
71 
73  bool SAL_CALL loadRelative(
74  ::oslGenericFunction baseModule, ::rtl::OUString const & relativePath,
75  ::sal_Int32 mode = SAL_LOADMODULE_DEFAULT)
76  {
77  unload();
78  m_Module = osl_loadModuleRelative(baseModule, relativePath.pData, mode);
79  return is();
80  }
81 
83  bool SAL_CALL loadRelative(
84  oslGenericFunction baseModule, char const * relativePath,
85  sal_Int32 mode = SAL_LOADMODULE_DEFAULT)
86  {
87  unload();
88  m_Module = osl_loadModuleRelativeAscii(baseModule, relativePath, mode);
89  return is();
90  }
91 
92  void SAL_CALL unload()
93  {
94  if (m_Module)
95  {
96  osl_unloadModule(m_Module);
97  m_Module = NULL;
98  }
99  }
100 
101 #endif
102 
103  bool SAL_CALL is() const
104  {
105  return m_Module != NULL;
106  }
107 
108  void* SAL_CALL getSymbol( const ::rtl::OUString& strSymbolName)
109  {
110  return osl_getSymbol( m_Module, strSymbolName.pData );
111  }
112 
125  oslGenericFunction SAL_CALL getFunctionSymbol( const ::rtl::OUString& ustrFunctionSymbolName ) const
126  {
127  return osl_getFunctionSymbol( m_Module, ustrFunctionSymbolName.pData );
128  }
129 
131  oslGenericFunction SAL_CALL getFunctionSymbol(char const * name) const {
132  return osl_getAsciiFunctionSymbol(m_Module, name);
133  }
134 
135  operator oslModule() const
136  {
137  return m_Module;
138  }
139 
147  void release() { m_Module = NULL; }
148 
149 private:
150  oslModule m_Module;
151 
152 };
153 
154 }
155 
156 #endif
157 
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static bool getUrlFromAddress(void *addr,::rtl::OUString &libraryUrl)
Definition: module.hxx:23
Definition: module.hxx:17
SAL_DLLPUBLIC oslModule osl_loadModuleRelativeAscii(oslGenericFunction baseModule, char const *relativePath, sal_Int32 mode)
Load a module located relative to some other module.
~Module()
Definition: module.hxx:55
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:182
void release()
Release the module so that it will not be unloaded from the destructor.
Definition: module.hxx:147
void unload()
Definition: module.hxx:92
Module()
Definition: module.hxx:44
Module(const ::rtl::OUString &strModuleName, sal_Int32 nRtldMode=SAL_LOADMODULE_DEFAULT)
Definition: module.hxx:48
SAL_DLLPUBLIC oslModule osl_loadModule(rtl_uString *strModuleName, sal_Int32 nRtldMode)
Load a shared library or module.
oslGenericFunction getFunctionSymbol(const ::rtl::OUString &ustrFunctionSymbolName) const
Get function address by the function name in the module.
Definition: module.hxx:125
static bool getUrlFromAddress(oslGenericFunction addr,::rtl::OUString &libraryUrl)
Get module URL from the specified function address in the module.
Definition: module.hxx:40
void(* oslGenericFunction)(void)
Generic Function pointer type that will be used as symbol address.
Definition: module.h:46
SAL_DLLPUBLIC oslGenericFunction osl_getFunctionSymbol(oslModule Module, rtl_uString *ustrFunctionSymbolName)
Lookup the specified function symbol name.
pData
Definition: ustring.hxx:334
#define SAL_LOADMODULE_DEFAULT
Definition: module.h:34
SAL_DLLPUBLIC sal_Bool osl_getModuleURLFromAddress(void *pv, rtl_uString **pustrURL)
Lookup URL of module which is mapped at the specified address.
SAL_DLLPUBLIC oslModule osl_loadModuleRelative(oslGenericFunction baseModule, rtl_uString *relativePath, sal_Int32 mode)
Load a module located relative to some other module.
bool load(const ::rtl::OUString &strModuleName, sal_Int32 nRtldMode=SAL_LOADMODULE_DEFAULT)
Definition: module.hxx:64
bool is() const
Definition: module.hxx:103
void * oslModule
Definition: module.h:39
SAL_DLLPUBLIC oslGenericFunction osl_getAsciiFunctionSymbol(oslModule Module, const char *pSymbol)
Lookup the specified function symbol name.
void * getSymbol(const ::rtl::OUString &strSymbolName)
Definition: module.hxx:108
SAL_DLLPUBLIC void * osl_getSymbol(oslModule Module, rtl_uString *strSymbolName)
lookup the specified symbol name.
SAL_DLLPUBLIC void osl_unloadModule(oslModule Module)
Release the module.
bool loadRelative(::oslGenericFunction baseModule,::rtl::OUString const &relativePath,::sal_Int32 mode=SAL_LOADMODULE_DEFAULT)
Definition: module.hxx:73
SAL_DLLPUBLIC sal_Bool osl_getModuleURLFromFunctionAddress(oslGenericFunction pf, rtl_uString **pustrFunctionURL)
Lookup URL of module which is mapped at the specified function address.
oslGenericFunction getFunctionSymbol(char const *name) const
Definition: module.hxx:131
bool loadRelative(oslGenericFunction baseModule, char const *relativePath, sal_Int32 mode=SAL_LOADMODULE_DEFAULT)
Definition: module.hxx:83
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:358