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