OpenWalnut 1.3.1
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WMODULELOADER_H 00026 #define WMODULELOADER_H 00027 00028 #include <set> 00029 #include <string> 00030 #include <vector> 00031 00032 #include <boost/filesystem.hpp> 00033 #include <boost/shared_ptr.hpp> 00034 00035 #include "../common/WLogger.h" 00036 #include "../common/WSharedAssociativeContainer.h" 00037 #include "../common/WSharedLib.h" 00038 00039 #include "WModule.h" 00040 00041 /** 00042 * Loads module prototypes from shared objects in a given directory and injects it into the module factory. 00043 */ 00044 class WModuleLoader 00045 { 00046 public: 00047 /** 00048 * Constructor. It does not load any files. Use load to do this. 00049 * 00050 */ 00051 explicit WModuleLoader(); 00052 00053 /** 00054 * Destructor, closes all handles to shared libraries. 00055 */ 00056 ~WModuleLoader(); 00057 00058 /** 00059 * Load the module prototypes from the shared libraries. 00060 * 00061 * \param ticket A write ticket to a shared container. 00062 */ 00063 void load( WSharedAssociativeContainer< std::set< boost::shared_ptr< WModule > > >::WriteTicket ticket ); 00064 00065 /** 00066 * Returns the prefix of a shared module library filename. 00067 * 00068 * \return the prefix. 00069 */ 00070 static std::string getModulePrefix(); 00071 00072 private: 00073 /** 00074 * All the loaded shared libraries. Get freed on destruction. So do NOT free this instance while the libs are used. 00075 */ 00076 std::vector< boost::shared_ptr< WSharedLib > > m_libs; 00077 00078 /** 00079 * Load the module prototypes from the shared libraries from the specified directory. It traverses the subdirectories and searches there. 00080 * Traversion depth is 1. 00081 * 00082 * \param ticket A write ticket to a shared container. 00083 * \param dir the directory to load 00084 * \param level the traversion level 00085 */ 00086 void load( WSharedAssociativeContainer< std::set< boost::shared_ptr< WModule > > >::WriteTicket ticket, boost::filesystem::path dir, 00087 unsigned int level = 0 ); 00088 }; 00089 00090 #endif // WMODULELOADER_H