OpenWalnut 1.2.5
WKernel.h
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 WKERNEL_H
00026 #define WKERNEL_H
00027 
00028 #include <string>
00029 #include <vector>
00030 
00031 #include <boost/shared_ptr.hpp>
00032 
00033 #include "../common/WLogger.h"
00034 #include "../graphicsEngine/WGraphicsEngine.h"
00035 #include "WExportKernel.h"
00036 #include "WModule.h"
00037 
00038 // forward declarations
00039 class WGUI;
00040 class WModuleContainer;
00041 class WModuleFactory;
00042 class WROIManager;
00043 class WSelectionManager;
00044 class WThreadedRunner;
00045 
00046 /**
00047  * \defgroup kernel Kernel
00048  *
00049  * \brief
00050  * This library implements the central part of OpenWalnut that manages
00051  * the interaction between GUI, GraphicsEngine and DataHandler.
00052  */
00053 
00054 /**
00055  * OpenWalnut kernel, managing modules and interaction between
00056  * GUI, GE and DataHandler
00057  * \ingroup kernel
00058  */
00059 class OWKERNEL_EXPORT WKernel: public WThreadedRunner
00060 {
00061 public:
00062 
00063     /**
00064      * Returns pointer to the running kernel or a new if no kernel was there.
00065      * If a running kernel exists the function return it and does not check if
00066      * ge and gui of the running kernel are equivalent to the ones given as parameters.
00067      *
00068      * \param ge initialized graphics engine.
00069      * \param gui initialized gui.
00070      * \return the kernel instance.
00071      */
00072     static WKernel* instance( boost::shared_ptr< WGraphicsEngine > ge, boost::shared_ptr< WGUI > gui );
00073 
00074     /**
00075      * Destructor.
00076      */
00077     virtual ~WKernel();
00078 
00079     /**
00080      * Stops execution of the modules in the root container. Note that this does not wait for the kernel thread since this could
00081      * cause a dead lock. This is actually an alias for getRootContainer()->stop().
00082      */
00083     void finalize();
00084 
00085     /**
00086      * Returns pointer to currently running instance of graphics engine.
00087      *
00088      * \return the graphics engine instance.
00089      */
00090     boost::shared_ptr< WGraphicsEngine > getGraphicsEngine() const;
00091 
00092     /**
00093      * Returns pointer to the currently running kernel.
00094      *
00095      * \return the kernel instance.
00096      */
00097     static WKernel* getRunningKernel();
00098 
00099     /**
00100      * Determines whether all threads should finish.
00101      *
00102      * \return true if so.
00103      */
00104     const WBoolFlag& isFinishRequested() const;
00105 
00106     /**
00107      * Load specified datasets. It immediately returns and starts another thread, which actually loads the data.
00108      *
00109      * \param fileNames list of filenames to load. The registered notification handler for the root container will get notified on
00110      * error and success.
00111      */
00112     void loadDataSets( std::vector< std::string > fileNames );
00113 
00114     /**
00115      * Loads the specified files synchronously.
00116      *
00117      * \param fileNames list of filenames to load. The registered notification handler for the root container will get notified on
00118      * error and success.
00119      */
00120     void loadDataSetsSynchronously( std::vector< std::string > fileNames );
00121 
00122     /**
00123      * Function combines to modules. This is a simple alias for "getRootContainer()->applyModule". It runs synchronously, which
00124      * could freeze the calling thread for a couple of time.
00125      *
00126      * \param applyOn the module which already has to be in the container and to apply the other one on.
00127      * \param prototype the prototype of the module to apply on the other one specified.
00128      *
00129      * \return the newly created module connected with the one specified in applyOn.
00130      */
00131     boost::shared_ptr< WModule > applyModule( boost::shared_ptr< WModule > applyOn, boost::shared_ptr< WModule > prototype );
00132 
00133     /**
00134      * Returns the root module container. This is the actual module graph container.
00135      *
00136      * \return the root container.
00137      */
00138     boost::shared_ptr< WModuleContainer > getRootContainer() const;
00139 
00140     /**
00141      * Getter for the associated GUI.
00142      *
00143      * \return the GUI.
00144      */
00145     boost::shared_ptr< WGUI > getGui() const;
00146 
00147     /**
00148      * get for roi manager
00149      *
00150      * \return Pointer to the ROI manager.
00151      */
00152     boost::shared_ptr< WROIManager> getRoiManager();
00153 
00154     /**
00155      * get for selection manager
00156      *
00157      * \return Pointer to the selection manager.
00158      */
00159     boost::shared_ptr< WSelectionManager> getSelectionManager();
00160 
00161 protected:
00162     /**
00163      * Constructor is protected because this class is a singleton. Awaits an INITIALIZED graphics engine an gui.
00164      *
00165      * \param ge initialized graphics engine.
00166      * \param gui initialized gui.
00167      */
00168     WKernel( boost::shared_ptr< WGraphicsEngine > ge, boost::shared_ptr< WGUI > gui );
00169 
00170     /**
00171      * Function that has to be overwritten for execution. It gets executed in a separate thread after run()
00172      * has been called.
00173      */
00174     virtual void threadMain();
00175 
00176     /**
00177      * The Gui.
00178      */
00179     boost::shared_ptr< WGUI > m_gui;
00180 
00181     /**
00182      * Pointer to an initialized graphics engine.
00183      */
00184     boost::shared_ptr< WGraphicsEngine > m_graphicsEngine;
00185 
00186     /**
00187      * Pointer to a roi manager
00188      */
00189     boost::shared_ptr< WROIManager >m_roiManager;
00190 
00191     /**
00192      * pointer to a selection manager
00193      */
00194     boost::shared_ptr< WSelectionManager >m_selectionManager;
00195 
00196     /**
00197      * The module factory to use.
00198      */
00199     boost::shared_ptr< WModuleFactory > m_moduleFactory;
00200 
00201     /**
00202      * The container containing the modules.
00203      */
00204     boost::shared_ptr< WModuleContainer > m_moduleContainer;
00205 
00206 private:
00207     /**
00208      * Loads all the modules it can find.
00209      */
00210     void loadModules();
00211 
00212     /**
00213      * Initializes the graphics engine, data handler and so on.
00214      */
00215     void init();
00216 
00217     /**
00218      * Pointer to the unique instance of this singleton class.
00219      */
00220     static WKernel* m_kernel;
00221 };
00222 
00223 #endif  // WKERNEL_H
00224 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends