OpenWalnut  1.4.0
WModuleCombiner.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 WMODULECOMBINER_H
26 #define WMODULECOMBINER_H
27 
28 #ifndef Q_MOC_RUN
29 #include <boost/shared_ptr.hpp>
30 #endif
31 
32 #include "../common/WThreadedRunner.h"
33 
34 #include "WModuleContainer.h"
35 
36 
37 /**
38  * 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
39  * 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
40  * 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
41  * 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
42  * all specific combiner classes from this one.
43  */
45  public boost::enable_shared_from_this< WModuleCombiner >
46 {
47 public:
48  /**
49  * Creates an empty combiner.
50  *
51  * \param target the target container where to add the modules to.
52  */
53  explicit WModuleCombiner( boost::shared_ptr< WModuleContainer > target );
54 
55  /**
56  * Creates an empty combiner. This constructor automatically uses the kernel's root container as target container.
57  */
59 
60  /**
61  * Destructor.
62  */
63  virtual ~WModuleCombiner();
64 
65  /**
66  * Apply the internal module structure to the target container. Be aware, that this operation might take some time, as modules can be
67  * connected only if they are "ready", which, at least with WMData modules, might take some time.
68  *
69  * \note: to have asynchronous loading, use run().
70  */
71  virtual void apply() = 0;
72 
73  /**
74  * Run thread and call apply(). This is useful to apply a combiner asynchronously.
75  */
76  virtual void run();
77 
78 protected:
79  /**
80  * Function that has to be overwritten for execution. It gets executed in a separate thread after run()
81  * has been called. It actually calls apply() in another thread.
82  */
83  virtual void threadMain();
84 
85  /**
86  * The module container to use for the modules.
87  */
88  boost::shared_ptr< WModuleContainer > m_container;
89 
90 private:
91 };
92 
93 #endif // WMODULECOMBINER_H
94 
Base class for all classes needing to be executed in a separate thread.
This is a base class for all module combination classes.
virtual void threadMain()
Function that has to be overwritten for execution.
boost::shared_ptr< WModuleContainer > m_container
The module container to use for the modules.
WModuleCombiner()
Creates an empty combiner.
virtual void apply()=0
Apply the internal module structure to the target container.
virtual ~WModuleCombiner()
Destructor.
virtual void run()
Run thread and call apply().