OpenWalnut  1.3.1
WModuleLoader.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WMODULELOADER_H
26 #define WMODULELOADER_H
27 
28 #include <set>
29 #include <string>
30 #include <vector>
31 
32 #include <boost/filesystem.hpp>
33 #include <boost/shared_ptr.hpp>
34 
35 #include "../common/WLogger.h"
36 #include "../common/WSharedAssociativeContainer.h"
37 #include "../common/WSharedLib.h"
38 
39 #include "WModule.h"
40 
41 /**
42  * Loads module prototypes from shared objects in a given directory and injects it into the module factory.
43  */
45 {
46 public:
47  /**
48  * Constructor. It does not load any files. Use load to do this.
49  *
50  */
51  explicit WModuleLoader();
52 
53  /**
54  * Destructor, closes all handles to shared libraries.
55  */
57 
58  /**
59  * Load the module prototypes from the shared libraries.
60  *
61  * \param ticket A write ticket to a shared container.
62  */
63  void load( WSharedAssociativeContainer< std::set< boost::shared_ptr< WModule > > >::WriteTicket ticket );
64 
65  /**
66  * Returns the prefix of a shared module library filename.
67  *
68  * \return the prefix.
69  */
70  static std::string getModulePrefix();
71 
72 private:
73  /**
74  * All the loaded shared libraries. Get freed on destruction. So do NOT free this instance while the libs are used.
75  */
76  std::vector< boost::shared_ptr< WSharedLib > > m_libs;
77 
78  /**
79  * Load the module prototypes from the shared libraries from the specified directory. It traverses the subdirectories and searches there.
80  * Traversion depth is 1.
81  *
82  * \param ticket A write ticket to a shared container.
83  * \param dir the directory to load
84  * \param level the traversion level
85  */
86  void load( WSharedAssociativeContainer< std::set< boost::shared_ptr< WModule > > >::WriteTicket ticket, boost::filesystem::path dir,
87  unsigned int level = 0 );
88 };
89 
90 #endif // WMODULELOADER_H