29 #include <boost/regex.hpp>
31 #include "../common/WIOTools.h"
32 #include "../common/WPathHelper.h"
33 #include "../common/WSharedLib.h"
37 #include "WModuleLoader.h"
51 boost::filesystem::path dir,
unsigned int level )
53 for( boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator( dir );
54 i != boost::filesystem::directory_iterator(); ++i )
57 std::string suffix = getSuffix( i->leaf() );
58 std::string stem = i->path().stem();
61 std::string supposedFilename =
getModulePrefix() +
'_' + i->path().parent_path().filename()
66 std::string isFileName = i->path().filename();
70 std::string relPath = i->path().file_string();
71 relPath.erase( 0, dir.file_string().length() + 1 );
82 boost::smatch matches;
84 if( !boost::filesystem::is_directory( *i ) &&
85 ( boost::regex_match( i->path().string(), matches, CheckLibMMP ) ) &&
88 && supposedFilename == isFileName
95 boost::shared_ptr< WSharedLib > l = boost::shared_ptr< WSharedLib >(
new WSharedLib( i->path() ) );
98 W_LOADABLE_MODULE_SIGNATURE f;
99 l->fetchFunction< W_LOADABLE_MODULE_SIGNATURE >( W_LOADABLE_MODULE_SYMBOL, f );
109 "prototype instance.",
"Module Loader", LL_ERROR );
115 for( WModuleList::const_iterator iter = m.begin(); iter != m.end(); ++iter )
117 ( *iter )->setLocalPath( i->path().parent_path() );
118 ticket->get().insert( *iter );
122 wlog::debug(
"Module Loader" ) <<
"Loaded " << m.size() <<
" modules from " << relPath;
130 "Module Loader", LL_ERROR );
133 else if( ( level == 0 ) && boost::filesystem::is_directory( *i ) )
136 load( ticket, *i, level + 1 );
146 for( std::vector< boost::filesystem::path >::const_iterator path = allPaths.begin(); path != allPaths.end(); ++path )
151 if( !boost::filesystem::is_directory( *path ) || !boost::filesystem::exists( *path ) )
154 "\" failed. It is not a directory or does not exist." +
155 " Ignoring.",
"Module Loader", LL_WARNING );
161 load( ticket, *path );