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