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 stem = i->path().stem().string();
60 std::string relPath = i->path().string();
61 relPath.erase( 0, dir.string().length() + 1 );
73 boost::smatch matches;
74 bool matchLibName = boost::regex_match( i->path().filename().string(), matches, CheckLibMMP );
75 std::string libBaseName = matchLibName ? std::string( matches[2] ) :
"";
77 if( !boost::filesystem::is_directory( *i ) &&
85 boost::shared_ptr< WSharedLib > l = boost::shared_ptr< WSharedLib >(
new WSharedLib( i->path() ) );
88 W_LOADABLE_MODULE_SIGNATURE f;
89 l->fetchFunction< W_LOADABLE_MODULE_SIGNATURE >( W_LOADABLE_MODULE_SYMBOL, f );
99 "prototype instance.",
"Module Loader", LL_ERROR );
105 for( WModuleList::const_iterator iter = m.begin(); iter != m.end(); ++iter )
108 ( *iter )->setLibPath( i->path() );
110 ( *iter )->setPackageName( libBaseName );
115 ticket->get().insert( *iter );
121 wlog::debug(
"Module Loader" ) <<
"Loaded " << m.size() <<
" modules from " << relPath;
129 "Module Loader", LL_ERROR );
132 else if( ( level <= 10 ) &&
133 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 );