OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
WKernel.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 WKERNEL_H
26 #define WKERNEL_H
27 
28 #include <string>
29 #include <vector>
30 
31 #include <boost/shared_ptr.hpp>
32 
33 #include "../common/WLogger.h"
34 #include "../graphicsEngine/WGraphicsEngine.h"
35 #include "WExportKernel.h"
36 #include "WModule.h"
37 
38 // forward declarations
39 class WGUI;
40 class WModuleContainer;
41 class WModuleFactory;
42 class WROIManager;
43 class WSelectionManager;
44 class WThreadedRunner;
45 
46 /**
47  * \defgroup kernel Kernel
48  *
49  * \brief
50  * This library implements the central part of OpenWalnut that manages
51  * the interaction between GUI, GraphicsEngine and DataHandler.
52  */
53 
54 /**
55  * OpenWalnut kernel, managing modules and interaction between
56  * GUI, GE and DataHandler
57  * \ingroup kernel
58  */
59 class OWKERNEL_EXPORT WKernel: public WThreadedRunner
60 {
61 public:
62 
63  /**
64  * Returns pointer to the running kernel or a new if no kernel was there.
65  * If a running kernel exists the function return it and does not check if
66  * ge and gui of the running kernel are equivalent to the ones given as parameters.
67  *
68  * \param ge initialized graphics engine.
69  * \param gui initialized gui.
70  * \return the kernel instance.
71  */
72  static WKernel* instance( boost::shared_ptr< WGraphicsEngine > ge, boost::shared_ptr< WGUI > gui );
73 
74  /**
75  * Destructor.
76  */
77  virtual ~WKernel();
78 
79  /**
80  * Stops execution of the modules in the root container. Note that this does not wait for the kernel thread since this could
81  * cause a dead lock. This is actually an alias for getRootContainer()->stop().
82  */
83  void finalize();
84 
85  /**
86  * Returns pointer to currently running instance of graphics engine.
87  *
88  * \return the graphics engine instance.
89  */
90  boost::shared_ptr< WGraphicsEngine > getGraphicsEngine() const;
91 
92  /**
93  * Returns pointer to the currently running kernel.
94  *
95  * \return the kernel instance.
96  */
97  static WKernel* getRunningKernel();
98 
99  /**
100  * Determines whether all threads should finish.
101  *
102  * \return true if so.
103  */
104  const WBoolFlag& isFinishRequested() const;
105 
106  /**
107  * Load specified datasets. It immediately returns and starts another thread, which actually loads the data.
108  *
109  * \param fileNames list of filenames to load. The registered notification handler for the root container will get notified on
110  * error and success.
111  */
112  void loadDataSets( std::vector< std::string > fileNames );
113 
114  /**
115  * Loads the specified files synchronously.
116  *
117  * \param fileNames list of filenames to load. The registered notification handler for the root container will get notified on
118  * error and success.
119  */
120  void loadDataSetsSynchronously( std::vector< std::string > fileNames );
121 
122  /**
123  * Function combines to modules. This is a simple alias for "getRootContainer()->applyModule". It runs synchronously, which
124  * could freeze the calling thread for a couple of time.
125  *
126  * \param applyOn the module which already has to be in the container and to apply the other one on.
127  * \param prototype the prototype of the module to apply on the other one specified.
128  *
129  * \return the newly created module connected with the one specified in applyOn.
130  */
131  boost::shared_ptr< WModule > applyModule( boost::shared_ptr< WModule > applyOn, boost::shared_ptr< WModule > prototype );
132 
133  /**
134  * Returns the root module container. This is the actual module graph container.
135  *
136  * \return the root container.
137  */
138  boost::shared_ptr< WModuleContainer > getRootContainer() const;
139 
140  /**
141  * Getter for the associated GUI.
142  *
143  * \return the GUI.
144  */
145  boost::shared_ptr< WGUI > getGui() const;
146 
147  /**
148  * get for roi manager
149  *
150  * \return Pointer to the ROI manager.
151  */
152  boost::shared_ptr< WROIManager> getRoiManager();
153 
154  /**
155  * get for selection manager
156  *
157  * \return Pointer to the selection manager.
158  */
159  boost::shared_ptr< WSelectionManager> getSelectionManager();
160 
161 protected:
162  /**
163  * Constructor is protected because this class is a singleton. Awaits an INITIALIZED graphics engine an gui.
164  *
165  * \param ge initialized graphics engine.
166  * \param gui initialized gui.
167  */
168  WKernel( boost::shared_ptr< WGraphicsEngine > ge, boost::shared_ptr< WGUI > gui );
169 
170  /**
171  * Function that has to be overwritten for execution. It gets executed in a separate thread after run()
172  * has been called.
173  */
174  virtual void threadMain();
175 
176  /**
177  * The Gui.
178  */
179  boost::shared_ptr< WGUI > m_gui;
180 
181  /**
182  * Pointer to an initialized graphics engine.
183  */
184  boost::shared_ptr< WGraphicsEngine > m_graphicsEngine;
185 
186  /**
187  * Pointer to a roi manager
188  */
189  boost::shared_ptr< WROIManager >m_roiManager;
190 
191  /**
192  * pointer to a selection manager
193  */
194  boost::shared_ptr< WSelectionManager >m_selectionManager;
195 
196  /**
197  * The module factory to use.
198  */
199  boost::shared_ptr< WModuleFactory > m_moduleFactory;
200 
201  /**
202  * The container containing the modules.
203  */
204  boost::shared_ptr< WModuleContainer > m_moduleContainer;
205 
206 private:
207  /**
208  * Loads all the modules it can find.
209  */
210  void loadModules();
211 
212  /**
213  * Initializes the graphics engine, data handler and so on.
214  */
215  void init();
216 
217  /**
218  * Pointer to the unique instance of this singleton class.
219  */
220  static WKernel* m_kernel;
221 };
222 
223 #endif // WKERNEL_H
224