30 #include <boost/regex.hpp>
32 #include "../common/WIOTools.h"
33 #include "../common/WPathHelper.h"
34 #include "../common/WSharedLib.h"
35 #include "WModuleLoader.h"
49 boost::filesystem::path dir,
unsigned int level )
51 for( boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator( dir );
52 i != boost::filesystem::directory_iterator(); ++i )
55 std::string stem = i->path().stem().string();
58 std::string relPath = i->path().string();
59 relPath.erase( 0, dir.string().length() + 1 );
71 boost::smatch matches;
72 std::string fn = i->path().filename().string();
73 bool matchLibName = boost::regex_match( fn, matches, CheckLibMMP );
74 std::string libBaseName = matchLibName ? std::string( matches[2] ) :
"";
76 if( !boost::filesystem::is_directory( *i ) &&
84 std::shared_ptr< WSharedLib > l(
new WSharedLib( i->path() ) );
86 bool isLoadableModule =
false;
87 bool isLoadableArbitrary =
false;
90 if( l->existsFunction( W_LOADABLE_MODULE_SYMBOL ) )
93 W_LOADABLE_MODULE_SIGNATURE f;
94 l->fetchFunction< W_LOADABLE_MODULE_SIGNATURE >( W_LOADABLE_MODULE_SYMBOL, f );
96 isLoadableModule =
true;
110 for( WModuleList::const_iterator iter = m.begin(); iter != m.end(); ++iter )
113 ( *iter )->setLibPath( i->path() );
115 ( *iter )->setPackageName( libBaseName );
120 ticket->get().insert( *iter );
126 wlog::debug(
"Module Loader" ) <<
"Loaded " << m.size() <<
" modules from " << relPath;
132 if( l->existsFunction( W_LOADABLE_REGISTERARBITRARY_SYMBOL ) )
134 isLoadableArbitrary =
true;
144 if( !isLoadableModule && !isLoadableArbitrary )
146 wlog::warn(
"Module Loader" ) <<
"Library does neither contain a module nor another extension.";
152 "Module Loader", LL_ERROR );
155 else if( ( level <= 10 ) &&
156 boost::filesystem::is_directory( *i ) )
159 load( ticket, *i, level + 1 );
169 for( std::vector< boost::filesystem::path >::const_iterator path = allPaths.begin(); path != allPaths.end(); ++path )
174 if( !boost::filesystem::is_directory( *path ) || !boost::filesystem::exists( *path ) )
177 "\" failed. It is not a directory or does not exist." +
178 " Ignoring.",
"Module Loader", LL_WARNING );
184 load( ticket, *path );
190 typedef std::vector< PostponedLoad > Vec;
193 wlog::debug(
"WModuleLoader" ) <<
"Initializing extensions of \"" << ( *iter ).m_lib->getLibraryName() <<
"\"";
194 W_LOADABLE_REGISTERARBITRARY_SIGNATURE arbitraryRegister;
195 ( *iter ).m_lib->fetchFunction< W_LOADABLE_REGISTERARBITRARY_SIGNATURE >( W_LOADABLE_REGISTERARBITRARY_SYMBOL, arbitraryRegister );
196 arbitraryRegister( ( *iter ).m_path );
virtual const char * what() const
Returns the message string set on throw.
void addLogMessage(std::string message, std::string source="", LogLevel level=LL_DEBUG)
Appends a log message to the logging queue.
static WLogger * getLogger()
Returns pointer to the currently running logger instance.
void initializeExtensions()
The loader also stores information on which library provides the arbitrary registration mechanism.
std::vector< std::shared_ptr< WSharedLib > > m_libs
All the loaded shared libraries.
WModuleLoader()
Constructor.
static std::string getModulePrefix()
Returns the prefix of a shared module library filename.
~WModuleLoader()
Destructor, closes all handles to shared libraries.
std::vector< PostponedLoad > m_arbitraryRegisterLibs
The libs which need to be initialized when OW is loaded completely.
void load(WSharedAssociativeContainer< std::set< std::shared_ptr< WModule > > >::WriteTicket ticket)
Load the module prototypes from the shared libraries.
static boost::filesystem::path getModuleResourcePath(boost::filesystem::path moduleLibPath, std::string packageName)
The path to a given module's resources.
static std::vector< boost::filesystem::path > getAllModulePaths()
This returns a list of search paths for modules.
This class provides a common interface for thread-safe access to associative containers (set,...
This class loads shared libraries and provides function pointers.
static std::string getSystemSuffix()
Returns the suffix for libraries used on the system.
static std::string getSystemPrefix()
Returns the prefix used for libraries on the system.
WStreamedLogger debug(const std::string &source)
Logging a debug message.
WStreamedLogger warn(const std::string &source)
Logging a warning message.
Helper to store information on a lib which gets initialized later.