OpenWalnut  1.4.0
WModuleCombiner.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 WMODULECOMBINER_H
00026 #define WMODULECOMBINER_H
00027 
00028 #include <boost/shared_ptr.hpp>
00029 
00030 #include "../common/WThreadedRunner.h"
00031 
00032 #include "WModuleContainer.h"
00033 
00034 
00035 /**
00036  * This is a base class for all module combination classes. The basic idea is to hide the actual combination work from others. These classes may
00037  * be useful in the GUI. The GUI can create a module combiner instance in a special way, with an interface the GUI wants to have. Then, the
00038  * kernel can construct the actual module graph out of it. Another purpose is some kind of project file loading. One can write a combiner which
00039  * loads projects files and creates a module graph out of it. The only think which all the combiners need to know: the target container. Derive
00040  * all specific combiner classes from this one.
00041  */
00042 class  WModuleCombiner: public WThreadedRunner,
00043                                          public boost::enable_shared_from_this< WModuleCombiner >
00044 {
00045 public:
00046     /**
00047      * Creates an empty combiner.
00048      *
00049      * \param target the target container where to add the modules to.
00050      */
00051     explicit WModuleCombiner( boost::shared_ptr< WModuleContainer > target );
00052 
00053     /**
00054      * Creates an empty combiner. This constructor automatically uses the kernel's root container as target container.
00055      */
00056     WModuleCombiner();
00057 
00058     /**
00059      * Destructor.
00060      */
00061     virtual ~WModuleCombiner();
00062 
00063     /**
00064      * Apply the internal module structure to the target container. Be aware, that this operation might take some time, as modules can be
00065      * connected only if they are "ready", which, at least with WMData modules, might take some time.
00066      *
00067      * \note: to have asynchronous loading, use run().
00068      */
00069     virtual void apply() = 0;
00070 
00071     /**
00072      * Run thread and call apply(). This is useful to apply a combiner asynchronously.
00073      */
00074     virtual void run();
00075 
00076 protected:
00077     /**
00078      * Function that has to be overwritten for execution. It gets executed in a separate thread after run()
00079      * has been called. It actually calls apply() in another thread.
00080      */
00081     virtual void threadMain();
00082 
00083     /**
00084      * The module container to use for the modules.
00085      */
00086     boost::shared_ptr< WModuleContainer > m_container;
00087 
00088 private:
00089 };
00090 
00091 #endif  // WMODULECOMBINER_H
00092