fw4spl
Library.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #ifndef __FWRUNTIME_DL_LIBRARY_HPP__
8 #define __FWRUNTIME_DL_LIBRARY_HPP__
9 
10 #include "fwRuntime/RuntimeException.hpp"
11 #include "fwRuntime/dl/Posix.hpp"
12 #include "fwRuntime/dl/Win32.hpp"
13 
14 #include <boost/filesystem/path.hpp>
15 
16 namespace fwRuntime
17 {
18 
19 struct Bundle;
20 
21 namespace dl
22 {
23 
29 template< typename Implementor >
31 {
32 
39  LibraryBridge( const boost::filesystem::path & modulePath ) noexcept
40  : m_implementor( modulePath )
41  {
42  }
43 
47  ~LibraryBridge() noexcept
48  {
49  }
50 
51 
57  bool isLoaded() const noexcept
58  {
59  return m_implementor.isLoaded();
60  }
61 
69  const boost::filesystem::path getFullPath() const
70  {
71  return m_implementor.getFullPath();
72  }
73 
83  const boost::filesystem::path getPath() const
84  {
85  return m_implementor.getPath();
86  }
87 
95  void* getSymbol(const std::string& name) const
96  {
97  return m_implementor.getSymbol(name);
98  }
99 
103  void load()
104  {
105  m_implementor.load();
106  }
107 
113  void setBundle(const ::fwRuntime::Bundle* bundle) noexcept
114  {
115  m_implementor.setBundle(bundle);
116  }
117 
121  void unload()
122  {
123  m_implementor.unload();
124  }
125 
126 
127  private:
128 
132  Implementor m_implementor;
133 
134 
140  void operator=(const LibraryBridge&) noexcept
141  {
142  }
143 };
144 
145 
146 #if defined(linux) || defined(__linux) || defined(__MACOSX__)
147 typedef struct LibraryBridge< Posix > Library;
148 #else
149 typedef struct LibraryBridge< Win32 > Library;
150 #endif
151 
152 
153 } // namespace dl
154 
155 } // namespace fwRuntime
156 
157 
158 #endif // __FWRUNTIME_DL_LIBRARY_HPP__
void unload()
Undloads the module.
Definition: Library.hpp:121
The namespace fwRuntime contains classes to manage bundle, configuration element, extension point in ...
LibraryBridge(const boost::filesystem::path &modulePath) noexcept
Constructor.
Definition: Library.hpp:39
~LibraryBridge() noexcept
Destructor : does nothing.
Definition: Library.hpp:47
void * getSymbol(const std::string &name) const
Retrieves the address of a symbol specified by its name.
Definition: Library.hpp:95
const boost::filesystem::path getFullPath() const
Retrieves the file path of the library including the owning bundle&#39;s path.
Definition: Library.hpp:69
const boost::filesystem::path getPath() const
Retrieves the file path of the library.
Definition: Library.hpp:83
Defines the module class.This class is only a bridge to a native module implementor.
Definition: Library.hpp:30
void load()
Loads the module.
Definition: Library.hpp:103
bool isLoaded() const noexcept
Tells if the module is loaded.
Definition: Library.hpp:57
void setBundle(const ::fwRuntime::Bundle *bundle) noexcept
Sets the bundle the library is attached to.
Definition: Library.hpp:113