7 #include "fwRuntime/dl/Native.hpp" 9 #include "fwRuntime/Bundle.hpp" 10 #include "fwRuntime/Runtime.hpp" 12 #include <boost/filesystem/operations.hpp> 13 #include <boost/filesystem/path.hpp> 28 m_modulePath( modulePath ),
41 const ::boost::filesystem::path Native::getBundleLocation()
const 44 return ::fwRuntime::Runtime::getDefault()->getWorkingPath() /
"lib";
55 SLM_ASSERT(
"bundle not initialized", m_bundle != 0 );
57 ::boost::filesystem::path result;
59 result = this->getBundleLocation() / this->
getPath();
66 if( !::boost::filesystem::exists(result) )
68 throw RuntimeException(
"'" + result.string() +
"': invalid native module file name.");
70 if(_bMustBeFile && ::boost::filesystem::is_directory(result) )
72 throw RuntimeException(
"'" + result.string() +
"': is a directory. Perhaps dynamic library is missing.");
81 const ::boost::filesystem::path fullModulePath( this->getBundleLocation() / m_modulePath );
82 ::boost::regex nativeName;
84 #if defined(linux) || defined(__linux) 85 nativeName = ::boost::regex(
86 "lib" + fullModulePath.filename().string() + Bundle::s_VERSION_DELIMITER + m_bundle->
getVersion().
string() +
"\\.so" +
89 nativeName = ::boost::regex(
90 fullModulePath.filename().string() + Bundle::s_VERSION_DELIMITER + m_bundle->
getVersion().
string() +
92 #elif defined (__MACOSX__) 93 nativeName = ::boost::regex(
94 "lib" + fullModulePath.filename().string() + Bundle::s_VERSION_DELIMITER + m_bundle->
getVersion().
string() +
"[0-9\\.]*" +
106 SLM_ASSERT(
"bundle not initialized", m_bundle != 0 );
108 ::boost::filesystem::path result;
110 const ::boost::filesystem::path fullModulePath( this->getBundleLocation() / m_modulePath );
111 const ::boost::regex nativeFileRegex( this->
getNativeName() );
114 ::boost::filesystem::directory_iterator curDirEntry(fullModulePath.parent_path());
115 ::boost::filesystem::directory_iterator endDirEntry;
116 for(; curDirEntry != endDirEntry; ++curDirEntry)
118 ::boost::filesystem::path curEntryPath( *curDirEntry );
119 if( ::boost::regex_match( curEntryPath.filename().string(), nativeFileRegex ) )
121 result = m_modulePath.parent_path() / curEntryPath.filename();
134 SLM_ASSERT(
"bundle already initialized", m_bundle == 0 );
137 SLM_ASSERT(
"bundle not correctly attached", m_bundle == bundle );
142 void Native::operator=(
const Native&) noexcept
virtual ~Native() noexcept
Destructor : does nothing.
Defines the runtime exception class.
Native(const boost::filesystem::path &modulePath) noexcept
Constructor.
const boost::filesystem::path getFullPath(const bool _bMustBeFile=false) const
Retrieves the file path of the library including the owning bundle's path.
Defines the abstract class for native module implementors.
FWRUNTIME_API const Version & getVersion() const
Retrieves the version of the bundle.
The namespace fwRuntime contains classes to manage bundle, configuration element, extension point in ...
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
const boost::filesystem::path getPath() const
Retrieves the file path of the native library.
const ::boost::regex getNativeName() const
Retrieves the pattern of the dynamic library file name given the host OS.
Defines the bundle class.
FWRUNTIME_API const std::string string() const
String converter.
FWRUNTIME_APIconst::boost::filesystem::path & getLibraryLocation() const
Retrieves the bundle location.
void setBundle(const ::fwRuntime::Bundle *bundle) noexcept
Set the bundle the library is attached to.